コード例 #1
0
        /// <summary>
        /// Register blazorise and configures the default behaviour.
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <param name="configureOptions"></param>
        /// <returns></returns>
        public static IServiceCollection AddBlazorise(this IServiceCollection serviceCollection, Action <BlazoriseOptions> configureOptions = null)
        {
            serviceCollection.Replace(ServiceDescriptor.Transient <IComponentActivator, ComponentActivator>());

            // If options handler is not defined we will get an exception so
            // we need to initialize an empty action.
            configureOptions ??= _ => { };

            serviceCollection.AddSingleton(configureOptions);
            serviceCollection.AddSingleton <BlazoriseOptions>();
            serviceCollection.AddSingleton <IVersionProvider, VersionProvider>();
            serviceCollection.AddSingleton <IIdGenerator, IdGenerator>();
            serviceCollection.AddSingleton <IThemeCache, ThemeCache>();
            serviceCollection.AddSingleton <IValidationMessageLocalizerAttributeFinder, ValidationMessageLocalizerAttributeFinder>();
            serviceCollection.AddSingleton <IDateTimeFormatConverter, DateTimeFormatConverter>();

            foreach (var mapping in LocalizationMap
                     .Concat(ValidationMap)
                     .Concat(ServiceMap)
                     .Concat(JSModuleMap))
            {
                serviceCollection.AddScoped(mapping.Key, mapping.Value);
            }

            return(serviceCollection);
        }
コード例 #2
0
        static void ReadTable(string tableStr, LocalizationMap map)
        {
            using (var csv = new LW.CsvReader(new StringReader(tableStr), true, delimeter))
            {
                int columnsCount = csv.FieldCount;
                var headers      = csv.GetFieldHeaders();
                if (!headers.HasFieldNoBox("key", out int keyIndex))
                {
                    return;
                }

                Dictionary <int, LangCode> validKeys = new Dictionary <int, LangCode>(columnsCount);
                List <int> validKeysIds = new List <int>(columnsCount);
                for (int i = 0; i < columnsCount; ++i)
                {
                    if (i == keyIndex)
                    {
                        continue;
                    }
                    var codeStr = headers[i].ToLower();
                    if (!LocData.TryParseCode(codeStr, out var code))
                    {
                        continue;
                    }
                    validKeys[i] = code;
                    validKeysIds.Add(i);
                }

                int           keysCount = validKeysIds.Count;
                List <string> fields    = new List <string>(columnsCount);
                while (csv.ReadNextRecord())
                {
                    fields.Clear();
                    for (int i = 0; i < columnsCount; ++i)
                    {
                        fields.Add(csv[i]);
                    }
                    var trans = new Dictionary <LangCode, string>(keysCount);
                    for (int i = 0; i < keysCount; ++i)
                    {
                        int j = validKeysIds[i];
                        trans.Add(validKeys[j], fields[j]);
                    }
                    map.Add(fields[keyIndex], trans);
                }
            }
        }