Beispiel #1
0
        /// <summary>
        /// Create a new FolderType object.
        /// </summary>
        /// <param name="folderID">Initial value of the FolderID property.</param>
        /// <param name="folderExactLocation">Initial value of the FolderExactLocation property.</param>
        /// <param name="folderName">Initial value of the FolderName property.</param>
        /// <param name="lastEntry">Initial value of the LastEntry property.</param>
        /// <param name="fileSizeLimit">Initial value of the FileSizeLimit property.</param>
        /// <param name="nestedFolderRead">Initial value of the NestedFolderRead property.</param>
        /// <param name="searchingText">Initial value of the SearchingText property.</param>
        /// <param name="successfullyCreated">Initial value of the SuccessfullyCreated property.</param>
        public static FolderType CreateFolderType(global::System.Int64 folderID, global::System.String folderExactLocation, global::System.String folderName, global::System.DateTime lastEntry, global::System.Int32 fileSizeLimit, global::System.Boolean nestedFolderRead, global::System.String searchingText, global::System.Boolean successfullyCreated)
        {
            FolderType folderType = new FolderType();

            folderType.FolderID            = folderID;
            folderType.FolderExactLocation = folderExactLocation;
            folderType.FolderName          = folderName;
            folderType.LastEntry           = lastEntry;
            folderType.FileSizeLimit       = fileSizeLimit;
            folderType.NestedFolderRead    = nestedFolderRead;
            folderType.SearchingText       = searchingText;
            folderType.SuccessfullyCreated = successfullyCreated;
            return(folderType);
        }
Beispiel #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the FolderTypes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFolderTypes(FolderType folderType)
 {
     base.AddObject("FolderTypes", folderType);
 }
Beispiel #3
0
        /// <summary>
        /// Load all nested file names in the fileList List
        /// </summary>
        /// <param name="startingSize"></param>
        /// <param name="endingSize"></param>
        /// <param name="sizeType"></param>
        public void GenerateFileNames(DateTime startDate,
                                      DateTime endDate,
                                      int dateType              = -1,
                                      bool lookForDates         = false,
                                      bool getContents          = false,
                                      long startingSize         = -1,
                                      long endingSize           = -1,
                                      int sizeType              = -1,
                                      string includingExtension = "",
                                      string excudingExtension  = "",
                                      bool searchFromCache      = false,
                                      int expireCacheDays       = -1
                                      )
        {
            List <string> nestedDirectories = new List <string>();

            Flash.clearList();

            folder.directories = new List <string>();
            long FileID            = 0;
            bool PreviousListSame  = false;
            bool NeedToSearchAgain = false;

            TempSearchDirectories = TempSearchDirectories.OrderBy(n => n).ToList();
            SearchDirectories     = SearchDirectories.OrderBy(n => n).ToList();
            if (TempSearchDirectories.SequenceEqual(SearchDirectories))
            {
                PreviousListSame = true;
            }
            else
            {
                TempSearchDirectories = new List <string>();
                TempSearchDirectories = TempSearchDirectories.Concat(SearchDirectories).ToList();
            }

            if (PreviousListSame)
            {
                // there is no need to load again just search
                NeedToSearchAgain = true;

                //if (foundInDatabase && File.Exists(folderSavelocation) && File.Exists(fileSavelocation)) {
                goto Searching;
                //}
            }
            else
            {
                int size = 10 * 1024 * 1024;
                FilesList = new ListOfFiles <FileStructure>();

                FilesList.Capacity     = size;
                FilesList.SearchString = Flash.GetSearchText();
                folder.FilesList       = FilesList;
            }

            SearchDirectories.ForEach(searchDiretory => {
                //writing into the database.
                //look if that folder exist.
                int lastIndexSlash = searchDiretory.LastIndexOf('\\');

                string directoryName = "";
                if (lastIndexSlash > -1)
                {
                    directoryName = searchDiretory.Substring(lastIndexSlash + 1, searchDiretory.Length - lastIndexSlash - 1);
                }

                // look for this directoryName in the database.
                // in the database DirectoryName has been set to clustered index.
                // so it will be faster than search for exact location.

                var foundDirectories             = db.FolderTypes.Where(m => m.FolderName == directoryName).ToList();
                var CurrentDirectoryFromDatabase = foundDirectories.FirstOrDefault(m => m.FolderExactLocation == searchDiretory);
                float percentIncrease            = 0;

                bool foundInDatabase      = CurrentDirectoryFromDatabase != null;
                bool CacheExpired         = false;
                string folderSavelocation = "";
                string fileSavelocation   = "";
                // found in database
                if (foundInDatabase)
                {
                    folderSavelocation = CustomDataLocation + CurrentDirectoryFromDatabase.FolderID + ".txt";
                    fileSavelocation   = CustomDataLocation + CurrentDirectoryFromDatabase.FolderID + "_files.txt";
                }

                if (foundInDatabase && CurrentDirectoryFromDatabase.SuccessfullyCreated)
                {
                    var diff                  = DateTime.Now - CurrentDirectoryFromDatabase.LastEntry;
                    var days                  = diff.TotalDays / 24;
                    bool fileNotExist         = !File.Exists(folderSavelocation);
                    bool daysOver             = days > expireCacheDays && searchFromCache;
                    bool regularCacheForHours = !searchFromCache && (diff.TotalMinutes > 50);
                    if (fileNotExist || daysOver || regularCacheForHours)
                    {
                        CacheExpired = true;
                    }

                    if (lookForDates)
                    {
                        CacheExpired = true;
                    }
                }
                else
                {
                    CacheExpired = true;
                }

                if (!foundInDatabase)
                {
                    // create entry
                    // create folder into database
                    FolderType foldertype = new FolderType()
                    {
                        FolderExactLocation = searchDiretory,
                        FolderName          = directoryName,
                        LastEntry           = DateTime.Now,
                        ExcludeExt          = excudingExtension,
                        IncludeExt          = includingExtension,
                        FileSizeLimit       = sizeType,
                        StartingLimit       = startingSize,
                        EndingLimit         = endingSize,
                        SearchingText       = FilesList.GetSearchingTextAsOrganizeString,
                        SuccessfullyCreated = false
                    };
                    db.FolderTypes.AddObject(foldertype);

                    db.SaveChanges();
                    // new folder and load
                    folder.getNestedDirectories2(
                        searchDiretory,
                        ref FileID,
                        ref percentIncrease,
                        startDate,
                        endDate,
                        dateType,
                        getContents,
                        sizeType,
                        startingSize,
                        endingSize,
                        lookForDates);



                    //creating time , folder locations reassigned
                    folderSavelocation = CustomDataLocation + foldertype.FolderID + ".txt";
                    fileSavelocation   = CustomDataLocation + foldertype.FolderID + "_files.txt";


                    nestedDirectories = folder.directories;

                    Flash.StopInditerminateSateProcessing();
                    Flash.FlashStopGlobalTimer();

                    //if again read then write it into file system
                    FilesList.IsSavingNecessary = false;
                    folder.WriteObjectAsBinaryIntoFile(folderSavelocation, nestedDirectories);
                    folder.WriteObjectAsBinaryIntoFile(fileSavelocation, FilesList);

                    foldertype.SuccessfullyCreated = true;

                    db.SaveChanges();
                }
                else
                {
                    //found in database
                    if (CacheExpired)
                    {
                        // if cache is expired than 3 days then load again
                        //expired and load again

                        CurrentDirectoryFromDatabase.SuccessfullyCreated = false;

                        db.SaveChanges();

                        folder.getNestedDirectories2(
                            searchDiretory,
                            ref FileID,
                            ref percentIncrease,
                            startDate,
                            endDate,
                            dateType,
                            getContents,
                            sizeType,
                            startingSize,
                            endingSize,
                            lookForDates);
                        nestedDirectories = folder.directories;

                        Flash.StopInditerminateSateProcessing();
                        Flash.FlashStopGlobalTimer();

                        //if again read then write it into file system
                        new Thread(() => {
                            FilesList.IsSavingNecessary = false;

                            folder.WriteObjectAsBinaryIntoFile(folderSavelocation, nestedDirectories);
                            folder.WriteObjectAsBinaryIntoFile(fileSavelocation, FilesList);
                        }).Start();

                        //update database with date.
                        CurrentDirectoryFromDatabase.LastEntry           = DateTime.Now;
                        CurrentDirectoryFromDatabase.SearchingText       = FilesList.GetSearchingTextAsOrganizeString;
                        CurrentDirectoryFromDatabase.IncludeExt          = includingExtension;
                        CurrentDirectoryFromDatabase.ExcludeExt          = excudingExtension;
                        CurrentDirectoryFromDatabase.StartingLimit       = startingSize;
                        CurrentDirectoryFromDatabase.EndingLimit         = endingSize;
                        CurrentDirectoryFromDatabase.FileSizeLimit       = sizeType;
                        CurrentDirectoryFromDatabase.SuccessfullyCreated = true;
                        db.SaveChanges();
                    }
                    else
                    {
                        // if cache exist then load it from file.

                        var cachedDirectories = ((List <string>)folder.ReadObjectFromBinaryFile(folderSavelocation));
                        if (cachedDirectories != null)
                        {
                            nestedDirectories = nestedDirectories.Concat(cachedDirectories).ToList();
                        }

                        var cachedFiles = ((ListOfFiles <FileStructure>)folder.ReadObjectFromBinaryFile(fileSavelocation));
                        if (cachedFiles != null)
                        {
                            cachedFiles.AsParallel().ForAll(cacheFile => {
                                FilesList.Add(cacheFile);
                            });
                        }
                        if (FilesList.IsSavingNecessary)
                        {
                            new Thread(() => {
                                FilesList.IsSavingNecessary = false;
                                folder.WriteObjectAsBinaryIntoFile(folderSavelocation, nestedDirectories);
                                folder.WriteObjectAsBinaryIntoFile(fileSavelocation, FilesList);
                            }).Start();
                        }
                        NeedToSearchAgain = true;
                    }
                }
            });

Searching:
            if (NeedToSearchAgain)
            {
                searchAlgorithm.SearchAndAdd(FilesList,
                                             getContents,
                                             IncludingExtensionList,
                                             ExcludingExtensionList,
                                             startDate,
                                             endDate,
                                             dateType,
                                             sizeType,
                                             startingSize,
                                             endingSize,
                                             lookForDates,
                                             SearchEngineInterfaceFlash);
            }

            Flash.StopInditerminateSateProcessing();
            Flash.FlashStopGlobalTimer();
        }