Пример #1
0
        public bool SetActiveNavisionClient(NavisionClientInformation navisionClientInformation)
        {
            if (navisionClientInformation == null)
            {
                return(false);
            }

            NavClientInformation = navisionClientInformation;
            _objectDesigner      = NavClientInformation.ObjectDesigner as INSObjectDesigner;

            return(true);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public NavConnector(NavisionClientInformation client)
 {
     SetActiveNavisionClient(client);
 }