Beispiel #1
0
        /// <summary>
        /// Refreshes list of running clients.
        /// </summary>
        public void Refresh()
        {
            lock (lockthis)
            {
                Debug.WriteLine("Refreshing clients...");
                Hashtable rot        = ROT.GetROT(); //Read all objects of type C/SIDE from ROT
                Hashtable newClients = new Hashtable();

                foreach (object obj in rot.Keys)
                {
                    //ClientID clientID=new ClientID(rot.ObjectList[obj]);
                    //newClients.Add(clientID, AddClient(clientID, rot.ObjectList[obj]));
                    NAVClient client = null;
                    try {
                        client = new NAVClient(rot[obj]);
                        if (!objects.ContainsKey(client.Hwnd))
                        {
                            objects[client.Hwnd] = client;
                            //client.WatchObjChanges();
                            clients.Add(client);
                            newClients[client.Hwnd] = client;
                            Debug.WriteLine("Adding:" + client.Hwnd.ToString() + " " + client.MyId + " " + client.InstanceName);
                        }
                        else
                        {
                            newClients[client.Hwnd] = objects[client.Hwnd];
                            client.Dispose();
                        }
                    } catch (Exception)
                    {
                        if (client != null)
                        {
                            client.Dispose();
                        }
                    }
                }

                /// Remove deleted objects
                List <object> clientToDelete = new List <object>();
                foreach (object clientID in objects.Keys)
                {
                    if (!newClients.ContainsKey(clientID))
                    {
                        clientToDelete.Add(clientID);
                    }
                }

                foreach (object clientID in clientToDelete)
                {
                    RemoveClient((NAVClient)objects[clientID]);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Removes the client.
 /// </summary>
 /// <param name="client">The client.</param>
 public void RemoveClient(NAVClient client)
 {
     Debug.WriteLine("Removing:" + client.Hwnd);
     if (lastActiveClient == client)
     {
         lastActiveClient = null;
     }
     clients.Remove(client);
     if (objects[client.Hwnd] != null)
     {
         Marshal.ReleaseComObject(client.RotObject);
     }
     objects.Remove(client.Hwnd);
     client.Dispose();
 }
Beispiel #3
0
        /// <summary>
        /// Adds the clients into collection if not already there.
        /// </summary>
        /// <param name="objName">The NAV client obj. from ROT</param>
        /// <returns>New or existing NAVClient object representing given obj</returns>
        private NAVClient AddClient(object clientID, object clientObj)
        {
            /*
             * foreach (object obj in objects.Keys)
             * {
             *  if (((NAVClient)objects[obj]).RotObject.Equals(clientObj))
             *  {
             *      return (NAVClient)objects[obj];
             *  }
             * }
             * */

            NAVClient client = null;

            try
            {
                client = new NAVClient(clientObj, clientID);
                if (objects.ContainsKey(clientID))
                {
                    client.Dispose();
                    return((NAVClient)objects[clientID]);
                }
                objects.Add(clientID, client);
                clients.Add(client);
                Debug.WriteLine("Adding:" + clientID + " " + client.MyId);
                return(client);
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Dispose();
                }
                return(null);
            }
        }
Beispiel #4
0
        public static Hashtable GetROT()
        {
            lock (lockthis)
            {
                Hashtable       objectList;
                List <IMoniker> rotList;
                rotList    = new List <IMoniker>();
                objectList = new Hashtable();
                IBindCtx            ctx   = null;
                IRunningObjectTable table = null;
                IEnumMoniker        mon   = null;
                IMoniker[]          lst   = new IMoniker[1];
                try
                {
                    NativeMethods.CreateBindCtx(0, out ctx);
                    ctx.GetRunningObjectTable(out table);
                    table.EnumRunning(out mon);
                    Debug.WriteLine("ROT:");
                    Debug.Indent();
                    while (mon.Next(1, lst, IntPtr.Zero) == 0)
                    {
                        string displayName;
                        lst[0].GetDisplayName(ctx, lst[0], out displayName);
                        //Debug.WriteLine(displayName);
                        if ((displayName.IndexOf("!C/SIDE!") != -1) /*&& (displayName.IndexOf("database=") !=-1)*/)
                        {
                            try
                            {
                                rotList.Add(lst[0]);
                                object   obj;
                                int      ret      = table.GetObject(lst[0], out obj);
                                ClientID clientID = new ClientID(obj);

                                int hash;
                                lst[0].Hash(out hash);
                                using (NAVClient c = new NAVClient(obj)) {
                                    //CheckInterface(obj);
                                    Debug.WriteLine(c.Hwnd + ":" + displayName);
                                    objectList[clientID.Id] = obj;
                                }
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("ROT NAV Obj exception:" + e.Message);
                            }
                        }
                    }
                    Debug.Unindent();
                    return(objectList);
                }
                finally
                {
                    if (ctx != null)
                    {
                        Marshal.ReleaseComObject(ctx);
                    }
                    if (mon != null)
                    {
                        Marshal.ReleaseComObject(mon);
                    }
                    if (table != null)
                    {
                        Marshal.ReleaseComObject(table);
                    }
                }
            }
        }