public IEnumerable <Common.ISerializable> Parse(CommandSerializer cs) { if (data == null) { yield break; } var packages = new List <ArraySegment <byte> >(); using (var stream = new MemoryStream(data)) { var ps = new PackageSerializer(); ps.Package += (s, e) => packages.Add(e.Data); ps.Run(stream); } foreach (var p in packages) { using (var mem = new MemoryStream(p.Array, p.Offset, p.Count, false)) { var cmd = cs.DeserializeCommand(mem); if (cmd != null) { yield return(cmd); } } } }
public void StartLogging() { SerializationDocument = CommandSerializer.CreateEmptySerializationDocument(); LoggingStarted = true; InvokeStateChanged(); }
public async Task BuilderDeserialize() { using (var memoryStream = new MemoryStream()) { using (var builder = new MessageProtocolWriter(memoryStream)) { builder.Write( ab => ab.Write("GET"), ab => ab.Write("key1"), ab => ab.Write(true), ab => ab.Write(5), ab => ab.Write(1.2d), ab => ab.Write((long)int.MaxValue + 1), ab => ab.WriteError("errorcod", "error message")); await builder.FlushAsync(); Assert.IsTrue(memoryStream.Length > 0); } memoryStream.Position = 0; var commands = await CommandSerializer.DeserializeAsync(memoryStream); Assert.AreEqual(1, commands.Count); var command = commands[0]; Assert.AreEqual("GET", command.Keyword); Assert.AreEqual("key1", (command.Parameters.Span[0] as StringProtocolObject)?.Value); Assert.AreEqual(true, (command.Parameters.Span[1] as BooleanProtocolObject)?.Value); Assert.AreEqual(5, (command.Parameters.Span[2] as IntegerProtocolObject)?.Value); Assert.AreEqual(1.2d, (command.Parameters.Span[3] as DoubleProtocolObject)?.Value); Assert.AreEqual((long)int.MaxValue + 1, (command.Parameters.Span[4] as LongProtocolObject)?.Value); Assert.AreEqual("errorcod", (command.Parameters.Span[5] as ErrorProtocolObject)?.Code); Assert.AreEqual("error message", (command.Parameters.Span[5] as ErrorProtocolObject)?.Message); } }
private void m_server_ReceivedFull(object sender, TcpReceivedEventArgs e) { Command command = null; try { command = CommandSerializer.DeserializeCommand(e.Data); } catch (EncoderFallbackException ex) { if (OnCommandError != null) { OnCommandError(this, new TcpErrorEventArgs(e.Client, ex)); } return; } if (OnCommandReceived != null) { OnCommandReceived(this, new CommandReceivedArgs(command, (User)e.Client.Tag)); } SendCommand(command); }
public async Task DeserializeTest() { using (var memStream = new MemoryStream()) using (var binaryWriter = new BinaryWriter(memStream)) { binaryWriter.Write(new ArrayProtocolObject { Items = new MessageProtocolObject[] { new StringProtocolObject { Value = "SET" }, new StringProtocolObject { Value = "Test:Key:SubKey" }, new BlobProtocolObject { Bytes = Guid.NewGuid().ToByteArray() } } }); memStream.Position = 0; var commands = await CommandSerializer.DeserializeAsync(memStream); Assert.AreEqual(1, commands.Count); Assert.AreEqual("SET", commands[0].Keyword); Assert.AreEqual(2, commands[0].Parameters.Length); var parameters = commands[0].Parameters.ToArray(); Assert.IsInstanceOfType(parameters[0], typeof(StringProtocolObject)); var param1String = parameters[0] as StringProtocolObject; Assert.AreEqual("Test:Key:SubKey", param1String.Value); Assert.IsInstanceOfType(parameters[1], typeof(BlobProtocolObject)); } }
// old code from the past private void DumpNoPath(Vec target) { var all = whatToFill.Cast <bool>().Count(b => b); var done = Commands.Count(c => c is Fill); var bytes = CommandSerializer.Save(Commands.ToArray()); File.WriteAllBytes($@"c:\temp\020_.nbt", bytes); var s = ""; for (int y = 0; y < R; y++) { for (int z = 0; z < R; z++) { for (int x = R - 1; x >= 0; x--) { s += state.Get(new Vec(x, y, z)) ? "X" : "."; } s += "\r\n"; } s += "===r\n"; } File.WriteAllText(@"c:\1.txt", s); throw new InvalidOperationException($"Couldn't find path from {pos} to {target}; all={all}; done={done}; Commands.Count={Commands.Count}; {string.Join("; ", Commands.Take(20))}"); }
public void TestRequiredPositionalArgs() { Assert.Throws <CommandArgumentException>(delegate { CommandSerializer <PositionalRequiredTest> .Parse(new string[] { }); }); }
public void TestActionsWithMissingParameter() { Assert.Throws <CommandArgumentException>(delegate { CommandSerializer <ActionsTestWithInputString> .Parse(new[] { "--name", "foo", "--password" }); }); }
public void LoadLogFile(string fileName) { Commands = CommandSerializer.DeserializeDocument(fileName); ReplayStarted = true; ReplayIndex = 0; InvokeStateChanged(); }
public void TestInvalidMultipleAlias() { Assert.Throws <CommandArgumentException>(delegate { CommandSerializer <AliasesTest> .Parse(new[] { "-stv", "test" }); }); }
public void TestActionsWithInputStrings() { var result = CommandSerializer <ActionsTestWithInputString> .Parse(new[] { "--name", "foo", "--password", "bar" }); Assert.AreEqual("foo", result.Name); Assert.AreEqual("bar", result.Password); }
public void TestDate() { var date = "2018-08-18T07:22:16.0000000Z"; var result = CommandSerializer <DateTest> .Parse(new[] { "--date", date }); Assert.AreEqual(DateTime.Parse(date), result.Date); }
public void TestNonExistingAction() { Assert.Throws <CommandArgumentException>(delegate { CommandSerializer <AliasTest> .Parse(new[] { "--aaa" }); }); }
public void TestFileAndDirectory() { var result = CommandSerializer <FileAndDirectoryTest> .Parse(new[] { "--file", "toto.txt", "--directory", "foo/bar" }); Assert.IsFalse(result.File.Exists); Assert.IsFalse(result.Directory.Exists); }
public void Temp([Values(3)] int problemId) { var problem = ProblemSolutionFactory.LoadProblem($"FR{problemId:D3}"); //var assembler = new GreedyPartialSolver(problem.TargetMatrix, new ThrowableHelperFast(problem.TargetMatrix)); //var disassembler = new InvertorDisassembler(new GreedyPartialSolver(problem.SourceMatrix, new ThrowableHelperFast(problem.SourceMatrix)), problem.SourceMatrix); //var solver = new SimpleReassembler(disassembler, assembler); var commonPart = problem.SourceMatrix.Intersect(problem.TargetMatrix); commonPart = new ComponentTrackingMatrix(commonPart).GetGroundedVoxels(); File.WriteAllBytes(Path.Combine(FileHelper.ProblemsDir, "FR666_tgt.mdl"), commonPart.Save()); File.WriteAllBytes(Path.Combine(FileHelper.ProblemsDir, "FR666_src.mdl"), commonPart.Save()); var solver = new GreedyPartialSolver(problem.SourceMatrix, commonPart, new ThrowableHelperFast(commonPart, problem.SourceMatrix)); List <ICommand> commands = new List <ICommand>(); try { foreach (var command in solver.Solve()) { commands.Add(command); } //commands.AddRange(solver.Solve()); } catch (Exception e) { Log.For(this).Error($"Unhandled exception in solver for {problem.Name}", e); throw; } finally { Console.WriteLine(commands.Take(5000).ToDelimitedString("\n")); var bytes = CommandSerializer.Save(commands.ToArray()); File.WriteAllBytes(GetSolutionPath(FileHelper.SolutionsDir, "FR666"), bytes); } }
public void Disassemble() { var problem = ProblemSolutionFactory.LoadProblem("FD120"); //var solver = new InvertorDisassembler(new DivideAndConquer(problem.SourceMatrix, true), problem.SourceMatrix); //var solver = new InvertorDisassembler(new GreedyPartialSolver(problem.SourceMatrix, new Matrix(problem.R), new ThrowableHelperFast(problem.SourceMatrix)), problem.SourceMatrix); var solver = new InvertorDisassembler(new HorizontalSlicer(problem.SourceMatrix, 6, 6, true), problem.SourceMatrix); //var solver = new HorizontalSlicer(problem.SourceMatrix, 6, 6, true); List <ICommand> commands = new List <ICommand>(); try { commands.AddRange(solver.Solve()); } catch (Exception e) { Log.For(this).Error($"Unhandled exception in solver for {problem.Name}", e); throw; } finally { var bytes = CommandSerializer.Save(commands.ToArray()); File.WriteAllBytes(GetSolutionPath(FileHelper.SolutionsDir, problem.Name), bytes); } var state = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix); new Interpreter(state).Run(commands); }
public void TestAliases() { var result = CommandSerializer <AliasesTest> .Parse(new[] { "-sS" }); Assert.IsTrue(result.Set1); Assert.IsTrue(result.Set2); Assert.IsFalse(result.Set3); }
public RepositoryConfiguration() { Marshal = new CopyResulMarshal(); Synchronize = new SingleWriterMultipleReaders(); CommandSerializer = new CommandSerializer(); JournalFactory = new JournalFactory(); SnapshotArchiver = new DeleteArchivedSnapshots(); }
public void TestOnSamleTraces(string commandFilename, string problemFilename) { var content = File.ReadAllBytes(commandFilename); var commands = CommandSerializer.Load(content); var state = new DeluxeState(null, Matrix.Load(File.ReadAllBytes(problemFilename))); new Interpreter(state).Run(commands); }
public void TestOnSamleTraces([ValueSource(nameof(GetModels))] string filename) { var content = File.ReadAllBytes(filename); var commands = CommandSerializer.Load(content); var newContent = CommandSerializer.Save(commands); Assert.AreEqual(content, newContent); }
void sendCon() { CommandSerializer com = new CommandSerializer("ac-con").AddArg(this.connector.CubeGrid.GridSizeEnum); AddVector(this.connector.GetPosition(), com); AddVector(this.connector.WorldMatrix.Forward, com); this.igc.SendBroadcastMessage(this.serverChannel, com.ToString()); }
public void Deserialize() { var s = new CustomCommandSerializer().Serialize("White.NonCoreTests.CustomCommands.dll", "IBazCommand", "Foo", new object[] { "bar", 1 }); ICommand customCommand; bool result = new CommandSerializer(new CommandAssemblies()).TryDeserializeCommand(s, out customCommand); Assert.AreEqual(true, result); }
public void DeserializeInvalidString() { ICommand customCommand; bool result = new CommandSerializer(new CommandAssemblies()).TryDeserializeCommand("merylstreep", out customCommand); Assert.AreEqual(false, result); Assert.AreEqual(null, customCommand); }
public void TestActions() { var result = CommandSerializer <ActionsTest> .Parse(new[] { "--set1", "--set2" }); Assert.IsTrue(result.Set1); Assert.IsTrue(result.Set2); Assert.IsFalse(result.Set3); }
public void TestList() { var result = CommandSerializer <ListTest> .Parse(new[] { "-c", "red", "green", "blue" }); Assert.AreEqual(3, result.Color.Count); Assert.AreEqual("red", result.Color[0]); Assert.AreEqual("green", result.Color[1]); Assert.AreEqual("blue", result.Color[2]); }
public void TestArray() { var result = CommandSerializer <ArrayTest> .Parse(new[] { "--array", "1", "2", "100" }); Assert.AreEqual(3, result.Numbers.Length); Assert.AreEqual(1, result.Numbers[0]); Assert.AreEqual(2, result.Numbers[1]); Assert.AreEqual(100, result.Numbers[2]); }
public void TestHelp() { var helpText = CommandSerializer <HelpTest> .GetHelp(); TestContext.Out.WriteLine(helpText); System.Diagnostics.Debug.WriteLine(helpText); Assert.IsNotEmpty(helpText); Assert.IsTrue(helpText.StartsWith("Usage")); }
static MenuHelper() { /* * Create one instance of guiControllerCommand for each existing public command. * This instance is later used in every context menu (instances of commands are shared * among the existing menus) */ foreach (List <CommandDescriptor> scopeCommands in PublicCommandsHelper.publicCommandsByScope.Values) { foreach (CommandDescriptor commandDescriptor in scopeCommands) { guiControllerCommand guiC = new guiControllerCommand(); CommandDescriptor descriptor = commandDescriptor; guiC.ControllerCommandFactoryMethod = delegate { return(CommandSerializer.CreateCommandObject(descriptor.CommandType)); }; guiC.ControllerCommandType = commandDescriptor.CommandType; guiC.ControllerCommandDescription = commandDescriptor.CommandDescription; guiCommandsForControllerCommands[commandDescriptor.CommandType] = guiC; } } foreach (Type t in typeof(guiScopeCommand).Assembly.GetTypes()) { if (t.IsSubclassOf(typeof(guiScopeCommand))) { ScopeAttribute a = (ScopeAttribute)t.GetCustomAttributes(typeof(ScopeAttribute), true).FirstOrDefault(); if (a != null) { #if SILVERLIGHT foreach (ScopeAttribute.EScope scope in EnumHelper.GetValues(typeof(ScopeAttribute.EScope))) #else foreach (ScopeAttribute.EScope scope in Enum.GetValues(typeof(ScopeAttribute.EScope))) #endif { if (scope == ScopeAttribute.EScope.None) { continue; } if (a.Scope.HasFlag(scope)) { localCommandsByScope.CreateSubCollectionIfNeeded(scope); localCommandsByScope[scope].Add((guiScopeCommand)t.GetConstructor(Type.EmptyTypes).Invoke(null)); } } if (a.Scope == ScopeAttribute.EScope.None) { localCommandsByScope.CreateSubCollectionIfNeeded(a.Scope); localCommandsByScope[a.Scope].Add((guiScopeCommand)t.GetConstructor(Type.EmptyTypes).Invoke(null)); } } } } }
public void TestBasicClass() { var result = CommandSerializer <BasicClassTest> .Parse(new[] { "--isCar", "--wheelCount", "4", "--Colors", "red", "black" }); Assert.IsTrue(result.IsCar); Assert.AreEqual(4, result.WheelCount); Assert.AreEqual(2, result.Colors.Count); Assert.AreEqual("red", result.Colors[0]); Assert.AreEqual("black", result.Colors[1]); }
public void TestPositionalArgs() { var result = CommandSerializer <PositionalTest> .Parse(new[] { "blue", "-a", "foo", "bar", "2000" }); Assert.IsTrue(result.IsAutomatic); Assert.AreEqual("blue", result.Color); Assert.AreEqual(3, result.Features.Count); Assert.AreEqual("foo", result.Features[0]); Assert.AreEqual("bar", result.Features[1]); Assert.AreEqual("2000", result.Features[2]); }
public void TestDeserialization() { TestSerialization(); XDocument scriptDocument = new XDocument(); //scriptDocument.Load("TestCommandSerialization.xml"); List <CommandBase> deserializeScript = CommandSerializer.DeserializeDocument(scriptDocument); Assert.Inconclusive(); }
public void Serialize_ClientListCommand() { var commandSerializer = new CommandSerializer(); var clientListCommand = new ClientListCommand { SenderInformation = new ServerInformation(string.Empty,string.Empty,new Version()), AvailableClients =new List<IClientInformation>(), }; commandSerializer.Serialize(clientListCommand); }