//TODO
        public static string ResolveVirtualPath(string virtPath, bool addTrailingSlash = true)
        {
            if (virtPath == null)
            {
                virtPath = "";
            }

            var webHostEnvironment = CommonServiceProvider.GetService <IWebHostEnvironment>();

            if (virtPath.StartsWith("~") && !Uri.IsWellFormedUriString(virtPath, UriKind.Absolute))
            {
                var rootPath = "/";
                if (!string.IsNullOrEmpty(webHostEnvironment.WebRootPath) && webHostEnvironment.WebRootPath.Length > 1)
                {
                    rootPath = webHostEnvironment.WebRootPath.Trim('/');
                }
                virtPath = virtPath.Replace("~", rootPath);
            }
            if (addTrailingSlash)
            {
                virtPath += "/";
            }
            else
            {
                virtPath = virtPath.TrimEnd('/');
            }
            return(virtPath.Replace("//", "/"));
        }
Beispiel #2
0
        public void Test003()
        {
            var commonServiceProvider = new CommonServiceProvider();

            var actual = commonServiceProvider.GetService <IAssemblyAsGlobalSettingRepository>();

            Assert.AreEqual(typeof(AssemblyAsGlobalSettingRepository), actual.GetType());
        }
Beispiel #3
0
        static WebPath()
        {
            var section = CommonServiceProvider.GetService <Configuration.Storage>();

            if (section != null)
            {
                Appenders = section.Appender;
            }
        }
Beispiel #4
0
        public void Test002()
        {
            var commonServiceProvider = new CommonServiceProvider();

            commonServiceProvider.AddOrReplace <Object>("TEST OBJECT");

            var actual = commonServiceProvider.GetService <Object>();

            Assert.AreEqual("TEST OBJECT", actual);
        }
Beispiel #5
0
        public static async Task Main(string[] args)
        {
            var host = Host.CreateDefaultBuilder(args)
                       .ConfigureAppConfiguration((hostContext, config) =>
            {
                var buided = config.Build();
                var path   = buided["pathToConf"];
                if (!Path.IsPathRooted(path))
                {
                    path = Path.GetFullPath(Path.Combine(hostContext.HostingEnvironment.ContentRootPath, path));
                }
                config.SetBasePath(path);
                var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
                config
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env}.json", true)
                .AddJsonFile("autofac.json")
                .AddJsonFile("storage.json")
                .AddJsonFile("notify.json")
                .AddJsonFile("kafka.json")
                .AddJsonFile($"kafka.{env}.json", true);
            })
                       .ConfigureServices((hostContext, services) =>
            {
                services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
                services.AddWebItemManager();

                var serviceProvider = services.BuildServiceProvider();
                ConfigurationManager.Init(serviceProvider);
                CommonServiceProvider.Init(serviceProvider);
                serviceProvider.UseWebItemManager();

                var c = ConfigurationManager.GetSetting <NotifyServiceCfg>("notify");
                c.Init();
                services.AddSingleton(c);
                services.AddSingleton <DbWorker>();
                services.AddSingleton <NotifyCleaner>();
                services.AddSingleton <NotifySender>();
                services.AddSingleton <NotifyService>();
                services.AddHostedService <NotifyServiceLauncher>();
            })
                       .UseConsoleLifetime()
                       .Build();

            using (host)
            {
                // Start the host
                await host.StartAsync();

                // Wait for the host to shutdown
                await host.WaitForShutdownAsync();
            }
        }
        public UserManager(IUserService service)
        {
            userService = service;

            systemUsers = Configuration.Constants.SystemAccounts.ToDictionary(a => a.ID, a => new UserInfo {
                ID = a.ID, LastName = a.Name
            });
            systemUsers[Constants.LostUser.ID]     = Constants.LostUser;
            systemUsers[Constants.OutsideUser.ID]  = Constants.OutsideUser;
            systemUsers[Constants.NamingPoster.ID] = Constants.NamingPoster;
            Accessor = CommonServiceProvider.GetService <IHttpContextAccessor>();
        }
        public static string ResolvePhysicalPath(string physPath, IDictionary <string, string> storageConfig)
        {
            physPath = Normalize(physPath, false).TrimStart('~');

            var webHostEnvironment = CommonServiceProvider.GetService <IWebHostEnvironment>();

            if (physPath.Contains(Constants.STORAGE_ROOT_PARAM))
            {
                physPath = physPath.Replace(Constants.STORAGE_ROOT_PARAM, StorageRoot ?? storageConfig[Constants.STORAGE_ROOT_PARAM]);
            }

            if (!Path.IsPathRooted(physPath))
            {
                physPath = Path.GetFullPath(Path.Combine(webHostEnvironment.ContentRootPath, physPath.Trim(Path.DirectorySeparatorChar)));
            }
            return(physPath);
        }
        static WebSkin()
        {
            try
            {
                var dir = Path.Combine(CommonServiceProvider.GetService <IWebHostEnvironment>().ContentRootPath, "~/skins/default/");
                if (!Directory.Exists(dir))
                {
                    return;
                }

                foreach (var f in Directory.GetFiles(dir, "common_style.*.css"))
                {
                    BaseCultureCss.Add(Path.GetFileName(f).Split('.')[1]);
                }
            }
            catch
            {
            }
        }
Beispiel #9
0
        public static bool Exists(string relativePath)
        {
            var path = GetPath(relativePath);

            if (!Existing.ContainsKey(path))
            {
                if (Uri.IsWellFormedUriString(path, UriKind.Relative) && HttpContext.Current != null)
                {
                    //Local
                    Existing[path] = File.Exists(Path.Combine(CommonServiceProvider.GetService <IWebHostEnvironment>().ContentRootPath, path));
                }
                if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
                {
                    //Make request
                    Existing[path] = CheckWebPath(path);
                }
            }
            return(Existing[path]);
        }
        public static void SaveColorTheme(string theme)
        {
            var settings = new ColorThemesSettings {
                ColorThemeName = theme, FirstRequest = false
            };
            var path         = "/skins/" + ThemeFolderTemplate;
            var resolvedPath = path.ToLower().Replace(ThemeFolderTemplate, theme);

            try
            {
                var filePath = Path.Combine(CommonServiceProvider.GetService <IWebHostEnvironment>().ContentRootPath, resolvedPath);
                if (Directory.Exists(filePath))
                {
                    settings.Save();
                }
            }
            catch (Exception)
            {
            }
        }
        public static string GetThemeFolderName(string path)
        {
            var folderName   = GetColorThemesSettings();
            var resolvedPath = path.ToLower().Replace(ThemeFolderTemplate, folderName);

            //TODO check
            var urlHelper = CommonServiceProvider.GetService <IUrlHelper>();

            if (!urlHelper.IsLocalUrl(resolvedPath))
            {
                resolvedPath = urlHelper.Action(resolvedPath);
            }

            try
            {
                var filePath = Path.Combine(CommonServiceProvider.GetService <IWebHostEnvironment>().ContentRootPath, resolvedPath);
                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException("", path);
                }
            }
            catch (Exception)
            {
                resolvedPath = path.ToLower().Replace(ThemeFolderTemplate, "default");

                if (!urlHelper.IsLocalUrl(resolvedPath))
                {
                    resolvedPath = urlHelper.Action(resolvedPath);
                }

                var filePath = Path.Combine(CommonServiceProvider.GetService <IWebHostEnvironment>().ContentRootPath, resolvedPath);

                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException("", path);
                }
            }

            return(resolvedPath);
        }
        private void Configure()
        {
            if (!configured)
            {
                var config  = CommonServiceProvider.GetService <Configuration.Storage>();
                var handler = config.GetHandler("s3");
                if (handler != null)
                {
                    var props = handler.GetProperties();
                    bucket          = props["bucket"];
                    accessKey       = props["acesskey"];
                    secretAccessKey = props["secretaccesskey"];
                    region          = props["region"];
                }
                configErrors = string.IsNullOrEmpty(CoreContext.Configuration.BaseDomain) || //localhost
                               string.IsNullOrEmpty(accessKey) ||
                               string.IsNullOrEmpty(secretAccessKey) ||
                               string.IsNullOrEmpty(bucket) ||
                               string.IsNullOrEmpty(region);

                configured = true;
            }
        }
        public static void Export(Options options)
        {
            var services = new ServiceCollection();
            var startup  = new Startup();

            startup.ConfigureServices(services);
            var serviceProvider = services.BuildServiceProvider();

            CommonServiceProvider.Init(serviceProvider);
            ConfigurationManager.Init(serviceProvider);

            var cultures        = new List <string>();
            var projects        = new List <ResFile>();
            var enabledSettings = new EnabledSettings();
            Action <string, string, string, string, string, string> export = null;

            try
            {
                var(project, module, filePath, exportPath, culture, format, key) = options;

                if (format == "json")
                {
                    export = JsonManager.Export;
                }
                else
                {
                    export = ResxManager.Export;
                }

                if (string.IsNullOrEmpty(exportPath))
                {
                    exportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                }

                if (!Path.IsPathRooted(exportPath))
                {
                    exportPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), exportPath));
                }

                if (!Directory.Exists(exportPath))
                {
                    Console.WriteLine("Error!!! Export path doesn't exist! Please enter a valid directory path.");
                    return;
                }

                enabledSettings = ConfigurationManager.GetSetting <EnabledSettings>("enabled");
                cultures        = ResourceData.GetCultures().Where(r => r.Available).Select(r => r.Title).Intersect(enabledSettings.Langs).ToList();
                projects        = ResourceData.GetAllFiles();

                ExportWithProject(project, module, filePath, culture, exportPath, key);

                Console.WriteLine("The data has been successfully exported!");
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
            }

            void ExportWithProject(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(projectName))
                {
                    ExportWithModule(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    var projectToExport = projects
                                          .Where(r => string.IsNullOrEmpty(r.ModuleName) || r.ModuleName == moduleName)
                                          .Where(r => string.IsNullOrEmpty(r.FileName) || r.FileName == fileName)
                                          .Select(r => r.ProjectName)
                                          .Intersect(enabledSettings.Projects);

                    foreach (var p in projectToExport)
                    {
                        ExportWithModule(p, moduleName, fileName, culture, exportPath, key);
                    }
                }
            }

            void ExportWithModule(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(moduleName))
                {
                    ExportWithFile(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    var moduleToExport = projects
                                         .Where(r => r.ProjectName == projectName)
                                         .Where(r => string.IsNullOrEmpty(r.FileName) || r.FileName == fileName)
                                         .Select(r => r.ModuleName);

                    foreach (var m in moduleToExport)
                    {
                        ExportWithFile(projectName, m, fileName, culture, exportPath, key);
                    }
                }
            }

            void ExportWithFile(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    ExportWithCulture(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    foreach (var f in projects.Where(r => r.ProjectName == projectName && r.ModuleName == moduleName).Select(r => r.FileName))
                    {
                        ExportWithCulture(projectName, moduleName, f, culture, exportPath, key);
                    }
                }
            }

            void ExportWithCulture(string projectName, string moduleName, string fileName, string culture, string exportPath, string key)
            {
                if (!string.IsNullOrEmpty(culture))
                {
                    export(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    ParallelEnumerable.ForAll(cultures.AsParallel(), c => export(projectName, moduleName, fileName, c, exportPath, key));
                }
            }
        }
 static StorageFactory()
 {
     Cache = new KafkaCache <DataStoreCacheItem>();
     Cache.Subscribe((r) => DataStoreCache.Remove(r.TenantId, r.Module), CacheNotifyAction.Remove);
     Section = new Lazy <Configuration.Storage>(() => CommonServiceProvider.GetService <Configuration.Storage>(), true);
 }