Beispiel #1
0
 public GameletMountChecker(IRemoteCommand remoteCommand, IDialogUtil dialogUtil,
                            CancelableTask.Factory cancelableTaskFactory)
 {
     _remoteCommand         = remoteCommand;
     _dialogUtil            = dialogUtil;
     _cancelableTaskFactory = cancelableTaskFactory;
 }
Beispiel #2
0
        private void ExecuteRemoteCommand(IRemoteCommand command)
        {
            Analyzer.Serial.SendPacket(command.GetBytes());

            timer.Restart();

            bool commandExecuted = false;

            while (!commandExecuted)
            {
                if (timer.ElapsedMilliseconds >= timeToWaitResponse)
                {
                    //Logger.Info("[Command executor] - Слишком долгое ожидание ответа от устройства.");

                    Analyzer.Serial.SendPacket(command.GetBytes());

                    timer.Restart();
                }

                if (Protocol.CommandTypes.SIMPLE_COMMAND == command.GetType())
                {
                    commandExecuted = CheckCommandStatus(command,
                                                         CommandStateResponse.CommandStates.COMMAND_EXECUTE_STARTED);
                }
                else if (Protocol.CommandTypes.WAITING_COMMAND == command.GetType())
                {
                    commandExecuted = CheckCommandStatus(command,
                                                         CommandStateResponse.CommandStates.COMMAND_EXECUTE_FINISHED);
                }
            }

            timer.Stop();
        }
Beispiel #3
0
        /// <summary>
        /// Performs the actions on a certain queue item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="doc"></param>
        private void ProcessQueueItem(RevitQueueItem item, Document doc)
        {
            string dllLocation = item.DllLocation;
            string className   = item.ClassName;
            //foreach of those.
            //load the dll with reflection
            Type           type    = LoadDllWithReflection(dllLocation, className);
            IRemoteCommand command = GetCommandFromType(type);

            //Check for transaction attribute, start one if automatic
            Transaction transaction = StartAutomaticTransaction(type, doc);

            //run the execute method
            Result result = command.RunRemotely(doc);

            //close the transaction
            if (transaction != null && result == Result.Succeeded)
            {
                transaction.Commit();
            }

            if (transaction != null && (result == Result.Cancelled || result == Result.Failed))
            {
                transaction.RollBack();
            }

            item.MarkComplete();
        }
        /// <summary>
        /// Builds an HTTP request based on the specified remote Command
        /// </summary>
        /// <param name="command">the command we'll send to the server</param>
        /// <returns>an HTTP request, which will perform this command</returns>
        public virtual WebRequest CreateWebRequest(IRemoteCommand command)
        {
            WebRequest request = WebRequest.Create(BuildCommandString(command.CommandString));

            request.Timeout = Timeout.Infinite;
            return(request);
        }
Beispiel #5
0
        public void DetachClient(IRemoteCommand iClient)
        {
            if (iClient == null)
            {
                return;
            }

            try
            {
                lock (lockObject)
                {
                    if (dicClients.ContainsKey(iClient.Sender))
                    {
                        dicClients.Remove(iClient.Sender);
                    }
                }
                if (UserLogout != null)
                {
                    UserLogout(iClient.Sender);
                }
            }
            catch (Exception ex)
            {
                log.Info(iClient.Sender + "DetachError" + ex.Message);
            }
            finally
            {
            }
        }
Beispiel #6
0
 public RemoteDeploy(IRemoteCommand remoteCommand, IRemoteFile remoteFile,
                     ManagedProcess.Factory managedProcessFactory,
                     IFileSystem fileSystem)
 {
     _remoteCommand         = remoteCommand;
     _remoteFile            = remoteFile;
     _managedProcessFactory = managedProcessFactory;
     _fileSystem            = fileSystem;
 }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        protected void FinishCurrentCommand()
        {
            var temp = m_currentCommand;

            // we delay the remove so we see small file downloads, otherwise it would be dropped instantly (download too fast)
            Dispatcher.DelayInvoke(TimeSpan.FromMilliseconds(2000), () => ViewModelCommands.RemoveItem(temp));
            m_currentCommand = null;
            ExecuteNextCommandIfPossible();
        }
Beispiel #8
0
 public SshManager(IGameletClientFactory gameletClientFactory, ICloudRunner cloudRunner,
                   ISshKeyLoader sshKeyLoader, ISshKnownHostsWriter sshKnownHostsWriter,
                   IRemoteCommand remoteCommand)
 {
     this.gameletClientFactory = gameletClientFactory;
     this.cloudRunner          = cloudRunner;
     this.sshKeyLoader         = sshKeyLoader;
     this.sshKnownHostsWriter  = sshKnownHostsWriter;
     this.remoteCommand        = remoteCommand;
 }
Beispiel #9
0
 public bool TryMerge(IRemoteCommand other, out IRemoteCommand?mergedCommand)
 {
     if (other is CreatureTemplateReloadRemoteCommand remoteCommand)
     {
         var merged = entries.Union(remoteCommand.entries).ToArray();
         mergedCommand = new CreatureTemplateReloadRemoteCommand(merged);
         return(true);
     }
     mergedCommand = null;
     return(false);
 }
Beispiel #10
0
 public void Register(IRemoteCommand command)
 {
     if (this.State != CommunicationState.Opened)
     {
         Debug.WriteLine("Can not regisger command, Remote Command Communication Error!", "Error");
         return;
     }
     commandManager.Add(command);
     Channel.Register(command.ID, command.UIType, command.UIData);
     //ThreadPool.QueueUserWorkItem((o)=>Channel.Register(command.ID, command.UIType, command.UIData));
 }
Beispiel #11
0
        /// <summary>
        /// Gets the command from type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private IRemoteCommand GetCommandFromType(Type type)
        {
            IRemoteCommand command = Activator.CreateInstance(type) as IRemoteCommand;

            if (command == null)
            {
                throw new Exception("Could not get Remote Command");
            }

            return(command);
        }
Beispiel #12
0
        public async Task <string> ExecuteCommand(IRemoteCommand command)
        {
            if (trinitySoapClient == null)
            {
                return("");
            }

            var response = await trinitySoapClient.ExecuteCommand(command.GenerateCommand());

            return(response.Message);
        }
Beispiel #13
0
        public bool TryMerge(IRemoteCommand other, out IRemoteCommand?mergedCommand)
        {
            mergedCommand = null;
            if (other is ReloadRemoteCommand same && same.remoteCommand == remoteCommand)
            {
                mergedCommand = other;
                return(true);
            }

            return(false);
        }
            public bool TryMerge(IRemoteCommand other, out IRemoteCommand mergedCommand)
            {
                mergedCommand = null;
                if (other is MergableCommand mergableCommand)
                {
                    mergedCommand = new MergableCommand(cmd + mergableCommand.cmd);
                    return(true);
                }

                return(false);
            }
Beispiel #15
0
        public void SetUp()
        {
            gameletClient        = Substitute.For <IGameletClient>();
            gameletClientFactory = Substitute.For <GameletClient.Factory>();
            gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(gameletClient);

            cloudRunner         = Substitute.For <ICloudRunner>();
            sshKeyLoader        = Substitute.For <ISshKeyLoader>();
            sshKnownHostsWriter = Substitute.For <ISshKnownHostsWriter>();
            remoteCommand       = Substitute.For <IRemoteCommand>();

            sshManager = new SshManager(gameletClientFactory, cloudRunner, sshKeyLoader,
                                        sshKnownHostsWriter, remoteCommand);
        }
        private ContextMenuStrip GetContextMenuStrip()
        {
            var            notifyContextMenu     = new ContextMenuStrip();
            bool           hasConfiguredCommands = false;
            IRemoteCommand previous = null;

            foreach (IRemoteCommand command in _commandsManager.Cast <IRemoteCommand>().OrderBy(c => c.GetType().ToString()))
            {
                if (command.Configured)
                {
                    if (previous != null && !string.Equals(previous.GetType().ToString(), command.GetType().ToString()))
                    {
                        notifyContextMenu.Items.Add("-");
                    }
                    var commandButton = new ToolStripMenuItem(command.CommandTitle)
                    {
                        Image = command.TrayIcon
                    };
                    commandButton.Click += (s, e) => command.RunCommand();
                    notifyContextMenu.Items.Add(commandButton);
                    hasConfiguredCommands = true;
                    previous = command;
                }
            }
            if (hasConfiguredCommands)
            {
                notifyContextMenu.Items.Add("-");
            }

            var settings = new ToolStripMenuItem("Settings")
            {
                Image = Resources.Settings.ToBitmap()
            };

            settings.Click += SettingsClick;
            notifyContextMenu.Items.Add(settings);

            notifyContextMenu.Items.Add("-");

            var exit = new ToolStripMenuItem("Exit")
            {
                Image = Resources.Exit.ToBitmap()
            };

            exit.Click += Exit;
            notifyContextMenu.Items.Add(exit);

            return(notifyContextMenu);
        }
        /// <summary>
        /// Builds an HTTP request based on the specified remote Command
        /// </summary>
        /// <param name="command">the command we'll send to the server</param>
        /// <returns>an HTTP request, which will perform this command</returns>
        public virtual WebRequest CreateWebRequest(IRemoteCommand command)
        {
            byte[] data = BuildCommandPostData(command.CommandString);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            request.Timeout     = Timeout.Infinite;

            Stream rs = request.GetRequestStream();

            rs.Write(data, 0, data.Length);
            rs.Close();

            return(request);
        }
Beispiel #18
0
        public DateTime Ping(IRemoteCommand iClient)
        {
            if (iClient == null)
            {
                return(DateTime.MinValue);
            }
            string s = iClient.Sender;

            if (s != null)
            {
                return(DateTime.Now);
            }
            else
            {
                return(DateTime.MinValue);
            }
        }
Beispiel #19
0
 public GameletSelectorLegacyFlow(
     IDialogUtil dialogUtil, ICloudRunner runner,
     InstanceSelectionWindow.Factory gameletSelectionWindowFactory,
     CancelableTask.Factory cancelableTaskFactory,
     IGameletClientFactory gameletClientFactory, ISshManager sshManager,
     IRemoteCommand remoteCommand, ActionRecorder actionRecorder)
 {
     _dialogUtil = dialogUtil;
     _runner     = runner;
     _gameletSelectionWindowFactory = gameletSelectionWindowFactory;
     _cancelableTaskFactory         = cancelableTaskFactory;
     _gameletClientFactory          = gameletClientFactory;
     _sshManager    = sshManager;
     _remoteCommand = remoteCommand;
     _mountChecker  =
         new GameletMountChecker(remoteCommand, dialogUtil, cancelableTaskFactory);
     _actionRecorder = actionRecorder;
 }
Beispiel #20
0
 public GameletSelectorFactory(IDialogUtil dialogUtil, ICloudRunner runner,
                               InstanceSelectionWindow.Factory gameletSelectionWindowFactory,
                               CancelableTask.Factory cancelableTaskFactory,
                               IGameletClientFactory gameletClientFactory,
                               ISshManager sshManager, IRemoteCommand remoteCommand,
                               IGameLaunchBeHelper gameLaunchBeHelper,
                               JoinableTaskContext taskContext)
 {
     _dialogUtil = dialogUtil;
     _runner     = runner;
     _gameletSelectionWindowFactory = gameletSelectionWindowFactory;
     _cancelableTaskFactory         = cancelableTaskFactory;
     _gameletClientFactory          = gameletClientFactory;
     _sshManager         = sshManager;
     _remoteCommand      = remoteCommand;
     _gameLaunchBeHelper = gameLaunchBeHelper;
     _taskContext        = taskContext;
 }
 public GameletSelector(IDialogUtil dialogUtil, ICloudRunner runner,
                        InstanceSelectionWindow.Factory gameletSelectionWindowFactory,
                        CancelableTask.Factory cancelableTaskFactory,
                        IGameletClientFactory gameletClientFactory, ISshManager sshManager,
                        IRemoteCommand remoteCommand, IGameLaunchBeHelper gameLaunchBeHelper,
                        JoinableTaskContext taskContext, ActionRecorder actionRecorder)
 {
     _dialogUtil = dialogUtil;
     _runner     = runner;
     _gameletSelectionWindowFactory = gameletSelectionWindowFactory;
     _cancelableTaskFactory         = cancelableTaskFactory;
     _gameletClientFactory          = gameletClientFactory;
     _sshManager    = sshManager;
     _remoteCommand = remoteCommand;
     _mountChecker  =
         new GameletMountChecker(remoteCommand, dialogUtil, cancelableTaskFactory);
     _gameLaunchBeHelper = gameLaunchBeHelper;
     _taskContext        = taskContext;
     _actionRecorder     = actionRecorder;
 }
Beispiel #22
0
        public bool AttachClient(IRemoteCommand iClient)
        {
            if (iClient == null)
            {
                return(false);
            }
            IRemoteCommand iPreviousClient = null;

            try
            {
                lock (lockObject)
                {
                    if (dicClients.ContainsKey(iClient.Sender))
                    {
                        iPreviousClient = dicClients[iClient.Sender];
                        dicClients.Remove(iClient.Sender);
                    }
                    dicClients.Add(iClient.Sender, iClient);
                }
                if (UserLogin != null)
                {
                    UserLogin(iClient.Sender);
                }
            }
            catch (Exception ex)
            {
                log.Info(iClient.Sender + "登录时发生错误", ex);
                return(false);
            }
            try
            {
                if (iPreviousClient != null)
                {
                    iPreviousClient.LogOff();
                }
            }
            catch
            {
            }
            return(true);
        }
Beispiel #23
0
        public RemoteMuxCommandBuilder(String Command, IList <TunerController> tunerController) : base(Command)
        {
            IRemoteCommand myCommand = null;

            if (String.IsNullOrEmpty(Command))
            {
                throw new ArgumentNullException("Command is null");
            }
            var parts = Command.Split(' ');

            if (parts.Length < 3)
            {
                throw new ArgumentException("Invalid number of arguments!");
            }
            var cmd = new MuxControlCommand();

            // Parse MUX id args...
            int muxId;

            if (!int.TryParse(parts[1], out muxId))
            {
                throw new ArgumentException($"Unexpected MuxId value '{parts[1]}'!");
            }
            cmd.MuxId = muxId;

            // Parse action arg...
            try
            {
                cmd.Action = (MuxControlCommand.Mux_action)Enum.Parse(typeof(MuxControlCommand.Mux_action), parts[2], true);
            }
            catch (Exception)
            {
                throw new ArgumentException($"Unexpected ACTION value '{parts[2]}'!");
            }

            cmd.TunnerController = tunerController;
            myCommand            = cmd;

            this.Command = myCommand;
        }
Beispiel #24
0
        /// <summary>
        /// commands are special job that contains a single task and cab be run only by administrators
        /// A command job is not scheduled (it runs immediately)
        /// </summary>
        /// <param name="commandLine">the command to execute</param>
        /// <param name="info">provides additional property values used by command. if no additional property values, set to null</param>
        /// <param name="nodes">indentify the nodes on which the command will run.</param>
        /// <param name="userName">the name of the runas user, in the form domain\username</param>
        /// <param name="password">the password for the runas user</param>
        public void CreateCommand(string commandLine, ICommandInfo info, IStringCollection nodes, string userName, string password)
        {
            if (UserPrivilege.Admin != _scheduler.GetUserPrivilege())
            {
                return;
            }

            manualReset.Reset();

            //create the command
            IRemoteCommand command = _scheduler.CreateCommand(commandLine, info, nodes);

            //subscribe to one or more events before starting the command
            command.OnCommandJobState  += OnJobStateCallback;
            command.OnCommandTaskState += OnCommandTaskStateCallback;
            command.OnCommandOutput    += OnCommandOutputCallback;
            command.OnCommandRawOutput += OnCommandRawOutputCallback;

            command.StartWithCredentials(userName, password);

            manualReset.WaitOne();
        }
Beispiel #25
0
        /// <summary>
        ///
        /// </summary>
        protected void ExecuteNextCommandIfPossible()
        {
            if (m_currentCommand != null)
            {
                return;
            }

            if (m_pendingCommands.Count == 0)
            {
                return;
            }

            m_currentCommand = m_pendingCommands.Dequeue();
            if (IsCommandCancelled(m_currentCommand.Id))
            {
                m_currentCommand = null;
                ExecuteNextCommandIfPossible();
            }
            else
            {
                m_currentCommand.DoExecute();
            }
        }
 public void SetUp()
 {
     _remoteCommand = Substitute.For <IRemoteCommand>();
     _dialogUtil.ShowYesNo(Arg.Any <string>(), Arg.Any <string>()).Returns(false);
     _actionRecorder = new ActionRecorder(Substitute.For <IMetrics>());
 }
 internal void Add(IRemoteCommand command)
 {
     _commands.Add(command.ID, command);
 }
 /// <summary>
 /// Builds an HTTP request based on the specified remote Command
 /// </summary>
 /// <param name="command">the command we'll send to the server</param>
 /// <returns>an HTTP request, which will perform this command</returns>
 public virtual WebRequest CreateWebRequest(IRemoteCommand command)
 {
     WebRequest request = WebRequest.Create(BuildCommandString(command.CommandString));
     request.Timeout = Timeout.Infinite;
     return request;
 }
Beispiel #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 protected void AddCommand(IRemoteCommand command)
 {
     m_pendingCommands.Enqueue(command);
     ViewModelCommands.AddItem(command);
     ExecuteNextCommandIfPossible();
 }
        /// <summary>
        /// Builds an HTTP request based on the specified remote Command
        /// </summary>
        /// <param name="command">the command we'll send to the server</param>
        /// <returns>an HTTP request, which will perform this command</returns>
        public virtual WebRequest CreateWebRequest(IRemoteCommand command)
        {
            byte[] data = BuildCommandPostData(command.CommandString);

            HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            request.Timeout = Timeout.Infinite;

            Stream rs = request.GetRequestStream();
            rs.Write(data, 0, data.Length);
            rs.Close();

            return request;
        }
Beispiel #31
0
 public bool TryMerge(IRemoteCommand other, out IRemoteCommand?mergedCommand)
 {
     mergedCommand = Singleton;
     return(true);
 }
Beispiel #32
0
 public Fjärrkontroll(IRemoteCommand upp, IRemoteCommand ner)
 {
     this.upp = upp;
     this.ner = ner;
 }
Beispiel #33
0
 private bool CheckCommandStatus(IRemoteCommand command, CommandStateResponse.CommandStates expectedState)
 {
     return(ExecutedCommandId == command.GetId() && ExecutedCommandState == expectedState);
 }