本文整理汇总了C#中Reader类的典型用法代码示例。如果您正苦于以下问题:C# Reader类的具体用法?C# Reader怎么用?C# Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reader类属于命名空间,在下文中一共展示了Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestVector
public void TestVector()
{
Reader rdr = new Reader();
NLVector vec = (NLVector)rdr.ReadFirstForm("[]");
Assert.IsNotNull(vec);
Assert.AreEqual(0, vec.Contents.Length);
vec = (NLVector) rdr.ReadFirstForm("[1]");
Assert.IsNotNull(vec);
Assert.AreEqual(1, vec.Contents.Length);
long ival = (long)vec.Contents[0];
Assert.AreEqual(1, ival);
vec = (NLVector)rdr.ReadFirstForm("[ 1, 2]");
Assert.IsNotNull(vec);
Assert.AreEqual(2, vec.Contents.Length);
ival = (long)vec.Contents[0];
Assert.AreEqual(1, ival);
ival = (long)vec.Contents[1];
Assert.AreEqual(2, ival);
vec = (NLVector)rdr.ReadFirstForm(" [ [, 42 ] \"a\" ]");
Assert.IsNotNull(vec);
Assert.AreEqual(2, vec.Contents.Length);
NLVector vval = (NLVector)vec.Contents[0];
Assert.AreEqual(42, (long)vval.Contents[0]);
string sval = (string)vec.Contents[1];
Assert.AreEqual("a", sval);
}
示例2: TestReadsLines
public void TestReadsLines()
{
Reader reader = new Reader(new StringReader("Line 0\n Line 1\nLine 2 \n\n\n Line 3 \n Line 4 "));
int lineNumber = 0;
foreach (Line line in reader)
Assert.AreEqual($"Line {lineNumber++}", line.Content);
}
示例3: OnNavigatedTo
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator)
{
MessageBox.Show("You must deploy this sample to a device, instead of the emulator so that you can get a video stream including a barcode/QR code");
this.IsEnabled = false;
base.NavigationService.GoBack();
}
else
{
string type = "";
if (NavigationContext.QueryString.TryGetValue("type", out type) && type == "qrcode")
{
_reader = new QRCodeReader();
}
else
{
_reader = new EAN13Reader();
}
_photoCamera = new PhotoCamera();
_photoCamera.Initialized += new EventHandler<CameraOperationCompletedEventArgs>(cam_Initialized);
_videoBrush.SetSource(_photoCamera);
BarCodeRectInitial();
base.OnNavigatedTo(e);
}
}
示例4: assertHTMLStripsTo
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void assertHTMLStripsTo(java.io.Reader input, String gold, java.util.Set<String> escapedTags) throws Exception
public static void assertHTMLStripsTo(Reader input, string gold, ISet<string> escapedTags)
{
HTMLStripCharFilter reader;
if (null == escapedTags)
{
reader = new HTMLStripCharFilter(input);
}
else
{
reader = new HTMLStripCharFilter(input, escapedTags);
}
int ch = 0;
StringBuilder builder = new StringBuilder();
try
{
while ((ch = reader.read()) != -1)
{
builder.Append((char)ch);
}
}
catch (Exception e)
{
if (gold.Equals(builder.ToString()))
{
throw e;
}
throw new Exception("('" + builder.ToString() + "' is not equal to '" + gold + "'). " + e.Message, e);
}
assertEquals("'" + builder.ToString() + "' is not equal to '" + gold + "'", gold, builder.ToString());
}
示例5: TestBrokenSearchTreePointer
public void TestBrokenSearchTreePointer()
{
using (var reader = new Reader(Path.Combine(TestDataRoot, "MaxMind-DB-test-broken-pointers-24.mmdb")))
{
reader.Find("1.1.1.32");
}
}
示例6: Parse
public override void Parse(byte[] buffer)
{
Reader reader = new Reader(new MemoryStream(buffer));
reader.ReadByte(); // Id
MessageId = reader.ReadInt32();
int count = reader.ReadInt32();
Arguments = new KeyValuePair<type, object>[count];
for (int i = 0; i < count; i++)
{
var key = (type)reader.ReadInt32();
object value = null;
switch (key)
{
case type.Text:
value = reader.ReadString(Encoding.Unicode);
break;
case type.Number:
value = reader.ReadInt32();
break;
case type.NpcName:
value = reader.ReadInt32();
break;
case type.ItemName:
value = reader.ReadInt32();
break;
case type.SkillName:
value = reader.ReadInt32();
reader.ReadInt32(); //there are 4 more bytes after this... the skill level by chance?
break;
}
Arguments[i] = new KeyValuePair<type, object>(key, value);
}
}
示例7: CreateSeparateServices
static OrderController CreateSeparateServices()
{
var reader = new Reader<Order>();
var saver = new Saver<Order>();
var deleter = new Deleter<Order>();
return new OrderController(reader, saver, deleter);
}
示例8: TestParallelFor
public void TestParallelFor(FileAccessMode mode)
{
var count = 0;
var ipsAndResults = new Dictionary<IPAddress, string>();
var rand = new Random();
using (var reader = new Reader(Path.Combine("..", "..", "TestData", "GeoLite2-City.mmdb"), mode))
{
while (count < 10000)
{
var ip = new IPAddress(rand.Next(int.MaxValue));
var resp = reader.Find(ip);
if (resp != null && !ipsAndResults.ContainsKey(ip))
{
ipsAndResults.Add(ip, resp.ToString());
count++;
}
}
var ips = ipsAndResults.Keys.ToArray();
Parallel.For(0, ips.Length, i =>
{
var ipAddress = ips[i];
var result = reader.Find(ipAddress);
var resultString = result.ToString();
var expectedString = ipsAndResults[ipAddress];
if (resultString != expectedString)
throw new Exception($"Non-matching result. Expected {expectedString}, found {resultString}");
});
}
}
示例9: read_atom
public static MalVal read_atom(Reader rdr)
{
string token = rdr.next();
string pattern = @"(^-?[0-9]+$)|(^-?[0-9][0-9.]*$)|(^nil$)|(^true$)|(^false$)|^("".*"")$|:(.*)|(^[^""]*$)";
Regex regex = new Regex(pattern);
Match match = regex.Match(token);
//Console.WriteLine("token: ^" + token + "$");
if (!match.Success) {
throw new ParseError("unrecognized token '" + token + "'");
}
if (match.Groups[1].Value != String.Empty) {
return new Mal.types.MalInt(int.Parse(match.Groups[1].Value));
} else if (match.Groups[3].Value != String.Empty) {
return Mal.types.Nil;
} else if (match.Groups[4].Value != String.Empty) {
return Mal.types.True;
} else if (match.Groups[5].Value != String.Empty) {
return Mal.types.False;
} else if (match.Groups[6].Value != String.Empty) {
string str = match.Groups[6].Value;
str = str.Substring(1, str.Length-2)
.Replace("\\\"", "\"")
.Replace("\\n", "\n");
return new Mal.types.MalString(str);
} else if (match.Groups[7].Value != String.Empty) {
return new Mal.types.MalString("\u029e" + match.Groups[7].Value);
} else if (match.Groups[8].Value != String.Empty) {
return new Mal.types.MalSymbol(match.Groups[8].Value);
} else {
throw new ParseError("unrecognized '" + match.Groups[0] + "'");
}
}
示例10: Read2
public static SimplyInt Read2(Reader reader)
{
SimplyInt result = new SimplyInt();
result.Field1 = -reader.Read<int>();
result.Field2 = reader.Read<uint>();
return result;
}
示例11: cmdImport_Click
protected void cmdImport_Click(object sender, EventArgs e)
{
var connection = new SQLServerConnect();
//for live db
//connection.SetupConnectionString("Server=MyPetsFW.db.3554730.hostedresource.com;USER ID=MyPetsFW;Password=DevryWeb460;Database=MyPetsFW;Trusted_Connection=False;");
//for my local db
//connection.SetupConnectionString("JON/Chris", "", @"Jon\SQLEXPRESS", "MyPetsFW");
connection.SetupConnectionString("TestUser", "testuser", @"Jon\SQLEXPRESS", "MyPetsFW");
var reader = new Reader
{
VendorID = 1,
LogFile = @"C:\WEB460\DataImport\Output\Import09.log",
DebugLevel = 3
};
const string fileName = @"C:\WEB460\DataImport\20090310-Products.txt";
//string output = !reader.DoImport(fileName, connection) ?
// "There was an problem with the import." :
// "Import Successful.";
//Console.WriteLine(output);
lblError.Text = !reader.DoImport(fileName, connection) ? "There was an problem with the import" : "Import Successful";
}
示例12: ReceiveEventArgs
public ReceiveEventArgs(Socket socket, ArrayList sockets)
{
this.socket = socket;
this.clients = sockets;
this.reader = new Reader(this.socket);
this.writer = new Writer(this.socket);
}
示例13: Parse
public override void Parse(byte[] buffer)
{
Reader reader = new Reader(new MemoryStream(buffer));
reader.ReadByte(); // Id
int Count = reader.ReadByte();
reader.ReadByte(); // ?
List = new List<Model.GameServer>(Count);
for (int i = 0; i < Count; i++)
List.Add(new Model.GameServer()
{
Id = reader.ReadByte(),
Address = string.Format("{0}.{1}.{2}.{3}", // ToDo: replace to native
reader.ReadByte().ToString(),
reader.ReadByte().ToString(),
reader.ReadByte().ToString(),
reader.ReadByte().ToString()),
Port = reader.ReadInt32(),
Age = reader.ReadByte(),
PvP = reader.ReadByte() != 0,
Online = reader.ReadInt16(),
Maximum = reader.ReadInt16(),
State = reader.ReadByte() != 0,
Poop = string.Format("{0}-{1}-{2}-{3}-{4}", // ToDo: What is?
reader.ReadByte().ToString("X2"),
reader.ReadByte().ToString("X2"),
reader.ReadByte().ToString("X2"),
reader.ReadByte().ToString("X2"),
reader.ReadByte().ToString("X2"))
});
}
示例14: GeoIP
static GeoIP()
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ProxySearch.Engine.Resources.GeoLite2-Country.mmdb"))
{
Reader = new Reader(stream);
}
}
示例15: Parse
public override void Parse(byte[] buffer)
{
Reader reader = new Reader(new MemoryStream(buffer));
reader.ReadByte(); // Id
Reason = (ReasonType)reader.ReadByte();
}