コード例 #1
0
        public static async Task <ServiceOperationResult> AddOrUpdateLogView(LogView logView, bool saveOnCompletion = false)
        {
            var serviceOperationHelper = new ServiceOperationHelper(typeof(LogView), Plurality.Single, ServiceOperation.Add, _targetName, logView.Name);
            await Task.Run(() =>
            {
                try
                {
                    var index = GetLogViewIndexByName(logView.Name);
                    if (index < 0)
                    {
                        //If item isn't in settings, add it
                        serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting);
                        Settings.Default.XmlLogViews.Add(logView.ExportToXml());
                    }
                    else
                    {
                        //If item is in settings, update it
                        serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting);
                        Settings.Default.XmlLogViews[index] = logView.ExportToXml();
                    }
                    serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded);

                    if (saveOnCompletion)
                    {
                        serviceOperationHelper.ServiceOperationResult = SaveSettings();
                    }
                }
                catch (Exception ex)
                {
                    serviceOperationHelper.LogServiceOperation(ex.Message);
                }
            });

            return(serviceOperationHelper.ServiceOperationResult);
        }