Ejemplo n.º 1
0
        private void SetupCommonOptions(ISetCommonOptions result, ref string[] paths, ref IFilter filter)
        {
            m_options.MainAction = result.MainOperation;
            result.MessageSink   = m_messageSink;

            switch (m_options.MainAction)
            {
            case OperationMode.Backup:
                break;

            default:
                //It only makes sense to enable auto-creation if we are writing files.
                if (!m_options.RawOptions.ContainsKey("disable-autocreate-folder"))
                {
                    m_options.RawOptions["disable-autocreate-folder"] = "true";
                }
                break;
            }

            //Load all generic modules
            m_options.LoadedModules.Clear();

            foreach (Library.Interface.IGenericModule m in DynamicLoader.GenericLoader.Modules)
            {
                m_options.LoadedModules.Add(new KeyValuePair <bool, Library.Interface.IGenericModule>(Array.IndexOf <string>(m_options.DisableModules, m.Key.ToLower()) < 0 && (m.LoadAsDefault || Array.IndexOf <string>(m_options.EnableModules, m.Key.ToLower()) >= 0), m));
            }

            // Make the filter read-n-write able in the generic modules
            var pristinefilter = string.Join(System.IO.Path.PathSeparator.ToString(), FilterExpression.Serialize(filter));

            m_options.RawOptions["filter"] = pristinefilter;

            // Store the URL connection options separately, as these should only be visible to modules implementing IConnectionModule
            var conopts = new Dictionary <string, string>(m_options.RawOptions);
            var qp      = new Library.Utility.Uri(m_backend).QueryParameters;

            foreach (var k in qp.Keys)
            {
                conopts[(string)k] = qp[(string)k];
            }

            foreach (var mx in m_options.LoadedModules)
            {
                if (mx.Key)
                {
                    if (mx.Value is Library.Interface.IConnectionModule)
                    {
                        mx.Value.Configure(conopts);
                    }
                    else
                    {
                        mx.Value.Configure(m_options.RawOptions);
                    }

                    if (mx.Value is Library.Interface.IGenericSourceModule)
                    {
                        var sourcemodule = (Library.Interface.IGenericSourceModule)mx.Value;

                        if (sourcemodule.ContainFilesForBackup(paths))
                        {
                            var sourceoptions = sourcemodule.ParseSourcePaths(ref paths, ref pristinefilter, m_options.RawOptions);

                            foreach (var sourceoption in sourceoptions)
                            {
                                m_options.RawOptions[sourceoption.Key] = sourceoption.Value;
                            }
                        }
                    }

                    if (mx.Value is Library.Interface.IGenericCallbackModule)
                    {
                        ((Library.Interface.IGenericCallbackModule)mx.Value).OnStart(result.MainOperation.ToString(), ref m_backend, ref paths);
                    }
                }
            }

            // If the filters were changed by a module, read them back in
            if (pristinefilter != m_options.RawOptions["filter"])
            {
                filter = FilterExpression.Deserialize(m_options.RawOptions["filter"].Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries));
            }
            m_options.RawOptions.Remove("filter"); // "--filter" is not a supported command line option

            OperationRunning(true);

            if (m_options.HasLoglevel)
            {
                Library.Logging.Log.LogLevel = m_options.Loglevel;
            }

            if (!string.IsNullOrEmpty(m_options.Logfile))
            {
                var path = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(m_options.Logfile));
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                m_logfilescope = Logging.Log.StartScope(m_logfile = new Library.Logging.StreamLog(m_options.Logfile));
            }

            result.VerboseErrors = m_options.DebugOutput;
            result.VerboseOutput = m_options.Verbose;

            if (m_options.HasTempDir)
            {
                Library.Utility.TempFolder.SystemTempPath = m_options.TempDir;
                if (Library.Utility.Utility.IsClientLinux)
                {
                    m_resetKeys["TMPDIR"] = Environment.GetEnvironmentVariable("TMPDIR");
                    Environment.SetEnvironmentVariable("TMPDIR", m_options.TempDir);
                }
                else
                {
                    m_resetKeys["TMP"]  = Environment.GetEnvironmentVariable("TMP");
                    m_resetKeys["TEMP"] = Environment.GetEnvironmentVariable("TEMP");
                    Environment.SetEnvironmentVariable("TMP", m_options.TempDir);
                    Environment.SetEnvironmentVariable("TEMP", m_options.TempDir);
                }
            }

            if (m_options.HasForcedLocale)
            {
                try
                {
                    var locale = m_options.ForcedLocale;
                    DoGetLocale(out m_resetLocale, out m_resetLocaleUI);
                    m_doResetLocale = true;
                    // Wrap the call to avoid loading issues for the setLocale method
                    DoSetLocale(locale, locale);
                }
                catch (Exception ex) // or only: MissingMethodException
                {
                    Library.Logging.Log.WriteMessage(Strings.Controller.FailedForceLocaleError(ex.Message), Logging.LogMessageType.Warning);
                    m_doResetLocale = false;
                    m_resetLocale   = m_resetLocaleUI = null;
                }
            }

            if (!string.IsNullOrEmpty(m_options.ThreadPriority))
            {
                m_resetPriority = System.Threading.Thread.CurrentThread.Priority;
                System.Threading.Thread.CurrentThread.Priority = Library.Utility.Utility.ParsePriority(m_options.ThreadPriority);
            }

            if (string.IsNullOrEmpty(m_options.Dbpath))
            {
                m_options.Dbpath = DatabaseLocator.GetDatabasePath(m_backend, m_options);
            }

            ValidateOptions(result);
        }
Ejemplo n.º 2
0
        private void SetupCommonOptions(ISetCommonOptions result, ref string[] paths, ref IFilter filter)
        {
            m_options.MainAction = result.MainOperation;
            result.MessageSink   = m_messageSink;

            switch (m_options.MainAction)
            {
            case OperationMode.Backup:
                break;

            default:
                //It only makes sense to enable auto-creation if we are writing files.
                if (!m_options.RawOptions.ContainsKey("disable-autocreate-folder"))
                {
                    m_options.RawOptions["disable-autocreate-folder"] = "true";
                }
                break;
            }

            //Load all generic modules
            m_options.LoadedModules.Clear();

            foreach (Library.Interface.IGenericModule m in DynamicLoader.GenericLoader.Modules)
            {
                m_options.LoadedModules.Add(new KeyValuePair <bool, Library.Interface.IGenericModule>(Array.IndexOf <string>(m_options.DisableModules, m.Key.ToLower()) < 0 && (m.LoadAsDefault || Array.IndexOf <string>(m_options.EnableModules, m.Key.ToLower()) >= 0), m));
            }

            var conopts = new Dictionary <string, string>(m_options.RawOptions);
            var qp      = new Library.Utility.Uri(m_backend).QueryParameters;

            foreach (var k in qp.Keys)
            {
                conopts[(string)k] = qp[(string)k];
            }

            // Make the filter read-n-write able in the generic modules
            var pristinefilter = conopts["filter"] = string.Join(System.IO.Path.PathSeparator.ToString(), FilterExpression.Serialize(filter));

            foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
            {
                if (mx.Key)
                {
                    if (mx.Value is Library.Interface.IConnectionModule)
                    {
                        mx.Value.Configure(conopts);
                    }
                    else
                    {
                        mx.Value.Configure(m_options.RawOptions);
                    }

                    if (mx.Value is Library.Interface.IGenericCallbackModule)
                    {
                        ((Library.Interface.IGenericCallbackModule)mx.Value).OnStart(result.MainOperation.ToString(), ref m_backend, ref paths);
                    }
                }
            }

            // If the filters were changed, read them back in
            if (pristinefilter != conopts["filter"])
            {
                filter = FilterExpression.Deserialize(conopts["filter"].Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries));
            }

            OperationRunning(true);

            if (m_options.HasLoglevel)
            {
                Library.Logging.Log.LogLevel = m_options.Loglevel;
            }

            if (!string.IsNullOrEmpty(m_options.Logfile))
            {
                m_hasSetLogging = true;
                var path = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(m_options.Logfile));
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                Library.Logging.Log.CurrentLog = new Library.Logging.StreamLog(m_options.Logfile);
            }

            result.VerboseErrors = m_options.DebugOutput;
            result.VerboseOutput = m_options.Verbose;

            if (m_options.HasTempDir)
            {
                Library.Utility.TempFolder.SystemTempPath = m_options.TempDir;
                if (Library.Utility.Utility.IsClientLinux)
                {
                    m_resetKeys["TMPDIR"] = Environment.GetEnvironmentVariable("TMPDIR");
                    Environment.SetEnvironmentVariable("TMPDIR", m_options.TempDir);
                }
                else
                {
                    m_resetKeys["TMP"]  = Environment.GetEnvironmentVariable("TMP");
                    m_resetKeys["TEMP"] = Environment.GetEnvironmentVariable("TEMP");
                    Environment.SetEnvironmentVariable("TMP", m_options.TempDir);
                    Environment.SetEnvironmentVariable("TEMP", m_options.TempDir);
                }
            }

            if (m_options.HasForcedLocale)
            {
                var locale = m_options.ForcedLocale;
                m_resetLocale   = System.Globalization.CultureInfo.DefaultThreadCurrentCulture;
                m_resetLocaleUI = System.Globalization.CultureInfo.DefaultThreadCurrentUICulture;
                m_doResetLocale = true;
                System.Globalization.CultureInfo.DefaultThreadCurrentCulture   = locale;
                System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = locale;
            }

            if (!string.IsNullOrEmpty(m_options.ThreadPriority))
            {
                m_resetPriority = System.Threading.Thread.CurrentThread.Priority;
                System.Threading.Thread.CurrentThread.Priority = Library.Utility.Utility.ParsePriority(m_options.ThreadPriority);
            }

            if (string.IsNullOrEmpty(m_options.Dbpath))
            {
                m_options.Dbpath = DatabaseLocator.GetDatabasePath(m_backend, m_options);
            }

            ValidateOptions(result);

            Library.Logging.Log.WriteMessage(Strings.Controller.StartingOperationMessage(m_options.MainAction), Logging.LogMessageType.Information);
        }