Exemplo n.º 1
0
        /// <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>
 /// Serializes instance of <typeparamref name="T"/> to file system.
 /// </summary>
 /// <param name="indent">
 /// Contains whether the output uses multiline format.
 /// </param>
 public virtual void SerializeToLocalFile(bool indent = false)
 {
     if (!string.IsNullOrEmpty(TargetFileName))
     {
         JsonSerializer.SingletonInstance.Serialize <T>((T)(object)this, CoreSyncProcessor.GetFullName(TargetFileName), indent);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Executes command functionalities of <see cref="SyncCommand"/>.
 /// </summary>
 protected override void Execute()
 {
     if (Prompt.GetYesNo("Do you want to detach synchronization directory? If no external directory is set, encrypted data will be deleted.", true))
     {
         CoreSyncProcessor.Detach();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Executes command functionalities of <see cref="PassphraseCommand"/>.
 /// </summary>
 protected override void Execute()
 {
     if (GetPassphrase(out string passphrase))
     {
         CoreSyncProcessor.SetPassphrase(passphrase);
     }
 }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Executes command functionalities of <see cref="SyncCommand"/>.
 /// </summary>
 protected override void Execute()
 {
     if (Prompt.GetYesNo("Do you want to reset synchronization directory? If no external directory is set, encrypted data will be deleted. Use 'config' command to change values.", true))
     {
         if (GetPassphrase(out string passphrase))
         {
             CoreSyncProcessor.Reset(passphrase, EncryptedDirectory);
         }
     }
 }
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Executes command functionalities of <see cref="SyncCommand"/>.
        /// </summary>
        protected override void Execute()
        {
            if (!CoreSyncProcessor.IsInitialized())
            {
                if (GetPassphrase(out string passphrase))
                {
                    CoreSyncProcessor.Initialize(passphrase, EncryptedDirectory);
                }
            }
            else
            {
                Console.WriteLine("Error: Working directory already initialized.");

                CommandLineApplication.Execute <ResetCommand>();
            }
        }
Exemplo n.º 9
0
        /// <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);
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Executes command functionalities of <see cref="SyncCommand"/>.
 /// </summary>
 protected override void Execute()
 {
     CoreSyncProcessor.Configure(EncryptedDirectory);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Executes command functionalities of <see cref="SyncCommand"/>.
 /// </summary>
 protected override void Execute() => CoreSyncProcessor.Synchronize(SubdirectoryPath);