Esempio n. 1
0
        public virtual PartialViewResult _PartialTags()
        {
            System.Web.HttpContext currentContext = System.Web.HttpContext.Current;

            string userid        = currentContext.User.Identity.GetUserId().ToString();
            var    records       = IndexCRUD.GetAllUserIndexRecords(userid).ToList();
            var    tagrecords    = records.Select(item => item.tag).Distinct().ToList();
            var    targetsString = String.Concat(tagrecords);

            string[] taglist        = targetsString.Split(new string[] { " <> " }, StringSplitOptions.None);
            var      distingtaglist = taglist.Skip(1).Distinct();
            var      tags           = new List <TagViewModel>();

            foreach (var item in distingtaglist)
            {
                var tmp = new TagViewModel();
                tmp.tag = item;
                tags.Add(tmp);
            }

            //var tags =
            //var tags = new List<TagViewModel>() ;
            //string tagstring = null;
            //foreach (var item in records)

            //{

            //    tagstring = tagstring + item.tag;

            //}

            return(PartialView(tags));
        }
Esempio n. 2
0
        public void Configuration(IAppBuilder app)
        {// Storage is the only thing required for basic configuration.
            ConfigureAuth(app);
            // Just discover what configuration options do you have.
            var optionsServer = new BackgroundJobServerOptions
            {
                Queues = new[] { "ahigh", "clow", "default" }
            };

            GlobalConfiguration.Configuration
            .UseSqlServerStorage(@"Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Hangfire.mdf;Initial Catalog=Hangfire;Integrated Security=True");
            //.UseActivator(...)
            //.UseLogProvider(...)

            app.UseHangfireServer(optionsServer);
            app.UseHangfireDashboard("/Dashboard", new DashboardOptions()
            {
                Authorization = new[] { new HangfireAuthorizationFilter() }
            }

                                     );

            RecurringJob.AddOrUpdate(() => IndexCRUD.AddUpdateLuceneIndex(Path.Combine(GlobalVariables.MyAppPath, "UsersData")), Cron.Weekly(System.DayOfWeek.Saturday, 1)); //update ındex weekly check If files deleted or added outsite of site
            RecurringJob.AddOrUpdate(() => IndexCRUD.Optimize(), Cron.Daily(2));                                                                                             //optimize index every day
        }
Esempio n. 3
0
        JsonResult IDriver.Rename(string target, string name)//done didnt tested
        {
            FullPath fullPath = ParsePath(target);
            var      answer   = new ReplaceResponse();

            answer.Removed.Add(target);
            RemoveThumbs(fullPath);
            if (fullPath.Directory != null)
            {
                var oldpathllist   = new List <string>();
                var oldfolderfiles = Directory.GetFiles(fullPath.Directory.FullName, "*", SearchOption.AllDirectories);
                foreach (var oldfiles in oldfolderfiles)
                {
                    oldpathllist.Add(oldfiles);
                }
                string newPath = Path.Combine(fullPath.Directory.Parent.FullName, name);
                System.IO.Directory.Move(fullPath.Directory.FullName, newPath);
                answer.Added.Add(DTOBase.Create(new DirectoryInfo(newPath), fullPath.Root));//when create new folder dont need add to it in index
                var newfolderfiles = Directory.GetFiles(newPath, "*", SearchOption.AllDirectories);
                var newpathllist   = new List <string>();
                foreach (var newfiles in newfolderfiles)
                {
                    newpathllist.Add(newfiles);
                }
                BackgroundJob.Enqueue(() => IndexCRUD.OnRenameResponseFolder(oldpathllist, newpathllist));
            }
            else
            {
                string newPath = Path.Combine(fullPath.File.DirectoryName, name);
                File.Move(fullPath.File.FullName, newPath);
                IndexCRUD.OnRename(fullPath.File.FullName, newPath); //just rename and change create access time etc
                answer.Added.Add(DTOBase.Create(new FileInfo(newPath), fullPath.Root));
            }
            return(Json(answer));
        }
Esempio n. 4
0
        JsonResult IDriver.MakeFile(string target, string name)//done didnt tested
        {
            FullPath fullPath = ParsePath(target);
            FileInfo newFile  = new FileInfo(Path.Combine(fullPath.Directory.FullName, name));

            newFile.Create().Close();
            IndexCRUD.OnUpload(Path.Combine(fullPath.Directory.FullName, name));//can use upload doing same thing
            return(Json(new AddResponse(newFile, fullPath.Root)));
        }
Esempio n. 5
0
        public virtual ActionResult DeleteTag(string[] paths, string tag)
        {
            if (tag != "")
            {
                while (true)
                {
                    try
                    {
                        var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
                        using (var writer = new IndexWriter(IndexCRUD._directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
                        {
                            foreach (var path in paths)
                            {
                                var query = IndexCRUD.SearchNotAnalyzed(path, "FullPath").FirstOrDefault();
                                if (query.tag != null)
                                {
                                    var model = new IndexModel();
                                    model.name              = query.name;
                                    model.md5               = query.md5;
                                    model.size              = query.size;
                                    model.userid            = query.userid;
                                    model.laccess_time      = query.laccess_time;
                                    model.display_directory = query.display_directory;
                                    model.directory         = query.directory;
                                    model.create_time       = query.create_time;
                                    model.content           = query.content;
                                    model.lmodified_time    = query.lmodified_time;
                                    model.fullpath          = query.fullpath;
                                    model.extension         = query.extension;

                                    string updatedtag = query.tag.Replace(String.Format(" <> {0}", tag), "");
                                    model.tag = updatedtag;



                                    var record = IndexCRUD.IndexModelToDoc(model);

                                    writer.UpdateDocument(new Term("FullPath", path), record);
                                }
                            }

                            analyzer.Close();
                            writer.Dispose();
                            break;
                        }
                    }
                    catch (LockObtainFailedException)

                    {
                    }
                }
            }

            return(new EmptyResult());
        }
Esempio n. 6
0
        public virtual PartialViewResult _PartialContent(string fullpath)
        {
            var result = IndexCRUD.SearchNotAnalyzed(fullpath, "FullPath").FirstOrDefault();

            var model = new IndexContentViewModel();

            model.content = result.content;
            model.name    = result.name;

            return(PartialView(model));
        }
Esempio n. 7
0
        protected void Application_Start()
        {
            GlobalVariables.MyAppPath = Server.MapPath("~");

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            IndexCRUD.CreateFolders();
            IndexCRUD.CreateEmptyIndexFiles();
        }
Esempio n. 8
0
        JsonResult IDriver.Remove(IEnumerable <string> targets)//done*
        {
            var            pathlist = new List <string>();
            RemoveResponse answer   = new RemoveResponse();

            foreach (string item in targets)
            {
                FullPath fullPath = ParsePath(item);

                RemoveThumbs(fullPath);

                if (fullPath.Directory != null)
                {
                    var filesinfolder = Directory.GetFiles(fullPath.Directory.FullName, "*", SearchOption.AllDirectories);

                    System.IO.Directory.Delete(fullPath.Directory.FullName, true);
                    foreach (var files in filesinfolder)
                    {
                        //LuceneIndexController.StopBackgroundJob(files, "UpdateLuceneIndexContent"); //stop before delete if textextraction continue

                        //LuceneIndexController.OnDelete(files);
                        pathlist.Add(files);
                    }
                }
                else
                {
                    //LuceneIndexController.StopBackgroundJob(fullPath.File.FullName, "UpdateLuceneIndexContent"); //stop before delete if textextraction continue
                    File.Delete(fullPath.File.FullName);
                    //LuceneIndexController.OnDelete(fullPath.File.FullName);
                    pathlist.Add(fullPath.File.FullName);
                }
                answer.Removed.Add(item);
            }
            BackgroundJob.Enqueue(() => IndexCRUD.OnDeleteResponse(pathlist));
            return(Json(answer));
        }
Esempio n. 9
0
        JsonResult IDriver.Upload(string target, System.Web.HttpFileCollectionBase targets)//done*
        {
            FullPath        dest     = ParsePath(target);
            var             response = new AddResponse();
            List <FileInfo> fileList = new List <FileInfo>();

            if (dest.Root.MaxUploadSize.HasValue)
            {
                for (int i = 0; i < targets.AllKeys.Length; i++)
                {
                    HttpPostedFileBase file = targets[i];
                    if (file.ContentLength > dest.Root.MaxUploadSize.Value)
                    {
                        return(Error.MaxUploadFileSize());
                    }
                }
            }
            for (int i = 0; i < targets.AllKeys.Length; i++)
            {
                HttpPostedFileBase file = targets[i];
                FileInfo           path = new FileInfo(Path.Combine(dest.Directory.FullName, Path.GetFileName(file.FileName)));

                if (path.Exists)
                {
                    if (dest.Root.UploadOverwrite)
                    {
                        //if file already exist we rename the current file,
                        //and if upload is succesfully delete temp file, in otherwise we restore old file
                        string tmpPath  = path.FullName + Guid.NewGuid();
                        bool   uploaded = false;
                        try
                        {
                            file.SaveAs(tmpPath);
                            uploaded = true;
                        }
                        catch { }
                        finally
                        {
                            if (uploaded)
                            {
                                File.Delete(path.FullName);
                                File.Move(tmpPath, path.FullName);
                                //LuceneIndexController.OnUpload(path.FullName);
                                fileList.Add(new FileInfo(path.FullName));
                            }
                            else
                            {
                                File.Delete(tmpPath);
                            }
                        }
                    }
                    else
                    {
                        string duplicatedname = Helper.GetDuplicatedName(path);
                        file.SaveAs(Path.Combine(path.DirectoryName, duplicatedname));
                        //LuceneIndexController.OnUpload(duplicatedname);
                        fileList.Add(new FileInfo(Path.Combine(path.DirectoryName, duplicatedname)));
                    }
                }
                else
                {
                    file.SaveAs(path.FullName);
                    fileList.Add(new FileInfo(path.FullName));
                    //LuceneIndexController.OnUpload(path.FullName);
                }
                response.Added.Add((FileDTO)DTOBase.Create(new FileInfo(path.FullName), dest.Root));
            }


            BackgroundJob.Enqueue(() => IndexCRUD.OnUploadResponse(fileList));
            return(Json(response));
        }
Esempio n. 10
0
        JsonResult IDriver.Paste(string source, string dest, IEnumerable <string> targets, bool isCut)//todo:gonna look at that later !!!!!!!!!!!
        {
            FullPath        destPath = ParsePath(dest);
            ReplaceResponse response = new ReplaceResponse();

            foreach (var item in targets)
            {
                FullPath src         = ParsePath(item);
                string   oldpathname = null;
                if (src.Directory == null)
                {
                    oldpathname = src.File.FullName;
                }
                if (src.Directory != null)
                {
                    DirectoryInfo newDir = new DirectoryInfo(Path.Combine(destPath.Directory.FullName, src.Directory.Name));

                    if (newDir.Exists)
                    {
                        var filesindirdest = Directory.GetFiles(newDir.FullName, "*", SearchOption.AllDirectories);
                        Directory.Delete(newDir.FullName, true);
                        foreach (var fileindirdest in filesindirdest)
                        {
                            IndexCRUD.DeleteLuceneIndex(fileindirdest);
                        }
                    }
                    if (isCut)
                    {
                        RemoveThumbs(src);

                        var filesindirsrc = Directory.GetFiles(src.Directory.FullName, "*", SearchOption.AllDirectories);
                        src.Directory.MoveTo(newDir.FullName);
                        var filesindirdestnew = Directory.GetFiles(newDir.FullName, "*", SearchOption.AllDirectories);


                        for (int i = 0; i < filesindirsrc.Count(); i++)
                        {
                            IndexCRUD.OnMove(filesindirdestnew[i], filesindirsrc[i], isCut);
                        }


                        response.Removed.Add(item);
                    }
                    else
                    {
                        var filesindirsrc = Directory.GetFiles(src.Directory.FullName, "*", SearchOption.AllDirectories);
                        DirectoryCopy(src.Directory, newDir.FullName, true);
                        var filesindirdestnew = Directory.GetFiles(newDir.FullName, "*", SearchOption.AllDirectories);



                        for (int i = 0; i < filesindirsrc.Count(); i++)
                        {
                            IndexCRUD.OnMove(filesindirdestnew[i], filesindirsrc[i], isCut);
                        }
                    }
                    response.Added.Add(DTOBase.Create(newDir, destPath.Root));
                }
                else
                {
                    string newFilePath = Path.Combine(destPath.Directory.FullName, Path.GetFileName(oldpathname));
                    if (File.Exists(newFilePath))
                    {
                        //if(LuceneIndexController.CalculateMD5(newFilePath)==LuceneIndexController.CalculateMD5(src.File.FullName))
                        //{
                        File.Delete(newFilePath);
                        IndexCRUD.DeleteLuceneIndex(newFilePath);
                    }

                    if (isCut)
                    {
                        RemoveThumbs(src);
                        src.File.MoveTo(newFilePath);
                        IndexCRUD.OnMove(newFilePath, oldpathname, isCut);
                        response.Removed.Add(item);
                    }
                    else
                    {
                        File.Copy(src.File.FullName, newFilePath);
                        IndexCRUD.OnMove(newFilePath, oldpathname, isCut);
                    }
                    response.Added.Add(DTOBase.Create(new FileInfo(newFilePath), destPath.Root));
                }
            }
            return(Json(response));
        }
Esempio n. 11
0
        public virtual PartialViewResult _PartialUserSearchFiles(string SearchTerm, string SearchField, string RecordCount, int?Page, string SortOrder, string[] Tags)
        {
            System.Web.HttpContext currentContext = System.Web.HttpContext.Current;


            if (SearchField == "DisplayDirectory" && SearchTerm != "")
            {
                SearchTerm = SearchTerm.Replace("\\", "\\" + "\\");
            }


            string userid = currentContext.User.Identity.GetUserId().ToString();

            if (SearchTerm != "")
            {
                SearchTerm = "(" + SearchTerm + ")" + "AND userid:" + userid;
            }
            string searchTags = null;

            if (Tags != null)
            {
                foreach (var item in Tags)
                {
                    searchTags = searchTags + "Tag:" + item + " OR ";
                }
                searchTags = searchTags.Substring(0, searchTags.Length - 4);
                if (SearchTerm != "")
                {
                    SearchTerm = "(" + "(" + SearchTerm + ")" + "AND userid:" + userid + ")" + " AND " + searchTags;
                }
            }


            //// create default Lucene search index directory
            //if (!Directory.Exists(DMSIndex.DMSIndex._luceneDir)) Directory.CreateDirectory(DMSIndex.DMSIndex._luceneDir);

            // perform Lucene search
            int RecordCount1 = 1;
            int FileCount    = IndexCRUD.GetAllUserIndexRecords(userid).Count();

            if (RecordCount != null && RecordCount != "All")
            {
                RecordCount1 = Int32.Parse(RecordCount);
            }
            else
            {
                RecordCount1 = FileCount;
            }

            int PageSize   = (RecordCount1); // sayfadaki veri sayısı
            int PageNumber = (Page ?? 1);    // sayfa seçilmediyse page değişkenine 1 ata
            IEnumerable <IndexModel> _searchResults = IndexCRUD.SearchDefault(SearchTerm, SearchField);

            if (SearchField == "")
            {
                _searchResults = IndexCRUD.SearchDefault(SearchTerm);
            }

            else
            {
                IndexCRUD.SearchDefault(SearchTerm, SearchField);
            }



            if (string.IsNullOrEmpty(SearchTerm) && searchTags == null)
            {
                _searchResults = IndexCRUD.GetAllUserIndexRecords(userid);
            }
            else if (string.IsNullOrEmpty(SearchTerm) && searchTags != null)
            {
                _searchResults = IndexCRUD.GetAllUserIndexRecordsCategorised(userid, searchTags);
            }
            var x     = _searchResults;
            var files = from s in _searchResults
                        select s;

            switch (SortOrder)
            {
            case "ZA":
                files = files.OrderByDescending(s => s.name);

                break;

            case "AZ":
                files = files.OrderBy(s => s.name);

                break;

            case "S-":
                files = files.OrderByDescending(s => s.size);

                break;

            case "S+":
                files = files.OrderBy(s => s.size);

                break;

            case "CT-":
                files = files.OrderByDescending(s => s.create_time);

                break;

            case "CT+":
                files = files.OrderBy(s => s.create_time);

                break;

            case "MT-":
                files = files.OrderByDescending(s => s.lmodified_time);

                break;

            case "MT+":
                files = files.OrderBy(s => s.lmodified_time);

                break;

            default:
                files = files.OrderBy(s => s.name);

                break;
            }
            var viewmodel = new List <IndexRecordViewModel>();

            foreach (var item in files)

            {
                var temp = new IndexRecordViewModel();
                temp.fullpath          = item.fullpath;
                temp.name              = item.name;
                temp.display_directory = item.display_directory;
                temp.laccess_time      = item.laccess_time;
                temp.lmodified_time    = item.lmodified_time;
                temp.create_time       = item.create_time;

                temp.size = FormatByteSize(item.size);
                viewmodel.Add(temp);
            }



            IPagedList Pagedfiles = viewmodel.ToPagedList(PageNumber, PageSize);

            return(PartialView("_PartialUserSearchFiles", Pagedfiles));
        }