예제 #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]);
                }
            }
        }
예제 #2
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);
            }
        }
예제 #3
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();
 }