コード例 #1
0
ファイル: TaskUtil.cs プロジェクト: jseward/MpsAgent
        /// <summary>
        /// Runs the specified action periodically (including amidst exceptions) until explicitly cancelled.
        /// </summary>
        /// <param name="action">The operation to perform periodically.</param>
        /// <param name="systemOperations"></param>
        /// <param name="intervalBetweenRuns">Delay between performing the operation (if the operation completes or if there is an exception).</param>
        /// <param name="cancellationToken">Mostly used for unit testing.</param>
        /// <returns></returns>
        public static async Task RunUntilCancelled(
            Func <Task> action,
            ISystemOperations systemOperations,
            TimeSpan intervalBetweenRuns,
            CancellationToken cancellationToken,
            MultiLogger logger)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    await action();
                }
                catch (Exception e)
                {
                    logger.LogException(e);
                }

                try
                {
                    await systemOperations.Delay((int)intervalBetweenRuns.TotalMilliseconds, cancellationToken);
                }
                catch (TaskCanceledException ex)
                {
                    logger.LogInformation($"{nameof(RunUntilCancelled)} stopped with {nameof(TaskCanceledException)}: {ex}");
                }
            }
        }
コード例 #2
0
        internal static Patch GetProjectPatch(ISystemOperations so, ISession session, string evfPath)
        {
            var folderIniPath = so.PathCombine(session.FolderPath, "Project.ini");
            var fileIniPath   = so.PathCombine(evfPath, "Project.ini");
            var folderHasIni  = so.FileExists(folderIniPath);
            var fileHasIni    = so.FileExists(fileIniPath);

            if (folderHasIni && fileHasIni)
            {
                if (session.Action == ActionType.Extract)
                {
                    return(Patch.MakeProjectChange(so.FileReadAllText(folderIniPath, Encoding.UTF8), so.FileReadAllText(fileIniPath, Encoding.UTF8)));
                }
                else
                {
                    return(Patch.MakeProjectChange(so.FileReadAllText(fileIniPath, Encoding.UTF8), so.FileReadAllText(folderIniPath, Encoding.UTF8)));
                }
            }
            else if (!folderHasIni && !fileHasIni)
            {
                return(null);
            }
            else if (session.Action == ActionType.Extract ? !folderHasIni : !fileHasIni)
            {
                return(Patch.MakeInsertion("Project", ModuleType.Ini, so.FileReadAllText(session.Action == ActionType.Extract ? fileIniPath : folderIniPath, Encoding.UTF8)));
            }
            else
            {
                return(null); // never suggest deleting Project.INI
            }
        }
コード例 #3
0
        internal static Patch GetLicensesPatch(ISystemOperations so, ISession session, string evfPath)
        {
            var folderLicensesPath = so.PathCombine(session.FolderPath, "LicenseKeys.bin");
            var fileLicensesPath   = so.PathCombine(evfPath, "LicenseKeys.bin");
            var folderHasLicenses  = so.FileExists(folderLicensesPath);
            var fileHasLicenses    = so.FileExists(fileLicensesPath);

            if (folderHasLicenses && fileHasLicenses)
            {
                if (session.Action == ActionType.Extract)
                {
                    return(Patch.MakeLicensesChange(so.FileReadAllBytes(folderLicensesPath), so.FileReadAllBytes(fileLicensesPath)));
                }
                else
                {
                    return(Patch.MakeLicensesChange(so.FileReadAllBytes(fileLicensesPath), so.FileReadAllBytes(folderLicensesPath)));
                }
            }
            else if (!folderHasLicenses && !fileHasLicenses)
            {
                return(null);
            }
            else if (session.Action == ActionType.Extract ? !folderHasLicenses : !fileHasLicenses)
            {
                return(Patch.MakeLicensesChange(new byte[0], so.FileReadAllBytes(session.Action == ActionType.Extract ? fileLicensesPath : folderLicensesPath)));
            }
            else
            {
                return(Patch.MakeLicensesChange(so.FileReadAllBytes(session.Action == ActionType.Extract ? folderLicensesPath : fileLicensesPath), new byte[0]));
            }
        }
コード例 #4
0
 protected SessionHostConfigurationBase(VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, SessionHostsStartInfo sessionHostsStartInfo)
 {
     _logger                = logger;
     VmConfiguration        = vmConfiguration;
     _systemOperations      = systemOperations;
     _sessionHostsStartInfo = sessionHostsStartInfo;
 }
コード例 #5
0
        public AdminViewModel(ISystemOperations salesService)
        {
            _userService = salesService;
            Users        = new ObservableCollection <UserEntity>();

            ReloadServiceContextAsync()
            .Wait();
        }
コード例 #6
0
ファイル: ActiveSession.cs プロジェクト: RayCulp/VCS-VBASync
 internal ActiveSession(ISystemOperations so, ISession session, ISessionSettings sessionSettings)
 {
     _so               = so;
     _session          = session;
     _sessionSettings  = sessionSettings;
     _tempFolder       = new VbaTemporaryFolder(so);
     _repositoryFolder = new VbaRepositoryFolder(so, session, sessionSettings);
 }
コード例 #7
0
 protected BaseSessionHostRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations)
 {
     _logger           = logger;
     _vmConfiguration  = vmConfiguration;
     _systemOperations = systemOperations;
 }
コード例 #8
0
ファイル: ProcessRunner.cs プロジェクト: PlayFab/MpsAgent
 public ProcessRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations,
     IProcessWrapper processWrapper = null)
     : base(vmConfiguration, logger, systemOperations)
 {
     _processWrapper = processWrapper;
 }
コード例 #9
0
        internal static IEnumerable <Patch> GetModulePatches(ISystemOperations so, ISession session, ISessionSettings sessionSettings,
                                                             ILocateModules folderModuleLocator, IList <KeyValuePair <string, Tuple <string, ModuleType> > > folderModules,
                                                             ILocateModules fileModuleLocator, IList <KeyValuePair <string, Tuple <string, ModuleType> > > fileModules)
        {
            IList <KeyValuePair <string, Tuple <string, ModuleType> > > oldModules;
            IList <KeyValuePair <string, Tuple <string, ModuleType> > > newModules;
            ILocateModules oldModuleLocator;
            ILocateModules newModuleLocator;

            if (session.Action == ActionType.Extract)
            {
                oldModules       = folderModules;
                newModules       = fileModules;
                oldModuleLocator = folderModuleLocator;
                newModuleLocator = fileModuleLocator;
            }
            else
            {
                oldModules       = fileModules;
                newModules       = folderModules;
                oldModuleLocator = fileModuleLocator;
                newModuleLocator = folderModuleLocator;
            }

            if (sessionSettings.IgnoreEmpty)
            {
                oldModules = oldModules.Where(kvp => ModuleProcessing.HasCode(kvp.Value.Item1)).ToList();
                newModules = newModules.Where(kvp => ModuleProcessing.HasCode(kvp.Value.Item1)).ToList();
            }

            // find modules which aren't in both lists and record them as new/deleted
            var patches = new List <Patch>();

            patches.AddRange(GetDeletedModuleChanges(oldModules, newModules, session.Action, sessionSettings.DeleteDocumentsFromFile));
            patches.AddRange(GetNewModuleChanges(oldModules, newModules, session.Action, sessionSettings.AddNewDocumentsToFile));

            // this also filters the new/deleted modules from the last step
            var sideBySide = (from o in oldModules
                              join n in newModules on o.Key equals n.Key
                              select new SideBySideArgs {
                Name = o.Key,
                OldType = o.Value.Item2,
                NewType = n.Value.Item2,
                OldText = o.Value.Item1,
                NewText = n.Value.Item1
            }).ToArray();

            patches.AddRange(GetFrxChanges(so, oldModuleLocator, newModuleLocator, sideBySide.Where(x => x.NewType == ModuleType.Form).Select(x => x.Name)));
            sideBySide = sideBySide.Where(sxs => sxs.OldText != sxs.NewText).ToArray();
            foreach (var sxs in sideBySide)
            {
                patches.AddRange(Patch.CompareSideBySide(sxs));
            }

            return(patches);
        }
コード例 #10
0
        public MultiplayerSettingsValidator(MultiplayerSettings settings, ISystemOperations systemOperations = null)
        {
            if (settings == null)
            {
                throw new ArgumentException("Settings cannot be null");
            }
            _settings = settings;

            _systemOperations = systemOperations ?? SystemOperations.Default;
        }
コード例 #11
0
 public MultiplayerServerManager(
     ISystemOperations systemOperations,
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISessionHostRunnerFactory sessionHostRunnerFactory)
 {
     _sessionHostRunnerFactory = sessionHostRunnerFactory;
     _systemOperations         = systemOperations;
     _logger          = logger;
     _vmConfiguration = vmConfiguration;
 }
コード例 #12
0
ファイル: ProcessRunner.cs プロジェクト: jseward/MpsAgent
 public ProcessRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations,
     IProcessWrapper processWrapper = null)
 {
     _logger           = logger;
     _vmConfiguration  = vmConfiguration;
     _systemOperations = systemOperations;
     _processWrapper   = processWrapper;
 }
コード例 #13
0
        public LoginAndRegistrationViewModel(ISystemOperations systemOperations,
                                             SignInViewModel signIn,
                                             RegistrationViewModel registration)
        {
            _registration     = registration;
            _sighInUser       = signIn;
            _systemOperations = systemOperations;
            Users             = new ObservableCollection <UserEntity>();

            ReloadUsersAsync()
            .Wait();
        }
コード例 #14
0
 public MultiplayerServerManager(
     ISystemOperations systemOperations,
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISessionHostRunnerFactory sessionHostRunnerFactory,
     BasicAssetExtractor basicAssetExtractor = null)
 {
     _sessionHostRunnerFactory = sessionHostRunnerFactory;
     _systemOperations         = systemOperations;
     _logger              = logger;
     _vmConfiguration     = vmConfiguration;
     _basicAssetExtractor = new BasicAssetExtractor(_systemOperations, _logger);
 }
コード例 #15
0
 internal static bool FrxFilesAreDifferent(ISystemOperations so, string frxPath1, string frxPath2, out string explain)
 {
     try
     {
         var frxBytes1 = so.FileReadAllBytes(frxPath1);
         var frxBytes2 = so.FileReadAllBytes(frxPath2);
         using (var frxCfStream1 = new MemoryStream(frxBytes1, 24, frxBytes1.Length - 24, false))
             using (var frxCfStream2 = new MemoryStream(frxBytes2, 24, frxBytes2.Length - 24, false))
                 using (var cf1 = new CompoundFile(frxCfStream1))
                     using (var cf2 = new CompoundFile(frxCfStream2))
                     {
                         return(CfStoragesAreDifferent(cf1.RootStorage, cf2.RootStorage, out explain));
                     }
     }
     catch (Exception ex)
     {
         explain = ex.Message;
         return(true);
     }
 }
コード例 #16
0
 private static IEnumerable <Patch> GetFrxChanges(ISystemOperations fo, ILocateModules oldModuleLocator,
                                                  ILocateModules newModuleLocator, IEnumerable <string> frmModules)
 {
     foreach (var modName in frmModules)
     {
         var oldFrxPath = oldModuleLocator.GetFrxPath(modName);
         var newFrxPath = newModuleLocator.GetFrxPath(modName);
         if (string.IsNullOrEmpty(oldFrxPath) && string.IsNullOrEmpty(newFrxPath))
         {
         }
         else if (!string.IsNullOrEmpty(oldFrxPath) && string.IsNullOrEmpty(newFrxPath))
         {
             yield return(Patch.MakeFrxDeletion(modName));
         }
         else if (string.IsNullOrEmpty(oldFrxPath) && !string.IsNullOrEmpty(newFrxPath))
         {
             yield return(Patch.MakeFrxChange(modName));
         }
         else if (FrxFilesAreDifferent(fo, oldFrxPath, newFrxPath, out var explain))
         {
             yield return(Patch.MakeFrxChange(modName));
         }
     }
 }
コード例 #17
0
 internal VbaRepositoryFolder(ISystemOperations so, ISession session, ISessionSettings settings) : base(so, session.FolderPath)
 {
     _settings = settings;
     _so       = so;
 }
コード例 #18
0
 public PlanExecutionHelper(IAppServiceProvider serviceProvider, ISystemOperations systemOperations)
 {
     this.serviceProvider  = serviceProvider;
     this.systemOperations = systemOperations;
 }
コード例 #19
0
 public LogInAndRegistrationPageViewModel(ISystemOperations _systemOperations,
                                          SignInViewModel sign,
                                          RegistrationViewModel registration)
 {
     SystemOperationsContext = new LoginAndRegistrationViewModel(_systemOperations, sign, registration);
 }
コード例 #20
0
 public SyncStepExecution(ISystemOperations systemOperations)
 {
     this.systemOperations = systemOperations;
 }
コード例 #21
0
 protected internal VbaFolder(ISystemOperations so, string folderPath)
 {
     _so        = so;
     FolderPath = folderPath;
 }
コード例 #22
0
 public AdminPageViewModel(ISystemOperations salesService)
 {
     UsersContext = new AdminViewModel(salesService);
 }
コード例 #23
0
ファイル: Hook.cs プロジェクト: RayCulp/VCS-VBASync
 internal Hook(ISystemOperations so, string content)
 {
     _so     = so;
     Content = content;
 }
コード例 #24
0
 public SessionHostProcessConfiguration(VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, SessionHostsStartInfo sessionHostsStartInfo)
     : base(vmConfiguration, logger, systemOperations, sessionHostsStartInfo)
 {
 }
コード例 #25
0
 public BasicAssetExtractor(ISystemOperations systemOperations = null, MultiLogger logger = null)
 {
     _systemOperations = systemOperations;
     _logger           = logger;
 }