git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorBellai Ádám <USER\adam.bellai>
Tue, 10 Oct 2017 12:52:03 +0000 (12:52 +0000)
committerBellai Ádám <USER\adam.bellai>
Tue, 10 Oct 2017 12:52:03 +0000 (12:52 +0000)
client/Maestro/MaestroForm.Source.cs
client/Maestro/MaestroForm.cs
client/Maestro/Sources/FileSystemSource.cs

index 7a1af3bc347b865af5a104b084ac38ebc4341341..fd47128f75a9eac3764fcf36a82d3736342aa1c0 100644 (file)
@@ -37,7 +37,8 @@ namespace Maestro {
 \r
             if (Configuration?.Source is UNCSource) {\r
                 logger.Debug("UNC source initialization");\r
-                source = new FileSystemSource(this, MessageBus, Configuration.Source.Filter);\r
+                Action<DateTime, string, Color> errorReporter = ReportError;\r
+                source = new FileSystemSource(this, MessageBus, Configuration.Source.Filter, errorReporter);\r
                 logger.Debug("UNC source created");\r
             }\r
             if (Configuration?.Source is NEXIOSource) {\r
index 038d9f80dfa49a5845cf0c5305ea5d3bea77e79b..97a9db7cd12d0b4f9743cbc3c318aa6745502d20 100644 (file)
@@ -260,7 +260,7 @@ namespace Maestro {
 \r
 \r
         public void ReportError(DateTime time, String message, Color color) {\r
-            systemMessageBindingSource.Insert(0, new SystemMessage() { Time = time, message = message});\r
+            systemMessageBindingSource.Insert(0, new SystemMessage() { Time = time, message = message });\r
             UpdateDataChanged();\r
             newMSGColor = color;\r
         }\r
index 3b24042c5e9cebe53897b16781efdc01b5ffcdb9..9656966ab0911ae792eb36d9b217b18760953388 100644 (file)
@@ -13,6 +13,8 @@ using System.Drawing;
 using NLog;\r
 \r
 namespace Maestro.Sources {\r
+    public delegate void ClearAndInitialize();\r
+\r
     class FileSystemSource : BindingList<FileSourceItem>, ISource {\r
         private readonly Logger logger = LogManager.GetCurrentClassLogger();\r
         private IMessageBus messageBus;\r
@@ -24,6 +26,9 @@ namespace Maestro.Sources {
         private List<FileSourceItem> cache = new List<FileSourceItem>();\r
         private BackgroundWorker pathWatcherWorker = new BackgroundWorker();\r
         private string path;\r
+        private bool initialized;\r
+        private ClearAndInitialize clearAndInitialize;\r
+        private Action<DateTime, string, Color> errorReporter;\r
 \r
         public DataGridViewColumn[] Columns {\r
             get {\r
@@ -66,28 +71,46 @@ namespace Maestro.Sources {
 \r
         public bool SupportsFiltering => true;\r
 \r
-        public FileSystemSource(Control parent, IMessageBus messageBus, String fileExtensionFilter) {\r
+        public FileSystemSource(Control parent, IMessageBus messageBus, String fileExtensionFilter, Action<DateTime, string, Color> errorReporter) {\r
             this.parent = parent;\r
             this.messageBus = messageBus;\r
             this.fileExtensionFilter = fileExtensionFilter;\r
             SetAcceptableExtensions();\r
             pathWatcherWorker.DoWork += pathWatcherWorker_watchPath;\r
-            pathWatcherWorker.ProgressChanged += pathWatcherWorker_progressChanged;\r
             pathWatcherWorker.WorkerReportsProgress = true;\r
-        }\r
-\r
-        private void pathWatcherWorker_progressChanged(object sender, ProgressChangedEventArgs e) {\r
-            InnerStartUp();\r
+            this.errorReporter = errorReporter;\r
         }\r
 \r
         private void pathWatcherWorker_watchPath(object sender, DoWorkEventArgs e) {\r
-            while (!(Directory.Exists(path))) {\r
-                \r
+            while (true) {\r
+                if (!(Directory.Exists(path))) {\r
+                    if (initialized) {\r
+                        WatchedDirDeleted();\r
+                    }\r
+                } else {\r
+                    if (!initialized)\r
+                        InnerStartUp();\r
+                }\r
             }\r
-            pathWatcherWorker.ReportProgress(0);\r
 \r
         }\r
 \r
+        private void WatchedDirDeleted() {\r
+            //errorReporter?.Invoke(DateTime.Now, String.Format("[FileSystemSource] {0} path can't be found.", path), Color.Red);\r
+            clearAndInitialize = new ClearAndInitialize(ClearDataGridView);\r
+            clearAndInitialize?.Invoke();\r
+        }\r
+\r
+        private void ClearDataGridView() {\r
+            this.parent.SafeCall(() => {\r
+                Clear();\r
+            }\r
+                );\r
+            cache.Clear();\r
+            initialized = false;\r
+            //todo errorreport küldése\r
+        }\r
+\r
         private void SetAcceptableExtensions() {\r
             if (fileExtensionFilter != null)\r
                 acceptableExtensions = fileExtensionFilter.Split(',')?.ToList();\r
@@ -96,14 +119,16 @@ namespace Maestro.Sources {
         public void Startup(Uri address) {\r
             string path = address.LocalPath;\r
             this.path = path;\r
-            if (Directory.Exists(path)) {\r
-                InnerStartUp();\r
-            } else pathWatcherWorker.RunWorkerAsync();\r
+            clearAndInitialize = ClearDataGridView;\r
+            //if (Directory.Exists(path))\r
+            //    InnerStartUp();\r
+            pathWatcherWorker.RunWorkerAsync();\r
         }\r
 \r
         private void InnerStartUp() {\r
             createWatch(path);\r
             Task.Run(() => initializeList(path));\r
+            initialized = true;\r
         }\r
 \r
 \r
@@ -137,15 +162,15 @@ namespace Maestro.Sources {
             watcher.Created += new FileSystemEventHandler(OnCreated);\r
             watcher.Deleted += new FileSystemEventHandler(OnDeleted);\r
             watcher.Renamed += new RenamedEventHandler(OnRenamed);\r
-            //watcher.Disposed += new EventHandler(OnDispose);\r
+            watcher.Error += new ErrorEventHandler(OnError);\r
             watcher.EnableRaisingEvents = true;\r
         }\r
 \r
-        public void OnDispose(object sender, RenamedEventArgs e) {\r
-\r
+        public void OnError(object sender, ErrorEventArgs e) {\r
+            logger.Debug(e.GetException().Message);\r
         }\r
 \r
-            public void OnRenamed(object sender, RenamedEventArgs e) {\r
+        public void OnRenamed(object sender, RenamedEventArgs e) {\r
             logger.Debug("{0} {1} {2}", e.ChangeType, e.OldName, e.Name);\r
             var item = this.Where(x => x.Name == e.OldName).SingleOrDefault();\r
             if (item == null)\r