Exemplo n.º 1
0
        private void changeEventBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            lock (lockObj)
            {
                WorkEventArg dwo = (WorkEventArg)e.Argument;

                if (dwo.CurrentItem != null)
                {
                    dwo.CurrentItem.Text             = dwo.FileName;
                    dwo.CurrentItem.SubItems[1].Text = DateTime.Now.ToLongTimeString();
                    Int64 currCount = Convert.ToInt64(dwo.CurrentItem.SubItems[2].Text.ToString()) + 1;
                    dwo.CurrentItem.SubItems[2].Text = currCount.ToString();
                }
                else
                {
                    ListViewItem mainItem = new ListViewItem(dwo.FileName);
                    mainItem.Tag = dwo.EventTypeString;
                    mainItem.SubItems.Add(DateTime.Now.ToLongTimeString());
                    //first time add a 1 for the count
                    mainItem.SubItems.Add("1");
                    mainItem.SubItems.Add(dwo.EventTypeString);
                    infoListView.Items.Add(mainItem);
                }
            }
        }
Exemplo n.º 2
0
        public void HandleFileSystemWatcherUpdate()
        {
            WorkEventArg doWorkEventObject = WorkEvents.Instance.GetEventObject();

            if (doWorkEventObject != null)
            {
                string fileName = doWorkEventObject.FileName;
                if (checkFilter(Path.GetDirectoryName(fileName)))
                {
                    string eventTypeString = doWorkEventObject.EventTypeString;

                    ListViewItem currItem = null;
                    lock (infoListView)
                    {
                        try
                        {
                            foreach (ListViewItem lvi in infoListView.Items)
                            {
                                if (lvi.Text == fileName && lvi.Tag.ToString() == eventTypeString)
                                {
                                    currItem = lvi;
                                    continue;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }

                    WorkEventArg dwo = new WorkEventArg(fileName, eventTypeString, currItem);

                    // DoWorkEventArgs dw = new DoWorkEventArgs(dwo);

                    if (!changeEventBackgroundWorker.IsBusy)
                    {
                        changeEventBackgroundWorker.RunWorkerAsync(dwo);
                    }
                    else
                    {
                        WorkEvents.Instance.Add(dwo);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void HandleFileSystemWatcherUpdate(EventType eventType, System.IO.FileSystemEventArgs e)
        {
            try {
                string fileName = fileSystemWatcher.Path + e.Name;
                if (checkFilter(Path.GetDirectoryName(fileName)))
                {
                    string eventTypeString = string.Empty;
                    switch (eventType)
                    {
                    case EventType.changed:
                    {
                        if (!fileChangedCheckBox.Checked)
                        {
                            // return immediately, if the user doesn't want to  listen for this event
                            return;
                        }
                        eventTypeString = "changed";

                        break;
                    }

                    case EventType.created:
                    {
                        if (!fileCreatedCheckBox.Checked)
                        {
                            // return immediately, if the user doesn't want to  listen for this event
                            return;
                        }

                        eventTypeString = "created";
                        break;
                    }

                    case EventType.deleted:
                    {
                        if (!fileDeletedCheckBox.Checked)
                        {
                            // return immediately, if the user doesn't want to  listen for this event
                            return;
                        }
                        eventTypeString = "deleted";
                        break;
                    }

                    case EventType.renamed:
                    {
                        if (!fileRenamedCheckBox.Checked)
                        {
                            // return immediately, if the user doesn't want to  listen for this event
                            return;
                        }

                        eventTypeString = "renamed";
                        break;
                    }
                    }


                    ListViewItem currItem = null;
                    lock (infoListView)
                    {
                        try
                        {
                            foreach (ListViewItem lvi in infoListView.Items)
                            {
                                if (lvi.Text == fileName && lvi.Tag.ToString() == eventTypeString)
                                {
                                    currItem = lvi;
                                    continue;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }

                    WorkEventArg dwo = new WorkEventArg(fileName, eventTypeString, currItem);

                    // DoWorkEventArgs dw = new DoWorkEventArgs(dwo);

                    if (!changeEventBackgroundWorker.IsBusy)
                    {
                        changeEventBackgroundWorker.RunWorkerAsync(dwo);
                    }
                    else
                    {
                        WorkEvents.Instance.Add(dwo);
                    }
                }
            }
            catch (Exception ex)
            {
                String outMessage = string.Format("{0} - {1} : Exception {2} : {3}{4}", DateTime.Now, ex.Message, ex.GetType(), e.Name, Environment.NewLine);
                File.AppendAllText("discoFilesError.log", outMessage);
                //MessageBox.Show(this, outMessage, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }