Beispiel #1
0
        public IActionResult Del(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(Json(new { msg = "xml文件名不能为空" }));
            }
            else if (string.IsNullOrEmpty(name.ToLower().Replace(".xml", "")))
            {
                return(Json(new { msg = "xml文件名填写不正确" }));
            }
            else
            {
                System.IO.File.Delete(name);

                var map = BaseConfig.GetValue <SqlMap>("SqlMap", FastApiExtension.config.mapFile);
                if (!map.Path.Exists(a => string.Compare(a, name) == 0))
                {
                    var dic = new Dictionary <string, object>();
                    map.Path.Remove(name);
                    dic.Add("SqlMap", map);
                    var json = BaseJson.ModelToJson(dic);
                    System.IO.File.WriteAllText(FastApiExtension.config.mapFile, json);

                    FastMap.InstanceMap();
                }

                return(Json(new { msg = "操作成功" }));
            }
        }
Beispiel #2
0
        static RedisInfo()
        {
            var config = BaseConfig.GetValue <ConfigModel>(AppSettingKey.Redis, "db.json");

            _db  = config.Db;
            conn = new Lazy <ConnectionMultiplexer>(() => { return(ConnectionMultiplexer.Connect(config.Server)); });
        }
Beispiel #3
0
        public IActionResult Del(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(Json(new { msg = "xml文件名不能为空" }));
            }
            else if (string.IsNullOrEmpty(name.ToLower().Replace(".xml", "")))
            {
                return(Json(new { msg = "xml文件名填写不正确" }));
            }
            else
            {
                var xmlPath = string.Format("map/{0}", name);
                System.IO.File.Delete(xmlPath);

                var map = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json");
                if (map.Path.Exists(a => a.ToLower() == string.Format("map/{0}", name.ToLower())))
                {
                    var dic = new Dictionary <string, object>();
                    map.Path.Remove("map/" + name);
                    dic.Add("SqlMap", map);
                    var json = BaseJson.ModelToJson(dic);
                    System.IO.File.WriteAllText("map.json", json);

                    FastMap.InstanceMap();
                }

                return(Json(new { msg = "操作成功" }));
            }
        }
Beispiel #4
0
        public IActionResult OnPostDel(DelParam item)
        {
            var result = new Dictionary <string, object>();

            if (string.IsNullOrEmpty(item.name.ToLower().Replace(".xml", "")))
            {
                result.Add("msg", "xml文件名填写不正确");
            }
            else
            {
                System.IO.File.Delete(item.name);

                var map = BaseConfig.GetValue <SqlMap>("SqlMap", FastApiExtension.config.mapFile, false);
                if (!map.Path.Exists(a => string.Compare(a, item.name) == 0))
                {
                    var dic = new Dictionary <string, object>();
                    map.Path.Remove(item.name);
                    dic.Add("SqlMap", map);
                    var json = BaseJson.ModelToJson(dic);
                    System.IO.File.WriteAllText(FastApiExtension.config.mapFile, json);

                    FastMap.InstanceMap();
                }

                result.Add("msg", "操作成功");
            }
            return(new JsonResult(result));
        }
Beispiel #5
0
        public Task <Dictionary <string, object> > XmlDelAsyn(object name)
        {
            var result = new Dictionary <string, object>();

            if (string.IsNullOrEmpty(name.ToStr().ToLower().Replace(".xml", "")))
            {
                result.Add("msg", "xml文件名填写不正确");
            }
            else
            {
                System.IO.File.Delete(name.ToStr());
                var map = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json", false);
                if (map.Path.Exists(a => a.ToLower() == string.Format("map/{0}", name.ToStr().ToLower())))
                {
                    var dic = new Dictionary <string, object>();
                    map.Path.Remove("map/" + name.ToStr());
                    dic.Add("SqlMap", map);
                    var json = BaseJson.ModelToJson(dic);
                    System.IO.File.WriteAllText("map.json", json);

                    FastMap.InstanceMap();
                }

                result.Add("msg", "操作成功");
            }
            return(Task.FromResult(result));
        }
Beispiel #6
0
        public void OnGet()
        {
            var xml = BaseConfig.GetValue <SqlMap>("SqlMap", FastApiExtension.config.mapFile, false);

            xml.Path.ForEach(a => {
                if (System.IO.File.Exists(a))
                {
                    Map.Add(a, System.IO.File.ReadAllText(a));
                }
            });
        }
Beispiel #7
0
        public void OnGet()
        {
            var xml = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json");

            xml.Path.ForEach(a => {
                if (System.IO.File.Exists(a))
                {
                    Map.Add(a, System.IO.File.ReadAllText(a));
                }
            });
        }
Beispiel #8
0
        public IActionResult OnPostXml(SaveParam item)
        {
            var result = new Dictionary <string, object>();

            try
            {
                if (string.IsNullOrEmpty(item.name.ToLower().Replace(".xml", "")))
                {
                    result.Add("msg", "xml文件名填写不正确");
                    result.Add("Issuccess", false);
                }
                else
                {
                    var xmlPath = string.Format("map/{0}", item.name);
                    using (var xmlWrite = System.IO.File.Create(xmlPath))
                    {
                        xmlWrite.Write(Encoding.Default.GetBytes(item.xml));
                    }

                    if (IFast.CheckMap(xmlPath))
                    {
                        var map = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json");

                        if (!map.Path.Exists(a => a.ToLower() == string.Format("map/{0}", item.name.ToLower())))
                        {
                            var dic = new Dictionary <string, object>();
                            map.Path.Add(string.Format("map/{0}", item.name));
                            dic.Add("SqlMap", map);
                            var json = BaseJson.ModelToJson(dic);
                            System.IO.File.WriteAllText("map.json", json);
                        }

                        FastMap.InstanceMap();
                        result.Add("msg", "操作成功");
                        result.Add("Issuccess", true);
                    }
                    else
                    {
                        result.Add("msg", "操作失败");
                        result.Add("Issuccess", false);
                    }
                }
                return(new JsonResult(result));
            }
            catch (Exception ex)
            {
                BaseLog.SaveLog(ex.StackTrace, "xml");
                result.Add("msg", ex.Message);
                result.Add("Issuccess", false);
                return(new JsonResult(result));
            }
        }
Beispiel #9
0
        public Task <Dictionary <string, object> > XmlSaveAsyn(object name, object xml)
        {
            var IFast  = ServiceContext.Engine.Resolve <IFastRepository>();
            var result = new Dictionary <string, object>();

            try
            {
                if (string.IsNullOrEmpty(name.ToStr().ToLower().Replace(".xml", "")))
                {
                    result.Add("msg", "xml文件名填写不正确");
                    result.Add("Issuccess", false);
                }
                else
                {
                    using (var xmlWrite = System.IO.File.Create(name.ToStr()))
                    {
                        xmlWrite.Write(Encoding.Default.GetBytes(xml.ToStr()));
                    }

                    if (IFast.CheckMap(name.ToStr()))
                    {
                        var map = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json", false);

                        if (!map.Path.Exists(a => a.ToLower() == string.Format("map/{0}", name.ToStr().ToLower())))
                        {
                            var dic = new Dictionary <string, object>();
                            map.Path.Add(string.Format("map/{0}", name.ToStr()));
                            dic.Add("SqlMap", map);
                            var json = BaseJson.ModelToJson(dic);
                            System.IO.File.WriteAllText("map.json", json);
                        }

                        FastMap.InstanceMap();
                        result.Add("msg", "操作成功");
                        result.Add("Issuccess", true);
                    }
                    else
                    {
                        result.Add("msg", "操作失败");
                        result.Add("Issuccess", false);
                    }
                }
                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                BaseLog.SaveLog(ex.StackTrace, "xml");
                result.Add("msg", ex.Message);
                result.Add("Issuccess", false);
                return(Task.FromResult(result));
            }
        }
Beispiel #10
0
        public IActionResult Xml()
        {
            var model = new Dictionary <string, object>();
            var map   = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json");

            map.Path.ForEach(a => {
                if (System.IO.File.Exists(a))
                {
                    model.Add(a, System.IO.File.ReadAllText(a));
                }
            });

            ViewData.Model = model;
            return(View());
        }
Beispiel #11
0
        public IActionResult Xml(string xml, string name)
        {
            try
            {
                if (string.IsNullOrEmpty(xml) || string.IsNullOrEmpty(name))
                {
                    return(Json(new { msg = "xml或文件名不能为空", Issuccess = false }));
                }
                else if (string.IsNullOrEmpty(name.ToLower().Replace(".xml", "")))
                {
                    return(Json(new { msg = "xml文件名填写不正确", Issuccess = false }));
                }
                else
                {
                    var xmlPath = string.Format("map/{0}", name);
                    using (var xmlWrite = System.IO.File.Create(xmlPath))
                    {
                        xmlWrite.Write(Encoding.Default.GetBytes(xml));
                    }

                    if (IFast.CheckMap(xmlPath))
                    {
                        var map = BaseConfig.GetValue <SqlMap>("SqlMap", "map.json");

                        if (!map.Path.Exists(a => a.ToLower() == string.Format("map/{0}", name.ToLower())))
                        {
                            var dic = new Dictionary <string, object>();
                            map.Path.Add(string.Format("map/{0}", name));
                            dic.Add("SqlMap", map);
                            var json = BaseJson.ModelToJson(dic);
                            System.IO.File.WriteAllText("map.json", json);
                        }

                        FastMap.InstanceMap();
                        return(Json(new { msg = "操作成功", Issuccess = true }));
                    }
                    else
                    {
                        return(Json(new { msg = "操作失败", Issuccess = false }));
                    }
                }
            }
            catch (Exception ex)
            {
                BaseLog.SaveLog(ex.StackTrace, "xml");
                return(Json(new { msg = ex.Message, Issuccess = false }));
            }
        }
 public MongoDbRepository(IOptions <ConfigModel> options)
 {
     try
     {
         if (options == null || options.Value.ConnStr == null)
         {
             config = BaseConfig.GetValue <ConfigModel>(AppSettingKey.MongoDb, "db.json");
             client = new MongoClient(config.ConnStr);
         }
         else
         {
             config = options.Value;
             client = new MongoClient(config.ConnStr);
         }
     }
     catch
     {
         throw new Exception(@"services.AddFastMongoDb(a => { a.ConnStr = ''; a.DbName = ''; }); 
                             or ( services.AddFastMongoDb(); and db.json add MongoDb:{'ConnStr':'mongodb address','DbName':'dbname','Max'': 100,'Min': 10} )");
     }
 }
Beispiel #13
0
 public RedisRepository(IOptions <ConfigModel> options)
 {
     if (options == null)
     {
         try
         {
             var config = BaseConfig.GetValue <ConfigModel>(AppSettingKey.Redis, "db.json");
             _db     = config.Db;
             Context = ConnectionMultiplexer.Connect(config.Server);
         }
         catch
         {
             throw new Exception("services.AddFastRedis(a => { a.Server = 'redis address' });");
         }
     }
     else
     {
         var config = options.Value;
         _db     = config.Db;
         Context = ConnectionMultiplexer.Connect(config.Server);
     }
 }
        /// <summary>
        /// 初始化map 3
        /// </summary>
        /// <returns></returns>
        private void InstanceMap(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json")
        {
            var list   = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile);
            var config = DataConfig.Get(dbKey, null, dbFile);
            var db     = new DataContext(dbKey);
            var query  = new DataQuery {
                Config = config, Key = dbKey
            };

            list.Path.ForEach(p => {
                var info = new FileInfo(p);
                var key  = BaseSymmetric.Generate(info.FullName);

                if (!DbCache.Exists(config.CacheType, key))
                {
                    var temp       = new MapXmlModel();
                    temp.LastWrite = info.LastWriteTime;
                    temp.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""));
                    temp.FileName  = info.FullName;
                    if (MapXml.SaveXml(dbKey, key, info, config, db))
                    {
                        DbCache.Set <MapXmlModel>(config.CacheType, key, temp);
                    }
                }
                else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0)
                {
                    DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(a => { DbCache.Remove(config.CacheType, a); });

                    var model       = new MapXmlModel();
                    model.LastWrite = info.LastWriteTime;
                    model.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""));
                    model.FileName  = info.FullName;
                    if (MapXml.SaveXml(dbKey, key, info, config, db))
                    {
                        DbCache.Set <MapXmlModel>(config.CacheType, key, model);
                    }
                }
            });

            if (config.IsMapSave)
            {
                query.Config.DesignModel = FastData.Core.Base.Config.CodeFirst;
                if (query.Config.DbType == DataDbType.Oracle)
                {
                    var listInfo      = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                    var listAttribute = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList();
                    BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute);
                }

                if (query.Config.DbType == DataDbType.MySql)
                {
                    var listInfo      = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                    var listAttribute = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList();
                    BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute);
                }

                if (query.Config.DbType == DataDbType.SqlServer)
                {
                    var listInfo      = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                    var listAttribute = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList();
                    BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute);
                }
            }

            db.Dispose();
        }
Beispiel #15
0
        public static void InstanceMapResource(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json")
        {
            var projectName = Assembly.GetCallingAssembly().GetName().Name;
            var config      = DataConfig.Get(dbKey, projectName, dbFile);
            var db          = new DataContext(dbKey);
            var assembly    = Assembly.Load(projectName);
            var map         = new MapConfigModel();

            using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, mapFile)))
            {
                if (resource != null)
                {
                    using (var reader = new StreamReader(resource))
                    {
                        var content = reader.ReadToEnd();
                        map.Path = BaseJson.JsonToModel <List <string> >(BaseJson.JsonToDic(BaseJson.ModelToJson(BaseJson.JsonToDic(content).GetValue(AppSettingKey.Map))).GetValue("Path").ToStr());
                    }
                }
                else
                {
                    map = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile);
                }
            }

            if (map.Path == null)
            {
                return;
            }

            map.Path.ForEach(a =>
            {
                using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, a.Replace("/", "."))))
                {
                    var xml = "";
                    if (resource != null)
                    {
                        using (var reader = new StreamReader(resource))
                        {
                            xml = reader.ReadToEnd();
                        }
                    }
                    var info = new FileInfo(a);
                    var key  = BaseSymmetric.Generate(info.FullName);
                    if (!DbCache.Exists(config.CacheType, key))
                    {
                        var temp       = new MapXmlModel();
                        temp.LastWrite = info.LastWriteTime;
                        temp.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml);
                        temp.FileName  = info.FullName;
                        if (MapXml.SaveXml(dbKey, key, info, config, db))
                        {
                            DbCache.Set <MapXmlModel>(config.CacheType, key, temp);
                        }
                    }
                    else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0)
                    {
                        DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(f => { DbCache.Remove(config.CacheType, f); });

                        var model       = new MapXmlModel();
                        model.LastWrite = info.LastWriteTime;
                        model.FileKey   = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml);
                        model.FileName  = info.FullName;
                        if (MapXml.SaveXml(dbKey, key, info, config, db))
                        {
                            DbCache.Set <MapXmlModel>(config.CacheType, key, model);
                        }
                    }
                }
            });
        }