Пример #1
0
 /// <summary>
 /// Ensures a custom formatter is included in the chain, just before the default formatter is executed.
 /// </summary>
 public static void AddFormatter(IValueFormatter formatter)
 {
     if (!Formatters.Contains(formatter))
     {
         Formatters.Insert(Formatters.Count - 2, formatter);
     }
 }
 public ValueArrayPropertySpecification(PropertyInfo property, int position, IValueConverter <TValue> valueConverter, IValueFormatter <TValue> valueFormatter)
     : base(property, position)
 {
     _valueConverter = valueConverter;
     _valueFormatter = valueFormatter;
     _sliceFactory   = Multiple;
 }
Пример #3
0
 public FormatValueArrayPropertySpecification(PropertyInfo property, int position, IValueConverter <TValue> valueConverter,
                                              IValueFormatter <TValue> valueFormatter)
     : base(property, position)
 {
     _valueConverter = valueConverter;
     _valueFormatter = valueFormatter;
 }
Пример #4
0
 /// <summary>
 /// Creates an instance of <see cref="TelemetryConverterBase"/> using default value formatter (<see cref="ApplicationInsightsJsonValueFormatter"/>).
 /// </summary>
 public TelemetryConverterBase()
 {
     if (ValueFormatter != null)
     {
         ValueFormatter = new ApplicationInsightsJsonValueFormatter();
     }
 }
Пример #5
0
 /// <summary>
 /// Removes a custom formatter that was previously added though <see cref="AddFormatter"/>.
 /// </summary>
 public static void RemoveFormatter(IValueFormatter formatter)
 {
     if (customFormatters.Contains(formatter))
     {
         customFormatters.Remove(formatter);
     }
 }
Пример #6
0
        private void EnsureInitialized()
        {
            if (_initialized)
            {
                return;
            }

            if (_optionFactory != null)
            {
                var op = new TransformOptions();
                _optionFactory.Invoke(op);

                if (op.TokenExtractors.Any())
                {
                    _tokens = new ReadOnlyCollection <ITokenExtractor>(op.TokenExtractors);
                }

                _tokenResolver      = op.TokenResolver;
                _formatter          = op.Formatter;
                _disabledLocalCache = op.DisabledLocalCache;
                _globalParameters   = op.GlobalParameters;
            }

            if (_tokens?.Any() != true)
            {
                _tokens = DefaultTokenExtractors;
            }

            _tokenResolver ??= DefaultTokenResolver;
            _formatter ??= DefaultConvertor;

            _initialized = true;
        }
 public ReportParameterHolder(ReportParameterWcf parameter, IValueFormatter formatter)
 {
     this.parameter = parameter;
     this.formatter = formatter;
     if (parameter.ItemsSource != null && parameter.ItemsSource.Contains("{"))
     {
         var items = JsonConvert.DeserializeObject <List <CodeName> >(parameter.ItemsSource, new JsonSerializerSettings
         {
             ContractResolver      = new CodeNameContractResolver(parameter),
             Error                 = CodeNameErrorHandler,
             MissingMemberHandling = MissingMemberHandling.Error,
         });
         if (parameter.ValueMember == parameter.DisplayMember)
         {
             items.Run(i => i.name = i.code);
         }
         ItemsView = new CollectionViewSource {
             Source = items
         };
         parameter.ValueMember   = "code";
         parameter.DisplayMember = "name";
     }
     if (parameter.MultiValueField)
     {
         Value = new ObservableCollection <object>();
     }
     ConvertAndSetDefault();
 }
Пример #8
0
 public SqlSortedDictionary(string dictionaryName, IDbConnection db, IValueFormatter formatter,
                            DbCommandBuilder commandBuilder, bool inMemory)
     : base(dictionaryName, db, formatter, commandBuilder)
 {
     InMemoryTable = inMemory;
     EnsureTable();
 }
Пример #9
0
 public DefaultMapperSettings(
     ITypeMapper?typeMapper         = null,
     IValueFormatter?valueFormatter = null)
 {
     _typeMapper     = typeMapper ?? DefaultTypeMapper.Instance;
     _valueFormatter = valueFormatter ?? Formatter.FullToStringFormatter;
 }
Пример #10
0
 /// <summary>
 /// Ensures a custom formatter is included in the chain, just before the default formatter is executed.
 /// </summary>
 public static void AddFormatter(IValueFormatter formatter)
 {
     if (!Formatters.Contains(formatter))
     {
         Formatters.Insert(Formatters.Count - 2, formatter);
     }
 }
 /// <summary>
 /// Removes a custom formatter that was previously added though <see cref="AddFormatter"/>.
 /// </summary>
 public static void RemoveFormatter(IValueFormatter formatter)
 {
     if (customFormatters.Contains(formatter))
     {
         customFormatters.Remove(formatter);
     }
 }
 /// <summary>
 /// Ensures a custom formatter is included in the chain, just before the default formatter is executed.
 /// </summary>
 public static void AddFormatter(IValueFormatter formatter)
 {
     if (!customFormatters.Contains(formatter))
     {
         customFormatters.Insert(0, formatter);
     }
 }
Пример #13
0
 public ExpressionProcessor(IReadOnlyDictionary <string, object> variables, StringBuilder builder, bool expandPartially, IValueFormatter valueFormatter)
 {
     this.variables           = variables;
     this.builder             = builder;
     this.expandPartially     = expandPartially;
     this.unexpandedVariables = new List <VarSpec>();
     this.valueFormatter      = valueFormatter ?? ValueFormatter;
 }
Пример #14
0
        public IValueFormatter GetFormatter(string name)
        {
            IValueFormatter formatter = null;

            _formatters.TryGetValue(name, out formatter);

            return(formatter);
        }
Пример #15
0
        public PropertyListPropertySpecification(PropertyInfo property, int position, IValueConverter <TValue> valueConverter, IValueFormatter <TValue> valueFormatter)
            : base(property, position)
        {
            _valueConverter = valueConverter;
            _valueFormatter = valueFormatter;

            SetList();
        }
Пример #16
0
        /// <summary>
        /// Create records from a collection
        /// </summary>
        /// <typeparam name="TType">Type of the collection</typeparam>
        /// <param name="values">The collection to create records from</param>
        /// <returns>Created records</returns>
        /// <exception cref="WebExtras.Core.InvalidUsageException"></exception>
        public static DatatableRecords From <TType>(ICollection <TType> values)
            where TType : class
        {
            List <string[]> data = new List <string[]>();

            if (values == null)
            {
                return(new DatatableRecords());
            }

            if (!values.Any())
            {
                return(new DatatableRecords());
            }

            Type t = typeof(TType);

            foreach (TType value in values)
            {
                List <KeyValuePair <int, string> > indexedValues = new List <KeyValuePair <int, string> >();
                PropertyInfo[] props = value.GetType().GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    AOColumnAttribute[] attribs = (AOColumnAttribute[])prop.GetCustomAttributes(typeof(AOColumnAttribute), false);

                    if (attribs.Length == 0)
                    {
                        continue;
                    }

                    if (attribs.Length > 1)
                    {
                        throw new InvalidUsageException(
                                  string.Format("The property '{0}' on '{1}' can not have multiple decorations of AOColumn attribute", prop.Name, t.FullName));
                    }

                    // fact that we got here means that the current property is an AOColumn
                    IValueFormatter formatter = (IValueFormatter)(attribs[0].ValueFormatter == null ?
                                                                  new DefaultValueFormatter() :
                                                                  Activator.CreateInstance(attribs[0].ValueFormatter));

                    string val = formatter.Format(prop.GetValue(value, null), attribs[0].FormatString, value);

                    indexedValues.Add(new KeyValuePair <int, string>(attribs[0].Index, val));
                }

                data.Add(indexedValues.OrderBy(f => f.Key).Select(g => g.Value).ToArray());
            }

            DatatableRecords records = new DatatableRecords
            {
                iTotalDisplayRecords = data.Count,
                iTotalRecords        = data.Count,
                aaData = data.ToArray()
            };

            return(records);
        }
Пример #17
0
 /// <summary>
 /// Closes this instance.
 /// </summary>
 internal void Close()
 {
     if (_isInitialized)
     {
         LoggingConfiguration = null;
         _valueFormatter      = null;
         _isInitialized       = false;
         CloseLayoutRenderer();
     }
 }
        public SqlClientWritePrimitives(string connectionStringWithDefaultCatalogue, DbProviderFactory dbProviderFactory,
            IValueFormatter formatter, IRandomSymbolStringGenerator symbolGenerator, bool mustBeInATransaction,
            NameValueCollection configuration)
            : base(connectionStringWithDefaultCatalogue, dbProviderFactory, formatter, mustBeInATransaction, configuration)
        {
            SqlClientWritePrimitives.Logger.Debug("Entering constructor");

            this.symbolGenerator = symbolGenerator;

            SqlClientWritePrimitives.Logger.Debug("Exiting constructor");
        }
Пример #19
0
        /// <summary>
        /// Returns a human-readable representation of a particular object.
        /// </summary>
        /// <param name="value">The value for which to create a <see cref="System.String"/>.</param>
        /// <param name="nestedPropertyLevel">
        ///     The level of nesting for the supplied value. This is used for indenting the format string for objects that have
        ///     no <see cref="object.ToString()"/> override.
        /// </param>
        /// <param name="useLineBreaks">
        /// Indicates whether the formatter should use line breaks when the specific <see cref="IValueFormatter"/> supports it.
        /// </param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public static string ToString(object value, bool useLineBreaks = false, IList <object> processedObjects = null, int nestedPropertyLevel = 0)
        {
            if (processedObjects == null)
            {
                processedObjects = new List <object>();
            }

            IValueFormatter firstFormatterThatCanHandleValue = Formatters.First(f => f.CanHandle(value));

            return(firstFormatterThatCanHandleValue.ToString(value, useLineBreaks, processedObjects, nestedPropertyLevel));
        }
Пример #20
0
        public virtual IValueFormatter GetValueFormatter(string spelling, TextManager manager)
        {
            IValueFormatter formatter = null;

            if (!ValueFormatters.Any(x => (formatter = x.GetFor(spelling, this, manager)) != null))
            {
                throw new LocalizedKeyNotFoundException("Exceptions.ValueFormatterNotFound", "No parameter evaluator found for {0}", new { Text = spelling });
            }

            return(formatter);
        }
Пример #21
0
        private String callFormatter(Object value, IContainer container)
        {
            IValueFormatter formatter = container.GetFormatter(Formatter);

            if (formatter == null)
            {
                return(null);
            }

            return(formatter.Format(value));
        }
Пример #22
0
 public void Register(Axis axis, IValueFormatter presenter)
 {
     if (this.items.ContainsKey(axis))
     {
         this.items[axis] = presenter;
     }
     else
     {
         this.items.Add(axis, presenter);
     }
 }
Пример #23
0
 /// <summary>
 /// Tries to format value with provided formatter.
 /// In case of error default formatting will be used.
 /// </summary>
 /// <typeparam name="T">Value type.</typeparam>
 /// <param name="formatter">Formatter.</param>
 /// <param name="value">Value to format.</param>
 /// <param name="valueType">Optional value type.</param>
 /// <returns>Formatted string.</returns>
 public static string?TryFormat <T>(this IValueFormatter formatter, T?value, Type?valueType = null)
 {
     try
     {
         return(formatter.Format(value, valueType ?? typeof(T)));
     }
     catch
     {
         return(DefaultToStringFormatter.Instance.Format(value, valueType ?? typeof(T)));
     }
 }
Пример #24
0
        internal RestRequest(HttpMethod httpMethod, IRestClient restClient)
        {
            this.httpRequestMessage        = new HttpRequestMessage();
            this.httpRequestMessage.Method = httpMethod;
            this.restClient   = restClient;
            this.contentParts = new List <ContentPart>();

            this.formFormatter      = this.EnsureDefaultValueSet(this.restClient.Settings.FormFormatters);
            this.mediaTypeFormatter = this.EnsureDefaultValueSet(this.restClient.Settings.MediaTypeFormatters);
            this.valueFormatter     = this.EnsureDefaultValueSet(this.restClient.Settings.UrlParameterFormatters);
        }
        protected DbProviderWritePrimitives(string connectionStringWithDefaultCatalogue, DbProviderFactory dbProviderFactory,
            IValueFormatter formatter, bool mustBeInATransaction, NameValueCollection configuration)
        {
            DbProviderWritePrimitives.Logger.Debug("Entering constructor");

            this.connectionStringWithDefaultCatalogue = connectionStringWithDefaultCatalogue;
            this.dbProviderFactory = dbProviderFactory;
            this.formatter = formatter;
            this.mustBeInATransaction = mustBeInATransaction;
            this.configuration = configuration ?? new NameValueCollection();

            DbProviderWritePrimitives.Logger.Debug("Exiting constructor");
        }
Пример #26
0
 public ParameterValue(object value)
 {
     var other = value as ParameterValue;
     if (other != null)
     {
         Value = other.Value;
         DefaultFormat = other.DefaultFormat;
     }
     else
     {
         Value = value;
     }
 }
Пример #27
0
        public string FormatDisplayTextWith(IValueFormatter formatter)
        {
            var attribute = this.GetType().GetCustomAttribute<ViolationAttribute>();

            if (attribute == null || attribute.DisplayText == null)
            {
                return this.Name;
            }

            var description = attribute.DisplayText.Interpolate(this, formatter);

            return this.Name + ": " + description;
        }
        public void RecursiveFormatting()
        {
            List <KeyValuePair <string, object> > list = new List <KeyValuePair <string, object> >();

            list.Add(new KeyValuePair <string, object>("Key1", new LocalDate(2021, 01, 23)));
            list.Add(new KeyValuePair <string, object>("Key2", new [] { "a1", "a2" }));
            list.Add(new KeyValuePair <string, object>("Key3", ("Internal", 5)));

            IValueFormatter fullToStringFormatter = Formatter.FullRecursiveFormatter;
            string?         formattedValue        = fullToStringFormatter.TryFormat(list);

            formattedValue.Should().Be("[(Key1: 2021-01-23), (Key2: [a1, a2]), (Key3: (Internal, 5))]");
        }
Пример #29
0
        public ParameterValue(object value)
        {
            var other = value as ParameterValue;

            if (other != null)
            {
                Value         = other.Value;
                DefaultFormat = other.DefaultFormat;
            }
            else
            {
                Value = value;
            }
        }
 public HistoricalExcelService(MainRegionViewModel main,
     IEventContext eventContext, 
     IObjectServiceOperations objectServiceOperations,
     IInteractionService interactionService,
     IHistoricalTimeUtility historicalTimeUtility, 
     IValueFormatter valueFormatter,
     IApplicationProperties appliationProperties)
 {
     _historicalTimeUtility = historicalTimeUtility;
     _valueFormatter = valueFormatter;
     _objectServiceOperations = objectServiceOperations;
     _interactionService = interactionService;
     _appliationProperties = appliationProperties;
 }
Пример #31
0
        public CsvObjectWriter([NotNull] CsvWriter writer, [NotNull] IValueFormatter valueFormatter)
        {
            if (valueFormatter == null)
            {
                throw new ArgumentNullException("valueFormatter");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            this._valueFormatter = valueFormatter;
            this._writer         = writer;
        }
        protected AdoNetSortedDictionaryBase(string dictionaryName, IDbConnection db, IValueFormatter formatter,
                                             DbCommandBuilder commandBuilder)
        {
            Requires(!string.IsNullOrWhiteSpace(dictionaryName));
            Requires(db != null);
            Requires(formatter != null);
            Requires(commandBuilder != null);

            Formatter              = formatter;
            Builder                = commandBuilder;
            Db                     = db;
            TableName              = dictionaryName;
            EscapedTableName       = EscapeIdentifier(dictionaryName);
            EscapedKeyColumnName   = EscapeIdentifier("Key");
            EscapedValueColumnName = EscapeIdentifier("Value");
        }
Пример #33
0
        /// <summary>
        /// Registers the explicit formatter specified by <paramref name="formatter"/> parameter that would be used to format values of <paramref name="targetType"/> type.
        /// If there is already an explicit formatter specified for <paramref name="targetType"/> type, it would be overriden with new formatter.
        /// </summary>
        /// <param name="targetType">Type that would be formatted.</param>
        /// <param name="formatter">Formatter used to format given type.</param>
        /// <returns>Self.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="targetType"/> or <paramref name="formatter"/> is null.</exception>
        public ValueFormattingConfiguration RegisterExplicit(Type targetType, IValueFormatter formatter)
        {
            ThrowIfSealed();

            if (targetType == null)
            {
                throw new ArgumentNullException(nameof(targetType));
            }

            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            _explicitFormatters.AddOrUpdate(targetType, formatter, (key, existing) => formatter);
            return(this);
        }
Пример #34
0
        private string FormatValue(string propValue)
        {
            if (String.IsNullOrEmpty(Formatter))
            {
                return(propValue == null ? null : String.Format(Format, propValue));
            }

            Type            formatterType = Type.GetType(Formatter);
            IValueFormatter formatter     = Activator.CreateInstance(formatterType) as IValueFormatter;

            if (formatter == null)
            {
                return(String.Format(Format, propValue));
            }

            return(formatter.Format(propValue));
        }
Пример #35
0
        /// <summary>
        /// Returns a human-readable representation of a particular object.
        /// </summary>
        /// <param name="value">The value for which to create a <see cref="System.String"/>.</param>
        /// <param name="nestedPropertyLevel">
        ///     The level of nesting for the supplied value. This is used for indenting the format string for objects that have
        ///     no <see cref="object.ToString()"/> override.
        /// </param>
        /// <param name="useLineBreaks">
        /// Indicates whether the formatter should use line breaks when the specific <see cref="IValueFormatter"/> supports it.
        /// </param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public static string ToString(object value, bool useLineBreaks = false, IList <object> processedObjects = null, int nestedPropertyLevel = 0)
        {
            if (processedObjects == null)
            {
                processedObjects = new List <object>();
            }

            const int MaxDepth = 15;

            if (nestedPropertyLevel > MaxDepth)
            {
                return("{Maximum recursion depth was reached...}");
            }

            IValueFormatter firstFormatterThatCanHandleValue = Formatters.First(f => f.CanHandle(value));

            return(firstFormatterThatCanHandleValue.ToString(value, useLineBreaks, processedObjects, nestedPropertyLevel));
        }
        private static string FillPlaceholder(string valueSource, string format, object model, IValueFormatter formatter)
        {
            var property = model.GetType().GetProperty(valueSource);

            if (property == null)
            {
                throw new InvalidOperationException(string.Format("Property '{0}' does not exist", valueSource));
            }

            var value = property.GetValue(model);

            if (value == null)
            {
                return "";
            }

            return formatter.Format(value, format);
        }
        public MainRegionViewModel(IEventAggregator eventAggregator,
            IResourceDictionaryProvider resourceDictionaryProvider,
            IApplicationProperties appliationProperties,
            IEventContext eventContext,
            IObjectServiceOperations objectServiceOperations,
            IInteractionService interactionService,
            IHistoricalTimeUtility historicalTimeUtility,
            IPropertyNameService columnNameService,
            IHistoricalColumnService historicalColumnService,
            ISerializationService serializationService,
            IHelpExtension helpExtension,
            IValueFormatter valueFormatter,
            IHdaFileExportService hdaFileExportService,
            IDocumentationService documentationService)
            : base(eventContext, objectServiceOperations,
                  interactionService, historicalTimeUtility,
                  columnNameService, historicalColumnService,
                  serializationService, helpExtension,
                  valueFormatter, eventAggregator,
                  hdaFileExportService, documentationService)
        {
            _eventAggregator = eventAggregator;
            _eventContext = eventContext;
            _historicalTimeUtility = historicalTimeUtility;

            if (HistoricalExcelService.Current == null)
                HistoricalExcelService.Current = new HistoricalExcelService(this,
                    eventContext, objectServiceOperations, interactionService, historicalTimeUtility, valueFormatter, appliationProperties);

            ItemsHistoricalTimePeriodViewModel.Items.CollectionChanged += Items_CollectionChanged;

            ListViewModel.ExportCommand = new DelegateCommand(ExportPropertyList);
            ListViewModel.ExportCommandText = interactionService.TranslatingService.GetSystemText("Import");

            EventListViewModel.ExportCommand = new DelegateCommand(ExportEventList);
            EventListViewModel.ExportCommandText = interactionService.TranslatingService.GetSystemText("Import");

            SubscribeEvents();
        }
Пример #38
0
            protected string GetParameterValue(ParameterValue value, IValueFormatter valueFormatter, State state)
            {
                //Adjust time zone
                if (value.Value is DateTime)
                {
                    value.Value = ((DateTime)value.Value).AdjustToTimeZone(state.Context.TimeZoneInfo);
                }

                string formattedValue;

                try
                {
                    formattedValue = valueFormatter.FormatValue(value, state.Context);
                }
                catch
                {
                    //The formatter couldn't format the value. Just print the value.
                    formattedValue = "" + value.Value;
                }

                return(value.Format(state.Context.StringEncoder, formattedValue));
            }
        public static ParameterValue WithDefaultFormat <TValue>(this TValue value, string format)
        {
            var             manager          = LocalizationHelper.TextManager;
            IValueFormatter defaultFormatter = null;

            foreach (var dialect in manager.Dialects)
            {
                try
                {
                    defaultFormatter = dialect.Value.GetValueFormatter(format, manager);
                }
                catch { }
            }
            if (defaultFormatter == null)
            {
                throw new NullReferenceException("No format found for \"" + format);
            }

            var pv = ParameterValue.Wrap(value);

            pv.DefaultFormat = defaultFormatter;

            return(pv);
        }
Пример #40
0
 private static Type GetFormatterType(IValueFormatter formatter)
 {
     return formatter is DeferredInstantiatedFormatter ? ((DeferredInstantiatedFormatter) formatter).GetFormatterType() : formatter.GetType();
 }
Пример #41
0
 public Binding(String propertyPath, IValueFormatter formatter, String formatString = null)
 {
     PropertyPath = propertyPath;
     Formatter = formatter;
     FormatString = formatString;
 }
Пример #42
0
 public Binding(IValueProvider valueProvider, IValueFormatter formatter, String formatString = null)
 {
     ValueProvider = valueProvider;
     Formatter = formatter;
     FormatString = formatString;
 }
 public WritePrimitives(string connectionStringWithDefaultCatalogue, DbProviderFactory dbProviderFactory,
     IValueFormatter formatter, bool mustBeInATransaction, NameValueCollection configuration)
     : base(connectionStringWithDefaultCatalogue, dbProviderFactory, formatter, mustBeInATransaction,
         configuration)
 {
 }
        public static string Interpolate(this string input, object model, IValueFormatter formatter)
        {
            var output = PlaceholderRegex.Replace(input, m => FillPlaceholder(m.Groups["placeholder"].Value, m.Groups["format"].Value, model, formatter));

            return output;
        }
Пример #45
0
 /// <summary>
 /// Allows a platform-specific assembly to add formatters without affecting the ones added by callers of <see cref="AddFormatter"/>.
 /// </summary>
 /// <param name="formatters"></param>
 internal static void AddPlatformFormatters(IValueFormatter[] formatters)
 {
     foreach (var formatter in formatters)
     {
         if (!defaultFormatters.Contains(formatter))
         {
             defaultFormatters.Insert(0, formatter);
         }
     }
 }
Пример #46
0
 /// <summary>
 /// Ensures a custom formatter is included in the chain, just before the default formatter is executed.
 /// </summary>
 public static void AddFormatter(IValueFormatter formatter)
 {
     if (!customFormatters.Contains(formatter))
     {
         customFormatters.Insert(0, formatter);
     }
 }