Esempio n. 1
0
        void AddMetadataToListOfFiles(MetaData metadata)
        {
            ListOfFiles.Clear();

            bool showFilesFirst = AppSettings.ShowFilesFirst;
            var  items          = metadata.Contents.OrderBy(p => p.Is_Dir == showFilesFirst);

            foreach (var item in items)
            {
                var temp = item;
                var vm   = Ioc.GetInstance <MetaDataViewModel>(temp.Path);
                if (vm != null)
                {
                    ListOfFiles.Add(vm);
                }
                else
                {
                    var tempVm = new MetaDataViewModel(temp);
                    ListOfFiles.Add(tempVm);
                    Ioc.Register(() => tempVm, temp.Path);
                }
            }

            RaisePropertyChanged("ListOfFiles");
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            ListOfFiles <FileStructure> ls = new ListOfFiles <FileStructure>();

            ls.IsNaturalSearchEnabled = true;
            ls.SearchString           = this.textBox1.Text;
        }
Esempio n. 3
0
 public void RemoveFileFromList(object obj)
 {
     if (SelectedFileItem != null)
     {
         ListOfFiles.Remove(SelectedFileItem);
     }
 }
Esempio n. 4
0
        public SearchEngine()
        {
            InitializeComponent();
            threadGetFileNames = new Thread(() => GetDirectory());

            //SearchDirectories.Add(@"C:\Users\Alim\Desktop\Test 1");
            //SearchDirectories.Add(@"F:\TvShow\Mentlist Unordered");
            //SearchDirectories.Add(@"E:\Working");
            //SearchDirectories.Add(@"\\172.195.16.8\One Tera Byte New Hardrive");
            //SearchDirectories.Add(@"\\172.195.16.8\Animated Movie");
            //SearchDirectories.Add(@"\\172.195.16.8\Tv show 2");
            //SearchDirectories.Add(@"\\172.195.16.8\Games Collection 3");
            //SearchDirectories.Add(@"\\172.195.16.8\Hindi Movie");
            //SearchDirectories.Add(@"\\172.195.16.7\2012 Enlish Movie");


            if (!Directory.Exists(CustomDataLocation))
            {
                Directory.CreateDirectory(CustomDataLocation);
            }
            Flash = new FlashPropertise(SearchEngineInterfaceFlash);
            int size = 10 * 1024 * 1024;

            FilesList = new ListOfFiles <FileStructure>();

            FilesList.Capacity = size;

            folder = new Folder(SearchEngineInterfaceFlash, FilesList, IncludingExtensionList, ExcludingExtensionList);
        }
Esempio n. 5
0
        private void ClearFilenumbersAndList()
        {
            NumberOfFiles       = 0;
            FilesScanned        = 0;
            UnauthorizedFiles   = 0;
            FilesProcessedToZip = 0;

            ListOfFiles.Clear();
        }
Esempio n. 6
0
        public void GetFileNames()
        {
            listOfFiles.Clear();

            string[] xmlfiles = Directory.GetFiles(fileloc, "*.xml");
            foreach (string file in xmlfiles)
            {
                ListOfFiles.Add(System.IO.Path.GetFileNameWithoutExtension(file));
            }
        }
Esempio n. 7
0
        private void _addFileToCurrentSet(string file)
        {
            verifyDicom dicom = new verifyDicom();

            // Make sure the file is legal
            if (dicom.verify(file))
            {
                FileInfo fileInfo = new FileInfo(file);
                ListOfFiles.Add(fileInfo);
            }
        }
Esempio n. 8
0
        void LoadItemsHandler(MetaData metaData, bool forceReload)
        {
            _metaDataCache = metaData;

            Title = metaData.Name;

            if (IsInDesignMode)
            {
                ListOfFiles.Add(new MetaDataViewModel(new MetaData {
                    Path = "/Path1", Icon = "folder", Modified = "17-Apr-2012"
                }));
                ListOfFiles.Add(new MetaDataViewModel(new MetaData {
                    Path = "/App", Icon = "folder_app", Modified = "17-Apr-2012"
                }));
                ListOfFiles.Add(new MetaDataViewModel(new MetaData {
                    Path = "/file.cs", Icon = "page_white_csharp", Modified = "17-Apr-2012"
                }));
                ListOfFiles.Add(new MetaDataViewModel(new MetaData {
                    Path = "/file.pptx", Icon = "page_white_powerpoint", Modified = "17-Apr-2012"
                }));
                return;
            }


            if (!forceReload && !App.NeedDataRefresh)
            {
                if (ListOfFiles.Count > 0)
                {
                    return;
                }

                string   key  = GetCacheKeyName(metaData.Path);
                MetaData item = Cache.Current.Get <MetaData>(key);

                if (item != null)
                {
                    AddMetadataToListOfFiles(item);
                    return;
                }
            }

            App.NeedDataRefresh = false;
            if (!IsNetworkAvaialble)
            {
                MessageBox.Show(Labels.ConnectionErrorMessage, Labels.ConnectionErrorTitle, MessageBoxButton.OK);
                return;
            }

            IsLoading = true;
            Client.GetMetaDataAsync(metaData.Path, GetMetadataHandler, Fail);
        }
Esempio n. 9
0
        public List <String> RepoFiles()
        {
            if (ListOfFiles != null)
            {
                ListOfFiles.Clear();
            }
            DirectoryInfo directoryInfo = new DirectoryInfo(@"../../../RepositoryStorage");

            foreach (FileInfo f in directoryInfo.GetFiles())
            {
                ListOfFiles.Add(f.ToString());
            }
            return(ListOfFiles);
        }
        internal void fnDropFiles(DragEventArgs e)
        {
            if (tempListOfFiles == null)
            {
                tempListOfFiles = new ObservableCollection <stFileNames>();
            }
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                if (File.Exists(file))
                {
                    if (file.EndsWith(".gdt"))
                    {
                        if (ListOfFiles != null)
                        {
                            var alreadyincluded = ListOfFiles.Where(x => x.Text == file);
                            if (alreadyincluded.Count() > 0)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            ListOfFiles = new ObservableCollection <stFileNames>();
                        }
                        stFileNames st = new stFileNames();
                        st.Text = file;
                        ListOfFiles.Add(st);
                    }
                }
            }
            if (ListOfFiles.Count > 0)
            {
                SeeClear = Visibility.Visible;
            }
            else
            {
                SeeClear = Visibility.Collapsed;
            }
            if (rootFolder != null)
            {
                ImportGDT = Directory.Exists(rootFolder) && ListOfFiles.Count > 0;

                return;
            }
            ImportGDT = false;
        }
Esempio n. 11
0
        private void GetFiles(string value)
        {
            try
            {
                foreach (string directory in Directory.GetDirectories(value))
                {
                    if ((new DirectoryInfo(directory).Attributes & FileAttributes.Hidden) == 0)
                    {
                        if (Directory.GetDirectories(directory).Length > 0)
                        {
                            GetFiles(directory);
                        }

                        foreach (string file in Directory.GetFiles(directory))
                        {
                            if (AcceptedFileTypes.Any(file.Contains))
                            {
                                // Handle filepath too long! (And no, this is not the right way to do it. :))
                                if (file.Length < 250)
                                {
                                    var fileInfos = new FileInfo(file);

                                    ListOfFiles.Add(new File(fileInfos.Name, fileInfos.DirectoryName, fileInfos.Length, _fileTypeEnum.ToString()));
                                    NumberOfFiles += 1;
                                }

                                else
                                {
                                    // FIX THIS, NOT OK TO HANDLE THIS PROBLEM THIS WAY!!
                                    FilenameTooLongFiles += 1;
                                }
                            }

                            FilesScanned += 1;
                        }
                    }
                }


                // Leaf-folder
                if (NumberOfFiles == 0)
                {
                    foreach (string file in Directory.GetFiles(value))
                    {
                        if (AcceptedFileTypes.Any(file.Contains))
                        {
                            var fileInfos = new FileInfo(file);

                            ListOfFiles.Add(new File(fileInfos.Name, fileInfos.DirectoryName, fileInfos.Length, _fileTypeEnum.ToString()));
                            NumberOfFiles += 1;
                        }
                    }
                }
            }

            catch (UnauthorizedAccessException)
            {
                // Make a logger instead?
                UnauthorizedFiles += 1;
                Console.WriteLine("\n\n\nUnauthorized: " + UnauthorizedFiles + "\nFiles scanned: " + FilesScanned + "\nMovie-files found: " + NumberOfFiles);
            }
        }
Esempio n. 12
0
 private void _removeAllInputs(object obj)
 {
     ListOfFiles.Clear();
 }
Esempio n. 13
0
 public void ClearFields(object obj)
 {
     ListOfFiles.Clear();
 }
Esempio n. 14
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();
        }