Esempio n. 1
0
        public static FrameworkMenu FindMenu(string url)
        {
            if (url == null)
            {
                return(null);
            }
            url = url.ToLower();
            var menus = GlobalServices.GetRequiredService <GlobalData>()?.AllMenus;

            if (menus == null)
            {
                return(null);
            }
            //寻找菜单中是否有与当前判断的url完全相同的
            var menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url).FirstOrDefault();

            //如果没有,抹掉当前url的参数,用不带参数的url比对
            if (menu == null)
            {
                var pos = url.IndexOf("?");
                if (pos > 0)
                {
                    url  = url.Substring(0, pos);
                    menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url).FirstOrDefault();
                }
            }

            //如果还没找到,则判断url是否为/controller/action/id这种格式,如果是则抹掉/id之后再对比
            if (menu == null && url.EndsWith("/index"))
            {
                url  = url.Substring(0, url.Length - 6);
                menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url).FirstOrDefault();
            }
            return(menu);
        }
Esempio n. 2
0
        public static FrameworkMenu FindMenu(string url)
        {
            var menus = GlobalServices.GetRequiredService <GlobalData>()?.AllMenus;

            if (menus == null)
            {
                return(null);
            }
            //寻找菜单中是否有与当前判断的url完全相同的
            var menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url.ToLower()).FirstOrDefault();

            //如果没有,抹掉当前url的参数,用不带参数的url比对
            if (menu == null)
            {
                var pos = url.IndexOf("?");
                if (pos > 0)
                {
                    url  = url.Substring(0, pos);
                    menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url.ToLower()).FirstOrDefault();
                }
            }

            //如果还没找到,则判断url是否为/controller/action/id这种格式,如果是则抹掉/id之后再对比
            if (menu == null)
            {
                var split = url.Split('/');
                if (split.Length >= 2 && Guid.TryParse(split.Last(), out Guid longTest))
                {
                    var pos = url.LastIndexOf("/");
                    url  = url.Substring(0, pos);
                    menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url.ToLower()).FirstOrDefault();
                }
            }
            return(menu);
        }
Esempio n. 3
0
        /// <summary>
        /// OnConfiguring
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            switch (DBType)
            {
            case DBTypeEnum.SqlServer:
                try
                {
                    var Configs = GlobalServices.GetRequiredService <Configs>();
                    if (Configs.IsOldSqlServer == true)
                    {
                        optionsBuilder.UseSqlServer(CSName, op => op.UseRowNumberForPaging());
                    }
                    else
                    {
                        optionsBuilder.UseSqlServer(CSName);
                    }
                }
                catch
                {
                    optionsBuilder.UseSqlServer(CSName, op => op.UseRowNumberForPaging());
                }
                break;

            case DBTypeEnum.MySql:
                optionsBuilder.UseMySql(CSName);
                break;

            case DBTypeEnum.PgSql:
                optionsBuilder.UseNpgsql(CSName);
                break;

            case DBTypeEnum.Memory:
                optionsBuilder.UseInMemoryDatabase(CSName);
                break;

            case DBTypeEnum.SQLite:
                optionsBuilder.UseSqlite(CSName);
                break;

            case DBTypeEnum.Oracle:
                optionsBuilder.UseOracle(CSName);
                break;

            default:
                break;
            }
            try
            {
                var Configs = GlobalServices.GetRequiredService <Configs>();//如果是debug模式,将EF生成的sql语句输出到debug输出
                if (Configs.IsQuickDebug)
                {
                    optionsBuilder.EnableDetailedErrors();
                    optionsBuilder.EnableSensitiveDataLogging();
                    optionsBuilder.UseLoggerFactory(LoggerFactory);
                }
            }
            catch { }
            base.OnConfiguring(optionsBuilder);
        }
Esempio n. 4
0
        /// <summary>
        /// OnConfiguring
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            switch (DBType)
            {
            case DBTypeEnum.SqlServer:
                optionsBuilder.UseSqlServer(CSName);
                break;

            case DBTypeEnum.MySql:
                optionsBuilder.UseMySql(CSName, mySqlOptions =>
                {
                    if (string.IsNullOrEmpty(Version) == false)
                    {
                        mySqlOptions.ServerVersion(Version);
                    }
                });
                break;

            case DBTypeEnum.PgSql:
                optionsBuilder.UseNpgsql(CSName);
                break;

            case DBTypeEnum.Memory:
                optionsBuilder.UseInMemoryDatabase(CSName);
                break;

            case DBTypeEnum.SQLite:
                optionsBuilder.UseSqlite(CSName);
                break;

            case DBTypeEnum.Oracle:
                //optionsBuilder.UseOracle(CSName);
                break;

            default:
                break;
            }
            try
            {
                var Configs = GlobalServices.GetRequiredService <Configs>();//如果是debug模式,将EF生成的sql语句输出到debug输出
                if (Configs.IsQuickDebug)
                {
                    optionsBuilder.EnableDetailedErrors();
                    optionsBuilder.EnableSensitiveDataLogging();
                    optionsBuilder.UseLoggerFactory(LoggerFactory);
                }
            }
            catch { }
            base.OnConfiguring(optionsBuilder);
        }
Esempio n. 5
0
 public ILogger CreateLogger(string categoryName)
 {
     if (cs == null)
     {
         var config = GlobalServices.GetRequiredService <Configs>();
         cs = config.ConnectionStrings.Where(x => x.Key.ToLower() == "defaultlog").FirstOrDefault();
         if (cs == null)
         {
             cs = config.ConnectionStrings.Where(x => x.Key.ToLower() == "default").FirstOrDefault();
         }
         if (cs == null)
         {
             cs = config.ConnectionStrings.FirstOrDefault();
         }
     }
     return(new WTMLogger(categoryName, cs));
 }
Esempio n. 6
0
        public bool IsEnabled(LogLevel logLevel)
        {
            if (this.categoryName != "WalkingTec.Mvvm.Core.ActionLog")
            {
                return(false);
            }
            var levels = GlobalServices.GetRequiredService <IOptionsMonitor <LoggerFilterOptions> >();
            var l      = levels.CurrentValue.Rules.Where(x => x.ProviderName == "WTM").Select(x => x.LogLevel).FirstOrDefault();

            if (l == null)
            {
                l = levels.CurrentValue.MinLevel;
            }
            if (logLevel >= l)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// DoLog
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="logtype"></param>
        public void DoLog(string msg, ActionLogTypesEnum logtype = ActionLogTypesEnum.Debug)
        {
            var log = this.Log.GetActionLog();

            log.LogType    = logtype;
            log.ActionTime = DateTime.Now;
            log.Remark     = msg;
            LogLevel ll = LogLevel.Information;

            switch (logtype)
            {
            case ActionLogTypesEnum.Normal:
                ll = LogLevel.Information;
                break;

            case ActionLogTypesEnum.Exception:
                ll = LogLevel.Error;
                break;

            case ActionLogTypesEnum.Debug:
                ll = LogLevel.Debug;
                break;

            default:
                break;
            }
            GlobalServices.GetRequiredService <ILogger <ActionLog> >().Log <ActionLog>(ll, new EventId(), log, null, (a, b) => {
                return($@"
===WTM Log===
内容:{a.Remark}
地址:{a.ActionUrl}
时间:{a.ActionTime}
===WTM Log===
");
            });
        }
Esempio n. 8
0
File: Utils.cs Progetto: zz110/WTM
        public static string GetNugetVersion(string start = null, bool pre = false)
        {
            var Cache = GlobalServices.GetRequiredService <IDistributedCache>() as IDistributedCache;

            if (Cache.TryGetValue("nugetversion", out NugetInfo rv) == false || rv == null)
            {
                NugetInfo v    = APIHelper.CallAPI <NugetInfo>($"https://api-v2v3search-0.nuget.org/query?q=WalkingTec.Mvvm.Mvc&prerelease={pre.ToString().ToLower()}").Result;
                var       data = v;
                Cache.Add("nugetversion", data, new DistributedCacheEntryOptions()
                {
                    SlidingExpiration = new TimeSpan(0, 0, 36000)
                });
                rv = data;
            }

            if (string.IsNullOrEmpty(start))
            {
                return(rv.data[0]?.version);
            }
            else
            {
                return(rv.data[0].versions.Select(x => x.version).Where(x => x.StartsWith(start)).Last());
            }
        }
Esempio n. 9
0
        private byte[] DownLoadZipPackage(string FileName)
        {
            //文件根目录
            string RootPath = $"{GlobalServices.GetRequiredService<IHostingEnvironment>().WebRootPath}\\{FileName}";

            //文件夹目录
            string FilePath = $"{RootPath}//FileFolder";

            //压缩包目录
            string ZipPath = $"{RootPath}//{FileName}.zip";

            //打开文件夹
            DirectoryInfo FileFolder = new DirectoryInfo(FilePath);

            if (!FileFolder.Exists)
            {
                //创建文件夹
                FileFolder.Create();
            }
            else
            {
                //清空文件夹
                FileSystemInfo[] Files = FileFolder.GetFileSystemInfos();
                foreach (var item in Files)
                {
                    if (item is DirectoryInfo)
                    {
                        DirectoryInfo Directory = new DirectoryInfo(item.FullName);
                        Directory.Delete(true);
                    }
                    else
                    {
                        File.Delete(item.FullName);
                    }
                }
            }

            //放入数据
            for (int i = 0; i < ExportExcelCount; i++)
            {
                var    List     = EntityList.Skip(i * ExportMaxCount).Take(ExportMaxCount).ToList();
                var    WorkBook = GenerateWorkBook(List);
                string SavePath = $"{FilePath}/{FileName}_{i + 1}.xlsx";
                using (FileStream FS = new FileStream(SavePath, FileMode.CreateNew))
                {
                    WorkBook.Write(FS);
                }
            }

            //生成压缩包
            ZipFile.CreateFromDirectory(FilePath, ZipPath);

            //读取压缩包
            FileStream ZipFS = new FileStream(ZipPath, FileMode.Open, FileAccess.Read);

            byte[] bt = new byte[ZipFS.Length];
            ZipFS.Read(bt, 0, bt.Length);
            ZipFS.Close();

            //删除根目录文件夹
            DirectoryInfo RootFolder = new DirectoryInfo(RootPath);

            if (RootFolder.Exists)
            {
                RootFolder.Delete(true);
            }

            return(bt);
        }