private void Subcriber(byte [] byteBuffer, int size)
        {
            string content = Encoding.ASCII.GetString(byteBuffer, 0, size);

            if (fingerPrintManager != null && !string.IsNullOrEmpty(content))
            {
                try {
                    CommandObject command = JsonConvert.DeserializeObject <CommandObject>(content);
                    switch (command.Command)
                    {
                    case MessageCommandEnum.DISCONNECT: {
                        string ip = command.Data as string;
                        fingerPrintManager.Disconnect(ip);
                        break;
                    }

                    case MessageCommandEnum.CONNECT: {
                        string ip = command.Data as string;
                        fingerPrintManager.Connect(ip);
                        break;
                    }
                    }
                } catch (Exception ex) {
                    logger.Error(ex.Message, ex);
                }
            }
        }
        public static void DebugToConsole(this CommandObject cmd)
        {
            Console.WriteLine("-------Schema----------");

            for (int x = 0; x < cmd.Schema.NodeCount; x++)
            {
                Console.WriteLine(cmd.Schema[x]);
            }

            Console.WriteLine("-------Data----------");


            var rdr3 = cmd.ToCommand().MakeDataReader();

            while (!rdr3.IsEmpty)
            {
                Console.WriteLine(rdr3.Read());
            }

            Console.WriteLine("-------Reader----------");
            var rdr = cmd.ToCommand().MakeReader();

            Console.WriteLine(rdr.ToString());
            while (rdr.Read())
            {
                Console.WriteLine(rdr.ToString());
            }
            Console.WriteLine(rdr.ToString());

            Console.WriteLine("-------Text----------");

            Console.WriteLine(cmd.ToString());
        }
 public ManualResetEventSlim Send(CommandObject command)
 {
     if (!command.Schema.ProcessRuntimeID.HasValue)
     {
         return(Send(PacketMethods.CreatePacket(PacketContents.CommandSchemaWithData, 0, command.ToCommand().ToArray())));
     }
     else
     {
         int schemeRuntimeID;
         lock (m_knownSchemas)
         {
             if (!m_knownSchemas.TryGetValue(command.Schema.ProcessRuntimeID.Value, out schemeRuntimeID))
             {
                 if (command.Schema.ProcessRuntimeID == -1)
                 {
                     throw new Exception("Cannot serialize a schema that has not been defined in this process.");
                 }
                 schemeRuntimeID = m_knownSchemas.Count;
                 m_knownSchemas.Add(command.Schema.ProcessRuntimeID.Value, schemeRuntimeID);
                 Send(command.Schema.ToCommand(schemeRuntimeID));
             }
         }
         return(Send(command.ToDataCommandPacket(schemeRuntimeID)));
     }
 }
Exemple #4
0
 public ElseIfCommands(CommandObject root, bool src, bool expSrc)
 {
     Self   = new CommandObject <ElseIfCommands>(this);
     Root   = root;
     Src    = src;
     ExpSrc = expSrc;
 }
Exemple #5
0
        protected void InitRabbitClient()
        {
            client             = new RabbitMQClient("iClock Service Queue");
            client.OnRecieved += (model, message) =>
            {
                if (fingerPrinterManager != null && !string.IsNullOrEmpty(message))
                {
                    try
                    {
                        CommandObject command = client.JsonDeserialize(message);
                        switch (command.Command)
                        {
                        case MessageCommandEnum.DISCONNECT:
                        {
                            string ip = command.Data as string;
                            fingerPrinterManager.Disconnect(ip);
                            break;
                        }

                        case MessageCommandEnum.CONNECT:
                        {
                            string ip = command.Data as string;
                            fingerPrinterManager.Connect(ip);
                            break;
                        }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message, ex);
                    }
                }
            };
        }
Exemple #6
0
        public async Task ExecuteCommand_called_without_UserState_results_in_UserState_defaulted_to_Null_server()
        {
            var command = new CommandObject();
            var result  = await Csla.DataPortal.ExecuteAsync(command);

            Assert.AreEqual("Executed", result.AProperty);
        }
Exemple #7
0
        public AddressBookViewModel(AddressBook addressBook, Navigation navigation)
        {
            _addressBook = addressBook;
            _navigation  = navigation;

            _summaries = new MappedObservableCollection <Person, PersonSummaryViewModel>(
                person => new PersonSummaryViewModel(person),
                _addressBook.People);

            _navigation.PropertyChanged += NavigationPropertyChanged;

            _newCommandObject = new CommandObject(
                () =>
            {
                _navigation.SelectedPerson = _addressBook.NewPerson();
            });
            _deleteCommandObject = new CommandObject(
                () => _navigation.SelectedPerson != null,
                () =>
            {
                if (_navigation.SelectedPerson != null)
                {
                    _addressBook.DeletePerson(_navigation.SelectedPerson);
                    _navigation.SelectedPerson = null;
                }
            });
        }
Exemple #8
0
        public void CommandBase_AssertDefaultValues()
        {
            var cmd = new CommandObject();

              Assert.AreEqual(string.Empty, cmd.Name);
              Assert.AreEqual(0, cmd.Num);
        }
Exemple #9
0
 private void Delete(CommandObject command)
 {
     _repository.Delete(
         _repository.Get(
             command.PersonName
             )
         );
 }
Exemple #10
0
        public MainWindowViewModel()
        {
            this.AddCommand = new CommandObject();
            this.AddCommand.ExecuteAction = new Action <object>(this.Add);

            this.SaveCommand = new CommandObject();
            this.SaveCommand.ExecuteAction = new Action <object>(this.Save);
        }
Exemple #11
0
        public void HandleCommands()
        {
            Console.WriteLine("Please write a command, or type Help for a command list. Type quit to exit.");
            bool quit = false;

            while (!quit)
            {
                CommandObject command = null;
                try
                {
                    command = CommandObjectGenerator.ReturnCommandObject(Console.ReadLine());
                }
                catch
                {
                    Console.WriteLine("Please enter an appropriate value.");
                    continue;
                }

                switch (command.Command)
                {
                case Command.DELETE:
                    Delete(command);
                    break;

                case Command.GET:
                    IPerson user = GetUser(command);
                    if (user != null)
                    {
                        Console.WriteLine(user.ToString() != "" ? user.ToString() : "No user information found.");
                    }
                    else
                    {
                        Console.WriteLine("No user information found");
                    }
                    break;

                case Command.GETALL:
                    WriteAllUsers();
                    break;

                case Command.HELP:
                    DisplayHelp();
                    break;

                case Command.INSERT:
                    InsertUser(command);
                    break;

                case Command.SEARCH:
                    Search(command);
                    break;

                case Command.QUIT:
                    quit = true;
                    break;
                }
            }
        }
        public void PollStates()
        {
            var cmd = new CommandObject()
            {
                CommandType = GetCommandObject.TypeGetStates
            };

            SendCommand(cmd, GetStatesResponse);
        }
Exemple #13
0
        public void CommandBase_CanLoadProperties_WithObjectFactory()
        {
            var cmd = new CommandObject();

              LoadProperty(cmd, CommandObject.NameProperty, "Rocky");
              LoadProperty(cmd, CommandObject.NumProperty, 8);

              Assert.AreEqual("Rocky", cmd.Name);
              Assert.AreEqual(8, cmd.Num);
        }
Exemple #14
0
        private void InsertUser(CommandObject command)
        {
            bool success = _repository.Insert(
                new Person()
            {
                Name = command.PersonName,
                Age  = int.Parse(command.PersonAge)
            });

            Console.WriteLine("Success: " + success);
        }
Exemple #15
0
        private string GetJsonString(MessageCommandEnum command, object data)
        {
            CommandObject obj = new CommandObject()
            {
                Command = command,
                Data    = data
            };
            var setting = new JsonSerializerSettings();

            setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            return(JsonConvert.SerializeObject(obj, setting));
        }
Exemple #16
0
        public void CommandBase_CanLoadPropertiesUsingNonGenericPropertyInfo_WithObjectFactory()
        {
            var cmd = new CommandObject();

              IPropertyInfo nameProperty = (IPropertyInfo) CommandObject.NameProperty;
              IPropertyInfo numProperty = (IPropertyInfo)CommandObject.NumProperty;

              LoadProperty(cmd, nameProperty, "Rocky");
              LoadProperty(cmd, numProperty, 8);

              Assert.AreEqual("Rocky", cmd.Name);
              Assert.AreEqual(8, cmd.Num);
        }
Exemple #17
0
 public void ExecuteOff(int commandOffPosition)
 {
     if (PositionOutOfList(commandOffPosition, commandOffList))
     {
         nullCommand.Execute();
         lastCommand = nullCommand;
         lifoCommandList.Add(nullCommand);
         return;
     }
     commandOffList[commandOffPosition].Execute();
     lastCommand = commandOffList[commandOffPosition];
     lifoCommandList.Add(commandOffList[commandOffPosition]);
 }
        public void SendCommand(CommandObject cmd, Action <CommandResponseObject> responseCallback)
        {
            // Assign unique ID
            cmd.Id = ++_commandId;

            // Add ID to callback dict
            if (responseCallback != null)
            {
                _responseActions[cmd.Id] = responseCallback;
            }

            SendCommandWithoutId(cmd);
        }
Exemple #19
0
        private void Search(CommandObject command)
        {
            IPerson person = (_repository.Get(command.PersonName));

            if (person != null)
            {
                Console.WriteLine("Found: " + person);
            }
            else
            {
                Console.WriteLine("Not Found");
            }
        }
Exemple #20
0
        public void ExecuteCommand_called_without_UserState_results_in_UserState_defaulted_to_Null_server()
        {
            var context = GetContext();
            var command = new CommandObject();

            command.ExecuteServerCodeAsunch((o1, e1) =>
            {
                context.Assert.IsNull(e1.Error);
                context.Assert.AreEqual("Executed", e1.Object.AProperty);
                context.Assert.IsNull(e1.UserState);
                context.Assert.Success();
            });
            context.Complete();
        }
Exemple #21
0
            public void Help(string cmdname)
            {
                Console.WriteLine(CommandObject.GenCommandDetailsText(cmdname, StringComparison.OrdinalIgnoreCase));
                return;

                if (cmdname is null)
                {
                    Console.WriteLine(this.CommandObject.GenCommandOverviewText());
                }
                else
                {
                    Console.WriteLine(CommandObject.GenCommandDetailsText(cmdname, StringComparison.OrdinalIgnoreCase));
                }
            }
        /// <summary>Process the command</summary>
        /// <param name="obj"></param>
        /// <param name="socket">The socket currently open.</param>
        private void ProcessCommand(object obj, Socket socket)
        {
            CommandObject command = obj as CommandObject;

            if (!commands.ContainsKey(command.name))
            {
                throw new Exception("Cannot find a handler for command: " + command.name);
            }
            CommandArgs args = new CommandArgs();

            args.socket = socket;
            args.obj    = command.data;
            commands[command.name].Invoke(this, args);
        }
        public JsonResult ExecuteCommand(Context currentContext)
        {
            string        commandString = currentContext.CommandString;
            ResultObject  result        = null;
            CommandObject commandObject = new CommandObject {
                Command = commandString
            };

            if ((currentContext.Enabled) && (!currentContext.Forced))
            {
                currentContext.Backup();
                commandObject = LoadCommandObject(commandString, null);
                result        = InvokeCommand(currentContext, commandObject);
                if (result == null)
                {
                    commandObject = LoadCommandObject(commandString, currentContext);
                    result        = InvokeCommand(currentContext, commandObject);
                }
            }
            else if ((currentContext.Enabled) && (currentContext.Forced))
            {
                commandObject = LoadCommandObject(commandString, currentContext);
                result        = InvokeCommand(currentContext, commandObject);
            }
            else if (!currentContext.Enabled)
            {
                currentContext.Backup();
                commandObject = LoadCommandObject(commandString, null);
                result        = InvokeCommand(currentContext, commandObject);
            }

            if (result == null)
            {
                result = new ResultObject {
                    CurrentContext = currentContext
                };
                result.DisplayArray.Add(DisplayObject.UnknownCommand(commandObject.Command));
            }

            // The following statement turns the sound off if the user has muted the sound.
            // However, this sample project does not have real data storage from which to pull
            // the user's preference, so this is commented out for now.
            //
            // if (User.Identity.IsAuthenticated)
            //     if (!currentUser.Sound)
            //         result.DisplayArray.ForEach(x => x.PlaySound = false);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #24
0
        public string JsonSerialize(MessageCommandEnum command, object data)
        {
            CommandObject commandObject = new CommandObject()
            {
                Command = command,
                Data    = data
            };
            var config = new JsonSerializerSettings();

            config.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            return(JsonConvert.SerializeObject(new {
                Command = command,
                Data = data
            }, config));
        }
Exemple #25
0
        public void ExecuteCommand_called_with_UserState_results_in_UserState_set_on_server()
        {
            var    context   = GetContext();
            object userState = "state";
            var    command   = new CommandObject();

            command.ExecuteServerCodeAsunch((o1, e1) =>
            {
                context.Assert.IsNull(e1.Error);
                context.Assert.AreEqual("Executed", e1.Object.AProperty);
                context.Assert.AreEqual(userState, e1.UserState);
                context.Assert.Success();
            }, userState);
            context.Complete();
        }
 public SendKey(String name, int numHost, TaskManager tm, Server server)
 {
     InitializeComponent();
     nameApp.Text        = name;
     numServer           = numHost;
     actualServer        = server;
     commObj             = new CommandObject();
     commObj.Application = name;
     if (numServer > 1)
     {
         CheckPanel.Visibility = Visibility.Visible;
         panelForKey.Margin    = new Thickness(0, 50, 0, 0);
     }
     pageforNewConnection = tm;
     commandList          = new List <Input>();
     commandsField.Focus();
 }
Exemple #27
0
 public override void OnInvoke(CommandObject[] obj)
 {
     if (obj.Length == 2)
     {
         string        dest    = obj[0].GetValue <string>();
         string        src     = obj[1].GetValue <string>();
         CommandObject ptrDest = new CommandObject();
         ptrDest.type     = Program.engine.STRING;
         ptrDest.value    = src;
         ptrDest.IsNull   = false;
         ptrDest.ShowName = dest;
         Program.engine.SetObject(ptrDest);
     }
     else
     {
         Print("用法copys <dest(名称)> <src(名称)>");
     }
 }
        // This method loads the various command modules based on the current user's status.
        private ResultObject InvokeCommand(Context currentContext, CommandObject commandObject)
        {
            MethodInfo   commandMethods;
            Object       commandModule;
            ResultObject result = new ResultObject {
                CurrentContext = currentContext
            };

            if (User.Identity.IsAuthenticated)
            {
                // Load custom role command modules.
                if (User.Identity.Name.ToLower() == "admin")
                {
                    commandModule  = new AdminCommandModule(this, result);
                    commandMethods = typeof(AdminCommandModule).GetMethod(commandObject.Command.ToUpper());
                }
                else
                {
                    commandModule  = new UserCommandModule(this, result);
                    commandMethods = typeof(UserCommandModule).GetMethod(commandObject.Command.ToUpper());
                }
            }
            else
            {
                // Load visitor command module.
                commandModule  = new VisitorCommandModule(this, result);
                commandMethods = typeof(VisitorCommandModule).GetMethod(commandObject.Command.ToUpper());
            }

            // If a command was found, invoke its method. If not, return null.
            if (commandMethods != null)
            {
                result = (ResultObject)commandMethods.Invoke(commandModule, new object[] { commandObject.Args });
            }
            else
            {
                result = null;
            }

            return(result);
        }
Exemple #29
0
 public override void OnInvoke(CommandObject[] obj)
 {
     if (obj.Length != 4)
     {
         Print(Info.HelpText);
         return;
     }
     if (obj[0].type == Program.engine.STRING && !obj[0].IsNull &&
         obj[1].type == Program.engine.STRING && !obj[1].IsNull &&
         obj[2].type == Program.engine.STRING && !obj[1].IsNull &&
         obj[3].type == Program.engine.STRING && !obj[1].IsNull)
     {
         float x = 0f, y = 0f, z = 0f;
         if (!float.TryParse((string)obj[1].value, out x))
         {
             Print("指定的x,y,z参数必须都是表示单精度数字的字符串");
             return;
         }
         if (!float.TryParse((string)obj[2].value, out y))
         {
             Print("指定的x,y,z参数必须都是表示单精度数字的字符串");
             return;
         }
         if (!float.TryParse((string)obj[3].value, out z))
         {
             Print("指定的x,y,z参数必须都是表示单精度数字的字符串");
             return;
         }
         Vector3       vec = new Vector3(x, y, z);
         CommandObject co  = new CommandObject();
         co.type     = typeof(Vector3);
         co.ShowName = (string)obj[0].value;
         co.IsNull   = false;
         co.value    = vec;
         Program.engine.SetObject(co);
     }
     else
     {
         Print(Info.HelpText);
     }
 }
Exemple #30
0
        private void KeyHandler(KeyMessage obj)
        {
            CommandObject  cmd  = this.core.SaveData.commandList[obj.CmdIndex];
            FunctionObject func = this.core.findFunction(cmd.Command);

            if (func == null || string.IsNullOrEmpty(func.Name))
            {
                updateStatus("선택된 명령이 없습니다.");
            }
            else
            {
                try
                {
                    this.runCommand(func);
                    updateStatus(cmd.Command + " 실행.");
                }
                catch (Exception e)
                {
                    updateStatus(cmd.Command + " 실행 실패.");
                }
            }
        }
Exemple #31
0
        public void Process()
        {
            try
            {
                string fisrtMessage = GetMessage();
                if (!fisrtMessage.Contains("Test:Test"))
                {
                    Disconnect();
                    return;
                }
                SendMessage("Hi");
                while (true)
                {
                    string request = GetMessage();
                    if (request.Contains("Quit"))
                    {
                        Disconnect();
                    }
                    if (request != "")
                    {
                        Console.WriteLine("New request: " + request);
                    }

                    CommandObject command  = new CommandObject(request);
                    string        response = cmdHolder.DoCommand(command).Result;
                    SendMessage(response);
                }
            }
            catch (Exception e)
            {
                if (e.HResult == -2146233040)
                {
                    return;
                }
                Disconnect();
                return;
            }
        }
Exemple #32
0
        /// <summary>
        /// The main method to start the program as a service app.
        /// </summary>
        /// <param name="mode">The execution mode to start this service app as.</param>
        protected internal void Start(ExecutionMode mode = ExecutionMode.Default)
        {
            // TODO: rather use a mutex, but if this method gets called more than once, there a bigger problems
            lock (_syncRoot)
            {
                if (this.IsStopped)
                {
                    throw new InvalidOperationException("Cannot start ServiceApp that has already stopped");
                }

                if (!this.IsLoaded)
                {
                    var startupArgs = Environment.CommandLine;
                    this.StartupCommands = this._commandProcessor.Parse(startupArgs);
                    this._commandProcessor.ProcessNonActions(this.StartupCommands);

                    FileLogger.Log("Startup args: " + startupArgs);
                    this.ExecutionMode = mode;

                    EmitSacsVersion();
                    Messages.WriteDebug("Starting {0}. Execution mode: {1}", this.DisplayName, this.ExecutionMode);
                    this.Initialize();
                    this.IsLoaded = true;
                    Messages.WriteState(Enums.State.Started);
                    this._commandProcessor.ProcessActions(this.StartupCommands);
                    this.AwaitCommand();

                    // We will get here after a "stop" command is processed as that will unblock the thread in
                    // AwaitCommand().
                    FinalizeServiceApp();
                }
                else
                {
                    throw new InvalidOperationException("ServiceApp has already started");
                }
            }
        }
Exemple #33
0
        public async Task <IActionResult> Post([FromBody] CommandObject command)
        {
            try
            {
                HttpResult res = await this.simulatorFieldsCommander.HandleNewCommand(command);

                if (res.CommandResult == Result.Ok)
                {
                    return(Ok(res.Message));
                }
                else
                {
                    return(BadRequest(res.Message));
                }
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
 public void ExecuteOn(int commandOnPosition)
 {
     if (PositionOutOfList(commandOnPosition, commandOnList))
     {
         nullCommand.Execute();
         lastCommand = nullCommand;
         lifoCommandList.Add(nullCommand);
         return;
     }
     commandOnList[commandOnPosition].Execute();
     lastCommand = commandOffList[commandOnPosition];
     lifoCommandList.Add(commandOnList[commandOnPosition]);
 }
Exemple #35
0
 public void TestCommandBase()
 {
     Csla.ApplicationContext.GlobalContext.Clear();
     CommandObject obj = new CommandObject();
     Assert.AreEqual("Executed", obj.ExecuteServerCode().AProperty);
 }
 public void ExecuteCommand_called_with_UserState_results_in_UserState_set_on_server()
 {
   var context = GetContext();
   object userState = "state";
   var command = new CommandObject();
   command.ExecuteServerCodeAsunch((o1, e1) =>
                                     {
                                       context.Assert.IsNull(e1.Error);
                                       context.Assert.AreEqual("Executed", e1.Object.AProperty);
                                       context.Assert.AreEqual(userState, e1.UserState);
                                       context.Assert.Success();
                                     }, userState);
   context.Complete();
 }
 public void AddActionOn(CommandObject commandOn)
 {
     commandOnList.Add(commandOn);
 }
Exemple #38
0
 public object Execute(CommandObject command)
 {
     command.Result = true;
       return command;
 }
 public void ExecuteCommand_called_without_UserState_results_in_UserState_defaulted_to_Null_server()
 {
   var context = GetContext();
   var command = new CommandObject();
   command.ExecuteServerCodeAsunch((o1, e1) =>
                                     {
                                       context.Assert.IsNull(e1.Error);
                                       context.Assert.AreEqual("Executed", e1.Object.AProperty);
                                       context.Assert.IsNull(e1.UserState);
                                       context.Assert.Success();
                                     });
   context.Complete();
 }
 public void AddActionOff(CommandObject commandOff)
 {
     commandOffList.Add(commandOff);
 }