/// <summary> /// 获取当前页面的 ID. /// </summary> /// <param name="obj">_Object Type</param> /// <returns>当前页面的 ID.</returns> private string GetActiveObjectID(_ObjectType obj) { string currentPageId = ""; uint count = oneNoteApp.Windows.Count; foreach (OneNote.Window window in oneNoteApp.Windows) { if (window.Active) { switch (obj) { case _ObjectType.Notebook: currentPageId = window.CurrentNotebookId; break; case _ObjectType.Section: currentPageId = window.CurrentSectionId; break; case _ObjectType.SectionGroup: currentPageId = window.CurrentSectionGroupId; break; } currentPageId = window.CurrentPageId; } } return(currentPageId); }
/// <summary> /// Get ID of current page /// </summary> /// <param name="obj">_Object Type</param> /// <returns>current page Id</returns> public static string GetActiveObjectID(IApplication oneNoteApp, _ObjectType obj) { string currentPageId = ""; uint count = oneNoteApp.Windows.Count; foreach (Window window in oneNoteApp.Windows) { if (window.Active) { switch (obj) { case _ObjectType.Notebook: currentPageId = window.CurrentNotebookId; break; case _ObjectType.Section: currentPageId = window.CurrentSectionId; break; case _ObjectType.SectionGroup: currentPageId = window.CurrentSectionGroupId; break; } currentPageId = window.CurrentPageId; } } return currentPageId; }
public static object send_Instruction(A_Enums.TCPInstructions Instruction, string Data) { try { using (var tcpclnt = new TcpClient()) { tcpclnt.SendTimeout = 5000; tcpclnt.ReceiveTimeout = 5000; tcpclnt.Connect(ServerAdrdress, ServerPort); while (!tcpclnt.Connected) { System.Threading.Thread.Sleep(10); } String instruction = ""; switch (Instruction) { case A_Enums.TCPInstructions.ValidateBTag: instruction = "1-$" + Data + "$"; break; case A_Enums.TCPInstructions.ValidateClanTag: instruction = "2-$" + Data + "$"; break; case A_Enums.TCPInstructions.WriteLogEntry: instruction = "3-$" + Data + "$"; break; case A_Enums.TCPInstructions.GetLatestVersion: instruction = "4-$$"; break; case A_Enums.TCPInstructions.WriteBugReport: instruction = "5-$" + Data + "$"; break; case A_Enums.TCPInstructions.WriteSuggestionsReport: instruction = "6-$" + Data + "$"; break; case A_Enums.TCPInstructions.GetTotalUniqueUsers: instruction = "7-$$"; break; case A_Enums.TCPInstructions.GetActiveUsers: instruction = "8-$$"; break; case A_Enums.TCPInstructions.GetChangelog: instruction = "9-$$"; break; case A_Enums.TCPInstructions.GetBugReports: instruction = "10-$$"; break; case A_Enums.TCPInstructions.GetSuggestions: instruction = "11-$$"; break; case TCPInstructions.GetPowers: instruction = "12-$$"; break; case TCPInstructions.StorePower: instruction = "13-$" + Data + "$"; break; } using (var stm = tcpclnt.GetStream()) { ASCIIEncoding asen = new ASCIIEncoding(); byte[] ba = asen.GetBytes(instruction); stm.Write(ba, 0, ba.Length); byte[] bb = new byte[102400]; int k = stm.Read(bb, 0, 102400); int _DataSize = BitConverter.ToInt32(bb, 0); int _Header = BitConverter.ToInt32(bb, 4); //while (k < 4 + 4 + _DataSize) // System.Threading.Thread.Sleep(5); //while (k < 4 + 4 + _DataSize) // k = stm.Read(bb, k, 102400); byte[] _Data = new byte[_DataSize]; Buffer.BlockCopy(bb, 8, _Data, 0, _DataSize); _ObjectType Type = (_ObjectType)_Header; switch (Type) { case _ObjectType._String: string _String = Encoding.ASCII.GetString(_Data, 0, _Data.Length); return(_String as string); case _ObjectType._Int: string _Int = Encoding.ASCII.GetString(_Data, 0, _Data.Length); return(int.Parse(_Int)); case _ObjectType._DateTime: string _DateTime = Encoding.ASCII.GetString(_Data, 0, _Data.Length); return(DateTime.ParseExact(_DateTime, "yy.MM.d.H", System.Globalization.CultureInfo.InvariantCulture)); case _ObjectType._Bool: string _Bool = Encoding.ASCII.GetString(_Data, 0, _Data.Length); return(Convert.ToBoolean(_Bool)); case _ObjectType.List_string: List <string> list = new List <string>(); list = ByteArrayToList(_Data); return(list as List <string>); case _ObjectType.None: return(null); } } } return(null); } catch { return(null); } }