Ejemplo n.º 1
0
        /// <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}");
                }
            }
        }
Ejemplo n.º 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
            }
        }
Ejemplo n.º 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]));
            }
        }
Ejemplo n.º 4
0
 protected SessionHostConfigurationBase(VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, SessionHostsStartInfo sessionHostsStartInfo)
 {
     _logger                = logger;
     VmConfiguration        = vmConfiguration;
     _systemOperations      = systemOperations;
     _sessionHostsStartInfo = sessionHostsStartInfo;
 }
Ejemplo n.º 5
0
        public AdminViewModel(ISystemOperations salesService)
        {
            _userService = salesService;
            Users        = new ObservableCollection <UserEntity>();

            ReloadServiceContextAsync()
            .Wait();
        }
Ejemplo n.º 6
0
 internal ActiveSession(ISystemOperations so, ISession session, ISessionSettings sessionSettings)
 {
     _so               = so;
     _session          = session;
     _sessionSettings  = sessionSettings;
     _tempFolder       = new VbaTemporaryFolder(so);
     _repositoryFolder = new VbaRepositoryFolder(so, session, sessionSettings);
 }
Ejemplo n.º 7
0
 protected BaseSessionHostRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations)
 {
     _logger           = logger;
     _vmConfiguration  = vmConfiguration;
     _systemOperations = systemOperations;
 }
Ejemplo n.º 8
0
 public ProcessRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations,
     IProcessWrapper processWrapper = null)
     : base(vmConfiguration, logger, systemOperations)
 {
     _processWrapper = processWrapper;
 }
Ejemplo n.º 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);
        }
        public MultiplayerSettingsValidator(MultiplayerSettings settings, ISystemOperations systemOperations = null)
        {
            if (settings == null)
            {
                throw new ArgumentException("Settings cannot be null");
            }
            _settings = settings;

            _systemOperations = systemOperations ?? SystemOperations.Default;
        }
Ejemplo n.º 11
0
 public MultiplayerServerManager(
     ISystemOperations systemOperations,
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISessionHostRunnerFactory sessionHostRunnerFactory)
 {
     _sessionHostRunnerFactory = sessionHostRunnerFactory;
     _systemOperations         = systemOperations;
     _logger          = logger;
     _vmConfiguration = vmConfiguration;
 }
Ejemplo n.º 12
0
 public ProcessRunner(
     VmConfiguration vmConfiguration,
     MultiLogger logger,
     ISystemOperations systemOperations,
     IProcessWrapper processWrapper = null)
 {
     _logger           = logger;
     _vmConfiguration  = vmConfiguration;
     _systemOperations = systemOperations;
     _processWrapper   = processWrapper;
 }
Ejemplo n.º 13
0
        public LoginAndRegistrationViewModel(ISystemOperations systemOperations,
                                             SignInViewModel signIn,
                                             RegistrationViewModel registration)
        {
            _registration     = registration;
            _sighInUser       = signIn;
            _systemOperations = systemOperations;
            Users             = new ObservableCollection <UserEntity>();

            ReloadUsersAsync()
            .Wait();
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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));
         }
     }
 }
Ejemplo n.º 17
0
 internal VbaRepositoryFolder(ISystemOperations so, ISession session, ISessionSettings settings) : base(so, session.FolderPath)
 {
     _settings = settings;
     _so       = so;
 }
Ejemplo n.º 18
0
 public PlanExecutionHelper(IAppServiceProvider serviceProvider, ISystemOperations systemOperations)
 {
     this.serviceProvider  = serviceProvider;
     this.systemOperations = systemOperations;
 }
 public LogInAndRegistrationPageViewModel(ISystemOperations _systemOperations,
                                          SignInViewModel sign,
                                          RegistrationViewModel registration)
 {
     SystemOperationsContext = new LoginAndRegistrationViewModel(_systemOperations, sign, registration);
 }
Ejemplo n.º 20
0
 public SyncStepExecution(ISystemOperations systemOperations)
 {
     this.systemOperations = systemOperations;
 }
Ejemplo n.º 21
0
 protected internal VbaFolder(ISystemOperations so, string folderPath)
 {
     _so        = so;
     FolderPath = folderPath;
 }
Ejemplo n.º 22
0
 public AdminPageViewModel(ISystemOperations salesService)
 {
     UsersContext = new AdminViewModel(salesService);
 }
Ejemplo n.º 23
0
 internal Hook(ISystemOperations so, string content)
 {
     _so     = so;
     Content = content;
 }
Ejemplo n.º 24
0
 public SessionHostProcessConfiguration(VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, SessionHostsStartInfo sessionHostsStartInfo)
     : base(vmConfiguration, logger, systemOperations, sessionHostsStartInfo)
 {
 }
Ejemplo n.º 25
0
 public BasicAssetExtractor(ISystemOperations systemOperations = null, MultiLogger logger = null)
 {
     _systemOperations = systemOperations;
     _logger           = logger;
 }