Inheritance: IDisposable
 public static void Advertise(WmiSession wmisession)
 {
     foreach (Feature feature in features)
     {
         feature.doAdvert();
     }
 }
 public ClipboardStateMachine(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler)
 {
     this.clipboard        = clipboard;
     this.wmisession       = wmisession;
     this.exceptionhandler = exceptionhandler;
     restartTime           = 1000;
     lastStartAttempt      = DateTime.UtcNow;
 }
 public ClipboardAccess(WmiSession wmisession)
 {
     this.wmisession   = wmisession;
     xsSetClipboard    = wmisession.GetXenStoreItem("data/set_clipboard");
     xsReportClipboard = wmisession.GetXenStoreItem("data/report_clipboard");
     serverwatch       = xsSetClipboard.Watch(new EventArrivedEventHandler(OnServerClipboard));
     clientwatch       = xsReportClipboard.Watch(new EventArrivedEventHandler(OnClientClipboard));
 }
Beispiel #4
0
        public WmiSession GetXenStoreSession(string name)
        {
            lock (syncSingleton)
            {
                WmiSession session = new WmiSession(name, this);

                return(session);
            }
        }
Beispiel #5
0
 private WmiBase()
 {
     debugmsg = new Queue<string>();
     syncSingleton = new Object();
     xenbaselock = new Object();
     wmisession = new WmiSession("Base", this);
     xsupdated = wmisession.GetXenStoreItem("data/updated");
     xsupdatedcount = wmisession.GetXenStoreItem("data/update_cnt");
     xserror = wmisession.GetXenStoreItem("control/error");
 }
Beispiel #6
0
 private WmiBase()
 {
     debugmsg       = new Queue <string>();
     syncSingleton  = new Object();
     xenbaselock    = new Object();
     wmisession     = new WmiSession("Base", this);
     xsupdated      = wmisession.GetXenStoreItem("data/updated");
     xsupdatedcount = wmisession.GetXenStoreItem("data/update_cnt");
     xserror        = wmisession.GetXenStoreItem("control/error");
 }
Beispiel #7
0
        void WmiCapableServiceThreadHandler()
        {
            try
            {
                wmisession = WmiBase.Singleton.GetXenStoreSession("Features");

                wmisession.Log("Guest Agent Starting");
                Refresher.Add(new PVInstallation(this));

                wmisession.Log("About to run apps");

                RunProcess("wmiadap", "/f", "refresh WMI ADAP");
                RunProcess("diskperf", "-y", "enable disk perf counters");


                wmisession.Log("About to run features");
                new FeatureDumpLog(this);
                new FeatureGC(this);
                new FeaturePing(this);
                new FeatureDomainJoin(this);
                new FeatureSetComputerName(this);

                wmisession.Log("About to try snapshot");
                if (FeatureSnapshot.IsSnapshotSupported())
                {
                    new FeatureSnapshot(this);
                }
                else
                {
                    Debug.Print("Snapshot not supported on this platform");
                    FeatureSnapshot.removeSnapshot(wmisession);
                }
                new FeatureTerminalServicesReset(this);
                new FeatureTerminalServices(this);
                wmisession.Log("About to add refreshers");

                Refresher.Add(new NetInfo(this));
                Refresher.Add(new VolumeInfo());
                Refresher.Add(new MemoryInfo());

                wmisession.Log("About to add handlers ");
                clipboardhandler = new ClipboardManager(this);
                Disposer.Add(clipboardhandler);
                clipboardhandler.Run();
                Disposer.Add(WmiBase.Singleton.ListenForEvent("CitrixXenStoreUnsuspendedEvent", new EventArrivedEventHandler(handleUnsuspended)));

                Refresher.RefreshAll(true);
                wmisession.Log("running ");
                Refresher.Run(this);
            }
            catch (Exception e)
            {
                HandleException("Service handler", e);
            }
        }
 public EventLogger(WmiSession wmisession)
 {
     this.wmisession = wmisession;
     el = new EventLog();
     el.Source = Branding.Instance.getString("BRANDING_GuestAgentLogSource");
     if (!EventLog.SourceExists(el.Source))
     {
         //Create New Log
         EventLog.CreateEventSource(el.Source, Branding.Instance.getString("BRANDING_GuestAgentLogName"));
     }
 }
 public EventLogger(WmiSession wmisession)
 {
     this.wmisession = wmisession;
     el = new EventLog();
     el.Source = "XenGuestAgent";
     if (!EventLog.SourceExists("XenGuestAgent"))
     {
         //Create New Log
         EventLog.CreateEventSource("XenGuestAgent", "XenGuestAgentLog");
     }
 }
Beispiel #10
0
 public EventLogger(WmiSession wmisession)
 {
     this.wmisession = wmisession;
     el        = new EventLog();
     el.Source = BrandingControl.getString("BRANDING_GuestAgentLogSource");
     if (!EventLog.SourceExists(el.Source))
     {
         //Create New Log
         EventLog.CreateEventSource(el.Source, BrandingControl.getString("BRANDING_GuestAgentLogName"));
     }
 }
Beispiel #11
0
 public static void removeSnapshot(WmiSession wmisession)
 {
     try
     {
         wmisession.GetXenStoreItem("control/snapshot").Remove();
     }
     catch { };
     try
     {
         wmisession.GetXenStoreItem("control/feature-snapshot").Remove();
     }
     catch { }
 }
Beispiel #12
0
 public NetInfo(IExceptionHandler exceptionhandler)
 {
     updating = new Object();
     this.exceptionhandler = exceptionhandler;
     wmisession            = WmiBase.Singleton.GetXenStoreSession("Adapters");
     devicevif             = wmisession.GetXenStoreItem("device/vif");
     datavif      = wmisession.GetXenStoreItem("data/vif");
     numvif       = wmisession.GetXenStoreItem("data/num_vif");
     needsRefresh = true;
     onAddrChange(null, null);
     addrChangeHandler = new NetworkAddressChangedEventHandler(onAddrChange);
     NetworkChange.NetworkAddressChanged += addrChangeHandler;
     vifListen = devicevif.Watch(onVifChanged);
 }
 public NetInfo(IExceptionHandler exceptionhandler)
 {
     updating = new Object();
     this.exceptionhandler = exceptionhandler;
     wmisession = WmiBase.Singleton.GetXenStoreSession("Adapters");
     devicevif = wmisession.GetXenStoreItem("device/vif");
     datavif = wmisession.GetXenStoreItem("data/vif");
     numvif =  wmisession.GetXenStoreItem("data/num_vif");
     needsRefresh = true;
     onAddrChange(null, null);
     addrChangeHandler = new NetworkAddressChangedEventHandler(onAddrChange);
     NetworkChange.NetworkAddressChanged += addrChangeHandler;
     vifListen = devicevif.Watch(onVifChanged);
 }
        public WaitHandle Run()
        {
            WmiBase.Singleton.DebugMsg("Clipboard thread starting");
            wmisession = WmiBase.Singleton.GetXenStoreSession("Clipboard");
            clipboard  = new ClipboardAccess(wmisession);

            state = new ClipboardStateMachine(clipboard, wmisession, exceptionhandler);
            lock (statelock)
            {
                running = true;
                WaitHandle threadhandle = state.Run();
                shutdowncallback = ThreadPool.RegisterWaitForSingleObject(threadhandle, shutdownCallback, null, Timeout.Infinite, true);
            }
            return(done);
        }
Beispiel #15
0
 public VssSnapshot(VssSnapshot.Type type, List <string> volumes)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
     {
         throw new Exception("VssSnapshot must be initialised and used in a Single Thread Apartment");
     }
     this.type    = type;
     this.volumes = volumes;
     wmisession   = WmiBase.Singleton.GetXenStoreSession("Snapshot");
     client       = VssClientInit(type);
     if (client.Equals(IntPtr.Zero))
     {
         throw new VssSnapshotException();
     }
     foreach (string vol in volumes)
     {
         Debug.Print("Attempting to add" + vol);
         VssClientAddVolume(client, vol);
     }
 }
            public WorkerProcess(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler, IWorkerProcessHandler wphandler, IntPtr consoletoken)
            {
                this.clipboard        = clipboard;
                this.wmisession       = wmisession;
                this.exceptionhandler = exceptionhandler;
                this.wphandler        = wphandler;

                workerlock = new object();
                try
                {
                    comms = new CommServer(this);
                }
                catch (Exception e)
                {
                    wmisession.Log("Comms server failed to start:" + e.ToString());
                    throw;
                }
                try
                {
                    AddToXDIgnoreApplicationList();
                    string path     = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "Install_Dir", "");
                    string fullpath = string.Format("{0}\\" + Branding.Instance.getString("FILENAME_dpriv"), path);
                    string cmdline  = string.Format(Branding.Instance.getString("FILENAME_dpriv") + " {0}", comms.secret);
                    this.worker            = new SafeWaitHandle(Win32Impl.CreateUserProcess(consoletoken, fullpath, cmdline), true);
                    workerWaiter           = new ProcessWaitHandle(this.worker);
                    registeredWorkerWaiter = ThreadPool.RegisterWaitForSingleObject(workerWaiter, handleWorker, null, Timeout.Infinite, true);
                    this.workerrunning     = true;
                    wmisession.Log("Worker Process spawned");
                }
                catch (Exception e)
                {
                    wmisession.Log("Worker process spawn exception : " + e.ToString());
                    comms.CloseMessagePipes();

                    throw;
                }
            }
Beispiel #17
0
 public Feature(string name, string advertise, string control, bool controlmustexist, IExceptionHandler exceptionhandler)
 {
     this.exceptionhandler = exceptionhandler;
     this.name             = name;
     wmisession            = WmiBase.Singleton.GetXenStoreSession("Citrix Xen Service Feature : " + name);
     wmisession.Log("New Feature");
     controlKey            = wmisession.GetXenStoreItem(control);
     this.controlmustexist = controlmustexist;
     try
     {
         if (controlKey.value != "")
         {
             wmisession.Log("Control key " + control + ":" + controlKey.value);
         }
     }
     catch {}
     enabled  = true;
     listener = controlKey.Watch(new EventArrivedEventHandler(onFeatureWrapper));
     if (!advertise.Equals(""))
     {
         this.addAdvert(advertise);
     }
     Disposer.Add(this);
 }
 public VssSnapshot(VssSnapshot.Type type, List<string> volumes)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
     {
         throw new Exception("VssSnapshot must be initialised and used in a Single Thread Apartment");
     }
     this.type = type;
     this.volumes = volumes;
     wmisession = WmiBase.Singleton.GetXenStoreSession("Snapshot");
     client = VssClientInit(type);
     if (client.Equals(IntPtr.Zero))
     {
         throw new VssSnapshotException();
     }
     foreach (string vol in volumes)
     {
         Debug.Print("Attempting to add" + vol);
         VssClientAddVolume(client, vol);
     }
 }
 public ClipboardStateMachine(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler)
 {
     this.clipboard = clipboard;
     this.wmisession = wmisession;
     this.exceptionhandler = exceptionhandler;
     restartTime = 1000;
     lastStartAttempt = DateTime.UtcNow;
 }
 public XenAppSessionInfo()
 {
     wmisession    = WmiBase.Singleton.GetXenStoreSession("XenAppSession Reporter");
     xenAppSession = wmisession.GetXenStoreItemCached("data/xenapp_session_count");
 }
        void WmiCapableServiceThreadHandler()
        {
            try
            {
                wmisession = WmiBase.Singleton.GetXenStoreSession("Features");

                wmisession.Log("Guest Agent Starting");
                Refresher.Add(new PVInstallation(this));

                wmisession.Log("About to run apps");

                RunProcess("wmiadap","/f","refresh WMI ADAP");
                RunProcess("diskperf", "-y","enable disk perf counters");

                wmisession.Log("About to run features");
                new FeatureLicensed(this);
                new FeatureVSSLicensed(this);
                new FeatureDumpLog(this);
                new FeatureGC(this);
                new FeaturePing(this);
                new FeatureDomainJoin(this);
                new FeatureSetComputerName(this);
                new FeatureXSBatchCommand(this);
                new FeatureAutoUpdate(this);

                wmisession.Log("About to try snapshot");
                if (FeatureSnapshot.IsSnapshotSupported())
                {
                    Refresher.Add(new FeatureSnapshot(this));
                }
                else
                {
                    wmisession.Log("Snapshot not supported on this platform");
                    FeatureSnapshot.removeSnapshot(wmisession);
                }
                new FeatureTerminalServicesReset(this);
                new FeatureTerminalServices(this);
                new FeatureStaticIpSetting(this);
                wmisession.Log("About to add refreshers");

                Refresher.Add(new NetInfo(this));
                Refresher.Add(new VolumeInfo());
                Refresher.Add(new MemoryInfo());
                Refresher.Add(new XenAppSessionInfo());

                wmisession.Log("About to add handlers ");
                clipboardhandler = new ClipboardManager(this);
                Disposer.Add(clipboardhandler);
                clipboardhandler.Run();
                Disposer.Add(WmiBase.Singleton.ListenForEvent("CitrixXenStoreUnsuspendedEvent", new EventArrivedEventHandler(handleUnsuspended)));

                Refresher.RefreshAll(true);
                wmisession.Log("running ");
                Refresher.Run(this);

            }
            catch (Exception e)
            {
                HandleException("Service handler", e);
            }
        }
Beispiel #22
0
 public XenStoreItem(string name, WmiSession wmisession)
 {
     this.wmisession = wmisession;
     this.name       = name;
 }
 public StoredVolumes(WmiSession wmisession)
 {
     storedVolumes = new Dictionary<string, StoredVolume>();
     nextid = 0;
     this.wmisession = wmisession;
 }
Beispiel #24
0
 public MemoryInfo()
 {
     wmisession   = WmiBase.Singleton.GetXenStoreSession("Memory Reporter");
     meminfoFree  = wmisession.GetXenStoreItemCached("data/meminfo_free");
     meminfoTotal = wmisession.GetXenStoreItemCached("data/meminfo_total");
 }
 public XenAppSessionInfo()
 {
     wmisession = WmiBase.Singleton.GetXenStoreSession("XenAppSession Reporter");
     xenAppSession = wmisession.GetXenStoreItemCached("data/xenapp_session_count");
 }
Beispiel #26
0
 public XenStoreItem(string name, WmiSession wmisession)
 {
     this.wmisession = wmisession;
     this.name = name;
 }
        public WaitHandle Run()
        {
            WmiBase.Singleton.DebugMsg("Clipboard thread starting");
            wmisession = WmiBase.Singleton.GetXenStoreSession("Clipboard");
            clipboard = new ClipboardAccess(wmisession);

            state = new ClipboardStateMachine(clipboard, wmisession, exceptionhandler);
            lock (statelock)
            {
                running = true;
                WaitHandle threadhandle = state.Run();
                shutdowncallback = ThreadPool.RegisterWaitForSingleObject(threadhandle, shutdownCallback, null, Timeout.Infinite, true);
            }
            return done;
        }
Beispiel #28
0
        public WmiSession GetXenStoreSession(string name)
        {
            lock (syncSingleton)
            {

                WmiSession session = new WmiSession(name, this);

                return session;
            }
        }
 public static void Advertise(WmiSession wmisession)
 {
     foreach (Feature feature in features)
     {
         feature.doAdvert();
     }
 }
        public Feature(string name, string advertise, string control, bool controlmustexist, IExceptionHandler exceptionhandler)
        {
            this.exceptionhandler = exceptionhandler;
            this.name = name;
            wmisession = WmiBase.Singleton.GetXenStoreSession("Citrix Xen Service Feature : " + name);
            wmisession.Log("New Feature");
            controlKey = wmisession.GetXenStoreItem(control);
            this.controlmustexist = controlmustexist;
            try
            {
                if (controlKey.value != "")
                {
                    wmisession.Log("Control key "+control+":"+controlKey.value);
                }
            }
            catch {}
            enabled = true;
            listener = controlKey.Watch(new EventArrivedEventHandler(onFeatureWrapper));
            if (!advertise.Equals(""))
            {
                advert = wmisession.GetXenStoreItem(advertise);
                features.Add(this);

            }
            Disposer.Add(this);
        }
            public WorkerProcess(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler, IWorkerProcessHandler wphandler, IntPtr consoletoken)
            {
                this.clipboard = clipboard;
                this.wmisession = wmisession;
                this.exceptionhandler = exceptionhandler;
                this.wphandler = wphandler;

                workerlock = new object();
                try
                {
                    comms = new CommServer(this);
                }
                catch (Exception e)
                {
                    wmisession.Log("Comms server failed to start:" + e.ToString());
                    throw;
                }
                try
                {
                    string path = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "Install_Dir", "");
                    string fullpath = string.Format("{0}\\XenDpriv.exe", path);
                    string cmdline = string.Format("XenDpriv.exe {0}", comms.secret);
                    this.worker = new SafeWaitHandle(Win32Impl.CreateUserProcess(consoletoken, fullpath, cmdline), true);
                    workerWaiter = new ProcessWaitHandle(this.worker);
                    registeredWorkerWaiter = ThreadPool.RegisterWaitForSingleObject(workerWaiter, handleWorker, null, Timeout.Infinite, true);
                    this.workerrunning = true;
                    wmisession.Log("Worker Process spawned");
                }
                catch(Exception e)
                {
                    wmisession.Log("Worker process spawn exception : " + e.ToString());
                    comms.CloseMessagePipes();

                    throw;
                }
            }
 public static void removeSnapshot(WmiSession wmisession)
 {
     try
     {
         wmisession.GetXenStoreItem("control/snapshot").Remove();
     }
     catch { };
     try
     {
         wmisession.GetXenStoreItem("control/feature-snapshot").Remove();
     }
     catch { }
 }
Beispiel #33
0
 public XenStoreItemCached(string name, WmiSession wmisession)
     : base(name, wmisession)
 {
 }
                public StoredVolume(Win32Impl.Volume vol, WmiSession wmisession, long nextid)
                {
                    try
                    {
                        Id = nextid;
                        this.wmisession = wmisession;
                        WmiBase.Singleton.DebugMsg("Stored volume: new " + vol.Name);
                        path = getVolumePath();
                        WmiBase.Singleton.DebugMsg("creating " + path + "/name");
                        name = wmisession.GetXenStoreItemCached(path + "/name");
                        WmiBase.Singleton.DebugMsg(" : " + name.ToString());
                        size = wmisession.GetXenStoreItemCached(path + "/size");
                        free = wmisession.GetXenStoreItemCached(path + "/free");
                        volumeName = wmisession.GetXenStoreItemCached(path + "/volume_name");

                        filesystem = wmisession.GetXenStoreItemCached(path + "/filesystem");
                    }
                    catch
                    {
                        throw;
                    }
                    try
                    {
                        name.value = vol.Name;
                        size.value = vol.SizeBytes.ToString();
                        freebytes = vol.FreeBytes;
                        free.value = freebytes.ToString();
                        volumeName.value = vol.VolumeName;
                        filesystem.value = vol.FSName;
                    }
                    catch
                    {
                        throw;
                    }
                    try
                    {

                        mountPoints = new List<XenStoreItemCached>();
                        int i = 0;
                        foreach (string mountpoint in vol.pathnames)
                        {
                            XenStoreItemCached mp = wmisession.GetXenStoreItemCached(path + "/mount_points/" + i.ToString());
                            mp.value = mountpoint;
                            mountPoints.Add(mp);
                            i++;
                        }
                    }
                    catch
                    {
                        throw;
                    }

                    try
                    {
                        int i = 0;
                        extents = new List<XenStoreItemCached>();
                        WmiBase.Singleton.DebugMsg("About to iterrate through extent names");
                        foreach (string disk in getExtentNames(vol.extents))
                        {
                            XenStoreItemCached ext = wmisession.GetXenStoreItemCached(path + "/extents/" + i.ToString());
                            ext.value = disk;
                            extents.Add(ext);
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
 public MemoryInfo()
 {
     wmisession = WmiBase.Singleton.GetXenStoreSession("Memory Reporter");
     meminfoFree = wmisession.GetXenStoreItemCached("data/meminfo_free");
     meminfoTotal = wmisession.GetXenStoreItemCached("data/meminfo_total");
 }
Beispiel #36
0
 public XenStoreItemCached(string name, WmiSession wmisession) : base(name, wmisession)
 {
 }
Beispiel #37
0
 public VolumeInfo()
 {
     wmisession    = WmiBase.Singleton.GetXenStoreSession("Volume Management");
     storedVolumes = new StoredVolumes(wmisession);
 }
Beispiel #38
0
 public WmiWatchListener(WmiSession session, ManagementEventWatcher ev, string pathname) : base(ev)
 {
     this.pathname = pathname;
     this.session  = session;
     session.AddWatch(pathname);
 }
Beispiel #39
0
                public StoredVolume(Win32Impl.Volume vol, WmiSession wmisession, long nextid)
                {
                    try
                    {
                        Id = nextid;
                        this.wmisession = wmisession;
                        WmiBase.Singleton.DebugMsg("Stored volume: new " + vol.Name);
                        path = getVolumePath();
                        WmiBase.Singleton.DebugMsg("creating " + path + "/name");
                        name = wmisession.GetXenStoreItemCached(path + "/name");
                        WmiBase.Singleton.DebugMsg(" : " + name.ToString());
                        size       = wmisession.GetXenStoreItemCached(path + "/size");
                        free       = wmisession.GetXenStoreItemCached(path + "/free");
                        volumeName = wmisession.GetXenStoreItemCached(path + "/volume_name");

                        filesystem = wmisession.GetXenStoreItemCached(path + "/filesystem");
                    }
                    catch
                    {
                        throw;
                    }
                    try
                    {
                        name.value       = vol.Name;
                        size.value       = vol.SizeBytes.ToString();
                        freebytes        = vol.FreeBytes;
                        free.value       = freebytes.ToString();
                        volumeName.value = vol.VolumeName;
                        filesystem.value = vol.FSName;
                    }
                    catch
                    {
                        throw;
                    }
                    try
                    {
                        mountPoints = new List <XenStoreItemCached>();
                        int i = 0;
                        foreach (string mountpoint in vol.pathnames)
                        {
                            XenStoreItemCached mp = wmisession.GetXenStoreItemCached(path + "/mount_points/" + i.ToString());
                            mp.value = mountpoint;
                            mountPoints.Add(mp);
                            i++;
                        }
                    }
                    catch
                    {
                        throw;
                    }

                    try
                    {
                        int i = 0;
                        extents = new List <XenStoreItemCached>();
                        WmiBase.Singleton.DebugMsg("About to iterrate through extent names");
                        foreach (string disk in getExtentNames(vol.extents))
                        {
                            XenStoreItemCached ext = wmisession.GetXenStoreItemCached(path + "/extents/" + i.ToString());
                            ext.value = disk;
                            extents.Add(ext);
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
 public VolumeInfo()
 {
     wmisession = WmiBase.Singleton.GetXenStoreSession("Volume Management");
     storedVolumes = new StoredVolumes(wmisession);
 }
Beispiel #41
0
 public StoredVolumes(WmiSession wmisession)
 {
     storedVolumes   = new Dictionary <string, StoredVolume>();
     nextid          = 0;
     this.wmisession = wmisession;
 }
Beispiel #42
0
 public WmiWatchListener(WmiSession session, ManagementEventWatcher ev, string pathname)
     : base(ev)
 {
     this.pathname = pathname;
     this.session = session;
     session.AddWatch(pathname);
 }
 public ClipboardAccess(WmiSession wmisession)
 {
     this.wmisession = wmisession;
     xsSetClipboard = wmisession.GetXenStoreItem("data/set_clipboard");
     xsReportClipboard = wmisession.GetXenStoreItem("data/report_clipboard");
     serverwatch = xsSetClipboard.Watch(new EventArrivedEventHandler(OnServerClipboard));
     clientwatch = xsReportClipboard.Watch(new EventArrivedEventHandler(OnClientClipboard));
 }