Пример #1
0
        public override int Run(string[] remainingArguments)
        {
            try
            {
                var config = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>()
                                               .Where(x => x.ConfigKey == _configType.ToString()).ToLambda())
                             .SingleOrDefault();

                if (config == null)
                {
                    throw new ConsoleHelpAsException($"  *** Invalid config type '{_configType.ToString()}' ***");
                }

                config.ConfigValue = _configValue;

                _uow.Settings.Update(config);
                _uow.Commit();

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }
Пример #2
0
        static void ExportExcelChapter(ExcelPackage p, string name, Table table, ConfigType configType, string relativeDir)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("{\"list\":[");
            foreach (ExcelWorksheet worksheet in p.Workbook.Worksheets)
            {
                if (worksheet.Name.StartsWith("#"))
                {
                    continue;
                }
                if (worksheet.Dimension == null || worksheet.Dimension.End == null)
                {
                    continue;
                }
                Console.WriteLine("ExportExcelJson " + name);
                ExportSheetChapter(worksheet, name, table.HeadInfos, configType, sb);
            }

            sb.AppendLine("]}");

            string dir = string.Format(jsonDir, configType.ToString(), relativeDir);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string jsonPath = Path.Combine(dir, $"{name}.txt");

            using FileStream txt  = new FileStream(jsonPath, FileMode.Create);
            using StreamWriter sw = new StreamWriter(txt);
            sw.Write(sb.ToString());
        }
Пример #3
0
        private void UpdateConfig()
        {
            switch (ConfigType)
            {
            case ConfigType.FxCom:
                if (FxComConfig == null)
                {
                    Config = new FxComConfig();
                }
                break;

            case ConfigType.FxEnet:
                if (FxEnetConfig == null)
                {
                    Config = new FxEnetConfig();
                }
                break;

            case ConfigType.Q:
                if (QConfig == null)
                {
                    Config = new QConfig();
                }
                break;

            default:
                throw new NotSupportedException(ConfigType.ToString());
            }
        }
Пример #4
0
        static void ExportClass(string protoName, List <HeadInfo> classField, ConfigType configType)
        {
            string dir = string.Format(classDir, configType.ToString());

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string exportPath = Path.Combine(dir, $"{protoName}.cs");

            using FileStream txt  = new FileStream(exportPath, FileMode.Create);
            using StreamWriter sw = new StreamWriter(txt);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < classField.Count; i++)
            {
                HeadInfo headInfo = classField[i];
                if (headInfo.FieldAttribute.StartsWith("#"))
                {
                    continue;
                }
                sb.Append($"\t\t[ProtoMember({i + 1}, IsRequired  = true)]\n");
                sb.Append($"\t\tpublic {headInfo.FieldType} {headInfo.FieldName} {{ get; set; }}\n");
            }
            string content = template.Replace("(ConfigName)", protoName).Replace(("(Fields)"), sb.ToString());

            sw.Write(content);
        }
Пример #5
0
        static void ExportExcelJson(ExcelPackage p, string name, Dictionary <string, HeadInfo> classField, ConfigType configType)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("{\"list\":[");
            foreach (ExcelWorksheet worksheet in p.Workbook.Worksheets)
            {
                if (worksheet.Name.StartsWith("#"))
                {
                    continue;
                }
                ExportSheetJson(worksheet, name, classField, configType, sb);
            }
            sb.AppendLine("]}");

            string dir = string.Format(jsonDir, configType.ToString());

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string jsonPath = Path.Combine(dir, $"{name}.txt");

            using FileStream txt  = new FileStream(jsonPath, FileMode.Create);
            using StreamWriter sw = new StreamWriter(txt);
            sw.Write(sb.ToString());
        }
Пример #6
0
 public static string GetSpecificConfigValue(ConfigType configType)
 {
     using (var db = new MemoAppContext())
     {
         return(db.Configs.Where(config => config.ConfigId == configType.ToString()).FirstOrDefault()?.Value);
     }
 }
Пример #7
0
    public virtual bool writeToLocalConfigFile <TValue>(ConfigType configType, IDictionary <int, TValue> container) where TValue : UniqueBaseData
    {
        type = configType;

        Utils.Assert(container == null, "Read Config file :" + configType.ToString() + " null.");

        return(this.writeToLocalFile <TValue>(Config.LocalConfigs[configType].path, container));
    }
Пример #8
0
    public virtual bool writeToLocalConfigFile <T>(ConfigType configType, IList <T> container) where T : class
    {
        type = configType;

        Utils.Assert(container == null, "Read Config file :" + configType.ToString() + " null.");

        return(this.writeToLocalFile <T>(Config.LocalConfigs[configType].path, container));
    }
Пример #9
0
        public virtual bool readFromLocalConfigFile(ConfigType configType, IDictionary <K, V> container)
        {
            type = configType;

            Utils.Assert(container == null, "Read Config file :" + configType.ToString() + " null.");

            return(this.readFromLocalFile(Config.LocalConfigs[configType].path, container, Config.LocalConfigs[configType].format));
        }
Пример #10
0
 public IConfig Resolve(ConfigType configType = ConfigType.Basic)
 {
     if (configType == ConfigType.None)
     {
         return(this.uc.Resolve <IConfig>());
     }
     else
     {
         return(this.uc.Resolve <IConfig>(configType.ToString()));
     }
 }
Пример #11
0
        static void ExportSheetJson(ExcelWorksheet worksheet, string name, Dictionary <string, HeadInfo> classField, ConfigType configType, StringBuilder sb)
        {
            string configTypeStr = configType.ToString();

            for (int row = 6; row <= worksheet.Dimension.End.Row; ++row)
            {
                string prefix = worksheet.Cells[row, 2].Text.Trim();
                if (prefix.Contains("#"))
                {
                    continue;
                }

                if (prefix == "")
                {
                    prefix = "cs";
                }

                if (!prefix.Contains(configTypeStr))
                {
                    continue;
                }

                if (worksheet.Cells[row, 3].Text.Trim() == "")
                {
                    continue;
                }
                sb.Append("{");
                sb.Append($"\"_t\":\"{name}\"");
                for (int col = 3; col <= worksheet.Dimension.End.Column; ++col)
                {
                    string fieldName = worksheet.Cells[4, col].Text.Trim();
                    if (!classField.ContainsKey(fieldName))
                    {
                        continue;
                    }

                    HeadInfo headInfo = classField[fieldName];

                    if (headInfo == null)
                    {
                        continue;
                    }

                    string fieldN = headInfo.FieldName;
                    if (fieldN == "Id")
                    {
                        fieldN = "_id";
                    }
                    sb.Append($",\"{fieldN}\":{Convert(headInfo.FieldType, worksheet.Cells[row, col].Text.Trim())}");
                }
                sb.Append("},\n");
            }
        }
Пример #12
0
        public string GetConfigValue(ConfigType ct)
        {
            IConfigurationDataSource source = (from x in this.DataSourceAdapter.GetConfiguration()
                                               where x.Name == ct.ToString("g")
                                               select x).FirstOrDefault <IConfigurationDataSource>();

            if (source != null)
            {
                return(source.Value);
            }
            return(null);
        }
Пример #13
0
        static void ExportClass(string protoName, Dictionary <string, HeadInfo> classField, ConfigType configType, bool setattr = false)
        {
            string dir = GetClassDir(configType);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string exportPath = Path.Combine(dir, $"{protoName}.cs");

            using FileStream txt  = new FileStream(exportPath, FileMode.Create);
            using StreamWriter sw = new StreamWriter(txt);

            StringBuilder sb = new StringBuilder();

            foreach ((string _, HeadInfo headInfo) in classField)
            {
                if (headInfo == null)
                {
                    continue;
                }

                if (headInfo.FieldType == "json")
                {
                    continue;
                }

                if (!headInfo.FieldAttribute.Contains(configType.ToString()))
                {
                    continue;
                }
                if (setattr && headInfo.FieldType.IndexOf("float", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    sb.Append("\t\t[BsonRepresentation(MongoDB.Bson.BsonType.Double, AllowTruncation = true)]\n");
                }
                sb.Append($"\t\t/// <summary>{headInfo.FieldDesc}</summary>\n");
                sb.Append($"\t\t[ProtoMember({headInfo.FieldIndex})]\n");
                string fieldType = headInfo.FieldType;
                if (fieldType == "int[][]")
                {
                    fieldType = "string[]";
                }

                sb.Append($"\t\tpublic {fieldType} {headInfo.FieldName} {{ get; set; }}\n");
            }

            string content = template.Replace("(ConfigName)", protoName).Replace(("(Fields)"), sb.ToString());

            sw.Write(content);
        }
Пример #14
0
        /// <summary>
        /// Loads an existing config file of <paramref name="type"/>
        /// </summary>
        /// <param name="directory">Root Directory</param>
        /// <param name="type"></param>
        public VariableConfig(string directory, ConfigType type) : this()
        {
            Type = type;

            string path = Path.Combine(directory, type.ToString().ToLowerInvariant());

            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"Unable to load {type} config", path);
            }

            using var sr = new StreamReader(path);
            Read(sr);
        }
Пример #15
0
        public async static Task UpdateSpecificConfigAsync(ConfigType configType, string value)
        {
            using (var db = new MemoAppContext())
            {
                Config targetConfig = db.Configs.Where(config => config.ConfigId == configType.ToString()).FirstOrDefault();

                if (targetConfig == null)
                {
                    Config newConfig = new Config()
                    {
                        ConfigId = configType.ToString(),
                        Value    = value
                    };

                    db.Configs.Add(newConfig);
                }
                else
                {
                    targetConfig.Value = value;
                }

                await db.SaveChangesAsync();
            }
        }
Пример #16
0
 private static async ETTask <TextAsset> GetTextAssetAsync(ConfigType type)
 {
     if (!Application.isPlaying)
     {
         var       result = File.ReadAllText($"Assets/Res/Config/OperateConfig/{type.ToString()}.xml");
         TextAsset text   = new TextAsset(result);
         return(text);
     }
     else
     {
         try
         {
             var result = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync <GameObject>("Config");
             await result.Task;
             TextAsset configStr = result.Result.Get <TextAsset>(type.ToString());
             return(configStr);
         }
         catch (Exception ex)
         {
             Debug.LogError(ex.StackTrace);
         }
     }
     return(new TextAsset());
 }
Пример #17
0
        static void ExportSheetClass(ExcelWorksheet worksheet, Dictionary <string, HeadInfo> classField, ConfigType configType)
        {
            string    configTypeStr = configType.ToString();
            const int row           = 2;

            for (int col = 3; col <= worksheet.Dimension.End.Column; ++col)
            {
                if (worksheet.Name.StartsWith("#"))
                {
                    continue;
                }

                string fieldName = worksheet.Cells[row + 2, col].Text.Trim();
                if (fieldName == "")
                {
                    continue;
                }

                if (classField.ContainsKey(fieldName))
                {
                    continue;
                }

                string fieldCS = worksheet.Cells[row, col].Text.Trim().ToLower();
                if (fieldCS.Contains("#"))
                {
                    classField[fieldName] = null;
                    continue;
                }

                if (fieldCS == "")
                {
                    fieldCS = "cs";
                }

                if (!fieldCS.Contains(configTypeStr))
                {
                    classField[fieldName] = null;
                    continue;
                }

                string fieldDesc = worksheet.Cells[row + 1, col].Text.Trim();
                string fieldType = worksheet.Cells[row + 3, col].Text.Trim();

                classField[fieldName] = new HeadInfo(fieldCS, fieldDesc, fieldName, fieldType, col);
            }
        }
Пример #18
0
        static void ExportExcelJson(ExcelPackage p, string name, ConfigType configType)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("{\"list\":[");
            foreach (ExcelWorksheet worksheet in p.Workbook.Worksheets)
            {
                ExportSheetJson(worksheet, configType, sb);
            }
            sb.AppendLine("]}");

            string jsonPath = Path.Combine(string.Format(jsonDir, configType.ToString()), $"{name}.txt");

            using FileStream txt  = new FileStream(jsonPath, FileMode.Create);
            using StreamWriter sw = new StreamWriter(txt);
            sw.Write(sb.ToString());
        }
Пример #19
0
        private void UpdateConfig()
        {
            switch (ConfigType)
            {
            case ConfigType.Ascii:
                if (AsciiConfig == null)
                {
                    Config = new AsciiConfig();
                }
                break;

            case ConfigType.AsciiViaTcp:
                if (AsciiViaTcpConfig == null)
                {
                    Config = new AsciiViaTcpConfig();
                }
                break;

            case ConfigType.Rtu:
                if (RtuConfig == null)
                {
                    Config = new RtuConfig();
                }
                break;

            case ConfigType.RtuViaTcp:
                if (RtuViaTcpConfig == null)
                {
                    Config = new RTUviaTCPConfig();
                }
                break;

            case ConfigType.Tcp:
                if (TcpConfig == null)
                {
                    Config = new TcpConfig();
                }
                break;

            default:
                throw new NotSupportedException(ConfigType.ToString());
            }
        }
Пример #20
0
        public ActionResult Download(string configType)
        {
            ConfigType config = string.IsNullOrEmpty(configType)
                                    ? ConfigType.KpiAchievement
                                    : (ConfigType)Enum.Parse(typeof(ConfigType), configType);

            var viewModel = new ConfigurationViewModel()
            {
                PeriodeType  = "Yearly",
                Year         = DateTime.Now.Year,
                Month        = DateTime.Now.Month,
                ConfigType   = config.ToString(),
                Years        = _dropdownService.GetYears().MapTo <SelectListItem>(),
                Months       = _dropdownService.GetMonths().MapTo <SelectListItem>(),
                PeriodeTypes = _dropdownService.GetPeriodeTypes().MapTo <SelectListItem>()
            };

            return(PartialView("_Download", viewModel));
        }
Пример #21
0
        public void ChangePath(OpenFileDialog o, ConfigType configtype)
        {
            if (o.ShowDialog() != DialogResult.Cancel)
            {
                _registryKey = Registry.CurrentUser.OpenSubKey("Software\\Bestellsoftware", true);
                _registryKey.SetValue(configtype.ToString(), o.FileName);

                _registryKey.Close();
            }

            if (configtype == ConfigType.Bestellblattpfad)
            {
                BestellblattPfad = o.FileName;
            }
            else
            {
                WarenlistenPfad = o.FileName;
            }
        }
Пример #22
0
        public override int Run(string[] remainingArguments)
        {
            try
            {
                _uow.Settings.Create(
                    new tbl_Setting
                {
                    Id          = Guid.NewGuid(),
                    ConfigKey   = _configType.ToString(),
                    ConfigValue = _configValue,
                    Deletable   = true,
                    Created     = DateTime.UtcNow,
                });
                _uow.Commit();

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }
Пример #23
0
        static void ExportClass(string protoName, Dictionary <string, HeadInfo> classField, ConfigType configType)
        {
            string dir = GetClassDir(configType);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string exportPath = Path.Combine(dir, $"{protoName}.cs");

            using FileStream txt  = new FileStream(exportPath, FileMode.Create);
            using StreamWriter sw = new StreamWriter(txt);

            StringBuilder sb = new StringBuilder();

            foreach ((string _, HeadInfo headInfo) in classField)
            {
                if (headInfo == null)
                {
                    continue;
                }

                if (!headInfo.FieldCS.Contains(configType.ToString()))
                {
                    continue;
                }

                sb.Append($"\t\t/// <summary>{headInfo.FieldDesc}</summary>\n");
                sb.Append($"\t\t[ProtoMember({headInfo.FieldIndex})]\n");
                string fieldType = headInfo.FieldType;
                sb.Append($"\t\tpublic {fieldType} {headInfo.FieldName} {{ get; set; }}\n");
            }

            string content = template.Replace("(ConfigName)", protoName).Replace(("(Fields)"), sb.ToString());

            sw.Write(content);
        }
Пример #24
0
 public override void OnCreate()
 {
     base.OnCreate();
     UnitType   = typeof(TUnit);
     ConfigType = typeof(TConfig);
     GMgr       = BaseGlobal.GetSpawnMgr(UnitType) as BaseUnitSpawnMgr <TUnit, TConfig>;
     if (GMgr == null)
     {
         CLog.Error("错误! GMgr(BaseUnitSpawnMgr)为空:{0},{1}", UnitType.ToString(), ConfigType.ToString());
     }
 }
Пример #25
0
        public bool Set(ConfigType type, string plugin, string key, object value)
        {
            if (!this.IsRegistered(plugin, key))
            {
                return(false);
            }

            ConfigType dbType = this.GetType(plugin, key);

            if (dbType != type)
            {
                throw new InvalidCastException("Can't replace type " + dbType.ToString() + " with type " + type.ToString() + " at " + key + "@" + plugin);
            }
            if (type == ConfigType.Custom)
            {
                throw new ArgumentException("Can not set type Custom!");
            }

            plugin = plugin.ToLower();
            key    = key.ToLower();
            string format;

            if (!this.Exists(plugin, key))
            {
                format = "INSERT INTO CORE_Settings VALUES ('{0}', '{1}', '{2}', '{3}')";
            }
            else
            {
                format = "UPDATE CORE_Settings SET Value = '{3}', Type = '{2}' WHERE Section = '{0}' AND Key = '{1}'";
            }

            try
            {
                string valueString;
                switch (type)
                {
                case ConfigType.Color:
                    if (!Regex.Match((string)value, "^[#]?[0-9a-f]{6}$", RegexOptions.IgnoreCase).Success)
                    {
                        return(false);
                    }
                    valueString = (string)value;
                    if (valueString.Length == 7)
                    {
                        valueString = valueString.Substring(1);
                    }
                    break;

                case ConfigType.String:
                    valueString = (string)value;
                    ConfigurationEntry stringEntry = this.GetEntry(plugin, key);
                    if (stringEntry.Values != null && stringEntry.Values.Length > 0)
                    {
                        List <object> values = new List <object>(stringEntry.Values);
                        if (!values.Contains(value))
                        {
                            return(false);
                        }
                    }
                    break;

                case ConfigType.Password:
                    valueString = (string)value;
                    break;

                case ConfigType.Integer:
                    valueString = ((Int32)value).ToString();
                    ConfigurationEntry intEntry = this.GetEntry(plugin, key);
                    bool result = (intEntry.Values.Length < 1);
                    foreach (object intEntryValue in intEntry.Values)
                    {
                        try
                        {
                            if ((Int32)intEntryValue == (Int32)value)
                            {
                                result = true;
                            }
                        }
                        catch { }
                    }
                    if (!result)
                    {
                        return(false);
                    }
                    break;

                case ConfigType.Boolean:
                    valueString = "false";
                    if ((Boolean)value)
                    {
                        valueString = "true";
                    }
                    break;

                case ConfigType.Date:
                    valueString = TimeStamp.FromDateTime((DateTime)value).ToString();
                    break;

                case ConfigType.Time:
                    valueString = ((TimeSpan)value).Ticks.ToString();
                    break;

                case ConfigType.Dimension:
                    valueString = ((Server)value).ToString();
                    break;

                case ConfigType.Username:
                    if (this.Parent.GetUserID((string)value) < 1)
                    {
                        return(false);
                    }
                    valueString = (string)value;
                    break;

                default:
                    return(false);
                }
                string query = string.Format(format, Config.EscapeString(plugin), Config.EscapeString(key), type.ToString(), Config.EscapeString(valueString));
                if (this.Config.ExecuteNonQuery(query) > 0)
                {
                    ConfigurationChangedArgs args = new ConfigurationChangedArgs(type, plugin, key, value);
                    this.Parent.Events.OnConfigurationChanged(this.Parent, args);
                    return(true);
                }
            }
            catch { }
            return(false);
        }
Пример #26
0
        public object Get(ConfigType type, string plugin, string key, object defaultValue)
        {
            if (!this.IsRegistered(plugin, key))
            {
                return(defaultValue);
            }

            ConfigType dbType = this.GetType(plugin, key);
            bool       exists = this.Exists(plugin, key);

            if (dbType != type)
            {
                throw new InvalidCastException("Can't lookup type " + type.ToString() + " because it's registered as " + dbType.ToString() + " at " + key + "@" + plugin);
            }
            if (type == ConfigType.Custom)
            {
                throw new ArgumentException("Can not get type Custom!");
            }

            if (!exists)
            {
                lock (this.ConfigurationEntries)
                    if (this.ConfigurationEntries[plugin.ToLower()][key.ToLower()].Type != type)
                    {
                        throw new InvalidCastException();
                    }
                    else
                    {
                        return(this.ConfigurationEntries[plugin.ToLower()][key.ToLower()].DefaultValue);
                    }
            }

            plugin = Config.EscapeString(plugin.ToLower());
            key    = Config.EscapeString(key.ToLower());
            object result = null;

            try
            {
                using (IDbCommand command = this.Config.Connection.CreateCommand())
                {
                    command.CommandText = "SELECT Value FROM CORE_Settings WHERE Section = '" + plugin + "' AND Key = '" + key + "'";
                    IDataReader reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        switch (type)
                        {
                        case ConfigType.String:
                        case ConfigType.Username:
                        case ConfigType.Color:
                        case ConfigType.Password:
                            result = reader.GetString(0);
                            break;

                        case ConfigType.Integer:
                            result = (Int32)reader.GetInt64(0);
                            break;

                        case ConfigType.Boolean:
                            result = false;
                            if (reader.GetString(0).ToLower() == "true")
                            {
                                result = true;
                            }
                            break;

                        case ConfigType.Date:
                            result = TimeStamp.ToDateTime(reader.GetInt64(0));
                            break;

                        case ConfigType.Time:
                            result = new TimeSpan(reader.GetInt64(0));
                            break;

                        case ConfigType.Dimension:
                            result = (Server)Enum.Parse(typeof(Server), reader.GetString(0));
                            break;
                        }
                    }
                    reader.Close();
                }
            }
            catch { return(defaultValue); }
            return(result);
        }
Пример #27
0
 //Saves a value in User Settings
 public static void SaveConfig(ConfigType type, object content)
 {
     Properties.Settings.Default[type.ToString()] = content;
     Properties.Settings.Default.Save();
 }
Пример #28
0
    /// <summary>
    /// Reads the config files.
    /// </summary>
    /// <param name="path">Path.</param>

    private bool readConfig <T>(string path, IList <T> container) where T : class
    {
        Utils.Assert(string.IsNullOrEmpty(path), "Path is empty When reads " + type.ToString() + " Config Data.");
        return(this.readFile <T>(path, container, Config.LocalConfigs[type].format));
    }
Пример #29
0
        public string GetConfigValue(ConfigType ct)
        {
            IConfigurationData config = DataSourceAdapter.GetConfiguration().FirstOrDefault(x => x.Name == ct.ToString("g"));

            if (config != null)
            {
                return(config.Value);
            }

            return(null);
        }
Пример #30
0
        /// <summary>
        /// Loads a custom config file and returns the data associated with it.
        /// </summary>
        /// <param name="section">The name of the custom config file.</param>
        /// <returns>The data associated with the custom config file.</returns>
        public static KeyValueConfigurationCollection GetConfig(ConfigType configType)
        {
            ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();

            configMap.ExeConfigFilename = Path.Combine(Utilities.GetAppPath(), $@"cfg\{configType.ToString()}.config");
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);

            return(config.AppSettings.Settings);
        }