/// <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}"); } } }
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 } }
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])); } }
protected SessionHostConfigurationBase(VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, SessionHostsStartInfo sessionHostsStartInfo) { _logger = logger; VmConfiguration = vmConfiguration; _systemOperations = systemOperations; _sessionHostsStartInfo = sessionHostsStartInfo; }
public AdminViewModel(ISystemOperations salesService) { _userService = salesService; Users = new ObservableCollection <UserEntity>(); ReloadServiceContextAsync() .Wait(); }
internal ActiveSession(ISystemOperations so, ISession session, ISessionSettings sessionSettings) { _so = so; _session = session; _sessionSettings = sessionSettings; _tempFolder = new VbaTemporaryFolder(so); _repositoryFolder = new VbaRepositoryFolder(so, session, sessionSettings); }
protected BaseSessionHostRunner( VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations) { _logger = logger; _vmConfiguration = vmConfiguration; _systemOperations = systemOperations; }
public ProcessRunner( VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, IProcessWrapper processWrapper = null) : base(vmConfiguration, logger, systemOperations) { _processWrapper = processWrapper; }
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; }
public MultiplayerServerManager( ISystemOperations systemOperations, VmConfiguration vmConfiguration, MultiLogger logger, ISessionHostRunnerFactory sessionHostRunnerFactory) { _sessionHostRunnerFactory = sessionHostRunnerFactory; _systemOperations = systemOperations; _logger = logger; _vmConfiguration = vmConfiguration; }
public ProcessRunner( VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, IProcessWrapper processWrapper = null) { _logger = logger; _vmConfiguration = vmConfiguration; _systemOperations = systemOperations; _processWrapper = processWrapper; }
public LoginAndRegistrationViewModel(ISystemOperations systemOperations, SignInViewModel signIn, RegistrationViewModel registration) { _registration = registration; _sighInUser = signIn; _systemOperations = systemOperations; Users = new ObservableCollection <UserEntity>(); ReloadUsersAsync() .Wait(); }
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); }
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); } }
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)); } } }
internal VbaRepositoryFolder(ISystemOperations so, ISession session, ISessionSettings settings) : base(so, session.FolderPath) { _settings = settings; _so = so; }
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); }
public SyncStepExecution(ISystemOperations systemOperations) { this.systemOperations = systemOperations; }
protected internal VbaFolder(ISystemOperations so, string folderPath) { _so = so; FolderPath = folderPath; }
public AdminPageViewModel(ISystemOperations salesService) { UsersContext = new AdminViewModel(salesService); }
internal Hook(ISystemOperations so, string content) { _so = so; Content = content; }
public SessionHostProcessConfiguration(VmConfiguration vmConfiguration, MultiLogger logger, ISystemOperations systemOperations, SessionHostsStartInfo sessionHostsStartInfo) : base(vmConfiguration, logger, systemOperations, sessionHostsStartInfo) { }
public BasicAssetExtractor(ISystemOperations systemOperations = null, MultiLogger logger = null) { _systemOperations = systemOperations; _logger = logger; }