public HttpResponseMessage Settings(string Template)
        {
            string data = (string)ActiveModule.ModuleSettings["data"];

            try
            {
                string templateFilename = HostingEnvironment.MapPath("~/" + Template);
                string prefix           = Path.GetFileNameWithoutExtension(templateFilename) + "-";

                JObject json = FilesRepository.GetSchemaAndOptionsJson(AppConfig.Instance.SchemaFolder, AppConfig.Instance.PortalFolder(PortalSettings), prefix);

                if (!string.IsNullOrEmpty(data))
                {
                    try
                    {
                        json["data"] = JObject.Parse(data);
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.Error("Settings Json Data : " + data, ex);
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, json));
            }
            catch (Exception exc)
            {
                Log.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Beispiel #2
0
        public ActionResult Send(FormCollection collection)
        {
            try
            {
                string           fileid = collection.GetValue("FieldId").AttemptedValue;
                int              fileId = Convert.ToInt32(fileid);
                PubSubRepository psr    = new PubSubRepository();
                FilesRepository  fr     = new FilesRepository();

                Models.File f   = fr.GetFile(fileId);
                FileSendTo  fst = new FileSendTo();

                string email   = collection.GetValue("Email").AttemptedValue;
                string message = collection.GetValue("Message").AttemptedValue;

                fst.Link    = f.Link;
                fst.Name    = f.Name;
                fst.OwnerFk = f.OwnerFk;
                fst.Message = message;
                fst.Email   = email;

                psr.AddToEmailQueue(fst);

                psr.DownloadEmailFromQueueAndSend();

                new LoggingRepository().Logging("File: " + f.Name + " Shared With: " + email + " At: " + DateTime.Now);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                new LoggingRepository().ErrorLogging(ex);
            }
            return(View());
        }
        public HttpResponseMessage EditImages(int id)
        {
            //string Template = "DesktopModules/OpenFiles/";
            try
            {
                JObject json = FilesRepository.GetSchemaAndOptionsJson(AppConfig.Instance.SchemaFolder, AppConfig.Instance.PortalFolder(PortalSettings), "images");

                //int moduleId = ActiveModule.ModuleID;
                if (id > 0)
                {
                    var item = Util.GetContentController().GetContentItem(id);
                    if (item != null && !string.IsNullOrEmpty(item.Content))
                    {
                        JObject dataJson = JObject.Parse(item.Content);
                        json["data"] = dataJson["crop"];
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, json));
            }
            catch (Exception exc)
            {
                Log.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public ActionResult Files()
        {
            FilesRepository fr          = new FilesRepository();
            var             listOfFiles = fr.GetFiles();

            return(View(listOfFiles));
        }
Beispiel #5
0
        public ActionResult DeleteAll(int[] ids)
        {
            //1. Requirement when opening a transaction: Connection has to be opened
            FilesRepository fr = new FilesRepository();

            fr.MyConnection.Open();

            fr.MyTransaction = fr.MyConnection.BeginTransaction(); //from this point onwards all code executed against the db will remain pending

            try
            {
                new LoggingRepository().Logging("Deleting multiple elements");
                foreach (int id in ids)
                {
                    fr.DeleteFile(id);
                }

                fr.MyTransaction.Commit(); //Commit: you are confirming the changes in the db
            }
            catch (Exception ex)
            {
                //Log the exception on the cloud
                new LoggingRepository().ErrorLogging(ex);
                fr.MyTransaction.Rollback(); //Rollback: it will reverse all the changes done within the try-clause in the db
            }

            fr.MyConnection.Close();

            CacheRepository cr = new CacheRepository();

            cr.UpdateCache(fr.GetFiles(User.Identity.Name));

            return(RedirectToAction("Index"));
        }
Beispiel #6
0
        public void FilesSplitByMaxSize()
        {
            var repository = new FilesRepository();
            var fileTarget = new FileTarget.FileTarget(repository)
            {
                Formatter   = (f) => $"{f.Message}",
                FileName    = (f) => $"{f.Sequence}.log",
                FolderPath  = ".\\log",
                MaxFileSize = 4,
                Encoding    = Encoding.Default
            };

            var l = Encoding.Default.GetBytes("aaaa").Length;

            fileTarget.Log(new LogEntry()
            {
                Message = "AAAA"
            });

            fileTarget.Log(new LogEntry()
            {
                Message = "BB"
            });

            fileTarget.Log(new LogEntry()
            {
                Message = "BB"
            });

            Assert.Equal(2, repository.files.Count);
            Assert.Equal(".\\log\\0.log", repository.files.First().Key);
            Assert.Equal(".\\log\\1.log", repository.files.Last().Key);
            Assert.Equal("AAAA\n", repository.files.First().Value);
            Assert.Equal("BB\nBB\n", repository.files.Last().Value);
        }
Beispiel #7
0
        private void IndexFolder(DateTime?startDate, int portalId, string folderPath)
        {
            LuceneController.ClearInstance();
            try
            {
                using (var lc = LuceneController.Instance)
                {
                    var fileIndexer = new DnnFilesRepository();
                    if (!startDate.HasValue)
                    {
                        Log.Logger.InfoFormat("Reindexing documents from Portal {0} folder {1}", portalId, folderPath);
                    }
                    var indexSince = FixedIndexingStartDate(portalId, startDate ?? DateTime.MinValue);
                    List <LuceneIndexItem> searchDocs = fileIndexer.GetPortalSearchDocuments(portalId, folderPath, true, indexSince).ToList();
                    Log.Logger.DebugFormat("Found {2} documents from Portal {0} folder {1} to index", portalId, folderPath, searchDocs.Count());

                    FieldConfig indexJson = FilesRepository.GetIndexConfig(portalId);
                    foreach (LuceneIndexItem indexItem in searchDocs)
                    {
                        Delete(indexItem, lc);
                        lc.Store.Add(LuceneMappingUtils.CreateLuceneDocument(indexItem, indexJson));
                    }
                    Log.Logger.DebugFormat("Indexed {2} documents from Portal {0} folder {1}", portalId, folderPath, searchDocs.Count());
                    lc.Store.Commit();
                    lc.Store.OptimizeSearchIndex(true);
                }
            }
            finally
            {
                LuceneController.ClearInstance();
            }
        }
        public ActionResult Create(File data)
        {
            string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();

            try
            {
                if (ModelState.IsValid)
                {
                    FilesRepository fr          = new FilesRepository();
                    UsersRepository ur          = new UsersRepository();
                    var             FileCreater = ur.GetUserByUsername(User.Identity.Name);

                    data.User_id = FileCreater.Username;
                    fr.AddFiles(data);


                    //new LogsRepository().Log(User.Identity.Name, controllerName + "\\" + actionName, "Post" + data.Id + "added", LogType.Information);
                    ViewBag.Message = "Item added successfully";

                    return(RedirectToAction("Upload", new { id = data.id }));
                }
                else
                {
                    ViewBag.Error = "Check your inputs";
                }
            }
            catch (Exception ex)
            {
                //new LogsRepository().Log(User.Identity.Name, controllerName + "\\" + actionName, ex, LogType.Error);
                ViewBag.Error = "Item failed to be added";
            }

            return(View());
        }
Beispiel #9
0
        public JsonResult Browse(string path)
        {
            //TODO:Add security checks

            var          files = new FilesRepository();
            BrowseResult result;

            if (string.IsNullOrEmpty(path) || path == "/")
            {
                var root     = files.GetRootFolder();
                var rootPath = VirtualPathUtility.AppendTrailingSlash(root != null ? root.Name : string.Empty);
                result = new BrowseResult
                {
                    Files        = files.Images(root),
                    Directories  = files.Folders(root),
                    Path         = rootPath,
                    ContentPaths = new[] { rootPath }
                };
            }
            else
            {
                result = new BrowseResult
                {
                    Files        = files.Images(path),
                    Directories  = files.Folders(path),
                    Path         = VirtualPathUtility.AppendTrailingSlash(path),
                    ContentPaths = new[] { VirtualPathUtility.AppendTrailingSlash(path) }
                };
            }
            return(Json(result));
        }
Beispiel #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var N = new NewsRepository();
            int _ID;

            if (int.TryParse(Request.QueryString["ID"], out _ID))
            {
                var SingleNews = N.ListNews(_ID).SingleOrDefault();

                if (SingleNews != null)
                {
                    ltrImgURL.Text    = string.Format("<a href=\"/Uploads/{0}\" class=\"mainImg\"  data-showpopup='true'><img src=\"Uploads/{0}?w=200\" /></a>", SingleNews.ImgURL);
                    ogTitle           =
                        ltrTitle.Text = SingleNews.Title;

                    ogDescription = SingleNews.Description;
                    ogUrl         = "http://new.smr.gov.ge/NewsDetails.aspx?ID=" + SingleNews.NewsID;
                    ogImg         = "http://new.smr.gov.ge/Uploads/" + SingleNews.ImgURL;

                    ltrDate.Text    = string.Format("{0:dd/MM/yyyy}", SingleNews.NewsDate);
                    ltrFulltxt.Text = SingleNews.FullText;

                    var G = new FilesRepository();
                    rptNewsGallery.DataSource = G.ListGalleryFiles(SingleNews.GalleryID).Where(w => !w.IsDefault.Value);
                    rptNewsGallery.DataBind();
                }
            }
        }
        public JsonResult Browse(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            BrowseResult result;
            if (string.IsNullOrEmpty(path) || path == "/")
            {
                var root = files.GetRootFolder();
                var rootPath = VirtualPathUtility.AppendTrailingSlash(root != null ? root.Name : string.Empty);
                result = new BrowseResult
                             {
                                 Files = files.Images(root),
                                 Directories = files.Folders(root),
                                 Path = rootPath,
                                 ContentPaths = new[] {rootPath}
                             };
            }
            else
            {
                result = new BrowseResult
                             {
                                 Files = files.Images(path),
                                 Directories = files.Folders(path),
                                 Path = VirtualPathUtility.AppendTrailingSlash(path),
                                 ContentPaths = new[] { VirtualPathUtility.AppendTrailingSlash(path) }
                             };
            }
            return Json(result);
        }
        public ActionResult Search(string keyword)
        {
            FilesRepository ir           = new FilesRepository();
            var             filteredList = ir.GetFiles().Where(File => File.Title.Contains(keyword));

            return(View("Files", filteredList));
            //metids list and search
        }
        public ActionResult Upload(Guid id)
        {
            //shows the page
            FilesRepository fr   = new FilesRepository();
            var             file = fr.GetFiles().SingleOrDefault(x => x.id == id);

            return(View(file));
        }
Beispiel #14
0
        protected FilesTests()
        {
            var repository        = new FilesRepository(Resolve <IDataContextFactory>());
            var storageRepository = new FilesStorageRepository("C:\\LinkMe\\UserFiles");

            _filesCommand = new FilesCommand(repository, storageRepository);
            _filesQuery   = new FilesQuery(repository, storageRepository);
        }
        public JsonResult Read(string path)
        {
            var files = new FilesRepository();

            var folders = files.Folders(path);

            var images = files.Images(path);

            return(Json(folders.Concat(images)));
        }
        public JsonResult Read(string path)
        {
            var files = new FilesRepository();

            var folders = files.Folders(path);

            var images = files.Images(path);

            return Json(folders.Concat(images));
        }
 public ActionResult Image(string path)
 {
     var files = new FilesRepository();
     var image = files.ImageByPath(path);
     if (image != null)
     {
         const string contentType = "image/png";
         return File(image.Image1, contentType);
     }
     throw new HttpException(404, "File Not Found");
 }
 public ActionResult Create(string path, FileBrowserEntry entry)
 {
     var files = new FilesRepository();
     var folder = files.GetFolderByPath(path);
     if (folder != null)
     {
         files.CreateDirectory(folder, entry.Name);
         return Json(new object[0]);
     }
     throw new HttpException(403, "Forbidden");
 }
Beispiel #19
0
        private void Add(LuceneIndexItem data, LuceneController storeInstance)
        {
            if (null == data)
            {
                throw new ArgumentNullException("data");
            }

            FieldConfig indexJson = FilesRepository.GetIndexConfig(data.PortalId);

            Store.Add(LuceneMappingUtils.CreateLuceneDocument(data, indexJson));
        }
        public ActionResult Create(string path, FileBrowserEntry entry)
        {
            var files  = new FilesRepository();
            var folder = files.GetFolderByPath(path);

            if (folder != null)
            {
                files.CreateDirectory(folder, entry.Name);
                return(Json(new object[0]));
            }
            throw new HttpException(403, "Forbidden");
        }
        public ActionResult Image(string path)
        {
            var files = new FilesRepository();
            var image = files.ImageByPath(path);

            if (image != null)
            {
                const string contentType = "image/png";
                return(File(image.Image1, contentType));
            }
            throw new HttpException(404, "File Not Found");
        }
Beispiel #22
0
        public UnitOfWork(AppDbContext dbContext)
        {
            _dbContext = dbContext;

            Users       = new UsersRepository(dbContext);
            Chats       = new ChatsRepository(dbContext);
            UsersChats  = new UsersChatsRepository(dbContext);
            Messages    = new MessagesRepository(dbContext);
            Files       = new FilesRepository(dbContext);
            FriendShips = new FriendShipsRepository(dbContext);
            Friends     = new FriendsRepository(dbContext);
        }
        public ActionResult DeleteFile(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var image = files.ImageByPath(path);
            if (image != null)
            {
                files.Delete(image);
                return Content("");
            }
            throw new HttpException(404, "File Not Found");
        }
        public void GetMatchingFiles()
        {
            var repository = new FilesRepository();

            var root = Path.GetFullPath(".");

            var pattern = Path.Combine(root, @"*Migrator.dll");

            var files = repository.GetMatchingFiles(pattern).Result;

            Assert.NotNull(files);
            Assert.True(files.Any(f => f.FullName.Equals(Path.Combine(root, "FluentMigrator.dll"))));
        }
Beispiel #25
0
        public ActionResult DeleteDirectory(string path)
        {
            //TODO:Add security checks

            var files  = new FilesRepository();
            var folder = files.GetFolderByPath(path);

            if (folder != null)
            {
                files.Delete(folder);
                return(Content(""));
            }
            throw new HttpException(404, "File Not Found");
        }
Beispiel #26
0
        public void Given_Files_When_GetFilesAsyncsIsCalled_Then_ShouldReturnZeroFiles()
        {
            RunOnDatabase(context =>
            {
                // ARRANGE
                var filesRepository = new FilesRepository(context);

                // ACT
                var files   = filesRepository.GetAllAsync();
                var counter = files.Result.Count;
                // ASSERT
                counter.Should().Be(0);
            });
        }
Beispiel #27
0
        public ActionResult DeleteFile(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var image = files.ImageByPath(path);

            if (image != null)
            {
                files.Delete(image);
                return(Content(""));
            }
            throw new HttpException(404, "File Not Found");
        }
Beispiel #28
0
        public ActionResult CreateDirectory(string path, string name)
        {
            //TODO:Add security checks

            var files  = new FilesRepository();
            var folder = files.GetFolderByPath(path);

            if (folder != null)
            {
                files.CreateDirectory(folder, name);
                return(Content(""));
            }
            throw new HttpException(403, "Forbidden");
        }
Beispiel #29
0
 public LibraryController(
     FilesRepository filesRepository,
     ReportRepository reportRepository,
     IRazorViewEngine viewEngine,
     ITempDataProvider tempDataProvider,
     IServiceProvider serviceProvider
     )
 {
     this._reportRepository = reportRepository;
     this._viewEngine       = viewEngine;
     this._filesRepository  = filesRepository;
     this._tempDataProvider = tempDataProvider;
     this._serviceProvider  = serviceProvider;
 }
Beispiel #30
0
        public void Given_Files_When_NewFileIsAdded_Then_ShouldHaveOneFileInDatabase()
        {
            RunOnDatabase(context =>
            {
                // ARRANGE
                var filesRepository = new FilesRepository(context);

                var file         = CreateFile(context, "C:\\folder\\file1.txt", "/download/5jtj5gitj4jrfs");
                var fileInserted = filesRepository.InsertAsync(file).Result;
                // ACT
                var result = filesRepository.GetByIdAsync(fileInserted.Id);
                // ASSERT
                result.Should().NotBe(null);
            });
        }
Beispiel #31
0
 public void Given_File_When_DeleteFileAsync_Then_ShouldBeTrue()
 {
     RunOnDatabase(context =>
     {
         // ARRANGE
         var filesRepository = new FilesRepository(context);
         var file            = CreateFile(context, "C:\\folder\\file1.txt", "/download/5jtj5gitj4jrfs");
         context.Files.Add(file);
         context.SaveChanges();
         // ACT
         var result = filesRepository.DeleteAsync(file.Id);
         // ASSERT
         result.Result.Should().Be(true);
     });
 }
 public ActionResult Details(Guid id)
 {
     try
     {
         FilesRepository ir = new FilesRepository();
         //encryption.decryptquerystring
         var myItem = ir.GetFiles().SingleOrDefault(x => x.id == id);
         return(View(myItem));
     }
     catch
     {
         TempData["error"] = "Value is not valid";
         return(RedirectToAction("List"));
     }
 }
        public static void Process()
        {
            var textEncriptado = CryptoService.Encrypt("wellyngton", 1);
            var decryptedText  = CryptoService.Decrypt(textEncriptado, 1);
            var file           = FilesRepository.OpenFile();

            file.decifrado = decryptedText;
            FilesRepository.SaveFile(file);
            var decryptedToSha1 = decryptedText.StringToSha1();

            file = FilesRepository.OpenFile();
            file.resumo_criptografico = decryptedToSha1;
            FilesRepository.SaveFile(file);
            var fileByte     = FilesRepository.GetFileString("answer.json");
            var responseSend = WebService <ResponseObject> .Post(fileByte);
        }
Beispiel #34
0
        public void Given_File_When_UpdateFileAsync_Then_ShouldBeTrue()
        {
            RunOnDatabase(context =>
            {
                // ARRANGE
                var filesRepository = new FilesRepository(context);
                var file            = CreateFile(context, "C:\\folder\\file1.txt", "/download/5jtj5gitj4jrfs");
                context.Files.Add(file);
                context.SaveChanges();
                // ACT
                file.Update(file.Path, "/download/xabcxsd", file.TestInstanceId, false);
                var result = filesRepository.UpdateAsync(file);
                // ASSERT

                result.Result.Should().Be(true);
            });
        }
Beispiel #35
0
        public ActionResult Delete(int id)
        {
            try
            {
                new LoggingRepository().Logging("Deleting one element");
                FilesRepository fr = new FilesRepository();
                fr.DeleteFile(id);
                CacheRepository cr = new CacheRepository();
                cr.UpdateCache(fr.GetFiles(User.Identity.Name));
            }
            catch (Exception ex)
            {
                new LoggingRepository().ErrorLogging(ex);
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Thumbnail(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var image = files.ImageByPath(path);
            if (image != null)
            {
                var desiredSize = new ImageSize {Width = ThumbnailWidth, Height = ThumbnailHeight};

                const string contentType = "image/png";

                var thumbnailCreator = new ThumbnailCreator(new FitImageResizer());

                using (var stream = new MemoryStream(image.Data.ToArray()))
                {
                    return File(thumbnailCreator.Create(stream, desiredSize, contentType), contentType);
                }
            }
            throw new HttpException(404, "File Not Found");
        }
 public ActionResult Destroy(string path, FileBrowserEntry entry)
 {
     var files = new FilesRepository();
     if (entry.EntryType == FileBrowserEntryType.File)
     {
         var image = files.ImageByPath(Path.Combine(path, entry.Name));
         if (image != null)
         {
             files.Delete(image);
             return Json(new object[0]);
         }
     } else 
     {
         var folder = files.GetFolderByPath(Path.Combine(path, entry.Name));
         if (folder != null)
         {
             files.Delete(folder);
             return Json(new object[0]);
         }
     } 
     throw new HttpException(404, "File Not Found");
 }
        public ActionResult Upload(string path, HttpPostedFileBase file)
        {
            //TODO:Add security checks

            if (file != null && !string.IsNullOrEmpty(path))
            {
                var files = new FilesRepository();
                var parentFolder = files.GetFolderByPath(path);
                if (parentFolder != null)
                {
                    files.SaveImage(parentFolder, file);
                    return Json(new FileEntry
                                    {
                                        Name = Path.GetFileName(file.FileName)
                                    }, "text/plain");
                }
            }
            throw new HttpException(404, "File Not Found");
        }
 public ActionResult Upload(string path, HttpPostedFileBase file)
 {
     if (file != null)
     {
         var files = new FilesRepository();
         var parentFolder = files.GetFolderByPath(path);
         if (parentFolder != null)
         {
             files.SaveImage(parentFolder, file);
             return Json(
                 new FileBrowserEntry
                 {
                     Name = Path.GetFileName(file.FileName),
                     Size = file.ContentLength
                 }
             , "text/plain");
         }
     }
     throw new HttpException(404, "File Not Found");
 }
        public ActionResult CreateDirectory(string path, string name)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var folder = files.GetFolderByPath(path);
            if (folder != null)
            {
                files.CreateDirectory(folder, name);
                return Content("");
            }
            throw new HttpException(403, "Forbidden");
        }
        public ActionResult DeleteDirectory(string path)
        {
            //TODO:Add security checks

            var files = new FilesRepository();
            var folder = files.GetFolderByPath(path);
            if (folder != null)
            {
                files.Delete(folder);
                return Content("");
            }
            throw new HttpException(404, "File Not Found");
        }