protected override void ProcessRecord() { var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); WriteObject(settings.DefaultJournalRoot); }
protected sealed override void ProcessRecord() { try { if (!string.IsNullOrEmpty(Location)) { Location = ResolvePath(Location); return; } var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); if (string.IsNullOrEmpty(settings.DefaultJournalRoot)) { throw new PSInvalidOperationException(Error); } Location = settings.DefaultJournalRoot; RunJournalCommand(); } catch (Exception e) { Log.Error(e, "Error encountered during ProcessRecord"); throw; } }
protected override void ProcessRecord() { var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); settings.NextUpdateCheck = DateTime.Now.AddDays(Days); settings.Save(encryptedStore); }
protected override void ProcessRecord() { var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); settings.DefaultJournalRoot = Location; settings.Save(encryptedStore); }
private void CheckForUpdates() { ProgressRecord progressRecord = null; try { var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); if (settings.NextUpdateCheck != null && DateTime.Now <= settings.NextUpdateCheck) { return; } progressRecord = new ProgressRecord(0, "Checking For Updates", "This won't take long..."); WriteProgress(progressRecord); var installedVersionResult = ScriptBlock.Create("Get-Module JournalCli -ListAvailable | select version").Invoke(); var installedVersion = (Version)installedVersionResult[0].Properties["Version"].Value; var sb = ScriptBlock.Create("Find-Module JournalCli | select version"); var ps = sb.GetPowerShell(); var result = ps.BeginInvoke(); if (!result.AsyncWaitHandle.WaitOne(12000)) { throw new TimeoutException("Unable to retrieve module update information within 12 seconds."); } var availableVersionsResults = ps.EndInvoke(result).ReadAll(); var availableVersions = availableVersionsResults.Select(x => new Version((string)x.Properties["Version"].Value)).ToList(); var newVersion = availableVersions.FirstOrDefault(x => x.IsBeta() == installedVersion.IsBeta()); if (newVersion > installedVersion) { WriteHostInverted("***** Update Available! *****"); WriteHostInverted($"You're currently using version {installedVersion}. Run 'Update-Module JournalCli' " + $"to upgrade to version {newVersion}, or run 'Suspend-JournalCliUpdateChecks' to snooze these notifications."); } settings.NextUpdateCheck = DateTime.Now.AddDays(7); settings.Save(encryptedStore); } catch (Exception e) { Log.Error(e, "Attempt to perform module update check failed."); } finally { if (progressRecord != null) { progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); } } }
protected override void ProcessRecord() { if (MyInvocation.InvocationName == "Get-DefaultJournalLocation") { WriteWarning("'Get-DefaultJournalLocation' is obsolete and will be removed in a future release. Use 'Get-JournalDefaultLocation' instead."); } var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); WriteObject(settings.DefaultJournalRoot); }
protected override void ProcessRecord() { var fileSystem = new FileSystem(); var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var path = UserSettings.Load(encryptedStore).BackupLocation; if (!string.IsNullOrEmpty(path) && fileSystem.Directory.Exists(path)) { SystemProcess.Start(path); } else { throw new PSInvalidOperationException("Backup location not found"); } }
protected override void RunJournalCommand() { var fileSystem = new FileSystem(); var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var settings = UserSettings.Load(encryptedStore); if (string.IsNullOrWhiteSpace(BackupLocation)) { if (string.IsNullOrWhiteSpace(settings.BackupLocation)) { throw new PSInvalidOperationException("Backup location not provided and no location was previously saved."); } } else { settings.BackupLocation = ResolvePath(BackupLocation); } if (!string.IsNullOrWhiteSpace(Password)) { settings.BackupPassword = Password; } if (SaveParameters) { encryptedStore.Save(settings); } if (!fileSystem.Directory.Exists(settings.BackupLocation)) { fileSystem.Directory.CreateDirectory(settings.BackupLocation); } var fileName = $"{DateTime.Now:yyyy.MM.dd.H.mm.ss.FFF}.zip"; var destinationPath = fileSystem.Path.Combine(settings.BackupLocation, fileName); var zip = new FastZip { CreateEmptyDirectories = true, Password = settings.BackupPassword }; zip.CreateZip(destinationPath, Location, true, null); }
protected override void ProcessRecord() { if (MyInvocation.InvocationName == "Open-BackupLocation") { WriteWarning("'Open-BackupLocation' is obsolete and will be removed in a future release. Use 'Open-JournalBackupLocation' instead."); } var fileSystem = new FileSystem(); var encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); var path = UserSettings.Load(encryptedStore).BackupLocation; if (!string.IsNullOrEmpty(path) && fileSystem.Directory.Exists(path)) { SystemProcess.Start(path); } else { throw new PSInvalidOperationException("Backup location not found"); } }
protected JournalCmdletBase() { _encryptedStore = EncryptedStoreFactory.Create <UserSettings>(); _settings = UserSettings.Load(_encryptedStore); }