예제 #1
0
        public SettingsViewModel(IScreen hostScreen)
            : base(hostScreen)
        {
            _settingsProvider = Locator.Current.GetRequiredService <ISettingsProvider>();
            _partsRepository  = Locator.Current.GetRequiredService <IPartRepository>();

            SaveSettings = ReactiveCommand.CreateFromTask(execute: ExecuteSaveSettings);

            var canAddCustomField = this.WhenAnyValue(vm => vm.NewCustomField, value =>
            {
                return(!string.IsNullOrWhiteSpace(value) &&
                       !CustomFields.Any(vm => vm.Value.Equals(value, StringComparison.Ordinal)));
            });

            AddCustomField = ReactiveCommand.Create(execute: ExecuteAddCustomField, canExecute: canAddCustomField);

            ImportCustomFields = ReactiveCommand.CreateCombined(new[]
            {
                SaveSettings,
                ReactiveCommand.CreateFromTask(
                    execute: ImportCustomFieldsAsync),
            });

            GoBack = ReactiveCommand.CreateFromTask(GoBackAsync);
        }
        public BsonDocument CreateBsonDocument(LogEventInfo logEvent)
        {
            var document = new BsonDocument();

            //基础信息
            if (IncloudBaseInfo && logEvent != null)
            {
                document.Add("TimeStamp", logEvent.TimeStamp);
                document.Add("Level", logEvent.Level.Name);
                document.Add("Message", logEvent.FormattedMessage);
                document.Add("LoggerName", logEvent.LoggerName);
            }
            ;

            //自定义字段
            if (IncloudCustomFields && CustomFields.Any())
            {
                foreach (var field in CustomFields)
                {
                    var bsonValue = GetBsonValueWithField(logEvent, field);
                    if (bsonValue == null)
                    {
                        continue;
                    }

                    document.Add(field.Name, bsonValue);
                }
            }

            //事件属性
            if (IncloudEventProperties && logEvent.HasProperties)
            {
                foreach (var property in logEvent.Properties)
                {
                    var propertyKey   = property.Key.ToString();
                    var propertyValue = property.Value.ToString();
                    if (IgnoredEventProperties.Contains(propertyKey) || document.Contains(propertyKey))
                    {
                        continue;
                    }

                    document.Add(propertyKey, propertyValue);
                }
            }

            //异常堆栈
            if (logEvent.Exception != null)
            {
                document.Add("Exception", new BsonDocument()
                {
                    { "Message", logEvent.Exception.Message },
                    { "Source", logEvent.Exception.Source },
                    { "StackTrace", logEvent.Exception.StackTrace.Trim() },
                });
            }

            return(document);
        }
예제 #3
0
 private void OnAddTask(string obj)
 {
     if (!string.IsNullOrEmpty(NewTask) || CustomFields.Any(x => !string.IsNullOrEmpty(x.Value)))
     {
         if (TaskTypeId == 0)
         {
             NewTask = "Can't add a task. Update Task Type from widget settings";
             return;
         }
         var task = _taskService.AddNewTask(TaskTypeId, NewTask, CustomFields.ToDictionary(x => x.Name, x => x.Value));
         foreach (var customField in CustomFields)
         {
             customField.Value = "";
         }
         var wm = new TaskViewModel(task, TaskType, this, _messagingService);
         wm.Persist();
         NewTask = "";
         OnTaskAdded();
     }
 }