public void LogData(LogType logType, string Message = "")
        {
            LogBox.Invoke(new Action(() =>
            {
                switch (logType)
                {
                case LogType.System:
                    LogBox.BindText(Color.DimGray, "[SYSTEM] ");
                    LogBox.BindText(Color.White, $"{Message}\n");
                    break;

                case LogType.Info:
                    LogBox.BindText(Color.DimGray, "[LOG] ");
                    LogBox.BindText(Color.FromArgb(85, 136, 238), $"{Message}\n");
                    break;

                case LogType.Error:
                    LogBox.BindText(Color.DimGray, "[ERROR] ");
                    LogBox.BindText(Color.Red, $"{Message}\n");
                    break;

                default:
                    break;
                }
            }));
        }
Exemple #2
0
        private void UpdateLog(string str)
        {
            var sb = $@"{DateTime.Now}	{str}{Environment.NewLine}";

            LogBox.Invoke(new Action(() => { LogBox.AppendText(sb); }));
            UpdateLogFile(sb);
        }
Exemple #3
0
 private void Log(string text)
 {
     LogBox.Invoke((MethodInvoker) delegate
     {
         LogBox.AppendText(text + "\n");
     });
 }
 private void Disconn_Click(object sender, EventArgs e)
 {
     if (LogManager.StopLogThread())
     {
         try
         {
             if (FormManager.GetTCPClient.Connected && FormManager.GetTCPClient.SendData(NetworkMessageSource.Client, NetworkMessageDestination.Service, NetworkMessageTypes.Disconnect))
             {
                 Thread.Sleep(500);
                 FormManager.GetTCPClient.CloseConnection();
             }
             selectedServer = null;
             connectedHost  = null;
             LogBox.Invoke((MethodInvoker) delegate { LogBox.Text = ""; });
             FormManager.GetMainWindow.Invoke((MethodInvoker) delegate
             {
                 ComponentEnableManager();
                 ServerSelectBox.Items.Clear();
                 ServerSelectBox.SelectedIndex = -1;
                 ServerInfoBox.Text            = "";
                 HostInfoLabel.Text            = $"Select a host below:";
             });
         }
         catch (Exception) { }
     }
 }
Exemple #5
0
 private void InvokeWriteLogString(string text)
 {
     if (LogBox.InvokeRequired)
     {
         LogBox.Invoke((MethodInvoker) delegate { LogBox.AppendText(text); });
     }
     else
     {
         LogBox.AppendText(text);
     }
 }
Exemple #6
0
 public void WriteLog(string log_str)
 {
     if (LogBox.InvokeRequired)
     {
         LogBox.Invoke(new Action(() =>
         {
             LogBox.Text += (DateTime.Now.ToString() + " : " + log_str);
             LogBox.AppendText("\r\n");
         }));
     }
 }
        private void Log(string str = "")
        {
            Action act = new Action(() => { LogBox.AppendText(str + "\r\n"); });

            if (LogBox.InvokeRequired)
            {
                LogBox.Invoke(act);
            }
            else
            {
                act();
            }
        }
Exemple #8
0
        public void AddLog(string message)
        {
            if (LogBox.InvokeRequired)
            {
                UpdateAddLogDelegate update = new UpdateAddLogDelegate(AddLog);
                LogBox.Invoke(update, message);
            }
            else
            {
                LogBox.Items.Add(message);

                // Make sure the last item is made visible
                LogBox.SelectedIndex = LogBox.Items.Count - 1;
                LogBox.ClearSelected();
            }
        }
        /// ------------------------------------------------------------------------------------
        protected override void PerformZipWork(ZipFile zip)
        {
            var restoreFolder = OtherDestFolder ?? SuggestedDestFolder;

            _targetFolderPreexisted = Directory.Exists(restoreFolder);

            zip.ExtractProgress += HandleZipExtractProgress;

            var text = LocalizationManager.GetString("DialogBoxes.RestoreDlg.RestoringProjectFilesMsg", "Restoring Project Files...");

            LogBox.Invoke((Action)(() => LogBox.WriteMessageWithFontStyle(FontStyle.Bold | FontStyle.Underline, text)));
            zip.ExtractSelectedEntries("*", string.Empty, restoreFolder, ExtractExistingFileAction.OverwriteSilently);

            if (_dataSourceFiles.Count > 0)
            {
                text = LocalizationManager.GetString("DialogBoxes.RestoreDlg.RestoringDataSourceFilesMsg", "Restoring Data Source Files...");
                LogBox.Invoke((Action)(() => LogBox.WriteMessageWithFontStyle(FontStyle.Bold | FontStyle.Underline, Environment.NewLine + text)));
                zip.ExtractSelectedEntries("*.*", "Data", restoreFolder, ExtractExistingFileAction.OverwriteSilently);
            }

            if (_audioFiles.Count > 0)
            {
                text = LocalizationManager.GetString("DialogBoxes.RestoreDlg.RestoringAudioFilesMsg", "Restoring Audio Files...");
                LogBox.Invoke((Action)(() => LogBox.WriteMessageWithFontStyle(FontStyle.Bold | FontStyle.Underline, Environment.NewLine + text)));
                zip.ExtractSelectedEntries("*.*", "Audio", restoreFolder, ExtractExistingFileAction.OverwriteSilently);
            }

            if (File.Exists(Path.Combine(restoreFolder, kBackupInfoFileName)))
            {
                File.Delete(Path.Combine(restoreFolder, kBackupInfoFileName));
            }

            if (Cancel || BackupRestoreException != null)
            {
                CleanUpAfterCancel(restoreFolder);
            }
            else
            {
                var updater = new RestoredPapDataSourceUpdater {
                    PapFile = CurrentProjectFileName
                };
                updater.Modify(restoreFolder, Path.Combine(restoreFolder, "Data"), false);
            }
        }
Exemple #10
0
 private void OnLogBox(string Message)
 {
     if (LogBox.InvokeRequired)
     {
         LogBox.Invoke(new OnLogBoxDelegate(OnLogBox), new object[] { Message });
     }
     else
     {
         if (LogBox.Lines.Length == 150)
         {
             LogBox.Clear();
             LogBox.AppendText(Message + Environment.NewLine);
         }
         else
         {
             LogBox.AppendText(Message + Environment.NewLine);
         }
     }
 }
Exemple #11
0
        private bool DriveReady(DriveInfo d)
        {
            if (!d.IsReady)
            {
                if (!NotReadyList.Contains(d.Name))
                {
                    LogBox.Invoke(new Action(() => LogBox.Text += "Drive " + d.Name + " is not ready" + Environment.NewLine));
                    NotReadyList.Add(d.Name);
                    AlreadyReadDrives.Remove(d.Name);

                    RemovableDrivesList.Invoke(
                        new Action(() =>
                    {
                        ListViewItem lvi = RemovableDrivesList.FindItemWithText(d.Name);
                        if (lvi != null)
                        {
                            lvi.Remove();
                        }
                    })
                        );
                    NonRemovableDrivesList.Invoke(
                        new Action(() =>
                    {
                        ListViewItem lvi = NonRemovableDrivesList.FindItemWithText(d.Name);
                        if (lvi != null)
                        {
                            lvi.Remove();
                        }
                    })
                        );
                }
                return(false);
            }
            else
            {
                if (NotReadyList.Contains(d.Name))
                {
                    NotReadyList.Remove(d.Name);
                }
            }
            return(true);
        }
Exemple #12
0
        private void LerLog()
        {
            string newFileLines = "";

            using (FileStream stream = File.Open(caminholog,
                                                 FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    newFileLines = reader.ReadToEnd();
                }
            }

            LogBox.Invoke(new Action(() =>
            {
                LogBox.Focus();
                LogBox.Select(LogBox.Text.Length, 0);
                LogBox.Text += LogBox.Text + "\n" + newFileLines;
                LogBox.Focus();
                LogBox.Select(LogBox.Text.Length, 0);
            }));
        }
Exemple #13
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Debug.WriteLine("bg worker started");

            while (true)
            {
                System.Threading.Thread.Sleep(500); // maybe make this a customizable setting

                var           RemovableDrives    = DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Removable);
                var           NonRemovableDrives = DriveInfo.GetDrives().Where(drive => drive.DriveType != DriveType.Removable);
                List <string> DrivesByName       = new List <string>();

                foreach (var d in RemovableDrives)
                {
                    if (!DriveReady(d))
                    {
                        continue;
                    }

                    RemovableDrivesList.Invoke(
                        new Action(() =>
                    {
                        ListViewItem lvi = RemovableDrivesList.FindItemWithText(d.Name);
                        if (lvi == null)
                        {
                            bool FindINF = false;
                            if (d.RootDirectory.GetFiles("Autorun.inf").Count() > 0)
                            {
                                FindINF = true;
                            }

                            string[] RowData = { d.VolumeLabel, d.DriveType.ToString(), d.DriveFormat, FindINF.ToString() };
                            RemovableDrivesList.Items.Add(d.Name).SubItems.AddRange(RowData);
                        }
                        DrivesByName.Add(d.Name);     // used to detect if drive was removed
                    }
                                   ));

                    if (!AlreadyReadDrives.ContainsKey(d.Name))
                    {
                        ReadAutoInfo(d.RootDirectory);
                        AlreadyReadDrives.Add(d.Name, d.VolumeLabel);
                    }
                }

                // remove drives from list that have been removed physically
                RemovableDrivesList.Invoke(
                    new Action(() =>
                {
                    List <ListViewItem> Tmplvi = new List <ListViewItem>();
                    foreach (ListViewItem lvi in RemovableDrivesList.Items)
                    {
                        Tmplvi.Add(lvi);
                    }
                    foreach (ListViewItem lvi in Tmplvi)
                    {
                        if (!DrivesByName.Contains(lvi.Text))         // if our listview item is no longer connected, remove it
                        {
                            AlreadyReadDrives.Remove(lvi.Text);
                            RemovableDrivesList.FindItemWithText(lvi.Text).Remove();
                        }
                    }
                })
                    );

                foreach (var d in NonRemovableDrives)
                {
                    if (!DriveReady(d))
                    {
                        continue;
                    }

                    try
                    {
                        bool FindINF = false;
                        if (d.RootDirectory.GetFiles("Autorun.inf").Count() > 0)
                        {
                            FindINF = true;
                        }

                        string[] RowData = { d.VolumeLabel, d.DriveType.ToString(), d.DriveFormat, FindINF.ToString() };

                        NonRemovableDrivesList.Invoke(
                            new Action(() => { if (NonRemovableDrivesList.FindItemWithText(d.Name) == null)
                                               {
                                                   NonRemovableDrivesList.Items.Add(d.Name).SubItems.AddRange(RowData);
                                               }
                                       })
                            );
                    }
                    catch (Exception err)
                    {
                        //MessageBox.Show(err.ToString());
                        LogBox.Invoke(new Action(() => LogBox.Text += "Drive " + d.Name + err.ToString() + Environment.NewLine));
                    }

                    if (Properties.Settings.Default != null)
                    {
                        if (Properties.Settings.Default.NonRemovableToo)
                        {
                            if (!AlreadyReadDrives.ContainsKey(d.Name))
                            {
                                ReadAutoInfo(d.RootDirectory);
                                AlreadyReadDrives.Add(d.Name, d.VolumeLabel);
                            }
                        }
                    }
                }
                //FirstRun = false;
            }
        }
Exemple #14
0
        void HandleFileWatch()
        {
            // setup a file watch
            FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();
            var           wh  = new AutoResetEvent(false);
            DirectoryInfo dir = new DirectoryInfo(PathTxtBox.Text).Parent;

            fileSystemWatcher.Path = dir.FullName;
            fileSystemWatcher.EnableRaisingEvents = true;
            fileSystemWatcher.Changed            += (s, ev) => wh.Set();
            // open a read only stream to tail it.

            var msg = "";

            while (doWork)
            {
                try
                {
                    if (streamReader == null)
                    {
                        doWork = false;
                        break;
                    }

                    if (streamReader.BaseStream.CanRead) // is the file still open?
                    {
                        msg = streamReader.ReadLine();   // note: this was opened when we picked a file. we assume its valid here.
                    }
                    else
                    {
                        doWork = false;
                        break;
                    }
                }
                catch (Exception)
                {
                    msg = "<<<< UNABLE TO PARSE LINE >>>>";
                }

                if (msg != null)
                {
                    LogBox.Invoke(new MethodInvoker(delegate()
                    {
                        lock (locker)
                        {
                            TryFilterLogMsg(msg);
                        }

                        Application.DoEvents();
                    }));
                }
                else
                {
                    UpdateLineLabel();
                    {
                        // batch update now.
                        if (WatchLogQueue.Count > 0)
                        {
                            this.BeginInvoke(new MethodInvoker(delegate()
                            {
                                lock (locker)
                                {
                                    LogBox.BeginUpdate();
                                    LogBox.Items.AddRange(WatchLogQueue.ToArray());

                                    if (LogBox.Items.Count > logLineLimit)
                                    {
                                        long reduceby = LogBox.Items.Count - logLineLimit;
                                        for (int i = 0; i < reduceby; i++)
                                        {
                                            LogBox.Items.RemoveAt(0);
                                        }
                                    }

                                    GoToListBottom();
                                    LogBox.EndUpdate();
                                    WatchLogQueue.Clear();
                                }
                            }));
                        }
                    }
                    wh.WaitOne(250);
                }
            }

            fileSystemWatcher.EnableRaisingEvents = false; // shut it down first.
            wh.Close();
            WatchLogQueue.Clear();
        }
Exemple #15
0
 private void MonchaHub_Loging(object sender, string e) => LogBox.Invoke(() => { LogBox.Items.Add(e); });