Example #1
0
        protected virtual BrowscapXmlHelper GetBrowscapXmlHelper()
        {
            if (Singleton <BrowscapXmlHelper> .Instance != null)
            {
                return(Singleton <BrowscapXmlHelper> .Instance);
            }
            string userAgentStringPath = "~/App_Data/browscap.xml";

            //no database created
            if (string.IsNullOrEmpty(userAgentStringPath))
            {
                return(null);
            }

            //prevent multi loading data
            lock (_locker)
            {
                //data can be loaded while we waited
                if (Singleton <BrowscapXmlHelper> .Instance != null)
                {
                    return(Singleton <BrowscapXmlHelper> .Instance);
                }

                string userAgentStringsPath            = _fileProvider.MapPath(userAgentStringPath);
                string crawlerOnlyUserAgentStringsPath = _fileProvider.MapPath("~/App_Data/browscap.crawlersonly.xml");

                BrowscapXmlHelper browscapXmlHelper = new BrowscapXmlHelper(userAgentStringsPath, crawlerOnlyUserAgentStringsPath, _fileProvider);
                Singleton <BrowscapXmlHelper> .Instance = browscapXmlHelper;

                return(Singleton <BrowscapXmlHelper> .Instance);
            }
        }
Example #2
0
 /// <summary>
 /// Try to write web.config file
 /// </summary>
 /// <returns></returns>
 protected virtual bool TryWriteWebConfig()
 {
     try
     {
         _fileProvider.SetLastWriteTimeUtc(_fileProvider.MapPath("~/web.config"), DateTime.UtcNow);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #3
0
        public virtual IActionResult Upload()
        {
            ViewData["resultCode"] = "failed";
            ViewData["result"]     = "No access to this functionality";
            return(View());


            if (Request.Form.Files.Count == 0)
            {
                throw new Exception("No file uploaded");
            }

            var uploadFile = Request.Form.Files.FirstOrDefault();

            if (uploadFile == null)
            {
                ViewData["resultCode"] = "failed";
                ViewData["result"]     = "No file name provided";
                return(View());
            }

            var fileName = _fileProvider.GetFileName(uploadFile.FileName);

            if (string.IsNullOrEmpty(fileName))
            {
                ViewData["resultCode"] = "failed";
                ViewData["result"]     = "No file name provided";
                return(View());
            }

            var directory = "~/wwwroot/images/uploaded/";
            var filePath  = _fileProvider.Combine(_fileProvider.MapPath(directory), fileName);

            var fileExtension = _fileProvider.GetFileExtension(filePath);

            if (!GetAllowedFileTypes().Contains(fileExtension))
            {
                ViewData["resultCode"] = "failed";
                ViewData["result"]     = $"Files with {fileExtension} extension cannot be uploaded";
                return(View());
            }

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                uploadFile.CopyTo(fileStream);
            }

            ViewData["resultCode"] = "success";
            ViewData["result"]     = "success";
            ViewData["filename"]   = Url.Content($"{directory}{fileName}");
            return(View());
        }