IEnumerable <ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var shellSettings = new List <ShellSettings>();

            foreach (var tenant in _appDataFolder.ListDirectories("Sites"))
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenant.Name);
                }
                var configurationContainer =
                    new ConfigurationBuilder()
                    .AddJsonFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "json")),
                                 true)
                    .AddXmlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "xml")),
                                true)
                    .AddYamlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "txt")),
                                 false);

                var config = configurationContainer.Build();

                var shellSetting = new ShellSettings(config);
                shellSettings.Add(shellSetting);

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
                }
            }

            return(shellSettings);
        }
Example #2
0
        public WarmupReportManager(
            ShellSettings shellSettings,
            IAppDataFolder appDataFolder) {
            _appDataFolder = appDataFolder;

            _warmupReportPath = _appDataFolder.Combine("Sites", _appDataFolder.Combine(shellSettings.Name, WarmupReportFilename));
        }
Example #3
0
        public void Init() {
            if (Directory.Exists(_basePath)) {
                Directory.Delete(_basePath, true);
            }

            Directory.CreateDirectory(_basePath);
            _appDataFolder = AppDataFolderTests.CreateAppDataFolder(_basePath);
            _webDownloader = new Mock<IWebDownloader>();
            _orchardServices = new StubOrchardServices();
            ((StubWorkContextAccessor.WorkContextImpl.StubSite) _orchardServices.WorkContext.CurrentSite).BaseUrl = "http://orchardproject.net";

            _settings = new WarmupSettingsPart { Record = new WarmupSettingsPartRecord() };
            _orchardServices.WorkContext.CurrentSite.ContentItem.Weld(_settings);
 
            var builder = new ContainerBuilder();
            builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
            builder.RegisterInstance(_orchardServices).As<IOrchardServices>();
            builder.RegisterType<DefaultLockFileManager>().As<ILockFileManager>();
            builder.RegisterType<WarmupUpdater>().As<IWarmupUpdater>();
            builder.RegisterType<StubClock>().As<IClock>();
            builder.RegisterType<WarmupReportManager>().As<IWarmupReportManager>();
            builder.RegisterInstance(new ShellSettings { Name = "Default" }).As<ShellSettings>();
            builder.RegisterInstance(_clock = new StubClock()).As<IClock>();
            builder.RegisterInstance(_webDownloader.Object).As<IWebDownloader>();
            _container = builder.Build();

            _lockFileManager = _container.Resolve<ILockFileManager>();
            _warmupUpdater = _container.Resolve<IWarmupUpdater>();
            _reportManager = _container.Resolve<IWarmupReportManager>();

            _warmupFilename = _appDataFolder.Combine(TenantFolder, "warmup.txt");
            _lockFilename = _appDataFolder.Combine(TenantFolder, "warmup.txt.lock");
        }
Example #4
0
        IEnumerable <ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var shellSettings = new List <ShellSettings>();

            foreach (var tenant in _appDataFolder.ListDirectories(_optionsAccessor.Value.Location))
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenant.Name);
                }
                var configurationContainer =
                    new ConfigurationBuilder()
                    .SetBasePath(_appDataFolder.RootPath)
                    .AddJsonFile(_appDataFolder.Combine(tenant.FullName, string.Format(SettingsFileNameFormat, "json")),
                                 true)
                    .AddXmlFile(_appDataFolder.Combine(tenant.FullName, string.Format(SettingsFileNameFormat, "xml")),
                                true)
                    .AddYamlFile(_appDataFolder.Combine(tenant.FullName, string.Format(SettingsFileNameFormat, "txt")),
                                 false);

                var config       = configurationContainer.Build();
                var shellSetting = ShellSettingsSerializer.ParseSettings(config);
                shellSetting.Location = tenant.Name;
                shellSettings.Add(shellSetting);

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
                }
            }

            return(shellSettings);
        }
Example #5
0
        public WarmupReportManager(
            ShellSettings shellSettings,
            IAppDataFolder appDataFolder)
        {
            _appDataFolder = appDataFolder;

            _warmupReportPath = _appDataFolder.Combine("Sites", _appDataFolder.Combine(shellSettings.Name, WarmupReportFilename));
        }
Example #6
0
        public PipelineFilePart Upload(HttpPostedFileBase input, string role, string tag)
        {
            var part        = _orchardServices.ContentManager.New <PipelineFilePart>(Common.PipelineFileName);
            var permissions = part.As <ContentPermissionsPart>();

            permissions.Enabled = true;

            permissions.ViewContent   = "Administrator";
            permissions.EditContent   = "Administrator";
            permissions.DeleteContent = "Administrator";

            permissions.ViewOwnContent   = "Authenticated";
            permissions.EditOwnContent   = "Authenticated";
            permissions.DeleteOwnContent = "Authenticated";

            if (role != "Private")
            {
                permissions.ViewContent += "," + role;
            }

            part.As <TitlePart>().Title = input.FileName;

            if (tag != string.Empty)
            {
                var tags = tag.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(t => !t.Equals(Common.AllTag, StringComparison.OrdinalIgnoreCase)).ToArray();
                if (tags.Any())
                {
                    _tagService.UpdateTagsForContentItem(part.ContentItem, tags);
                }
            }

            var exportFile = string.Format("{0}-{1}-{2}",
                                           _orchardServices.WorkContext.CurrentUser.UserName,
                                           _clock.UtcNow.ToString(FileTimestamp),
                                           Path.GetFileName(input.FileName)
                                           );

            if (!_appDataFolder.DirectoryExists(Common.FileFolder))
            {
                _appDataFolder.CreateDirectory(Common.FileFolder);
            }

            part.FullPath  = _appDataFolder.MapPath(_appDataFolder.Combine(Common.FileFolder, exportFile));
            part.Direction = "In";
            input.SaveAs(part.FullPath);
            _orchardServices.ContentManager.Create(part);

            _orchardServices.Notifier.Information(T("{0} uploaded successfully.", Path.GetFileName(input.FileName)));

            return(part);
        }
Example #7
0
        public PipelineFilePart Upload(HttpPostedFileBase input, string role, string tag, int number)
        {
            var part        = _orchardServices.ContentManager.New <PipelineFilePart>(Common.PipelineFileName);
            var permissions = part.As <ContentPermissionsPart>();

            permissions.Enabled = true;

            permissions.ViewContent   = "Administrator";
            permissions.EditContent   = "Administrator";
            permissions.DeleteContent = "Administrator";

            permissions.ViewOwnContent   = "Authenticated";
            permissions.EditOwnContent   = "Authenticated";
            permissions.DeleteOwnContent = "Authenticated";

            if (role != "Private")
            {
                permissions.ViewContent += "," + role;
            }

            part.OriginalName           = input.FileName;
            part.As <TitlePart>().Title = input.FileName;

            if (tag != string.Empty)
            {
                var tags = tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(t => !t.Equals(Common.AllTag, StringComparison.OrdinalIgnoreCase)).ToArray();
                if (tags.Any())
                {
                    _tagService.UpdateTagsForContentItem(part.ContentItem, tags);
                }
            }

            var exportFile = Common.GetSafeFileName(_orchardServices.WorkContext.CurrentUser.UserName, Path.GetFileName(input.FileName), number);

            var path = Common.GetAppFolder();

            if (!_appDataFolder.DirectoryExists(path))
            {
                _appDataFolder.CreateDirectory(path);
            }

            part.FullPath  = _appDataFolder.MapPath(_appDataFolder.Combine(path, exportFile));
            part.Direction = "In";
            input.SaveAs(part.FullPath);
            _orchardServices.ContentManager.Create(part);

            return(part);
        }
 public RelatedService(IAppDataFolder appDataFolder, ShellSettings shellSettings, IIndexManager indexManager, ILuceneAnalyzerProvider analyzerProvider)
 {
     _appDataFolder    = appDataFolder;
     _indexManager     = indexManager;
     _analyzerProvider = analyzerProvider;
     _basePath         = _appDataFolder.Combine("Sites", shellSettings.Name, "Indexes");
 }
        public LastSynchronizedDate(IAppDataFolder appDataFolder, ShellSettings shellSettings) {
            _appDataFolder = appDataFolder;
            _shellSettings = shellSettings;

            _basePath = _appDataFolder.Combine("Sites", _shellSettings.Name, "Packages");
            CreateBaseDirectoryIfItDoesNotExist();
        }
        IEnumerable <ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var tenantPaths = _appDataFolder
                              .ListDirectories("Sites")
                              .Select(path => _appDataFolder.MapPath(path));

            var shellSettings = new List <ShellSettings>();

            foreach (var tenantPath in tenantPaths)
            {
                _logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenantPath);

                var configurationContainer =
                    new ConfigurationBuilder()
                    .AddJsonFile(_appDataFolder.Combine(tenantPath, string.Format(SettingsFileNameFormat, "json")),
                                 true)
                    .AddXmlFile(_appDataFolder.Combine(tenantPath, string.Format(SettingsFileNameFormat, "xml")),
                                true)
                    .Add(
                        new DefaultFileConfigurationSource(
                            _appDataFolder.Combine(tenantPath, string.Format(SettingsFileNameFormat, "txt")), false));

                var config = configurationContainer.Build();

                var shellSetting = new ShellSettings {
                    Name = config["Name"],
                    DataConnectionString = config["DataConnectionString"],
                    DataProvider         = config["DataProvider"],
                    DataTablePrefix      = config["DataTablePrefix"],
                    RequestUrlHost       = config["RequestUrlHost"],
                    RequestUrlPrefix     = config["RequestUrlPrefix"]
                };

                TenantState state;
                shellSetting.State = Enum.TryParse(config["State"], true, out state)
                    ? state
                    : TenantState.Uninitialized;

                shellSettings.Add(shellSetting);

                _logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
            }

            return(shellSettings);
        }
        public FileSystemOutputCacheStorageProvider(IClock clock, IAppDataFolder appDataFolder, ShellSettings shellSettings)
        {
            _appDataFolder = appDataFolder;
            _clock         = clock;
            _shellSettings = shellSettings;
            _root          = _appDataFolder.Combine("OutputCache", _shellSettings.Name);

            Logger = NullLogger.Instance;
        }
Example #12
0
        private void ConvertToExport(string user, Process process, PipelineConfigurationPart part, string exportType, IDictionary <string, string> parameters)
        {
            var o = process.Output();

            switch (exportType)
            {
            case "xlsx":
                var folder = Common.GetAppFolder();
                if (!_appDataFolder.DirectoryExists(folder))
                {
                    _appDataFolder.CreateDirectory(folder);
                }

                var fileName = Common.GetSafeFileName(user, _slugService.Slugify(part.Title()), "xlsx");

                o.Provider = "excel";
                o.File     = _appDataFolder.MapPath(_appDataFolder.Combine(folder, fileName));
                break;

            case "geojson":
                o.Stream   = true;
                o.Provider = "geojson";
                o.File     = _slugService.Slugify(part.Title()) + ".geojson";
                break;

            case "kml":
                o.Stream   = true;
                o.Provider = "kml";
                o.File     = _slugService.Slugify(part.Title()) + ".kml";
                break;

            default:     //csv
                o.Stream    = true;
                o.Provider  = "file";
                o.Delimiter = ",";
                o.File      = _slugService.Slugify(part.Title()) + ".csv";
                break;
            }

            parameters["page"] = "0";

            foreach (var entity in process.Entities)
            {
                entity.Page = 0;
                entity.Fields.RemoveAll(f => f.System);

                foreach (var field in entity.GetAllFields())
                {
                    if (field.Alias == Common.BatchValueFieldName)
                    {
                        field.Output = false;
                    }
                    field.T      = string.Empty; // because short-hand has already been expanded
                    field.Output = field.Output && field.Export == "defer" || field.Export == "true";
                }
            }
        }
Example #13
0
 public LuceneIndexProvider(
     IAppDataFolder appDataFolder,
     ShellSettings shellSettings,
     ILuceneAnalyzerProvider analyzerProvider)
 {
     _appDataFolder    = appDataFolder;
     _analyzerProvider = analyzerProvider;
     _basePath         = _appDataFolder.Combine("Sites", shellSettings.Name, "Indexes");
     EnsureDirectoryExists();
 }
        public DefaultExtensionDependenciesManager(ICacheManager cacheManager, IAppDataFolder appDataFolder)
        {
            _cacheManager = cacheManager;
            _appDataFolder = appDataFolder;
            _writeThroughToken = new InvalidationToken();

            Logger = NullLogger.Instance;

            _persistencePath = appDataFolder.Combine(BasePath, FileName);
        }
        public DefaultDependenciesFolder(ICacheManager cacheManager, IAppDataFolder appDataFolder)
        {
            _cacheManager      = cacheManager;
            _appDataFolder     = appDataFolder;
            _writeThroughToken = new InvalidationToken();

            T = NullLocalizer.Instance;

            _persistencePath = appDataFolder.Combine(BasePath, FileName);
        }
Example #16
0
        public WarmupUpdater(
            IOrchardServices orchardServices, 
            ILockFileManager lockFileManager,
            IClock clock,
            IAppDataFolder appDataFolder,
            IWebDownloader webDownloader,
            IWarmupReportManager reportManager,
            ShellSettings shellSettings) {
            _orchardServices = orchardServices;
            _lockFileManager = lockFileManager;
            _clock = clock;
            _appDataFolder = appDataFolder;
            _webDownloader = webDownloader;
            _reportManager = reportManager;

            _lockFilename = _appDataFolder.Combine("Sites", _appDataFolder.Combine(shellSettings.Name, WarmupFilename + ".lock"));
            _warmupPath = _appDataFolder.Combine("Sites", _appDataFolder.Combine(shellSettings.Name, WarmupFilename));

            Logger = NullLogger.Instance;
        }
        protected override Directory GetDirectory(string indexName)
        {
            var cacheDirectoryPath = _appDataFolder.Combine("Sites", _shellSettings.Name, "IndexingCache", indexName);
            var cacheDirectoryInfo = new System.IO.DirectoryInfo(_appDataFolder.MapPath(cacheDirectoryPath));

            return(new AzureDirectory(
                       _storageAccount,
                       "lucene",
                       FSDirectory.Open(cacheDirectoryInfo),
                       false,
                       _shellSettings.Name + "/" + indexName));
        }
        public WarmupUpdater(
            IOrchardServices orchardServices,
            ILockFileManager lockFileManager,
            IClock clock,
            IAppDataFolder appDataFolder,
            IWebDownloader webDownloader,
            IWarmupReportManager reportManager,
            ShellSettings shellSettings)
        {
            _orchardServices = orchardServices;
            _lockFileManager = lockFileManager;
            _clock           = clock;
            _appDataFolder   = appDataFolder;
            _webDownloader   = webDownloader;
            _reportManager   = reportManager;

            _lockFilename = _appDataFolder.Combine("Sites", _appDataFolder.Combine(shellSettings.Name, WarmupFilename + ".lock"));
            _warmupPath   = _appDataFolder.Combine("Sites", _appDataFolder.Combine(shellSettings.Name, WarmupFilename));

            Logger = NullLogger.Instance;
        }
Example #19
0
        public void Init()
        {
            if (Directory.Exists(_basePath))
            {
                Directory.Delete(_basePath, true);
            }

            Directory.CreateDirectory(_basePath);
            _appDataFolder   = AppDataFolderTests.CreateAppDataFolder(_basePath);
            _webDownloader   = new Mock <IWebDownloader>();
            _orchardServices = new StubOrchardServices();
            ((StubWorkContextAccessor.WorkContextImpl.StubSite)_orchardServices.WorkContext.CurrentSite).BaseUrl = "http://orchardproject.net";

            _settings = new WarmupSettingsPart();

            _orchardServices.WorkContext.CurrentSite.ContentItem.Weld(_settings);
            _orchardServices.WorkContext.CurrentSite.ContentItem.Weld(new InfosetPart());

            var builder = new ContainerBuilder();

            builder.RegisterInstance(_appDataFolder).As <IAppDataFolder>();
            builder.RegisterInstance(_orchardServices).As <IOrchardServices>();
            builder.RegisterType <DefaultLockFileManager>().As <ILockFileManager>();
            builder.RegisterType <WarmupUpdater>().As <IWarmupUpdater>();
            builder.RegisterType <StubClock>().As <IClock>();
            builder.RegisterType <WarmupReportManager>().As <IWarmupReportManager>();
            builder.RegisterInstance(new ShellSettings {
                Name = "Default"
            }).As <ShellSettings>();
            builder.RegisterInstance(_clock = new StubClock()).As <IClock>();
            builder.RegisterInstance(_webDownloader.Object).As <IWebDownloader>();
            _container = builder.Build();

            _lockFileManager = _container.Resolve <ILockFileManager>();
            _warmupUpdater   = _container.Resolve <IWarmupUpdater>();
            _reportManager   = _container.Resolve <IWarmupReportManager>();

            _warmupFilename = _appDataFolder.Combine(TenantFolder, "warmup.txt");
            _lockFilename   = _appDataFolder.Combine(TenantFolder, "warmup.txt.lock");
        }
Example #20
0
        public void Set(string key, CacheItem cacheItem)
        {
            Retry(() => {
                if (cacheItem == null)
                {
                    throw new ArgumentNullException("cacheItem");
                }

                if (cacheItem.ValidFor <= 0)
                {
                    return;
                }

                var hash = GetCacheItemFileHash(key);

                lock (String.Intern(hash)) {
                    var filename = _appDataFolder.Combine(_content, hash);
                    using (var fileStream = _appDataFolder.CreateFile(filename)) {
                        using (var writer = new BinaryWriter(fileStream)) {
                            fileStream.Write(cacheItem.Output, 0, cacheItem.Output.Length);
                        }
                    }

                    using (var stream = SerializeMetadata(cacheItem)) {
                        filename = _appDataFolder.Combine(_metadata, hash);
                        using (var fileStream = _appDataFolder.CreateFile(filename)) {
                            stream.CopyTo(fileStream);
                        }
                    }
                }
            });
        }
Example #21
0
        public FilePart Upload(HttpPostedFileBase input)
        {
            var part       = _orchardServices.ContentManager.New <FilePart>("File");
            var exportFile = string.Format("{0}-{1}-{2}",
                                           _orchardServices.WorkContext.CurrentUser.UserName,
                                           _clock.UtcNow.ToString(FILE_TIMESTAMP),
                                           Path.GetFileName(input.FileName)
                                           );

            if (!_appDataFolder.DirectoryExists(TRANSFORMALIZE_FOLDER))
            {
                _appDataFolder.CreateDirectory(TRANSFORMALIZE_FOLDER);
            }

            part.FullPath  = _appDataFolder.MapPath(_appDataFolder.Combine(TRANSFORMALIZE_FOLDER, exportFile));
            part.Direction = "In";
            input.SaveAs(part.FullPath);
            _orchardServices.ContentManager.Create(part);
            _orchardServices.Notifier.Information(T("{0} uploaded successfully.", Path.GetFileName(input.FileName)));

            return(part);
        }
Example #22
0
        public void Configure(DbContextOptionsBuilder optionsBuilders)
        {
            var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);

            _appDataFolder.CreateDirectory(shellPath);

            var shellFolder = _appDataFolder.MapPath(shellPath);

            foreach (var provider in _dataServicesProviders)
            {
                provider.ConfigureContextOptions(optionsBuilders, string.Empty);
            }
        }
Example #23
0
        private void ConvertToExport(string user, Process process, PipelineConfigurationPart part, string exportType, IDictionary <string, string> parameters)
        {
            var o = process.Output();

            switch (exportType)
            {
            case "xlsx":
                if (!_appDataFolder.DirectoryExists(Common.FileFolder))
                {
                    _appDataFolder.CreateDirectory(Common.FileFolder);
                }

                var fileName = $"{user}-{_clock.UtcNow.ToString(FileTimestamp)}-{_slugService.Slugify(part.Title())}.xlsx";

                o.Provider = "excel";
                o.File     = _appDataFolder.MapPath(_appDataFolder.Combine(Common.FileFolder, fileName));
                break;

            case "geojson":
                o.Stream   = true;
                o.Provider = "geojson";
                o.File     = _slugService.Slugify(part.Title()) + ".geojson";
                break;

            case "kml":
                o.Stream   = true;
                o.Provider = "kml";
                o.File     = _slugService.Slugify(part.Title()) + ".kml";
                break;

            default:     //csv
                o.Stream    = true;
                o.Provider  = "file";
                o.Delimiter = ",";
                o.File      = _slugService.Slugify(part.Title()) + ".csv";
                break;
            }

            parameters["page"] = "0";

            foreach (var entity in process.Entities)
            {
                entity.Page = 0;
                entity.Fields.RemoveAll(f => f.System);

                foreach (var field in entity.GetAllFields())
                {
                    field.Output = field.Output && field.Export == "defer" || field.Export == "true";
                }
            }
        }
        public void Sweep()
        {
            foreach (var filename in _appDataFolder.ListFiles(_metadata).ToArray())
            {
                var hash = Path.GetFileName(filename);

                var validUntilUtc = _cacheManager.Get(hash, context => {
                    _signals.When(hash);

                    using (var stream = _appDataFolder.OpenFile(filename)) {
                        var cacheItem = FileSystemOutputCacheStorageProvider.DeserializeMetadata(stream);
                        return(cacheItem.ValidUntilUtc);
                    }
                });

                if (_clock.UtcNow > validUntilUtc)
                {
                    _appDataFolder.DeleteFile(_appDataFolder.Combine(_metadata, hash));
                    _appDataFolder.DeleteFile(_appDataFolder.Combine(_content, hash));
                    _signals.Trigger(filename);
                }
            }
        }
        public FileSystemOutputCacheBackgroundTask(
            IAppDataFolder appDataFolder, 
            ShellSettings shellSettings,
            ICacheManager cacheManager,
            IClock clock,
            ISignals signals) {
            _appDataFolder = appDataFolder;
            _shellSettings = shellSettings;
            _cacheManager = cacheManager;
            _clock = clock;
            _signals = signals;

            _root = _appDataFolder.Combine("OutputCache", _shellSettings.Name);
        }
Example #26
0
        public FileSystemOutputCacheBackgroundTask(
            IAppDataFolder appDataFolder,
            ShellSettings shellSettings,
            ICacheManager cacheManager,
            IClock clock,
            ISignals signals)
        {
            _appDataFolder = appDataFolder;
            _shellSettings = shellSettings;
            _cacheManager  = cacheManager;
            _clock         = clock;
            _signals       = signals;

            _root = _appDataFolder.Combine("OutputCache", _shellSettings.Name);
        }
        public SessionFactoryParameters GetSessionFactoryParameters()
        {
            var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);

            _appDataFolder.CreateDirectory(shellPath);

            var shellFolder = _appDataFolder.MapPath(shellPath);

            return(new SessionFactoryParameters {
                Provider = _shellSettings.DataProvider,
                DataFolder = shellFolder,
                ConnectionString = _shellSettings.DataConnectionString,
                RecordDescriptors = _shellBlueprint.Records,
            });
        }
Example #28
0
        public LuceneIndexProvider(IAppDataFolder appDataFolder, ShellSettings shellSettings) {
            _appDataFolder = appDataFolder;
            _analyzer = CreateAnalyzer();

            // TODO: (sebros) Find a common way to get where tenant's specific files should go. "Sites/Tenant" is hard coded in multiple places
            _basePath = _appDataFolder.Combine("Sites", shellSettings.Name, "Indexes");

            Logger = NullLogger.Instance;

            // Ensures the directory exists
            EnsureDirectoryExists();

            T = NullLocalizer.Instance;
            Logger = NullLogger.Instance;
        }
        private string WriteExportFile(string exportDocument)
        {
            var exportFile = string.Format("Export-{0}-{1}.xml", _orchardServices.WorkContext.CurrentUser.UserName, DateTime.UtcNow.Ticks);

            if (!_appDataFolder.DirectoryExists(ExportsDirectory))
            {
                _appDataFolder.CreateDirectory(ExportsDirectory);
            }

            var path = _appDataFolder.Combine(ExportsDirectory, exportFile);

            _appDataFolder.CreateFile(path, exportDocument);

            return(_appDataFolder.MapPath(path));
        }
        public LuceneIndexProvider(IAppDataFolder appDataFolder, ShellSettings shellSettings)
        {
            _appDataFolder = appDataFolder;
            _analyzer      = CreateAnalyzer();

            // TODO: (sebros) Find a common way to get where tenant's specific files should go. "Sites/Tenant" is hard coded in multiple places
            _basePath = _appDataFolder.Combine("Sites", shellSettings.Name, "Indexes");

            Logger = NullLogger.Instance;

            // Ensures the directory exists
            EnsureDirectoryExists();

            T      = NullLocalizer.Instance;
            Logger = NullLogger.Instance;
        }
        public void Configure(DbContextOptionsBuilder optionsBuilders)
        {
            var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);

            _appDataFolder.CreateDirectory(shellPath);

            var shellFolder = _appDataFolder.MapPath(shellPath);

            _dataServicesProviderFactory.CreateProvider(
                new DataServiceParameters {
                Provider         = _shellSettings.DataProvider,
                ConnectionString = _shellSettings.DataConnectionString,
                DataFolder       = shellFolder
            })
            .ConfigureContextOptions(optionsBuilders, _shellSettings.DataConnectionString);
        }
Example #32
0
        public string WriteExportFile(XDocument recipeDocument)
        {
            var exportFile = String.Format("Export-{0}-{1}.xml", _orchardServices.WorkContext.CurrentUser.UserName, _clock.UtcNow.Ticks);

            if (!_appDataFolder.DirectoryExists(ExportsDirectory))
            {
                _appDataFolder.CreateDirectory(ExportsDirectory);
            }

            var path = _appDataFolder.Combine(ExportsDirectory, exportFile);

            using (var writer = new XmlTextWriter(_appDataFolder.CreateFile(path), Encoding.UTF8)) {
                writer.Formatting = Formatting.Indented;
                recipeDocument.WriteTo(writer);
            }

            return(_appDataFolder.MapPath(path));
        }
Example #33
0
        public LuceneIndexProvider(
            IAppDataFolder appDataFolder,
            KoreSiteSettings siteSettings,
            Lazy <ILogger> logger)
        {
            this.appDataFolder = appDataFolder;
            this.analyzer      = CreateAnalyzer();

            // TODO: (sebros) Find a common way to get where tenant's specific files should go. "Sites/Tenant" is hard coded in multiple places
            this.basePath = appDataFolder.Combine("Sites", siteSettings.SiteName, "Indexes");

            this.logger = logger;

            // Ensures the directory exists
            EnsureDirectoryExists();

            T = NullLocalizer.Instance;
        }
        IEnumerable <ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var tenantPaths = _appDataFolder
                              .ListDirectories("Sites")
                              .Select(path => _appDataFolder.MapPath(path));

            var shellSettings = new List <ShellSettings>();

            foreach (var tenantPath in tenantPaths)
            {
                Logger.Information("ShellSettings found in '{0}', attempting to load.", tenantPath);

                IConfigurationSourceRoot configurationContainer =
                    new Microsoft.Framework.ConfigurationModel.Configuration()
                    .AddJsonFile(_appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "json")),
                                 true)
                    .AddXmlFile(_appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "xml")),
                                true)
                    .AddIniFile(_appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "ini")),
                                true)
                    .Add(
                        new DefaultFileConfigurationSource(
                            _appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "txt")), false));

                var shellSetting = new ShellSettings {
                    Name = configurationContainer.Get <string>("Name"),
                    DataConnectionString = configurationContainer.Get <string>("DataConnectionString"),
                    DataProvider         = configurationContainer.Get <string>("DataProvider"),
                    DataTablePrefix      = configurationContainer.Get <string>("DataTablePrefix"),
                    RequestUrlHost       = configurationContainer.Get <string>("RequestUrlHost"),
                    RequestUrlPrefix     = configurationContainer.Get <string>("RequestUrlPrefix")
                };

                TenantState state;
                shellSetting.State = Enum.TryParse(configurationContainer.Get <string>("State"), true, out state)
                    ? state
                    : TenantState.Uninitialized;

                shellSettings.Add(shellSetting);

                Logger.Information("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
            }

            return(shellSettings);
        }
        public DbContextOptions BuildConfiguration()
        {
            lock (this)
            {
                if (_dbContextOptions == null)
                {
                    var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);
                    _appDataFolder.CreateDirectory(shellPath);

                    var shellFolder = _appDataFolder.MapPath(shellPath);

                    _dbContextOptions = _dataServicesProviderFactory.CreateProvider(
                        new DataServiceParameters
                    {
                        Provider         = _shellSettings.DataProvider,
                        ConnectionString = _shellSettings.DataConnectionString,
                        DataFolder       = shellFolder
                    })
                                        .BuildContextOptions();
                }
            }
            return(_dbContextOptions);
        }
Example #36
0
 private string GetPathName(string shellName)
 {
     return(_appDataFolder.Combine("Sites", shellName, "mappings.bin"));
 }
 private string GetSettingsFileName(string indexName)
 {
     return(_appDataFolder.Combine("Sites", _shellSettings.Name, indexName + ".settings.xml"));
 }