/// <summary> /// Initializes a new instance of the <see cref="NAVClient"/> class. /// </summary> /// <param name="navObject">The nav object from ROT.</param> public NAVClient(object navObject) { Debug.WriteLine("NAVClient.New:" + myId); watchers = new List <FileSystemWatcher>(); rotObject = navObject; appBase = (INSAppBase)navObject; application = navObject as INSApplication; hyperlink = navObject as INSHyperlink; if (appBase == null) { throw (new InvalidDataException(@"ROT Object is not NAV!")); } if (hyperlink != null) { do { int handle; try { hyperlink.GetNavWindowHandle(out handle); hwnd = new IntPtr(handle); uint res = Win32.User32.GetWindowThreadProcessId(hwnd, out processID); StringBuilder text = new StringBuilder(1000); int res2 = Win32.User32.GetWindowText(hwnd, text, 1000); //if (text.ToString().IndexOf("TFS TRACKED") == -1) // Win32.User32.SetWindowText(hwnd, "TFS TRACKED " + text); } catch (Exception) { Thread.Sleep(500); } } while (hwnd == IntPtr.Zero); } appBase.GetInfos(out serverName, out databaseName, out companyName, out userName); }
public static void CheckInterface(object obj) { IObjectDesigner designer = obj as IObjectDesigner; Debug.WriteLineIf(designer != null, "Is IObjectDesigner");//* INSCallbackEnum callbackEnum = obj as INSCallbackEnum; Debug.WriteLineIf(callbackEnum != null, "Is INSCallbackEnum"); INSRec rec = obj as INSRec; Debug.WriteLineIf(rec != null, "Is INSRec"); INSAppBase appBase = obj as INSAppBase; Debug.WriteLineIf(appBase != null, "Is INSAppBase");//* INSApplication app = obj as INSApplication; Debug.WriteLineIf(app != null, "Is INSApplication");//* INSForm form = obj as INSForm; Debug.WriteLineIf(form != null, "Is INSForm"); INSHook hook = obj as INSHook; Debug.WriteLineIf(hook != null, "Is INSHook"); INSHyperlink hyper = obj as INSHyperlink; Debug.WriteLineIf(hyper != null, "Is INSHyperlink");//* INSMenuButton menub = obj as INSMenuButton; Debug.WriteLineIf(menub != null, "Is INSMenuButton"); INSTable table = obj as INSTable; Debug.WriteLineIf(table != null, "Is INSTable"); IConnectionPointContainer conn = obj as IConnectionPointContainer; Debug.WriteLineIf(conn != null, "Is IConnectionPointContainer"); }
//private const string ObjectDesignerGuid = "50000004-0000-1000-0001-0000836BD2D2"; public ObjectDesignerTest() { Hashtable runningObjects = GetActiveObjectList(DefaultMonikerName); foreach (DictionaryEntry de in runningObjects) { string progId = de.Key.ToString(); if (progId.IndexOf("{") != -1) { // Convert a class id into a friendly prog Id progId = ConvertClassIdToProgId(de.Key.ToString()); } object getObj = GetActiveObject(progId); if (getObj != null) { INSApplication app = getObj as INSApplication; IObjectDesigner objDis = getObj as IObjectDesigner; INSAppBase appBase = getObj as INSAppBase; INSHyperlink hyp = getObj as INSHyperlink; //Debug.WriteLine("App.="+app.GetType().FullName); if (hyp != null) { int handle; hyp.GetNavWindowHandle(out handle); Debug.WriteLine("WindowHandle=" + handle.ToString()); } if (appBase != null) { int res = 0; try { //res = appBase.Error("What<???"); } catch (Exception) {} //appBase.proc6(); //appBase.GetInfos(out a, out b,out c, out d); Debug.WriteLine("Appbase="); Debug.Indent(); Debug.WriteLine("res=" + res); //Debug.WriteLine("b=" + b); //Debug.WriteLine("c=" + c); //Debug.WriteLine("d=" + d); Debug.Unindent(); } if (objDis != null) { String version; int res = objDis.GetDatabaseName(out version); Debug.WriteLine("ObjDis=" + version); } if (app != null) { INSForm form; Debug.WriteLine("appGetform=" + app.GetForm(out form).ToString()); String hyperlink; if (form != null) { form.GetID(out hyperlink); /*form.GetButtons(out button); * if (button != null) * { * //button.proc3("Run"); * //button.proc4(0,"MyButtonB","MyButtonC"); * //Debug.WriteLine("Button="+button. * } * */ INSRec rec; CallBack callback = new CallBack(); form.GetRec(out rec); rec.EnumFieldValues(callback); Debug.WriteLine("form=" + form.ToString()); if (hyperlink != null) { Debug.WriteLine("FormID=" + hyperlink); } } } //this._objectDesigner = getObj as IObjectDesigner; } else { //Console.WriteLine("!!!!!FAILED TO fetch: " + progId); } } /* * if (this._objectDesigner == null) * { * throw new Exception("Could not connect to Dynamics NAV"); * } * */ }
public static List <NavisionClientInformation> CheckRot() { List <NavisionClientInformation> navisionClientsTemp = new List <NavisionClientInformation>(); bool isTimeout = true; List <RunningNavObject> runningNavObjects = null; Task t2 = new Task( () => { runningNavObjects = RunningObjectTable.GetRunningCOMObjectsByName(DEFAULTMONIKERNAME, COMPANYCHECKFORNAVISIONCLIENT); isTimeout = false; }); runningNavObjects = RunningObjectTable.GetRunningCOMObjectsByName(DEFAULTMONIKERNAME, COMPANYCHECKFORNAVISIONCLIENT); t2.WithTimeout(new TimeSpan(0, 0, 5)); t2.Start(); t2.Wait(5500); if (isTimeout) { throw new TimeoutException("Timeout"); } if (!runningNavObjects.Any()) { return(navisionClientsTemp); } foreach (RunningNavObject de in runningNavObjects) { RunningNavObject de1 = de; Task t = new Task( () => { INSObjectDesigner navObjectDesigner = de1.ComInstance as INSObjectDesigner; INSHyperlink hyperlink = de1.ComInstance as INSHyperlink; INSApplication application = de1.ComInstance as INSApplication; if (navObjectDesigner == null) { return; } NavisionClientInformation nci = new NavisionClientInformation(); try { navObjectDesigner.GetDatabaseName(out string value); if (value != null) { nci.DatabaseName = Encoding.GetEncoding(NavisionEncoding).GetString(Encoding.Default.GetBytes(value)); } navObjectDesigner.GetCompanyName(out value); if (value != null) { nci.CompanyName = Encoding.GetEncoding(NavisionEncoding).GetString(Encoding.Default.GetBytes(value)); } navObjectDesigner.GetServerName(out value); if (value != null) { nci.ServerName = Encoding.GetEncoding(NavisionEncoding).GetString(Encoding.Default.GetBytes(value)); } navObjectDesigner.GetServerType(out int value2); nci.ServerType = (ServerType)value2; nci.ObjectDesigner = navObjectDesigner; nci.Application = application; try { navObjectDesigner.GetCSIDEVersion(out string version); string[] str = version.Split(new[] { " " }, StringSplitOptions.None); nci.Version = float.Parse(str[1], CultureInfo.InvariantCulture); } catch { } hyperlink.GetNavWindowHandle(out int handle); nci.WindowHandle = handle; GetWindowThreadProcessId((IntPtr)handle, out uint processID); nci.ProcessID = (int)processID; nci.ExecutionPath = Path.GetDirectoryName(GetProcessPath(new IntPtr(handle))); nci.ExecutionFileName = GetProcessPath(new IntPtr(handle)); FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(nci.ExecutionFileName); nci.MajorVersion = myFileVersionInfo.FileMajorPart; } catch { navisionClientsTemp = null; throw new Exception("Communication Problem"); } if (navisionClientsTemp == null) { isTimeout = false; return; } if (navisionClientsTemp.Any( info => info.ServerName == nci.ServerName && info.DatabaseName == nci.DatabaseName)) { navisionClientsTemp = null; throw new Exception("Multiple Clients"); } navisionClientsTemp.Add(nci); isTimeout = false; }); t.WithTimeout(new TimeSpan(0, 0, 2)); t.Start(); t.Wait(2500); } if (isTimeout) { throw new Exception("Timeout"); } return(navisionClientsTemp); }