Esempio n. 1
0
        public void AddItem(string filename)
        {
            if (System.IO.File.Exists(filename))
            {
                var fileInfo = new FileInfo(filename);

                if (!files.Contains(fileInfo))
                {
                    fileInfo.CheckExtension();
                    if (fileInfo.Extension == null)
                    {
                        return;
                    }

                    Dispatcher.Invoke(() => files.Add(fileInfo));
                }
            }
            else
            {
                foreach (string ss in FilesEnumerator.EnumerateFiles(filename, "*.*", false))
                {
                    AddItem(ss);
                }
            }
        }
Esempio n. 2
0
        private async void ButtonBrowse_Click(object sender, RoutedEventArgs e)
        {
            Daramee.Winston.Dialogs.OpenFolderDialog ofd = new Daramee.Winston.Dialogs.OpenFolderDialog();
            ofd.FileName = MeasurePath.Text;
            if (ofd.ShowDialog() == false)
            {
                return;
            }

            (sender as Button).IsEnabled = FilesTree.IsEnabled = false;
            Indicator.Visibility         = Visibility.Visible;

            GCLatencyMode gcOldMode = GCSettings.LatencyMode;

            RuntimeHelpers.PrepareConstrainedRegions();

            try
            {
                GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

                await Task.Run(() =>
                {
                    var fileEnums = FilesEnumerator.EnumerateFiles(ofd.FileName, "*", false);
                    currentNode   = Node.FilesToNode(fileEnums);

                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        GC.TryStartNoGCRegion(Environment.Is64BitProcess ? (15 * 1024 * 1024) : (256 * 1024 * 1024));

                        FilesTree.ItemsSource  = new Node [] { currentNode };
                        TotalLines.DataContext = currentNode;

                        if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
                        {
                            GC.EndNoGCRegion();
                        }
                    }));
                });
            }
            finally
            {
                GCSettings.LatencyMode = gcOldMode;
            }

            Indicator.Visibility         = Visibility.Hidden;
            (sender as Button).IsEnabled = FilesTree.IsEnabled = true;

            MeasurePath.Text = ofd.FileName;
        }
Esempio n. 3
0
 public void AddItem(string s, bool directoryMode = false)
 {
     if (System.IO.File.Exists(s) || directoryMode)
     {
         var fileInfo = new FileInfo(s);
         if (!FileInfo.Files.Contains(fileInfo))
         {
             FileInfo.Files.Add(fileInfo);
         }
     }
     else
     {
         foreach (string ss in FilesEnumerator.EnumerateFiles(s, "*.*", false))
         {
             AddItem(ss, directoryMode);
         }
     }
 }
Esempio n. 4
0
        public static async Task <ExcelIndexer> ToIndexer(ExcelIndexerBuilderState state = null)
        {
            IndexedItem [] indexedItems = null;
            DateTime []    indexedDates = null;

            await Task.Run(() =>
            {
                using (LiteDatabase db = new LiteDatabase($"Filename=\"{Path.Combine ( Program.ProgramPath, "ExcelFilesCache.litedb" )}\"; Journal=true; Mode=Shared; Flush=true;"))
                {
                    var cacheFilesCollection  = db.GetCollection <CacheFiles> ("cachefiles");
                    var cachedItemsCollection = db.GetCollection <IndexedItem> ("indexed");

                    var newFile   = new ConcurrentQueue <CacheFiles> ();
                    var newRecord = new ConcurrentQueue <IndexedItem> ();

                    Parallel.ForEach(FilesEnumerator.EnumerateFiles(CustomizedValue.WorkingDirectory, "엑셀자료-*.xlsx", false).AsParallel(), (file) =>
                    {
                        if (file.Contains("일지 양식") || file.Contains("샘플") || Regex.IsMatch(file, todayRegexString))
                        {
                            return;
                        }
                        var fileItem = cacheFilesCollection.FindOne(Query.EQ("Filename", file));
                        if (fileItem != null)
                        {
                            if (fileItem.LastModifiedDateTime.ToString() == File.GetLastWriteTime(file).ToString())
                            {
                                if (state != null)
                                {
                                    Interlocked.Increment(ref state.excelFileCount);
                                    int recordCount = cachedItemsCollection.Find(Query.EQ("Filename", file)).Count();
                                    Interlocked.Add(ref state.totalItemCount, recordCount);
                                    FinderLog.Log($"{Path.GetFileName ( file )}으로부터 {recordCount}개를 이미 인덱싱 했음.");
                                }
                                return;
                            }
                            else
                            {
                                cachedItemsCollection.Delete(Query.EQ("Filename", file));
                                cacheFilesCollection.Delete(Query.EQ("Filename", file));
                                FinderLog.Log($"{Path.GetFileName ( file )}의 인덱싱 데이터가 최신이 아니므로 재인덱싱 시작.");
                            }
                        }
                        else
                        {
                            FinderLog.Log($"{Path.GetFileName ( file )}은 인덱싱되지 않은 파일임.");
                        }

                        try
                        {
                            OleDbConnection connection = new OleDbConnection(
                                $"Provider=\"Microsoft.ACE.OLEDB.12.0\";Data Source=\"{file}\";Extended Properties=\"Excel 12.0;HDR=NO\";"
                                );
                            connection.Open();

                            int count = 0;
                            //Regex.Replace ( connection.GetSchema ( "Tables" ).Rows [ 1 ] [ "TABLE_NAME" ] as string, "['\"]", "" );
                            using (OleDbCommand command = new OleDbCommand(
                                       selectQuery,
                                       connection
                                       ))
                            {
                                using (var reader = command.ExecuteReader())
                                {
                                    if (!reader.Read())
                                    {
                                        state?.OpeningFailedFiles.Enqueue(file);
                                        return;
                                    }

                                    while (reader.Read())
                                    {
                                        object websiteName = reader.GetValue(8);
                                        object url         = reader.GetValue(9);
                                        object baseUrl     = reader.GetValue(31);

                                        if (websiteName == DBNull.Value || url == DBNull.Value || baseUrl == DBNull.Value)
                                        {
                                            break;
                                        }

                                        newRecord.Enqueue(new IndexedItem(websiteName as string, url as string, baseUrl as string, file));

                                        ++count;
                                    }
                                }
                            }

                            connection.Close();

                            if (state != null)
                            {
                                Interlocked.Add(ref state.totalItemCount, count);
                                Interlocked.Increment(ref state.excelFileCount);
                            }

                            newFile.Enqueue(new CacheFiles()
                            {
                                Filename = file, LastModifiedDateTime = File.GetLastWriteTime(file)
                            });

                            FinderLog.Log($"{Path.GetFileName ( file )}의 데이터 {count}개 캐시 완료.");
                        }
                        catch (Exception ex)
                        {
                            FinderLog.Log($"{Path.GetFileName ( file )} 캐시 중 오류 발생: {ex.ToString ()}");
                            state?.OpeningFailedFiles.Enqueue(file);
                        }
                    });

                    cacheFilesCollection.Insert(newFile);
                    cachedItemsCollection.Insert(newRecord);

                    db.Shrink();

                    indexedItems          = new List <IndexedItem> (cachedItemsCollection.FindAll()).ToArray();
                    List <DateTime> dates = new List <DateTime> ();
                    foreach (var f in cacheFilesCollection.FindAll())
                    {
                        string date = "20" + Regex.Match(f.Filename, $"(.*)모니터링일지-[가-힣]+-([0-9][0-9][0-1][0-9][0-3][0-9])\\\\(.*).xlsx").Groups [2].Value;
                        dates.Add(new DateTime(int.Parse(date.Substring(0, 4)), int.Parse(date.Substring(4, 2)), int.Parse(date.Substring(6, 2))));
                    }
                    indexedDates = dates.ToArray();
                }
            });

            GC.Collect();

            return(new ExcelIndexer(indexedItems, indexedDates));
        }