Ejemplo n.º 1
0
        public void Configure(IDictionary <string, string> commandlineOptions)
        {
            commandlineOptions.TryGetValue(STARTUP_OPTION, out m_startScript);
            commandlineOptions.TryGetValue(REQUIRED_OPTION, out m_requiredScript);
            commandlineOptions.TryGetValue(FINISH_OPTION, out m_finishScript);

            string             tmpResultFormat;
            ResultExportFormat resultFormat;

            if (!commandlineOptions.TryGetValue(RESULT_FORMAT_OPTION, out tmpResultFormat))
            {
                resultFormat = ResultExportFormat.Duplicati;
            }
            else if (!Enum.TryParse(tmpResultFormat, true, out resultFormat))
            {
                resultFormat = ResultExportFormat.Duplicati;
            }

            resultFormatSerializer = ResultFormatSerializerProvider.GetSerializer(resultFormat);

            string t;

            if (!commandlineOptions.TryGetValue(TIMEOUT_OPTION, out t))
            {
                t = DEFAULT_TIMEOUT;
            }

            m_timeout = (int)Utility.Timeparser.ParseTimeSpan(t).TotalMilliseconds;

            m_options = commandlineOptions;

            m_options.TryGetValue(OPTION_LOG_FILTER, out var logfilterstring);
            var filter   = Utility.FilterExpression.ParseLogFilter(logfilterstring);
            var logLevel = Utility.Utility.ParseEnumOption(m_options, OPTION_LOG_LEVEL, DEFAULT_LOG_LEVEL);

            m_logstorage = new FileBackedStringList();
            m_logscope   = Logging.Log.StartScope(m => m_logstorage.Add(m.AsString(true)), m => {
                if (filter.Matches(m.FilterTag, out var result, out var match))
                {
                    return(result);
                }
        public void TestGetSerializerGivenJsonReturnsJsonSerializer()
        {
            IResultFormatSerializer serializer = ResultFormatSerializerProvider.GetSerializer(ResultExportFormat.Json);

            Assert.AreEqual(typeof(JsonFormatSerializer), serializer.GetType());
        }
        public void TestGetSerializerGivenDuplicatiReturnsDuplicatiSerializer()
        {
            IResultFormatSerializer serializer = ResultFormatSerializerProvider.GetSerializer(ResultExportFormat.Duplicati);

            Assert.AreEqual(typeof(DuplicatiFormatSerializer), serializer.GetType());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is the interception where the module can interact with the execution environment and modify the settings.
        /// </summary>
        /// <param name="commandlineOptions">A set of commandline options passed to Duplicati</param>
        public void Configure(IDictionary <string, string> commandlineOptions)
        {
            if (!ConfigureModule(commandlineOptions))
            {
                return;
            }

            m_isConfigured = true;
            commandlineOptions.TryGetValue(SubjectOptionName, out m_subject);
            commandlineOptions.TryGetValue(BodyOptionName, out m_body);
            m_options = commandlineOptions;

            string tmp;

            commandlineOptions.TryGetValue(ActionLevelOptionName, out tmp);
            if (!string.IsNullOrEmpty(tmp))
            {
                m_levels =
                    tmp
                    .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                    .Where(x => !string.IsNullOrWhiteSpace(x))
                    .Select(x => x.Trim())
                    .ToArray();
            }

            if (m_levels == null || m_levels.Length == 0)
            {
                m_levels =
                    DEFAULT_LEVEL
                    .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                    .Where(x => !string.IsNullOrWhiteSpace(x))
                    .Select(x => x.Trim())
                    .ToArray();
            }

            m_sendAll = Utility.Utility.ParseBoolOption(commandlineOptions, ActionOnAnyOperationOptionName);

            ResultExportFormat resultFormat;

            if (!commandlineOptions.TryGetValue(ResultFormatOptionName, out var tmpResultFormat))
            {
                resultFormat = DEFAULT_EXPORT_FORMAT;
            }
            else if (!Enum.TryParse(tmpResultFormat, true, out resultFormat))
            {
                resultFormat = DEFAULT_EXPORT_FORMAT;
            }

            m_resultFormatSerializer = ResultFormatSerializerProvider.GetSerializer(resultFormat);

            commandlineOptions.TryGetValue(LogLinesOptionName, out var loglinestr);
            if (!int.TryParse(loglinestr, out m_maxmimumLogLines))
            {
                m_maxmimumLogLines = DEFAULT_LOGLINES;
            }

            if (string.IsNullOrEmpty(m_subject))
            {
                m_subject = DEFAULT_SUBJECT;
            }
            if (string.IsNullOrEmpty(m_body))
            {
                m_body = DEFAULT_BODY;
            }

            m_options.TryGetValue(LogFilterOptionName, out var logfilterstring);
            var filter   = Utility.FilterExpression.ParseLogFilter(logfilterstring);
            var logLevel = Utility.Utility.ParseEnumOption(m_options, LogLevelOptionName, DEFAULT_LOG_LEVEL);

            m_logstorage = new FileBackedStringList();
            m_logscope   = Logging.Log.StartScope(m => m_logstorage.Add(m.AsString(true)), m => {
                if (filter.Matches(m.FilterTag, out var result, out var match))
                {
                    return(result);
                }