コード例 #1
0
        /// <summary>
        /// Creates all the specified virtual resources.
        /// </summary>
        public override void Start()
        {
            // Install all print queues for the specified user.
            InstallRemotePrinters();
            InstallLocalPrinters();

            // Perform user specific setup, but don't actually start the Office Worker on the
            // Citrix server.  Wait until the ExecuteResources is called for that.  This will
            // better simulate a simultaneous load on the Citrix server.

            ChangeResourceState(_credential.ResourceInstanceId, RuntimeState.Starting);

            ChangeMachineStatusMessage("Configuring User");
            ConfigureUserGroups(_credential);
            CitrixSessionManager.ConfigureLocalUserGroups(_credential, _citrixServer);

            ChangeMachineStatusMessage("Resetting Citrix");
            CitrixSessionManager.ResetCitrixSession(_credential.UserName, _citrixServer);

            // If a value is provided for the published app, then start it first.
            if (!string.IsNullOrEmpty(_worker.PublishedApp))
            {
                CitrixSessionManager.StartPublishedApp(_credential, _citrixServer, _worker.PublishedApp);
            }

            ChangeMachineStatusMessage("Starting Citrix User");
            StartCitrixUserSession();
        }
コード例 #2
0
        /// <summary>
        /// Starts the defined Virtual Resource process for the defined credential.
        /// </summary>
        /// <param name="credential">The user credential.</param>
        /// <param name="currentDirectory">The current directory.</param>
        protected override void StartUserProcess(OfficeWorkerCredential credential, string currentDirectory)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }

            Environment.SpecialFolder folder = (Environment.Is64BitOperatingSystem)
                ? Environment.SpecialFolder.ProgramFilesX86
                : Environment.SpecialFolder.ProgramFiles;

            var exeFile = Path.Combine
                          (
                Environment.GetFolderPath(folder),
                Resources.WFICA32Path
                          );

            TraceFactory.Logger.Debug("ICA Client: {0}".FormatWith(exeFile));

            int tries    = 0;
            int numTries = 5;

            while (tries < numTries)
            {
                if (CheckSessionStarted(credential, exeFile))
                {
                    break;
                }

                tries++;
                TraceFactory.Logger.Debug("Failed to start session, sleeping and trying again");

                if (!ProcessUtil.KillProcess(Resources.wfica32, currentUserOnly: false))
                {
                    TraceFactory.Logger.Debug("Failed to kill ICA process");
                }
                else
                {
                    TraceFactory.Logger.Debug("ICA process killed");
                }

                // Kill any session on the Citrix server
                CitrixSessionManager.ResetCitrixSession(credential.UserName, _citrixServer);

                Thread.Sleep(TimeSpan.FromSeconds(5));
            }

            if (tries >= numTries)
            {
                throw new ArgumentException("Unable to start Citrix process after {0} tries, for {1}".FormatWith(numTries, credential.UserName));
            }
            else
            {
                TraceFactory.Logger.Debug("Citrix session started");
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates all EventLogCollector virtual resources.
        /// </summary>
        public override void Start()
        {
            ChangeResourceState(RuntimeState.Starting);

            OpenManagementServiceEndpoint(_credential.UserName);

            ChangeMachineStatusMessage("Configuring User");
            CitrixSessionManager.ConfigureLocalUserGroups(_credential, _citrixServer);

            ChangeMachineStatusMessage("Resetting Citrix");
            CitrixSessionManager.ResetCitrixSession(_credential.UserName, _citrixServer);

            // Register and let the dispatcher know it's available to run.
            SessionProxyBackendConnection.RegisterResource(ServiceEndpoint);
        }
コード例 #4
0
        private void VirtualResourceEventBus_OnShutdownResource(object sender, EventArgs e)
        {
            TraceFactory.Logger.Info("Shutdown Session for {0}".FormatWith(_credential.UserName));
            try
            {
                ChangeMachineStatusMessage("Logoff Citrix");

                CitrixSessionManager.ResetCitrixSession(_credential.UserName, _citrixServer);
                CitrixSessionManager.RemoveFromAdminGroup(_credential, _citrixServer);
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error("Error ending session for user {0}".FormatWith(_credential.UserName), ex);
            }

            ChangeResourceState(RuntimeState.Offline);
        }
コード例 #5
0
        public override void Cleanup()
        {
            TraceFactory.Logger.Info("Cleanup Session for {0}".FormatWith(_credential.UserName));
            try
            {
                // Give the Citrix server a few seconds to gracefully log the user off the session before
                // sending the death signal through the KillCitrixSession().
                Thread.Sleep(TimeSpan.FromSeconds(2));

                ChangeMachineStatusMessage("Logoff Citrix");

                CitrixSessionManager.ResetCitrixSession(_credential.UserName, _citrixServer);
                // CitrixSessionManager.RemoveFromAdminGroup(_credential, _citrixServer);

                // Send a delete request to the Citrix Monitor service and request a cleanup.  This will
                // proceed to remove the user profile directory from the server to keep the disk space under
                // control.
                TraceFactory.Logger.Debug("Sending delete request for: {0}".FormatWith(_userProfile));
                string citrixHost = _citrixServer;
                using (CitrixQueueMonitorConnection client = CitrixQueueMonitorConnection.Create(citrixHost))
                {
                    //client.Channel.Cleanup(_credential.UserName, _userProfile);
                    client.Channel.Cleanup(_credential);
                }

                //the user configuration file deletion is moved here from startup program to allow for retries to work - Veda
                string remotePath = @"\\{0}\C$\VirtualResource\UserConfiguration".FormatWith(_citrixServer);
                string datFile    = @"{0}\{1}.dat".FormatWith(remotePath, _credential.UserName);
                if (File.Exists(datFile))
                {
                    File.Delete(datFile);
                }

                // Now that the user is logged out, purge all print queues on the local machine.
                // This also occurs on the Citrix server, both have to be purged in order to++
                // ensure that there are no print jobs left in a queue after a completed test.
                TraceFactory.Logger.Debug("Purging local print queues...");
                PurgeLocalPrintQueues();
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error("Error cleaning up Citrix session", ex);
            }
        }