예제 #1
0
 /// <summary>
 /// Execute commands from a file with SQL script against the context database
 /// </summary>
 /// <param name="fileProvider">File provider</param>
 /// <param name="filePath">Path to the file</param>
 protected void ExecuteSqlScriptFromFile(IMotelFileProvider fileProvider, string filePath)
 {
     filePath = fileProvider.MapPath(filePath);
     if (!fileProvider.FileExists(filePath))
     {
         return;
     }
     ExecuteSqlScript(fileProvider.ReadAllText(filePath, Encoding.Default));
 }
예제 #2
0
 public DownloadController(UserSettings customerSettings, IDownloadService downloadService,
                           IRentalPostService postService, IWorkContext workContext, IMotelFileProvider fileProvider, ILogger logger)
 {
     _customerSettings = customerSettings;
     _downloadService  = downloadService;
     _postService      = postService;
     _workContext      = workContext;
     _fileProvider     = fileProvider;
     _logger           = logger;
 }
예제 #3
0
 public WebHelper(HostingConfig hostingConfig,
                  IActionContextAccessor actionContextAccessor,
                  IHostApplicationLifetime hostApplicationLifetime,
                  IHttpContextAccessor httpContextAccessor,
                  IMotelFileProvider fileProvider,
                  IUrlHelperFactory urlHelperFactory)
 {
     _hostingConfig           = hostingConfig;
     _actionContextAccessor   = actionContextAccessor;
     _hostApplicationLifetime = hostApplicationLifetime;
     _httpContextAccessor     = httpContextAccessor;
     _fileProvider            = fileProvider;
     _urlHelperFactory        = urlHelperFactory;
 }
예제 #4
0
        /// <summary>
        /// Save data settings to the file
        /// </summary>
        /// <param name="settings">Data settings</param>
        /// <param name="fileProvider">File provider</param>
        public static void SaveSettings(DataSettings settings, IMotelFileProvider fileProvider = null)
        {
            Singleton <DataSettings> .Instance = settings ?? throw new ArgumentNullException(nameof(settings));

            fileProvider ??= CommonHelper.DefaultFileProvider;
            var filePath = fileProvider.MapPath(MotelDataSettingsDefaults.FilePath);

            //create file if not exists
            fileProvider.CreateFile(filePath);

            //save data settings to the file
            var text = JsonConvert.SerializeObject(Singleton <DataSettings> .Instance, Formatting.Indented);

            fileProvider.WriteAllText(filePath, text, Encoding.UTF8);
        }
예제 #5
0
 public PictureService(IMotelDataProvider dataProvider,
                       IDownloadService downloadService,
                       IEventPublisher eventPublisher,
                       IHttpContextAccessor httpContextAccessor,
                       IMotelFileProvider fileProvider,
                       IRepository <Picture> pictureRepository,
                       IRepository <PictureBinary> pictureBinaryRepository,
                       IRepository <PostPictureMaping> postPictureRepository,
                       IWebHelper webHelper,
                       MediaSettings mediaSettings)
 {
     _dataProvider            = dataProvider;
     _downloadService         = downloadService;
     _eventPublisher          = eventPublisher;
     _httpContextAccessor     = httpContextAccessor;
     _fileProvider            = fileProvider;
     _pictureRepository       = pictureRepository;
     _pictureBinaryRepository = pictureBinaryRepository;
     _postPictureRepository   = postPictureRepository;
     _webHelper     = webHelper;
     _mediaSettings = mediaSettings;
 }
예제 #6
0
 public AppDomainTypeFinder(IMotelFileProvider fileProvider = null)
 {
     _fileProvider = fileProvider ?? CommonHelper.DefaultFileProvider;
 }
예제 #7
0
 public WebAppTypeFinder(IMotelFileProvider fileProvider = null) : base(fileProvider)
 {
 }
예제 #8
0
        public static DataSettings LoadSettings(string filePath = null, bool reloadSettings = false, IMotelFileProvider fileProvider = null)
        {
            if (!reloadSettings && Singleton <DataSettings> .Instance != null)
            {
                return(Singleton <DataSettings> .Instance);
            }
            fileProvider ??= CommonHelper.DefaultFileProvider;
            filePath ??= fileProvider.MapPath(MotelDataSettingsDefaults.FilePath);
            if (!fileProvider.FileExists(filePath))
            {
                filePath = fileProvider.MapPath(MotelDataSettingsDefaults.ObsoleteFilePath);
                if (!fileProvider.FileExists(filePath))
                {
                    return(new DataSettings());
                }
                var dataSettings = new DataSettings();
                using (var reader = new StringReader(fileProvider.ReadAllText(filePath, Encoding.UTF8)))
                {
                    string settingsLine;
                    while ((settingsLine = reader.ReadLine()) != null)
                    {
                        var separatorIndex = settingsLine.IndexOf(':');
                        if (separatorIndex == -1)
                        {
                            continue;
                        }

                        var key   = settingsLine.Substring(0, separatorIndex).Trim();
                        var value = settingsLine.Substring(separatorIndex + 1).Trim();

                        switch (key)
                        {
                        case "DataProvider":
                            dataSettings.DataProvider = Enum.TryParse(value, true, out DataProviderType providerType) ? providerType : DataProviderType.Unknown;
                            continue;

                        case "DataConnectionString":
                            dataSettings.ConnectionString = value;
                            continue;

                        case "SQLCommandTimeout":
                            //If parsing isn't successful, we set a negative timeout, that means the current provider will usе a default value
                            dataSettings.SQLCommandTimeout = int.TryParse(value, out var timeout) ? timeout : -1;
                            continue;

                        default:
                            dataSettings.RawDataSettings.Add(key, value);
                            continue;
                        }
                    }
                }

                SaveSettings(dataSettings, fileProvider);

                //and delete the old one
                fileProvider.DeleteFile(filePath);

                Singleton <DataSettings> .Instance = dataSettings;
                return(Singleton <DataSettings> .Instance);
            }
            var text = fileProvider.ReadAllText(filePath, Encoding.UTF8);

            if (string.IsNullOrEmpty(text))
            {
                return(new DataSettings());
            }

            //get data settings from the JSON file
            Singleton <DataSettings> .Instance = JsonConvert.DeserializeObject <DataSettings>(text);

            return(Singleton <DataSettings> .Instance);
        }