예제 #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
            {
                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 = "操作成功" }));
            }
        }
예제 #2
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));
        }
예제 #3
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     FastMap.InstanceProperties("FastApiGatewayDb.DataModel", "FastApiGatewayDb.Ui.dll");
     FastMap.InstanceTable("FastApiGatewayDb.DataModel", "FastApiGatewayDb.Ui.dll");
     FastMap.InstanceMap();
 }
예제 #4
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 = "操作成功" }));
            }
        }
예제 #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));
        }
예제 #6
0
        protected void Application_Start()
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            FastMap.InstanceProperties("DataModel.AI", "EMR.Web.dll");
            FastMap.InstanceProperties("DataModel.CD", "EMR.Web.dll");
            FastMap.InstanceProperties("DataModel.CN", "EMR.Web.dll");
            FastMap.InstanceProperties("DataModel.GI", "EMR.Web.dll");

            FastMap.InstanceMap(AppEmr.DbConst.EmrDb);
        }
예제 #7
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));
            }
        }
예제 #8
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));
            }
        }
예제 #9
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 }));
            }
        }
예제 #10
0
        public void ConfigureServices(IServiceCollection services)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Encoding encoding = Encoding.GetEncoding("GB2312");

            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
            services.AddResponseCompression();

            services.AddFastData();
            services.AddFastApi();

            services.AddCors(options =>
            {
                options.AddPolicy("any", builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); });
            });

            services.AddMvc();

            FastMap.InstanceMap();
        }
예제 #11
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <IFastRepository, FastRepository>();
            services.AddSingleton <IRedisRepository, RedisRepository>();
            services.AddResponseCompression();
            services.AddRazorPages();
            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));

            ServiceContext.Init(new ServiceEngine(services.BuildServiceProvider()));
            FastMap.InstanceMap();
            FastMap.InstanceTable("FastEtlWeb.DataModel", "FastEtlWeb.dll");

            services.AddMvc(options =>
            {
                options.Filters.Add(new CheckFilter());
            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0).AddRazorPagesOptions(o =>
            {
                o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
                o.RootDirectory = "/Pages";
                o.Conventions.AddPageRoute("/Data", "");
            });
        }
예제 #12
0
        public void ConfigureServices(IServiceCollection services)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Encoding encoding = Encoding.GetEncoding("GB2312");

            services.AddResponseCompression();
            services.AddFastData();
            services.AddFastApi();

            services.AddCors(options =>
            {
                options.AddPolicy("any", builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); });
            });

            FastMap.InstanceMap();

            services.AddMvc(options => { options.Filters.Add(new CheckFilter()); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddRazorPagesOptions(o => {
                o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
                o.RootDirectory = "/Pages";
            });
        }
예제 #13
0
        public static IServiceCollection AddFastApi(this IServiceCollection serviceCollection, Action <ConfigApi> action)
        {
            var config = new ConfigApi();

            action(config);

            if (string.IsNullOrEmpty(config.dbKey))
            {
                throw new Exception("config dbkey is not null");
            }

            serviceCollection.AddSingleton <IFastRepository, FastRepository>();
            serviceCollection.AddSingleton <IFastApi, FastApi>();
            ServiceContext.Init(new ServiceEngine(serviceCollection.BuildServiceProvider()));

            Assembly.GetCallingAssembly().GetReferencedAssemblies().ToList().ForEach(a => {
                try
                {
                    if (!AppDomain.CurrentDomain.GetAssemblies().ToList().Exists(b => b.GetName().Name == a.Name))
                    {
                        Assembly.Load(a.Name);
                    }
                }
                catch (Exception ex) { }
            });

            if (config.IsResource)
            {
                FastMap.InstanceMapResource(config.dbKey, config.dbFile, config.mapFile, Assembly.GetCallingAssembly().GetName().Name);
            }
            else
            {
                FastMap.InstanceMap(config.dbKey, config.dbFile, config.mapFile);
            }

            FastApiExtension.config = config;
            return(serviceCollection);
        }
예제 #14
0
        public static IServiceCollection AddFastData(this IServiceCollection serviceCollection, Action <ConfigData> action)
        {
            config = new ConfigData();
            action(config);

            if (!config.IsResource && DataConfig.Get(config.dbKey, null, config.dbFile).CacheType == CacheType.Redis && ServiceContext.Engine.Resolve <IRedisRepository>() == null)
            {
                throw new System.Exception("ConfigureServices First add services.AddFastRedis(); Second add services.AddFastData()");
            }

            if (DataConfig.Get(config.dbKey, Assembly.GetCallingAssembly().GetName().Name, config.dbFile).CacheType == CacheType.Redis && ServiceContext.Engine.Resolve <IRedisRepository>() == null)
            {
                throw new System.Exception("ConfigureServices First add services.AddFastRedis(); Second add services.AddFastData()");
            }

            serviceCollection.AddSingleton <IFastRepository, FastRepository>();

            Assembly.GetCallingAssembly().GetReferencedAssemblies().ToList().ForEach(a =>
            {
                if (!AppDomain.CurrentDomain.GetAssemblies().ToList().Exists(b => b.GetName().Name == a.Name))
                {
                    try { Assembly.Load(a.Name); } catch (Exception ex) { }
                }
            });

            if (config.aop != null)
            {
                serviceCollection.AddSingleton <IFastAop>(config.aop);
            }

            if (!string.IsNullOrEmpty(config.NamespaceService))
            {
                FastMap.InstanceService(serviceCollection, config.NamespaceService);
            }

            ServiceContext.Init(new ServiceEngine(serviceCollection.BuildServiceProvider()));

            var projectName = Assembly.GetCallingAssembly().GetName().Name;

            if (config.IsResource)
            {
                FastMap.InstanceMapResource(config.dbKey, config.dbFile, config.mapFile, projectName);
            }
            else
            {
                FastMap.InstanceMap(config.dbKey, config.dbFile, config.mapFile);
            }

            if (config.IsCodeFirst && !string.IsNullOrEmpty(config.NamespaceCodeFirst) && config.IsResource)
            {
                FastMap.InstanceProperties(config.NamespaceCodeFirst, config.dbFile, projectName);
                FastMap.InstanceTable(config.NamespaceCodeFirst, config.dbKey, config.dbFile, projectName);
            }

            if (config.IsCodeFirst && !string.IsNullOrEmpty(config.NamespaceCodeFirst) && !config.IsResource)
            {
                FastMap.InstanceProperties(config.NamespaceCodeFirst, config.dbFile);
                FastMap.InstanceTable(config.NamespaceCodeFirst, config.dbKey, config.dbFile);
            }

            if (!string.IsNullOrEmpty(config.NamespaceProperties) && config.IsResource)
            {
                FastMap.InstanceProperties(config.NamespaceProperties, config.dbFile, projectName);
            }

            if (!string.IsNullOrEmpty(config.NamespaceProperties) && !config.IsResource)
            {
                FastMap.InstanceProperties(config.NamespaceProperties, config.dbFile);
            }

            return(serviceCollection);
        }