예제 #1
0
        private void OnOperationComplete(object result)
        {
            if (m_options != null && m_options.LoadedModules != null)
            {
                foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
                {
                    if (mx.Key && mx.Value is Duplicati.Library.Interface.IGenericCallbackModule)
                    {
                        try { ((Duplicati.Library.Interface.IGenericCallbackModule)mx.Value).OnFinish(result); }
                        catch (Exception ex) { Logging.Log.WriteMessage(string.Format("OnFinish callback {0} failed: {1}", mx.Key, ex.Message), Duplicati.Library.Logging.LogMessageType.Warning, ex); }
                    }
                }

                foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
                {
                    if (mx.Key && mx.Value is IDisposable)
                    {
                        try { ((IDisposable)mx.Value).Dispose(); }
                        catch (Exception ex) { Logging.Log.WriteMessage(string.Format("Dispose for {0} failed: {1}", mx.Key, ex.Message), Duplicati.Library.Logging.LogMessageType.Warning, ex); }
                    }
                }

                m_options.LoadedModules.Clear();
                OperationRunning(false);
            }

            if (m_hasSetLogging && Logging.Log.CurrentLog is Logging.StreamLog)
            {
                Logging.StreamLog sl = (Logging.StreamLog)Logging.Log.CurrentLog;
                Logging.Log.CurrentLog = null;
                sl.Dispose();
                m_hasSetLogging = false;
            }
        }
예제 #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));
            }

            // 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);
        }
예제 #3
0
        private void OnOperationComplete(object result)
        {
            if (m_options != null && m_options.LoadedModules != null)
            {
                foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
                {
                    if (mx.Key && mx.Value is Duplicati.Library.Interface.IGenericCallbackModule)
                    {
                        try { ((Duplicati.Library.Interface.IGenericCallbackModule)mx.Value).OnFinish(result); }
                        catch (Exception ex) { Logging.Log.WriteMessage(string.Format("OnFinish callback {0} failed: {1}", mx.Key, ex.Message), Duplicati.Library.Logging.LogMessageType.Warning, ex); }
                    }
                }

                foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
                {
                    if (mx.Key && mx.Value is IDisposable)
                    {
                        try { ((IDisposable)mx.Value).Dispose(); }
                        catch (Exception ex) { Logging.Log.WriteMessage(string.Format("Dispose for {0} failed: {1}", mx.Key, ex.Message), Duplicati.Library.Logging.LogMessageType.Warning, ex); }
                    }
                }

                m_options.LoadedModules.Clear();
                OperationRunning(false);
            }

            if (m_resetPriority != null)
            {
                System.Threading.Thread.CurrentThread.Priority = m_resetPriority.Value;
                m_resetPriority = null;
            }

            if (m_doResetLocale)
            {
                // Wrap the call to avoid loading issues for the setLocale method
                DoSetLocale(m_resetLocale, m_resetLocaleUI);

                m_doResetLocale = false;
                m_resetLocale   = null;
                m_resetLocaleUI = null;
            }

            if (m_resetKeys != null)
            {
                var keys = m_resetKeys.Keys.ToArray();
                foreach (var k in keys)
                {
                    try
                    {
                        Environment.SetEnvironmentVariable(k, m_resetKeys[k]);
                    }
                    catch { }

                    m_resetKeys.Remove(k);
                }
            }

            if (m_logfilescope != null)
            {
                m_logfilescope.Dispose();
                m_logfilescope = null;
            }

            if (m_logfile != null)
            {
                m_logfile.Dispose();
                m_logfile = null;
            }
        }
예제 #4
0
        private void OnOperationComplete(object result)
        {
            if (m_options != null && m_options.LoadedModules != null)
            {
                foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
                {
                    if (mx.Key && mx.Value is Duplicati.Library.Interface.IGenericCallbackModule)
                    {
                        try { ((Duplicati.Library.Interface.IGenericCallbackModule)mx.Value).OnFinish(result); }
                        catch (Exception ex) { Logging.Log.WriteMessage(string.Format("OnFinish callback {0} failed: {1}", mx.Key, ex.Message), Duplicati.Library.Logging.LogMessageType.Warning, ex); }
                    }
                }

                foreach (KeyValuePair <bool, Library.Interface.IGenericModule> mx in m_options.LoadedModules)
                {
                    if (mx.Key && mx.Value is IDisposable)
                    {
                        try { ((IDisposable)mx.Value).Dispose(); }
                        catch (Exception ex) { Logging.Log.WriteMessage(string.Format("Dispose for {0} failed: {1}", mx.Key, ex.Message), Duplicati.Library.Logging.LogMessageType.Warning, ex); }
                    }
                }

                m_options.LoadedModules.Clear();
                OperationRunning(false);
            }

            if (m_resetPriority != null)
            {
                System.Threading.Thread.CurrentThread.Priority = m_resetPriority.Value;
                m_resetPriority = null;
            }

            if (m_doResetLocale)
            {
                System.Globalization.CultureInfo.DefaultThreadCurrentCulture   = m_resetLocale;
                System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = m_resetLocaleUI;
                m_doResetLocale = false;
                m_resetLocale   = null;
            }

            if (m_resetKeys != null)
            {
                var keys = m_resetKeys.Keys.ToArray();
                foreach (var k in keys)
                {
                    try
                    {
                        Environment.SetEnvironmentVariable(k, m_resetKeys[k]);
                    }
                    catch { }

                    m_resetKeys.Remove(k);
                }
            }

            if (m_hasSetLogging && Logging.Log.CurrentLog is Logging.StreamLog)
            {
                Logging.StreamLog sl = (Logging.StreamLog)Logging.Log.CurrentLog;
                Logging.Log.CurrentLog = null;
                sl.Dispose();
                m_hasSetLogging = false;
            }
        }