public ConsoleWindow() { InitializeComponent(); AppendLogDelegate = new AppendLog(AppendWatchLog); this.Load += ConsoleWindow_Load; }
public void StartSync(string str) { if (this.InvokeRequired) { AppendLog al = new AppendLog(StartSync); this.Invoke(al, str); } else { int syncType = 0; try { syncType = int.Parse(str); } catch { } txtLog.Text = string.Empty; SyncHelp.StartSync(syncType); btnStart.Enabled = false; btnCancel.Enabled = false; btnStop.Enabled = true; btnSyncTime.Enabled = false; } }
void SetLastTime(string str) { if (lblLastUpdateTime.InvokeRequired) { AppendLog al = new AppendLog(SetLastTime); lblLastUpdateTime.Invoke(al, str); } else { lblLastUpdateTime.Text = str; } }
public void StartSync(string str) { if (this.InvokeRequired) { AppendLog al = new AppendLog(StartSync); this.Invoke(al, str); } else { txtLog.Text = string.Empty; SyncHelp.StartSync(); btnStart.Enabled = false; btnCancel.Enabled = false; btnStop.Enabled = true; } }
void SyncHelp_SyncEvent(string syncInfo) { if (string.IsNullOrEmpty(syncInfo)) { return; } if (txtLog.InvokeRequired) { AppendLog al = new AppendLog(SyncHelp_SyncEvent); txtLog.Invoke(al, syncInfo); } else { txtLog.Text += syncInfo; txtLog.SelectionStart = txtLog.Text.Split(new char[] { '\r', '\n' }).Length * 20; txtLog.ScrollToCaret(); } }
void SyncHelp_SyncFinish(string syncInfo) { if (this.InvokeRequired) { AppendLog al = new AppendLog(SyncHelp_SyncFinish); txtLog.Invoke(al, syncInfo); } else { Common._IsMainFormFirstShow = false; txtLog.Text += syncInfo; txtLog.SelectionStart = txtLog.Text.Split(new char[] { '\r', '\n' }).Length * 20; txtLog.ScrollToCaret(); if (syncInfo == "同步已完成!") { if (string.IsNullOrEmpty(Common._StorageName)) { DialogResult dr = MessageBox.Show("检测到当前[冷藏载体]无效或未绑定,是否前往进行设置?", "设置向导", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dr == DialogResult.Yes) { UCSetStorage uc = FrmParent.ParentForm.OpenForm(PageState.SetStorage) as UCSetStorage; uc.Disposed += new EventHandler(uc_Disposed); } else if (string.IsNullOrEmpty(Common._Destination)) { dr = MessageBox.Show("检测到当前[目的地]无效或未绑定,是否前往进行设置?", "设置向导", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dr == DialogResult.Yes) { FrmParent.ParentForm.OpenForm(PageState.SetDestin); } } } } Common.SaveOptRecord(syncInfo, txtLog.Text, DateTime.Now, string.Empty, -1); //if (Common._IsMainFormFirstShow) // AutoReturnMain(syncInfo); //else { btnStart.Enabled = true; btnStop.Enabled = false; btnCancel.Enabled = true; //} } }
public DrainPipeLog(String myUniqueString, Dictionary <string, object> myParameters = null) { #region handle parameters String AppendLogPathAndName = ""; Boolean CreateNew = false; Boolean FlushOnWrite = true; #region AsynchronousMode if (myParameters.ContainsKey("AsynchronousMode")) { AsynchronousMode = (Boolean)myParameters["AsynchronousMode"]; } else { AsynchronousMode = false; } #endregion #region MaximumAsyncBufferSize if (myParameters.ContainsKey("MaximumAsyncBufferSize")) { MaximumAsyncBufferSize = (Int32)myParameters["MaximumAsyncBufferSize"]; } else { MaximumAsyncBufferSize = 1024 * 1024 * 10; } #endregion #region AppendLogPathAndName if (myParameters.ContainsKey("AppendLogPath")) { AppendLogPathAndName = (String)myParameters["AppendLogPath"]; } else { AppendLogPathAndName = "sones.drainpipelog"; } AppendLogPathAndName = Path.Combine(AppendLogPathAndName, myUniqueString); #endregion #region CreateNew if (myParameters.ContainsKey("CreateNew")) { CreateNew = (Boolean)myParameters["CreateNew"]; } #endregion #region FlushOnWrite if (myParameters.ContainsKey("FlushOnWrite")) { FlushOnWrite = (Boolean)myParameters["FlushOnWrite"]; } #endregion #endregion _AppendLog = new AppendLog(AppendLogPathAndName, CreateNew, FlushOnWrite); WriteThreadInstance = new WriteThread(_AppendLog); #region Handle Asynchronous Mode if (AsynchronousMode) { Async_WriteThread = new Thread(new ThreadStart(WriteThreadInstance.Run)); Async_WriteThread.Start(); } #endregion }
public unsafe void AppendLogTest() { var sw = new Stopwatch(); var l1 = new AppendLog("../AppendLogTest", 100); var l2 = new AppendLog("../AppendLogTest", 100); var tcs = new TaskCompletionSource <int>(); var tcs2 = new TaskCompletionSource <int>(); var count = 1000000; //var bytes = new byte[500]; //for (int i = 0; i < 500; i++) { // bytes[i] = (byte)(i % 255); //} sw.Start(); var cnt = 0; l1.OnAppend += (buffer) => { var len = (int)buffer.Length; var message = new byte[len]; Marshal.Copy(buffer.Data, message, 0, len); //var lng = BitConverter.ToInt64(message, 0); //Assert.AreEqual(cnt, lng); if (count - 1 == cnt) { tcs.SetResult(cnt); } cnt++; }; var cnt2 = 0; l2.OnAppend += (buffer) => { var len = (int)buffer.Length; var message = new byte[len]; Marshal.Copy(buffer.Data, message, 0, len); //var lng = BitConverter.ToInt64(message, 0); //Assert.AreEqual(cnt, lng); if (count - 1 == cnt2) { tcs2.SetResult(cnt2); } cnt2++; }; for (int i = 0; i < count; i++) { l1.Append((long)i);//BitConverter.GetBytes((long)i))); // } tcs.Task.Wait(); tcs2.Task.Wait(); sw.Stop(); Console.WriteLine($"Elapsed msec: {sw.ElapsedMilliseconds}"); l1.Dispose(); l2.Dispose(); //Thread.Sleep(100000); }
public static void SetLogDest(AppendLog dest) { logDest = dest; }
public static void AppendMsgToLog(string Msg) { AppendLog?.Invoke(null, new LogEventArgs(Msg)); }
public WriteThread(AppendLog _AppendLog) { internalAppendLog = _AppendLog; Async_Buffer = new List <byte[]>(); }
/// <summary> /// Save settings into the given file. /// </summary> /// <param name="fileName">file to save settings to</param> /// <param name="syncPathList">list with paths to synchronize</param> public void SaveJob(string fileName, SyncPathList syncPathList) { XmlAttribute attr; XmlElement root; XmlNode node; XmlDocument doc = new XmlDocument(); XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); doc.AppendChild(xmlnode); root = doc.CreateElement("InZync"); // save paths to synchronize node = doc.CreateElement("SourcePaths"); foreach (PathPair pp in syncPathList) { XmlNode pathNode = doc.CreateElement("Path"); attr = doc.CreateAttribute("source"); attr.Value = pp.Source; pathNode.Attributes.Append(attr); attr = doc.CreateAttribute("destination"); attr.Value = pp.Destination; pathNode.Attributes.Append(attr); node.AppendChild(pathNode); } root.AppendChild(node); node = doc.CreateElement("ShowLog"); node.InnerText = ShowLogWindow.ToString(); root.AppendChild(node); node = doc.CreateElement("SaveLog"); node.InnerText = SaveLog.ToString(); root.AppendChild(node); node = doc.CreateElement("AppendLog"); node.InnerText = AppendLog.ToString(); root.AppendChild(node); node = doc.CreateElement("LogFile"); node.InnerText = LogFile; root.AppendChild(node); node = doc.CreateElement("ReadOnly"); node.InnerText = RemoveReadOnlyFlag.ToString(); root.AppendChild(node); node = doc.CreateElement("DirectoriesLikeFiles"); node.InnerText = DirectoriesLikeFiles.ToString(); root.AppendChild(node); node = doc.CreateElement("SubDirectories"); node.InnerText = SubDirectories.ToString(); root.AppendChild(node); node = doc.CreateElement("HiddenFiles"); node.InnerText = ProcessHiddenFiles.ToString(); root.AppendChild(node); node = doc.CreateElement("SystemFiles"); node.InnerText = ProcessSystemFiles.ToString(); root.AppendChild(node); node = doc.CreateElement("TerminateApp"); node.InnerText = TerminateApp.ToString(); root.AppendChild(node); node = doc.CreateElement("RunSilent"); node.InnerText = RunSilent.ToString(); root.AppendChild(node); node = doc.CreateElement("Extensions"); node.InnerText = ExtensionList; root.AppendChild(node); node = doc.CreateElement("ExcludedExtensions"); node.InnerText = ExcludedExtensionList; root.AppendChild(node); node = doc.CreateElement("SourceNewer"); node.InnerText = SourceNewer.ToString(); root.AppendChild(node); node = doc.CreateElement("SourceMissing"); node.InnerText = SourceMissing.ToString(); root.AppendChild(node); node = doc.CreateElement("DestNewer"); node.InnerText = DestNewer.ToString(); root.AppendChild(node); node = doc.CreateElement("DestMissing"); node.InnerText = DestMissing.ToString(); root.AppendChild(node); node = doc.CreateElement("BackupMode"); node.InnerText = BackupMode.ToString(); root.AppendChild(node); node = doc.CreateElement("Template"); node.InnerText = Template.ToString(); root.AppendChild(node); node = doc.CreateElement("ShowOnlyDifferentFiles"); node.InnerText = ShowOnlyDifferentFiles.ToString(); root.AppendChild(node); // save context menu entries node = doc.CreateElement("ContextMenuEntries"); for (int i = 0; i < ContextMenu.Count; i++) { string[] cme = ContextMenu[i].Split('\t'); XmlNode pathNode = doc.CreateElement("ContextMenuEntry"); attr = doc.CreateAttribute("caption"); attr.Value = cme[0]; pathNode.Attributes.Append(attr); attr = doc.CreateAttribute("file"); attr.Value = cme[1]; pathNode.Attributes.Append(attr); if (i == ContextDblClickIdx) { attr = doc.CreateAttribute("DblClick"); //attr.Value = cme[1]; pathNode.Attributes.Append(attr); } node.AppendChild(pathNode); } root.AppendChild(node); doc.AppendChild(root); doc.Save(fileName); }