/// <summary> /// Raises on execution of <see cref="CommandLineApplication"/> instance. /// </summary> /// <param name="app"> /// Contains instance of <see cref="CommandLineApplication"/>. /// </param> /// <returns> /// Returns exit code for instance of <see cref="CommandLineApplication"/>. /// </returns> protected virtual int OnExecute(CommandLineApplication app) { App = app; if (!string.IsNullOrEmpty(Directory)) { CoreSyncProcessor.WorkingDirectoryPath = CoreSyncProcessor.GetDataDirectory(Directory); } if (CoreSyncProcessor.LogNotification == null) { CoreSyncProcessor.LogNotification += (logEntry) => { Console.WriteLine(logEntry.ToString()); }; } try { if (Valid) { Execute(); } } catch (Exception e) { CoreSyncProcessor.Log(e); } return(0); }
/// <summary> /// Processes synchroniaztion of file system entries of <see cref="CoreSyncRepository"/>. /// </summary> public void ProcessSynchronizationOfFileSystemEntries() { if (CoreSyncConfiguration.SingletonInstance != null) { var sourceHeadEntriesBeforeSync = FilteredHeadEntries.Any(); CoreSyncProcessor.Log("Fetching head entries.", writeLogEntry: false); var encryptedHeadEntries = DataProcessor.GetEntries(CoreSyncConfiguration.SingletonInstance.GetEncryptedDirectory(CoreSyncHeadEntry.DirectoryName), true); if (encryptedHeadEntries.Any()) { CoreSyncHeadEntry.DeleteSourceHeadEntries(encryptedHeadEntries); CoreSyncHeadEntry.DecryptHeadEntries(encryptedHeadEntries); } CoreSyncProcessor.Log("Fetching source entries of file system.", writeLogEntry: false); var fileSystemEntryNames = Directory.GetFileSystemEntries(CoreSyncProcessor.ParentDirectoryPath, "*", SearchOption.AllDirectories) .Where(x => !x.Contains(CoreSyncProcessor.BaseDirectoryName) && CoreSyncConfiguration.IsValidEntryName(x)) .ToList(); CoreSyncHeadEntry.EncryptHeadEntries(encryptedHeadEntries, fileSystemEntryNames); if (sourceHeadEntriesBeforeSync) { CoreSyncHeadEntry.DeleteEncryptedHeadEntries(fileSystemEntryNames); } } else { CoreSyncProcessor.Log("Invalid configuration file.", CoreSyncLogLevel.Error); } }
/// <summary> /// Deletes instance of <typeparamref name="T"/> from file system. /// </summary> /// <param name="withEmptyParentDirectories"> /// Contains whether empty parent directories should be deleted. /// </param> /// <returns> /// Returns whether deltion process succeeded. /// </returns> public virtual bool DeleteInstance(bool withEmptyParentDirectories = false) { try { return(DataProcessor.Delete(TargetFileName, withEmptyParentDirectories)); } catch (Exception e) { CoreSyncProcessor.Log(e); } return(false); }
/// <summary> /// Decrypts instance of <typeparamref name="T"/> from file system. /// </summary> /// <param name="targetFileName"> /// Contains <see cref="string"/> value with target file name. /// </param> /// <param name="passphrase"> /// Contains <see cref="string"/> value with passphrase. /// </param> /// <returns> /// Returns instance of <typeparamref name="T"/>. /// </returns> public static T DecryptInstance(string targetFileName, string passphrase) { if (!string.IsNullOrEmpty(targetFileName)) { try { var configuration = CoreSyncConfiguration.SingletonInstance; return(Deserialize(DataProcessor.Decrypt(targetFileName, passphrase))); } catch (Exception e) { CoreSyncProcessor.Log(e); } } return(default);
/// <summary> /// Encrypts and saves instance of <typeparamref name="T"/> to file system. /// </summary> /// <param name="passphrase"> /// Contains <see cref="string"/> value with passphrase. /// </param> /// <returns> /// Returns whether encryption process succeeded. /// </returns> public virtual bool EncryptInstance(string passphrase) { if (!string.IsNullOrEmpty(TargetFileName)) { try { var configuration = CoreSyncConfiguration.SingletonInstance; return(DataProcessor.Encrypt(base.Serialize(), TargetFileName, passphrase)); } catch (Exception e) { CoreSyncProcessor.Log(e); } } return(false); }