Пример #1
0
        private static void VerifyTarget(ColumnMapping mapping, string paramName, int index, Model target)
        {
            var targetColumn = mapping.Target;

            if (targetColumn == null)
            {
                throw new ArgumentNullException(string.Format("{0}[{1}].{2}", paramName, index, nameof(ColumnMapping.Target)));
            }
            if (targetColumn.ParentModel != target)
            {
                throw new ArgumentException(DiagnosticMessages.ColumnMapper_InvalidTarget(targetColumn), string.Format("{0}[{1}].{2}", paramName, index, nameof(ColumnMapping.Target)));
            }
        }
Пример #2
0
 /// <summary>
 /// Writes logging message for connection closed.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="invoker">The invoker.</param>
 protected virtual void WriteConnectionClosed(TConnection connection, AddonInvoker invoker)
 {
     Debug.Assert(ShouldLog(LogCategory.ConnectionClosed));
     if (invoker.Exception != null)
     {
         Write(LogCategory.ConnectionClosed, DiagnosticMessages.DbLogger_ConnectionCloseError(DateTimeOffset.Now, invoker.Exception.Message));
     }
     else
     {
         Write(LogCategory.ConnectionClosed, DiagnosticMessages.DbLogger_ConnectionClosed(DateTimeOffset.Now));
     }
     Write(LogCategory.ConnectionClosed, Environment.NewLine);
 }
Пример #3
0
 /// <summary>
 /// Writes logging message for transaction committed.
 /// </summary>
 /// <param name="transaction">The transation.</param>
 /// <param name="invoker">The invoker.</param>
 protected virtual void WriteTransactionCommitted(ITransaction transaction, AddonInvoker invoker)
 {
     Debug.Assert(ShouldLog(LogCategory.TransactionCommitted));
     if (invoker.Exception != null)
     {
         Write(LogCategory.TransactionCommitted, DiagnosticMessages.DbLogger_TransactionCommitError(transaction.Name, transaction.Level, DateTimeOffset.Now, invoker.Exception.Message));
     }
     else
     {
         Write(LogCategory.TransactionCommitted, DiagnosticMessages.DbLogger_TransactionCommitted(transaction.Name, transaction.Level, DateTimeOffset.Now));
     }
     Write(LogCategory.TransactionCommitted, Environment.NewLine);
 }
Пример #4
0
 /// <summary>
 /// Writes logging message for transaction began.
 /// </summary>
 /// <param name="isolationLevel">The transaction isolation level.</param>
 /// <param name="name">The name of the transaction.</param>
 /// <param name="invoker">The invoker.</param>
 protected virtual void WriteTransactionBegan(IsolationLevel?isolationLevel, string name, AddonInvoker invoker)
 {
     Debug.Assert(ShouldLog(LogCategory.TransactionBegan));
     if (invoker.Exception != null)
     {
         Write(LogCategory.TransactionBegan, DiagnosticMessages.DbLogger_TransactionStartError(isolationLevel, name, DateTimeOffset.Now, invoker.Exception.Message));
     }
     else
     {
         Write(LogCategory.TransactionBegan, DiagnosticMessages.DbLogger_TransactionStarted(isolationLevel, name, DateTimeOffset.Now));
     }
     Write(LogCategory.TransactionBegan, Environment.NewLine);
 }
        /// <summary>
        /// Gets the property getter.
        /// </summary>
        /// <param name="returnType">The return type of the property.</param>
        /// <returns>The property getter.</returns>
        protected MethodInfo GetPropertyGetter(Type returnType)
        {
            returnType.VerifyNotNull(nameof(returnType));

            var propertyInfo = GetPropertyInfo(returnType);
            var result       = propertyInfo?.GetGetMethod(true);

            if (result == null)
            {
                throw new InvalidOperationException(DiagnosticMessages.NamedModelAttribute_FailedToResolvePropertyGetter(ModelType, Name, returnType));
            }
            return(result);
        }
Пример #6
0
 internal void VerifyFrozenMargins()
 {
     if (FrozenHeadTracksCount > HeadTracksCount)
     {
         throw new InvalidOperationException(DiagnosticMessages.Template_InvalidFrozenMargin(FrozenHeadName));
     }
     if (FrozenTailTracksCount > TailTracksCount)
     {
         throw new InvalidOperationException(DiagnosticMessages.Template_InvalidFrozenMargin(FrozenTailName));
     }
     if (Stretches > FrozenTailTracksCount)
     {
         throw new InvalidOperationException(DiagnosticMessages.Template_InvalidStretches(FrozenTailName));
     }
 }
Пример #7
0
        private static void Verify(IReadOnlyList <InputGesture> inputGestures)
        {
            if (inputGestures == null || inputGestures.Count == 0)
            {
                return;
            }

            for (int i = 0; i < inputGestures.Count; i++)
            {
                if (inputGestures[i] == null)
                {
                    throw new ArgumentException(DiagnosticMessages._ArgumentNullAtIndex(nameof(inputGestures), i), nameof(inputGestures));
                }
            }
        }
        public UseCases Compose(
            ApplicationEventsPresenter applicationEventsPresenter,
            DiagnosticMessages diagnosticMessages)
        {
            _watcher = FileSystemWatchers();

            var applicationUseCases = Synchronized(
                ApplicationUseCases(diagnosticMessages,
                                    PathOperationsContext(
                                        applicationEventsPresenter,
                                        diagnosticMessages)));

            _watcher.ReportChangesTo(FilteredWith(_filters, applicationUseCases));
            return(applicationUseCases);
        }
Пример #9
0
        private TagBuilder GenerateRadio()
        {
            // Note empty string is allowed.
            if (Value == null)
            {
                throw new InvalidOperationException(DiagnosticMessages.FormatInputTagHelper_ValueRequired(
                                                        nameof(Value).ToLowerInvariant(),
                                                        "<input>",
                                                        "type",
                                                        "radio"));
            }

            var isChecked = DataValue != null && string.Equals(DataValue.ToString(), Value, StringComparison.OrdinalIgnoreCase);

            return(Generator.GenerateRadioButton(ViewContext, FullHtmlFieldName, Column, Value, isChecked, htmlAttributes: null));
        }
Пример #10
0
 /// <summary>
 /// Writes logging message for connection opened.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="invoker">The invoker.</param>
 protected virtual void WriteConnectionOpened(TConnection connection, AddonInvoker invoker)
 {
     Debug.Assert(ShouldLog(LogCategory.ConnectionOpened));
     if (invoker.Exception != null)
     {
         Write(LogCategory.ConnectionOpened, invoker.IsAsync ? DiagnosticMessages.DbLogger_ConnectionOpenErrorAsync(DateTimeOffset.Now, invoker.Exception.Message) : DiagnosticMessages.DbLogger_ConnectionOpenError(DateTimeOffset.Now, invoker.Exception.Message));
     }
     else if (invoker.TaskStatus.HasFlag(TaskStatus.Canceled))
     {
         Write(LogCategory.ConnectionOpened, DiagnosticMessages.DbLogger_ConnectionOpenCanceled(DateTimeOffset.Now));
     }
     else
     {
         Write(LogCategory.ConnectionOpened, invoker.IsAsync ? DiagnosticMessages.DbLogger_ConnectionOpenAsync(DateTimeOffset.Now) : DiagnosticMessages.DbLogger_ConnectionOpen(DateTimeOffset.Now));
     }
     Write(LogCategory.ConnectionOpened, Environment.NewLine);
 }
Пример #11
0
        public ArtifactNotificationDriver StartApplication()
        {
            var watchersFactory = Substitute.For <FileSystemWatcherFactory>();

            _presenter          = Substitute.For <ApplicationEventsPresenter>();
            _diagnosticMessages = Substitute.For <DiagnosticMessages>();
            _systemServices     = Substitute.For <SystemServices>();
            _handControlledFileSystemWatcher = new ManuallyTriggerableFileSystemWatcher();

            watchersFactory.CreateFileSystemWatchers(_filters).Returns(_handControlledFileSystemWatcher);

            var compositionRoot = new CompositionRoot(watchersFactory, _systemServices, _filters);

            _useCases = compositionRoot.Compose(_presenter, _diagnosticMessages);
            _useCases.Initialize();
            return(this);
        }
Пример #12
0
        private static void VerifySource(ColumnMapping mapping, string paramName, int index, Model source)
        {
            var sourceColumn = mapping.Source;

            if (sourceColumn == null)
            {
                throw new ArgumentNullException(string.Format("{0}[{1}].{2}", paramName, index, nameof(ColumnMapping.Source)));
            }
            var sourceModels = sourceColumn.ScalarSourceModels;

            foreach (var model in sourceModels)
            {
                if (model != source)
                {
                    throw new ArgumentException(DiagnosticMessages.ColumnMapper_InvalidSourceParentModelSet(model), paramName);
                }
            }
        }
Пример #13
0
        private void Register(IMounter <TTarget, TProperty> item)
        {
            Type targetType = item.ParentType;

            if (_resultRegistrations.ContainsKey(targetType))
            {
                throw new InvalidOperationException(DiagnosticMessages.MounterManager_RegisterAfterUse(targetType.FullName));
            }

            RegistrationCollection registrations = _registrations.GetOrAdd(targetType, x => new RegistrationCollection());

            if (registrations.Contains(new Key(item)))
            {
                throw new InvalidOperationException(DiagnosticMessages.MounterManager_RegisterDuplicate(item.DeclaringType.FullName, item.Name));
            }

            registrations.Add(item);
        }
Пример #14
0
 internal virtual void VerifyFrozenMargins(string bindingsName)
 {
     if (GridRange.HorizontallyIntersectsWith(Template.FrozenLeft))
     {
         throw new InvalidOperationException(DiagnosticMessages.Binding_InvalidFrozenMargin(nameof(Template.FrozenLeft), bindingsName, Ordinal));
     }
     if (GridRange.VerticallyIntersectsWith(Template.FrozenTop))
     {
         throw new InvalidOperationException(DiagnosticMessages.Binding_InvalidFrozenMargin(nameof(Template.FrozenTop), bindingsName, Ordinal));
     }
     if (GridRange.HorizontallyIntersectsWith(Template.GridColumns.Count - Template.FrozenRight))
     {
         throw new InvalidOperationException(DiagnosticMessages.Binding_InvalidFrozenMargin(nameof(Template.FrozenRight), bindingsName, Ordinal));
     }
     if (GridRange.VerticallyIntersectsWith(Template.GridRows.Count - Template.FrozenBottom))
     {
         throw new InvalidOperationException(DiagnosticMessages.Binding_InvalidFrozenMargin(nameof(Template.FrozenBottom), bindingsName, Ordinal));
     }
 }
Пример #15
0
 private uint ParseHexChar(char c)
 {
     if (c >= '0' && c <= '9')
     {
         return((uint)(c - '0'));
     }
     else if (c >= 'A' && c <= 'F')
     {
         return((uint)((c - 'A') + 10));
     }
     else if (c >= 'a' && c <= 'f')
     {
         return((uint)((c - 'a') + 10));
     }
     else
     {
         throw new FormatException(DiagnosticMessages.StringJsonReader_InvalidHexChar(c, _index - 1));
     }
 }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of <see cref="KeyOutput"/> class.
        /// </summary>
        /// <param name="model">The source model.</param>
        public KeyOutput(Model model)
        {
            model.VerifyNotNull(nameof(model));
            var primaryKey = model.PrimaryKey;

            if (primaryKey == null)
            {
                throw new ArgumentException(DiagnosticMessages.DbTable_NoPrimaryKey(model), nameof(model));
            }

            _sourceDbAlias = model.DbAlias;
            _primaryKey    = new PK(this, primaryKey);
            var sortKeys = new ColumnSort[primaryKey.Count];

            for (int i = 0; i < sortKeys.Length; i++)
            {
                sortKeys[i] = primaryKey[i];
            }
            AddDbTableConstraint(new DbPrimaryKey(this, null, null, false, () => { return(sortKeys); }), true);
        }
Пример #17
0
        private TagBuilder GenerateCheckBox(TagHelperOutput output)
        {
            if (Column.DataType == typeof(string))
            {
                if (DataValue != null && !bool.TryParse(DataValue.ToString(), out _))
                {
                    throw new InvalidOperationException(DiagnosticMessages.FormatInputTagHelper_InvalidStringResult(DataValue, FullHtmlFieldName, typeof(bool)));
                }
            }
            else if (Column.DataType != typeof(bool) && Column.DataType != typeof(bool?))
            {
                throw new InvalidOperationException(DiagnosticMessages.FormatInputTagHelper_InvalidExpressionResult(
                                                        FullHtmlFieldName, Column.DataType, "<input>", typeof(bool), typeof(string), "type", "checkbox"));
            }

            // hiddenForCheckboxTag always rendered after the returned element
            var hiddenForCheckboxTag = Generator.GenerateHiddenForCheckbox(ViewContext, FullHtmlFieldName);

            if (hiddenForCheckboxTag != null)
            {
                var renderingMode = output.TagMode == TagMode.SelfClosing ? TagRenderMode.SelfClosing : TagRenderMode.StartTag;
                hiddenForCheckboxTag.TagRenderMode = renderingMode;

                if (ViewContext.FormContext.CanRenderAtEndOfForm)
                {
                    ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckboxTag);
                }
                else
                {
                    output.PostElement.AppendHtml(hiddenForCheckboxTag);
                }
            }

            bool?isChecked = null;

            if (DataValue != null && bool.TryParse(DataValue.ToString(), out var modelChecked))
            {
                isChecked = modelChecked;
            }
            return(Generator.GenerateCheckBox(ViewContext, FullHtmlFieldName, Column, isChecked, htmlAttributes: null));
        }
Пример #18
0
        /// <summary>
        /// Resizes this grid track.
        /// </summary>
        /// <param name="value">The new length.</param>
        public void Resize(GridLength value)
        {
            if (Orientation == Template?.Orientation && value.IsStar)
            {
                throw new ArgumentException(DiagnosticMessages.GridTrack_Resize_InvalidStarLength(Orientation), nameof(value));
            }

            var oldValue = _length;

            if (oldValue != value)
            {
                _length = value;
                if (!VariantByContainer)
                {
                    SetMeasuredLength(0);
                }
                Owner.OnResized(this, oldValue);
            }
            Resizable?.OnResized(this);
            LayoutManager?.InvalidateMeasure();
        }
Пример #19
0
        public async void Save()
        {
            async Task Check(CancellationToken cancellationToken)
            {
                DiagnosticMessages.Clear();

                foreach (ISettingsSectionViewModel item in Items)
                {
                    IEnumerable <DiagnosticMessage> diagnosticMessages = await item.GetDiagnosticMessages(cancellationToken);

                    DiagnosticMessages.AddRange(diagnosticMessages);
                }
            }

            await ExecutionContext.Execute(Check, "Validating settings.");

            if (DiagnosticMessages.Any(x => x.Severity >= Severity.Warning))
            {
                bool shouldContinue = await ShowDiagnosticMessages();

                if (!shouldContinue)
                {
                    return;
                }
            }

            async Task Save(CancellationToken cancellationToken)
            {
                foreach (ISettingsSectionViewModel item in Items)
                {
                    await item.Save(cancellationToken);
                }
            }

            await ExecutionContext.Execute(Save);

            await TryCloseAsync();
        }
        private T Eval(DataRow dataRow)
        {
            if (Param.ParentModel.DataSource.Kind != DataSourceKind.DataSet)
            {
                throw new InvalidOperationException(DiagnosticMessages.ColumnAggregateFunction_EvalOnNonDataSet(Param, Param.ParentModel.DataSource.Kind));
            }

            var modelChain = ResolveModelChain(dataRow);

            if (modelChain == null)
            {
                throw new ArgumentException(DiagnosticMessages.ColumnAggregateFunction_NoModelChain(Param.ToString()), nameof(dataRow));
            }

            EvalInit();

            int     lastIndex = modelChain.Count - 1;
            var     lastModel = modelChain[lastIndex];
            DataSet dataSet   = dataRow == null ? lastModel.DataSet : dataRow[lastModel];

            EvalTraverse(new DataSetChain(dataSet, modelChain, lastIndex));
            return(EvalReturn());
        }
Пример #21
0
        /// <summary>
        /// Binds an enum value column to <see cref="CheckBox"/>.
        /// </summary>
        /// <typeparam name="T">The enum type.</typeparam>
        /// <param name="source">The source column.</param>
        /// <param name="enumMemberValue">The value of enum member.</param>
        /// <param name="title">The title of the CheckBox. If null, the name of enum member will be used.</param>
        /// <returns>The row binding object.</returns>
        public static RowBinding <CheckBox> BindToCheckBox <T>(this Column <T> source, T enumMemberValue, object title = null)
            where T : struct, IConvertible
        {
            if (!typeof(T).IsEnum)
            {
                throw new ArgumentException(DiagnosticMessages.BindingFactory_EnumTypeRequired(nameof(T)), nameof(T));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new RowBinding <CheckBox>(
                       onSetup: (v, p) =>
            {
                if (v.Content == null)
                {
                    v.Content = title ?? Enum.GetName(typeof(T), enumMemberValue);
                }
            },
                       onRefresh: (v, p) => v.IsChecked = p.GetValue(source).HasFlag(enumMemberValue),
                       onCleanup: null)
                   .BeginInput(new PropertyChangedTrigger <CheckBox>(CheckBox.IsCheckedProperty), new ExplicitTrigger <CheckBox>())
                   .WithFlush(source, (r, v) =>
            {
                var value = r.GetValue(source);
                var newValue = value.GetNewValue(enumMemberValue, v);
                if (source.AreEqual(value, newValue))
                {
                    return false;
                }
                r.EditValue(source, newValue);
                return true;
            })
                   .EndInput());
        }
 public PathNotDetectedState(DiagnosticMessages diagnosticMessages)
 {
     _diagnosticMessages = diagnosticMessages;
 }
Пример #23
0
 public ApplicationUseCases(DiagnosticMessages diagnosticMessages, PathOperationsContext pathContext)
 {
     _diagnosticMessages = diagnosticMessages;
     _pathContext        = pathContext;
 }
Пример #24
0
 public FakeDiagnosticBubble(DiagnosticMessages diagnosticMessages)
 {
     _diagnosticMessages = diagnosticMessages;
 }
Пример #25
0
 public static string ArgumentIsNullOrEmptyList(object parameterName)
 {
     return(DiagnosticMessages.Common_ArgumentIsNullOrEmptyList(parameterName));
 }
Пример #26
0
 /// <summary>
 /// Writes logging message for command executing.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="invoker">The invoker.</param>
 protected virtual void WriteCommandExecuting(TCommand command, AddonInvoker invoker)
 {
     Debug.Assert(ShouldLog(LogCategory.CommandExecuting));
     Write(LogCategory.CommandExecuting, Environment.NewLine);
     LogCommand(command);
     Write(LogCategory.CommandExecuting, invoker.IsAsync ? DiagnosticMessages.DbLogger_CommandExecutingAsync(DateTimeOffset.Now) : DiagnosticMessages.DbLogger_CommandExecuting(DateTimeOffset.Now));
     Write(LogCategory.CommandExecuting, Environment.NewLine);
 }
Пример #27
0
 public static string FailedToResolveStaticProperty(Type type, string propertyName, Type propertyType)
 {
     return(DiagnosticMessages.Common_FailedToResolveStaticProperty(type, propertyName, propertyType));
 }
Пример #28
0
 public static string ArgumentIsNullOrWhitespace(string parameterName)
 {
     return(DiagnosticMessages.Common_ArgumentIsNullOrWhitespace(parameterName));
 }
Пример #29
0
 public ConcretePathStates(SystemServices systemServices, DiagnosticMessages diagnosticMessages, ApplicationEventsPresenter applicationEventsPresenter)
 {
     _systemServices             = systemServices;
     _diagnosticMessages         = diagnosticMessages;
     _applicationEventsPresenter = applicationEventsPresenter;
 }
Пример #30
0
        internal static Result Parse(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
            }

            GridLength?length    = null;
            double?    minLength = null;
            double?    maxLength = null;

            var splits     = value.Split(';');
            var splitCount = splits.Length;

            if (string.IsNullOrEmpty(splits[splits.Length - 1].Trim()))
            {
                splitCount--;
            }

            if (splitCount < 1 || splitCount > 3)
            {
                throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
            }

            for (int i = 0; i < splitCount; i++)
            {
                var result = ParseNameGridLengthPair(splits[i]);
                if (!result.HasValue)
                {
                    throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
                }

                var pair       = result.GetValueOrDefault();
                var name       = pair.Name;
                var gridLength = pair.GridLength;
                if (string.IsNullOrEmpty(name))
                {
                    if (length.HasValue)
                    {
                        throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
                    }
                    length = gridLength;
                }
                else if (name == "min")
                {
                    if (minLength.HasValue)
                    {
                        throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
                    }
                    minLength = gridLength.Value;
                }
                else
                {
                    Debug.Assert(name == "max");
                    if (maxLength.HasValue)
                    {
                        throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
                    }
                    maxLength = gridLength.Value;
                }
            }

            if (!length.HasValue)
            {
                throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
            }
            double min = minLength.HasValue ? minLength.GetValueOrDefault() : 0.0;
            double max = maxLength.HasValue ? maxLength.GetValueOrDefault() : double.PositiveInfinity;

            if (min < 0 || min > max)
            {
                throw new FormatException(DiagnosticMessages.GridLengthParser_InvalidInput(value));
            }

            return(new Result(length.GetValueOrDefault(), min, max));
        }