public Protocol(SocketWrapper socket, int protocol) { this.socketWrapper = socket; this.reader = new InputBuffer(socketWrapper.GetStream()); this.writer = new OutputBuffer(socketWrapper.GetStream()); this.ProtocolVersion = protocol; }
protected void SendPacket(Packet packet) { using (MemoryStream stream = new MemoryStream()) { OutputBuffer outgoing = new OutputBuffer(stream); outgoing.WriteVarInt(GetOutgoingID(packet)); packet.Write(outgoing); if (compression_treshold > 0) { var content = stream.ToArray(); outgoing = new OutputBuffer(); if (content.Length >= compression_treshold) { byte[] compressed_packet = ZlibUtils.Compress(content, (MemoryStream)outgoing.GetStream()); outgoing.WriteVarInt(compressed_packet.Length); outgoing.WriteData(compressed_packet); } else { outgoing.WriteVarInt(0); outgoing.WriteData(content); } } writer.WriteVarInt((int)outgoing.GetStream().Length); writer.WriteData(outgoing.ToArray()); outgoing.Dispose(); } }
static void Publisher() { var ctx = new ZContext(); var publisher = new ZSocket(ctx, ZSocketType.PUB); publisher.Bind("tcp://127.0.0.1:12345"); var src = new Record(); src.payload.Add("a", 1.0); src.payload.Add("b", 2.0); var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); for (;;) { Marshal.To(writer, src); // INCORRECT: // var str = Encoding.ASCII.GetString(output.Data.Array); // var updateFrame = new ZFrame(str); var updateFrame = new ZFrame(output.Data.Array, output.Data.Offset, output.Data.Count); publisher.Send(updateFrame); output.Position = 0; } }
public void TestEventDataSerialization() { //const string cvText = "CV:1234"; var variables = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("string", "string.Value"), new KeyValuePair <string, object>("int", 33), new KeyValuePair <string, object>("long", 101), new KeyValuePair <string, object>("date", DateTime.Now), }; var data = Utility.CreateData(1); EventDataRecord record = data.ConvertTo(); var output = new OutputBuffer(); var writer = new SimpleBinaryWriter <OutputBuffer>(output); var writeSerializer = new Serializer <SimpleBinaryWriter <OutputBuffer> >(typeof(EventDataRecord)); writeSerializer.Serialize(record, writer); var input = new InputBuffer(output.Data); var reader = new SimpleBinaryReader <InputBuffer>(input); var readSerializer = new Deserializer <SimpleBinaryReader <InputBuffer> >(typeof(EventDataRecord)); EventDataRecord resultRecord = readSerializer.Deserialize <EventDataRecord>(reader); EventData result = resultRecord.ConverTo(); Utility.VerifyEventData(data, result); }
const string scopeRegex = @"(\$\(.*\))"; // $( exp ) static void Main(string[] args) { var stopWatch = Stopwatch.StartNew(); // find script maches and shedule evaluation var template = File.ReadAllText("template"); Func <string, string> strip = str => str.Remove(str.LastIndexOf(')'), 1).TrimStart('$', '('); var maches = Regex.Matches(template, scopeRegex).Select((m) => (match: m, eval: CSharpScript.EvaluateAsync(strip(m.Value), globals: new Globals()))); // wait until evaluations are done and combine matches and evaluations results Task.WaitAll(maches.Select((m) => m.eval).ToArray()); var matchResults = maches.Select(x => (match: x.match, evalResult: x.eval.Result.ToString().ToCharArray())); // calculate new output length var evalResultsLength = matchResults.Sum(a => a.evalResult.Length); var evalsLength = matchResults.Sum(a => a.match.Value.Length); var newOutputLength = (template.Length - evalsLength) + evalResultsLength; // go through maches and replace it with eval results var outputBuffer = new OutputBuffer(template, newOutputLength); var enm = matchResults.GetEnumerator(); while (enm.MoveNext()) { (Match match, char[] taskResult) = enm.Current; outputBuffer.Add(match, taskResult); } outputBuffer.WrapUp(); stopWatch.Stop(); System.Console.WriteLine(TimeSpan.FromMilliseconds(stopWatch.ElapsedMilliseconds).Seconds); System.Console.WriteLine(outputBuffer.ToString()); }
public void Format_should_separate_groups_properly_when_formatting_with_custom_match(string testInput, string[] inputUsingNamespaces, string[] expectedOutputNamespaces) { // Arrange var inputUsings = inputUsingNamespaces.Select(ns => new UsingStatement() { Namespace = ns }); var rule = GroupingRule.Parse(testInput).Single(); var output = new OutputBuffer(); // Act rule.Format(output, inputUsings); // Assert var expectedUsings = expectedOutputNamespaces.Select(ns => (ns == "") ? "" : $"using {ns};"); output .GetLines() .Zip(expectedUsings) .Apply( ((string Actual, string Expected)pair, int index) => { pair.Actual.Should().Be(pair.Expected, because: $"line {index} should match"); });
public void Setup() { googleProtobufPersonBytes = BenchmarksData.ProtobufPerson().ToByteArray(); var protobufNetStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(protobufNetStream, BenchmarksData.ProtobufNetPerson()); protobufNetPersonBytes = protobufNetStream.ToArray(); var bondPerson = BenchmarksData.BondPerson(); var compactOutput = new OutputBuffer(256); var compactWriter = new CompactBinaryWriter <OutputBuffer>(compactOutput); var compactBondSerializer = new Serializer <CompactBinaryWriter <OutputBuffer> >(typeof(Bond.Person)); compactBondSerializer.Serialize(bondPerson, compactWriter); compactBondPersonBytes = compactOutput.Data.ToArray(); var fastOutput = new OutputBuffer(256); var fastWriter = new FastBinaryWriter <OutputBuffer>(fastOutput); var fastBondSerializer = new Serializer <FastBinaryWriter <OutputBuffer> >(typeof(Bond.Person)); fastBondSerializer.Serialize(bondPerson, fastWriter); fastBondPersonBytes = fastOutput.Data.ToArray(); jsonPerson = JsonConvert.SerializeObject(BenchmarksData.JSONPerson()); var xmlSerializer = new XmlSerializer(typeof(XML.Person)); var xmlStream = new MemoryStream(); xmlSerializer.Serialize(xmlStream, BenchmarksData.XMLPerson()); xmlPersonBytes = xmlStream.ToArray(); }
static void Main() { var src = new Example { Name = "FooBar", Constants = { 3.14, 6.28 } }; // Create de/serializer for the Example class and Compact Binary protocol. // This may take relatively long time so usually the objects should be cached and reused. var exampleSerializer = new Serializer <CompactBinaryWriter <OutputBuffer> >(typeof(Example)); var exampleDeserializer = new Deserializer <CompactBinaryReader <InputBuffer> >(typeof(Example)); var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); exampleSerializer.Serialize(src, writer); var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var dst = exampleDeserializer.Deserialize <Example>(reader); Debug.Assert(Comparer.Equal(src, dst)); }
void RoundtripObjectStream <T>(T obj) { // SimpleBinary { var output = new OutputBuffer(); var writer = new SimpleBinaryWriter <OutputBuffer>(output); Serialize.To(writer, obj); var input = new InputStream(new MemoryStream(output.buffer)); var reader = new SimpleBinaryReader <InputStream>(input); T obj2 = Deserialize <T> .From(reader); Assert.True(Comparer.Equal <T>(obj, obj2)); } // CompactBinary { var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, obj); var input = new InputStream(new MemoryStream(output.buffer)); var reader = new CompactBinaryReader <InputStream>(input); T obj2 = new Deserializer <CompactBinaryReader <InputStream> >(typeof(T)).Deserialize <T>(reader); Assert.True(Comparer.Equal <T>(obj, obj2)); } }
public bool SendMessage(Variant headers, string content) { //1. Add info about us headers[RTSP_HEADERS, RTSP_HEADERS_SERVER] = RTSP_HEADERS_SERVER_US; headers[RTSP_HEADERS, RTSP_HEADERS_X_POWERED_BY] = RTSP_HEADERS_X_POWERED_BY_US; //2. Add the content length if required if (content.Length > 0) { headers[RTSP_HEADERS, RTSP_HEADERS_CONTENT_LENGTH] = content.Length.ToString(); } //3. Add the session id if necessary if (!string.IsNullOrEmpty(_sessionId)) { headers[RTSP_HEADERS, RTSP_HEADERS_SESSION] = _sessionId; } var sb = new StringBuilder(); foreach (var header in headers[RTSP_HEADERS].Children) { sb.AppendLine(header.Key + ": " + header.Value); } sb.AppendLine(); sb.Append(content); OutputBuffer.Write(sb.ToString()); return(EnqueueForOutbound(OutputBuffer)); }
public void CorrectSerializeConvertCountBlobStruct() { var foo = new Decimals(); foo._dec = new decimal(19.91); foo._decVector.Add(new decimal(10.10)); foo._decVector.Add(new decimal(11.11)); foo._decList.AddLast(new decimal(12.12)); foo._decList.AddLast(new decimal(13.13)); foo._decList.AddLast(new decimal(14.14)); foo._decMap.Add(1, new decimal(15.15)); foo._decMap.Add(2, new decimal(16.16)); foo._decMap.Add(3, new decimal(17.17)); foo._decNullable = new decimal(20.20); foo._decRequired = new decimal(21.21); foo._decRequiredOptional = new decimal(22.22); var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); var serializer = new Serializer <CompactBinaryWriter <OutputBuffer> >(typeof(Decimals)); serializer.Serialize(foo, writer); Assert.AreEqual(foo.CountInstances(), BondTypeAliasConverter.ConvertFromDecimalCount); Assert.AreEqual(0, BondTypeAliasConverter.ConvertToDecimalCount); }
static void Main() { var obj = new Struct { n = 0x1000, str = "test", items = { 3.14, 0 } }; // OutputBuffer implements the Bond output stream interface on top // of a memory buffer. var output = new OutputBuffer(); // Use the Compact Binary protocol for encoding; the data will be // written to the OutputBuffer which will allocate memory as needed. var writer = new CompactBinaryWriter <OutputBuffer>(output); // The first calls to Serialize.To and Deserialize<T>.From can take // a relatively long time because they generate the // serializer/deserializer for a given type, protocol, and stream. // See the serializer example for a way to control this. Serialize.To(writer, obj); // At this point the OutputBuffer contains a serialized // representation of the object. // Use the Compact Binary protocol for decoding (the same protocol // that was used for encoding) and InputBuffer which implements the // input stream interface on top of a memory blob. var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var obj2 = Deserialize <Struct> .From(reader); ThrowIfFalse(Comparer.Equal(obj, obj2)); }
public void CorrectSerializeConvertCountLongStruct() { var foo = new Dates(); foo._date = MakeUtcDateTime(2015, 1, 8); foo._dateVector.Add(MakeUtcDateTime(2015, 1, 9)); foo._dateVector.Add(MakeUtcDateTime(2015, 1, 10)); foo._dateList.AddLast(MakeUtcDateTime(2015, 1, 11)); foo._dateList.AddLast(MakeUtcDateTime(2015, 1, 12)); foo._dateList.AddLast(MakeUtcDateTime(2015, 1, 13)); foo._dateMap.Add(1, MakeUtcDateTime(2015, 1, 14)); foo._dateMap.Add(2, MakeUtcDateTime(2015, 1, 15)); foo._dateMap.Add(3, MakeUtcDateTime(2015, 1, 16)); foo._dateNullable = MakeUtcDateTime(2015, 1, 17); foo._dateRequired = MakeUtcDateTime(2015, 1, 18); foo._dateRequiredOptional = MakeUtcDateTime(2015, 1, 19); var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); var serializer = new Serializer <CompactBinaryWriter <OutputBuffer> >(typeof(Dates)); serializer.Serialize(foo, writer); Assert.AreEqual(foo.CountInstances(), BondTypeAliasConverter.ConvertFromDateTimeCount); Assert.AreEqual(0, BondTypeAliasConverter.ConvertToDateTimeCount); }
public override void ComplexTest() { var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, complexInput); var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var complexOutput = Deserialize <Complex> .From(reader); WriteLine("{0}:{1},{2},{3},{4}", output.Data.Count, complexOutput.SimpleValue.Value, complexOutput.SimpleValue.ShortValue, complexOutput.SimpleValue.IntValue, complexOutput.SimpleValue.LongValue); for (int i = 0; i < complexOutput.ListValue.Count; i++) { WriteLine("{0},{1},{2},{3}", complexOutput.ListValue[i].Value, complexOutput.ListValue[i].ShortValue, complexOutput.ListValue[i].IntValue, complexOutput.ListValue[i].LongValue); } }
public void WatchdogScheduledItem_SerializationTest() { // Serialize to the output buffer as binary. OutputBuffer output = new OutputBuffer(); CompactBinaryWriter <OutputBuffer> writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, hcs); // De-serialize from the binary output. InputBuffer input = new InputBuffer(output.Data); CompactBinaryReader <InputBuffer> reader = new CompactBinaryReader <InputBuffer>(input); WatchdogScheduledItem hcs1 = Deserialize <WatchdogScheduledItem> .From(reader); Assert.IsTrue(hcs.Equals(hcs1)); // Using the generic BondCustomSerializer. using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { BondCustomSerializer <WatchdogScheduledItem> bcs = new BondCustomSerializer <WatchdogScheduledItem>(); bcs.Write(hcs, bw); ms.Position = 0L; using (BinaryReader br = new BinaryReader(ms)) { hcs1 = bcs.Read(br); Assert.IsTrue(hcs.Equals(hcs1)); } } } }
public void ParserExtractsRuleComponents() { //Arrange var buffer = new OutputBuffer() { BufferWidth = 133 }; var output = new Output(buffer); //Act var results = TestStrings .Select(s => new { String = s, Result = EntityReferenceParser.Parse(s) }) .ToList(); //Assert var report = results.AsReport(rep => rep .AddColumn(r => r.String, cc => cc.Heading("Input")) .AddColumn(r => r.Result.Valid, cc => { }) .AddChild(r => new[] { new { r.Result?.Error } }, erep => erep.AddColumn(e => e.Error, cc => { })) .AddChild(r => new[] { new { Result = r.Result?.EntityReference?.Describe() } }, drep => drep.AddColumn(e => e.Result ?? "NULL", cc => cc.Heading("Result"))) ); output.FormatTable(report); Approvals.Verify(output.Report); }
public override void Write(OutputBuffer output) { output.WriteVarInt(ProtocolVersion); output.WriteString(HostName); output.WriteShort(Port); output.WriteVarInt(Intent); }
internal void VarIntTestImpl() { IntTest <ushort> test16 = (value) => { var output = new OutputBuffer(); output.WriteVarUInt16(value); var input = new InputBuffer(output.Data); Assert.AreEqual(value, input.ReadVarUInt16()); }; IntTest <uint> test32 = (value) => { var output = new OutputBuffer(); output.WriteVarUInt32(value); var input = new InputBuffer(output.Data); Assert.AreEqual(value, input.ReadVarUInt32()); }; IntTest <ulong> test64 = (value) => { var output = new OutputBuffer(); output.WriteVarUInt64(value); var input = new InputBuffer(output.Data); Assert.AreEqual(value, input.ReadVarUInt64()); }; test16(ushort.MinValue); test16(ushort.MaxValue); test32(uint.MinValue); test32(uint.MaxValue); test64(ulong.MinValue); test64(ulong.MaxValue); }
private void WriteOutput() { var param1 = GetParameter(1); OutputBuffer.Add(param1); _iPointer += 2; }
public void CorrectSerializeConvertCountRef() { var foo = new RefObjects(); foo._ref = new RefObject("1111"); foo._refVector.Add(new RefObject("2222")); foo._refVector.Add(new RefObject("3333")); foo._refList.AddLast(new RefObject("4444")); foo._refList.AddLast(new RefObject("5555")); foo._refList.AddLast(new RefObject("6666")); foo._refMap.Add(1, new RefObject("7777")); foo._refMap.Add(2, new RefObject("8888")); foo._refMap.Add(3, new RefObject("9999")); foo._refNullable = new RefObject("10010"); foo._refRequired = new RefObject("11011"); foo._refRequiredOptional = new RefObject("12012"); var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); var serializer = new Serializer <CompactBinaryWriter <OutputBuffer> >(typeof(RefObjects)); serializer.Serialize(foo, writer); Assert.AreEqual(foo.CountInstances(), BondTypeAliasConverter.ConvertFromRefObjectCount); Assert.AreEqual(0, BondTypeAliasConverter.ConvertToRefObjectCount); }
static void Main() { var data = Enumerable.Range(0, 255).Select(i => (byte)i).ToArray(); var src = new Example { ListOfBlobs = { new ArraySegment <byte>(data, 0, 10), new ArraySegment <byte>(data, 10, 10) }, NullableBlob = new ArraySegment <byte>(data, 20, 10), UninitializedBlob = new ArraySegment <byte>(data, 30, 70) }; var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, src); var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var dst = Deserialize <Example> .From(reader); ThrowIfFalse(Comparer.Equal(src, dst)); }
private static byte[] ToByteArray(IMessage <T> input) { if (input == null) { return(null); } var output = new OutputBuffer(128); var writer = new CompactBinaryWriter <OutputBuffer>(output); input.Payload.Serialize(writer); var arraySegment = output.Data; if (arraySegment.Offset == 0 && arraySegment.Count == arraySegment.Array.Length) { // perfect match, so we can just return the backing buffer return(arraySegment.Array); } // size or offset doesn't line up, so we need to make a copy var bytes = new byte[arraySegment.Count]; Buffer.BlockCopy( src: arraySegment.Array, srcOffset: arraySegment.Offset, dst: bytes, dstOffset: 0, count: arraySegment.Count); return(bytes); }
public void EventListSerializtionRountTrip() { var evt = new Event { EventType = "AAA", Payload = new byte[8] }; var batch = new KafkaEventBusBatchContainer { Events = new List <Event> { evt } }; var output = new OutputBuffer(); var bondWriter = new SimpleBinaryWriter <OutputBuffer>(output); Serialize.To(bondWriter, batch); var data = output.Data.ToArray(); var input = new InputBuffer(data); var bondReader = new SimpleBinaryReader <InputBuffer>(input); var result = Deserialize <KafkaEventBusBatchContainer> .From(bondReader); result.Events.Should().BeEquivalentTo(batch.Events); }
static void Main() { // Define root node for a tree of strings var root = new Node <string> { data = "root" }; root.left = new Node <string> { data = "root/left" }; root.right = new Node <string> { data = "root/right" }; root.left.left = new Node <string> { data = "root/left/left" }; root.left.left.right = new Node <string> { data = "root/left/left/right" }; var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); Marshal.To(writer, root); var tree = Unmarshal <Node <string> > .From(output.Data); Debug.Assert(Comparer.Equal(root, tree)); }
static void Main(string[] args) { var asmName = new AssemblyName("Foo"); var asmBuilder = AssemblyBuilder.DefineDynamicAssembly (asmName, AssemblyBuilderAccess.RunAndSave); var moduleBuilder = asmBuilder.DefineDynamicModule("Foo", "Foo.exe"); var typeBuilder = moduleBuilder.DefineType("Program", TypeAttributes.Public); var methodBuilder = typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), new[] { typeof(string) }); var serializer = new Serializer <CompactBinaryWriter <OutputBuffer> >(typeof(AnswerConfig)); var expression = serializer.GetExpressions().First(); var visitor = new MyVisitor(); LambdaExpression exp = (LambdaExpression)visitor.Visit(expression); exp.CompileToMethod(methodBuilder); typeBuilder.CreateType(); asmBuilder.SetEntryPoint(methodBuilder); asmBuilder.Save("Foo.exe"); var output = new OutputBuffer(); var writer = new CompactBinaryWriter <OutputBuffer>(output); //BondExpressionsInterceptor.Serialize.To<CompactBinaryWriter<OutputBuffer>, Record>(writer, src); var input = new InputBuffer(output.Data); var reader = new CompactBinaryReader <InputBuffer>(input); var dst = Deserialize <Record> .From(reader); }
static ArraySegment <byte> SerializeStream() { // An output stream can be used to accumulate multiple serialized // structs. This can be done by re-using the same writer over the same // stream. var output = new OutputBuffer(); // Use Compact Binary protocol for encoding; the data will be written to // output which will allocate more memory as needed. var writer = new CompactBinaryWriter <OutputBuffer>(output); for (uint n = 1; n <= NumObjects; ++n) { var obj = new Struct { n = n, str = new string('#', (int)n) }; Serialize.To(writer, obj); } // At this point output contains the serialized representation // of a stream of objects. OutputStream.Data can be used to get // the written data. return(output.Data); }
public void VarInts_RoundTrip() { Action <ushort> test16 = value => { var output = new OutputBuffer(); output.WriteVarUInt16(value); var input = MakeInputStream(output.Data); Assert.AreEqual(value, input.ReadVarUInt16()); }; Action <uint> test32 = value => { var output = new OutputBuffer(); output.WriteVarUInt32(value); var input = MakeInputStream(output.Data); Assert.AreEqual(value, input.ReadVarUInt32()); }; Action <ulong> test64 = value => { var output = new OutputBuffer(); output.WriteVarUInt64(value); var input = MakeInputStream(output.Data); Assert.AreEqual(value, input.ReadVarUInt64()); }; test16(ushort.MinValue); test16(ushort.MaxValue); test32(uint.MinValue); test32(uint.MaxValue); test64(ulong.MinValue); test64(ulong.MaxValue); }
static void Main() { // Get runtime schemas for two "versions" of Example schema. // When using untagged protocols the consumer must have access to runtime schema of the data. var schema1 = Schema <Example1> .RuntimeSchema; var schema2 = Schema <Example2> .RuntimeSchema; // Create and cache deserializers for objects of type Example2 from payloads using the two schemas var deserializers = new Dictionary <string, Deserializer <SimpleBinaryReader <InputBuffer> > > { { "Example1", new Deserializer <SimpleBinaryReader <InputBuffer> >(typeof(Example2), schema1) }, { "Example2", new Deserializer <SimpleBinaryReader <InputBuffer> >(typeof(Example2), schema2) } }; // Create payload serializing an instance of Example1 var src = new Example1 { Enabled = true, Name = "Foo" }; var output = new OutputBuffer(); var writer = new SimpleBinaryWriter <OutputBuffer>(output); Serialize.To(writer, src); var input = new InputBuffer(output.Data); var reader = new SimpleBinaryReader <InputBuffer>(input); // Use the precreated deserializer to deserialize an instance of Example2 schema for Example1 var dst = deserializers["Example1"].Deserialize <Example2>(reader); Debug.Assert(src.Enabled == dst.Enabled); Debug.Assert(src.Name == dst.Name); }
public int FastBond() { var output = new OutputBuffer(256); var writer = new FastBinaryWriter <OutputBuffer>(output); fastBondSerializer.Serialize(BondPerson, writer); return(output.Data.Count); }
public static ArraySegment <byte> SerializeSP <T>(T obj, ushort version) { var output = new OutputBuffer(); var writer = new SimpleBinaryWriter <OutputBuffer>(output, version); Serialize.To(writer, obj); return(output.Data); }
public ScriptingHostRawUserInterface(ApplicationSettings settings) { Output = new OutputBuffer(); backgroundColor = settings.BackgroundColor; foregroundColor = settings.ForegroundColor; cursorPosition = new Coordinates(0, 0); windowPosition = new Coordinates(0, 0); cursorSize = 1; bufferSize = new Size(settings.HostWidth, Int32.MaxValue); windowSize = bufferSize; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { cmdSave.Visible = IsLoggedIn && (!string.IsNullOrEmpty(Request["id"]) || !string.IsNullOrEmpty(Request["load"])); } // We store the game in the Session, but use a dictionary keyed by GUIDs which // are stored in the ViewState. This allows the same user in the same browser // to open multiple games in different browser tabs. if (Games == null) { Games = new Dictionary<string, PlayerHandler>(); } if (OutputBuffers == null) { OutputBuffers = new Dictionary<string, OutputBuffer>(); } if (Resources == null) { Resources = new SessionResources(); } m_gameId = (string)ViewState["GameId"]; if (m_gameId == null) { m_gameId = Guid.NewGuid().ToString(); ViewState["GameId"] = m_gameId; } if (Page.IsPostBack) { if (Games.ContainsKey(m_gameId)) { m_player = Games[m_gameId]; } if (!OutputBuffers.ContainsKey(m_gameId)) { // TO DO: Think this only ever happens while debugging? return; } m_buffer = OutputBuffers[m_gameId]; } else { m_buffer = new OutputBuffer(); OutputBuffers.Add(m_gameId, m_buffer); } }
public StressTestShim(ITestOutputHelper output) { _output = output; _outbuff = new OutputBuffer(1024 * 200, output); }
public ThreadUnsafeOutput(UInt32 bufferLength) { this.buffer = new OutputBuffer(new Byte[bufferLength]); }
void SessionTimeoutMessage() { m_buffer = new OutputBuffer(null); m_buffer.AddJavaScriptToBuffer("sessionTimeout"); ClearJavaScriptBuffer(); }