Ejemplo n.º 1
0
 static public void Reset()
 {
     lock (syncRoot)
     {
         instance = null;
     }
 }
Ejemplo n.º 2
0
        public WmiSession(string sessionqualifier, WmiBase wmibase)
        {
            items        = new Dictionary <string, XenStoreItem>();
            cacheditems  = new Dictionary <string, XenStoreItemCached>();
            this.wmibase = wmibase;
            name         = sessionqualifier;

            // First check to see if a "Citrix Xen Service" session exists.  If
            // so, we use that
            // Otherwise we have to create a new session from scratch
            try
            {
                ObjectQuery obq = new ObjectQuery(String.Format("SELECT * from CitrixXenStoreSession WHERE Id=\"Citrix Xen Service: {0}\"", sessionqualifier));
                ManagementObjectSearcher mobs = new ManagementObjectSearcher(wmibase.Scope, obq);;
                session = WmiBase.getFirst(mobs.Get());
                session.InvokeMethod("EndSession", null);
            }
            catch
            {
            }
            ManagementBaseObject inparam = wmibase.XenBase.GetMethodParameters("AddSession");

            inparam["ID"] = String.Format("Citrix Xen Service: {0}", sessionqualifier);
            ManagementBaseObject outparam    = wmibase.XenBase.InvokeMethod("AddSession", inparam, null);
            UInt32      sessionid            = (UInt32)outparam["SessionId"];
            ObjectQuery query                = new ObjectQuery("SELECT * from CitrixXenStoreSession WHERE SessionId=" + sessionid.ToString());
            ManagementObjectSearcher objects = new ManagementObjectSearcher(wmibase.Scope, query);;

            session = WmiBase.getFirst(objects.Get());
        }
Ejemplo n.º 3
0
 public void HandleException(string from, Exception e)
 {
     try
     {
         if (e is ManagementException)
         {
             if (WmiBase.HandleManagementException(e as ManagementException))
             {
                 Debug.Print("WMI objects cannot be located.  Resetting service");
                 OnNeedsReset();
                 return;
             }
         }
         wmisession.Log("Unhandled exception from " + from + ".  Resetting service:\n" + e.ToString());
         wmisession.Log("Dumping stored debug messages");
         WmiBase.Singleton.DumpDebugMsg();
     }
     catch {
     }
     try
     {
         OnNeedsReset();
     }
     catch
     {
         Debug.Print("Reset failed");
     }
 }
Ejemplo n.º 4
0
        void ServiceThreadHandler()
        {
            try {
                Debug.Print("ServiceThreadHandler");
                needsShutdown.Reset();

                NetInfo.StoreChangedNetworkSettings();

                WmiBase.Reset();
                Debug.Print("WMI Check");
                if (WmiBase.Check())
                {
                    starting = true;
                    WmiCapableServiceThreadHandler();
                    starting = false;
                    running  = true;
                }
                else
                {
                    running = false;
                    WaitHandle[] waitHandles = new WaitHandle[]
                    {
                        (new WmiIncapableThread()).Incapable,
                        needsShutdown
                    };

                    Debug.Print("Waiting for WMI capability to begin");
                    try
                    {
                        EventLog.WriteEntry(Branding.Instance.getString("BRANDING_errNoWMI"));
                    }
                    catch { };

                    int activehandle = WaitHandle.WaitAny(waitHandles);
                    Debug.Print("Received event");

                    if (activehandle == 0)
                    {
                        try
                        {
                            EventLog.WriteEntry(Branding.Instance.getString("BRANDING_errNoWMI"));
                        }
                        catch { };
                        starting = true;
                        WmiCapableServiceThreadHandler();
                        starting = false;
                        running  = true;
                    }
                }
            }
            catch (Exception e) {
                HandleException("Main Service Thread", e);
            }
        }
Ejemplo n.º 5
0
        void ServiceThreadHandler()
        {
            try {
                Debug.Print("ServiceThreadHandler");
                needsShutdown.Reset();
                WmiBase.Reset();
                Debug.Print("WMI Check");
                if (WmiBase.Check())
                {
                    starting = true;
                    WmiCapableServiceThreadHandler();
                    starting = false;
                    running  = true;
                }
                else
                {
                    running = false;
                    WaitHandle[] waitHandles = new WaitHandle[]
                    {
                        (new WmiIncapableThread()).Incapable,
                        needsShutdown
                    };

                    Debug.Print("Waiting for WMI capability to begin");
                    try
                    {
                        EventLog.WriteEntry("Citrix Xen Guest Agent cannot find XenIface WMI interface");
                    }
                    catch { };

                    int activehandle = WaitHandle.WaitAny(waitHandles);
                    Debug.Print("Received event");

                    if (activehandle == 0)
                    {
                        try
                        {
                            EventLog.WriteEntry("Citrix Xen Guest Agent cannot find XenIface WMI interface");
                        }
                        catch { };
                        starting = true;
                        WmiCapableServiceThreadHandler();
                        starting = false;
                        running  = true;
                    }
                }
            }
            catch (Exception e) {
                HandleException("Main Service Thread", e);
            }
        }
Ejemplo n.º 6
0
 void WmiIncapableServiceThreadHandler(object nothing)
 {
     try {
         WmiBase.Reset();
         if (WmiBase.Check())
         {
             timer.Dispose();
             Incapable.Set();
         }
     }
     catch {
         timer.Dispose();
         Incapable.Set();
     }
 }
Ejemplo n.º 7
0
        void ServiceThreadShutdown()
        {
            try {
                try {
                    Refresher.Dispose();
                    Disposer.Dispose();
                }
                catch (Exception ex) {
                    wmisession.Log("Errors disposing of threads: " + ex.ToString());
                    throw;
                }

                wmisession.Log("Guest Agent Stopped");
                try
                {
                    wmisession.Dispose();
                }
                catch { }
            }
            catch {}
            finally {
                WmiBase.Reset();
            }
        }
Ejemplo n.º 8
0
        public WmiSession(string sessionqualifier, WmiBase wmibase)
        {
            items = new Dictionary<string, XenStoreItem>();
            cacheditems = new Dictionary<string, XenStoreItemCached>();
            this.wmibase = wmibase;
            name = sessionqualifier;

            // First check to see if a "Citrix Xen Service" session exists.  If
            // so, we use that
            // Otherwise we have to create a new session from scratch
            try
            {
                ObjectQuery obq = new ObjectQuery(String.Format("SELECT * from CitrixXenStoreSession WHERE Id=\"Citrix Xen Service: {0}\"", sessionqualifier));
                ManagementObjectSearcher mobs = new ManagementObjectSearcher(wmibase.Scope, obq); ;
                session = WmiBase.getFirst(mobs.Get());
                session.InvokeMethod("EndSession", null);
            }
            catch
            {
            }
            ManagementBaseObject inparam = wmibase.XenBase.GetMethodParameters("AddSession");
            inparam["ID"] = String.Format("Citrix Xen Service: {0}", sessionqualifier);
            ManagementBaseObject outparam = wmibase.XenBase.InvokeMethod("AddSession", inparam, null);
            UInt32 sessionid = (UInt32)outparam["SessionId"];
            ObjectQuery query = new ObjectQuery("SELECT * from CitrixXenStoreSession WHERE SessionId=" + sessionid.ToString());
            ManagementObjectSearcher objects = new ManagementObjectSearcher(wmibase.Scope, query); ;
            session = WmiBase.getFirst(objects.Get());
        }
Ejemplo n.º 9
0
 public static void Reset()
 {
     lock (syncRoot)
     {
         instance = null;
     }
 }