Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WizardConfiguration"/> class.
        /// </summary>
        public WizardConfiguration()
        {
            Ticket = new SessionTicket()
            {
                SessionOwner = UserManager.CurrentUser
            };

            SessionAssets = new AssetDetailCollection();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reserves all assets associated with this session using the specified key.
        /// </summary>
        /// <param name="sessionId">The session unique identifier.</param>
        /// <param name="reservationKey">The reservation key.</param>
        /// <returns></returns>
        /// <exception cref="System.ServiceModel.EndpointNotFoundException"></exception>
        public AssetDetailCollection Reserve(string sessionId, string reservationKey)
        {
            SetTraceSessionContext(sessionId);
            AssetDetailCollection assetDetails = new AssetDetailCollection();

            foreach (var item in assetDetails)
            {
                TraceFactory.Logger.Debug("Item availability:" + item.Availability);
            }

            if (!_proxyControllers.Contains(sessionId))
            {
                var msg = "Proxy not found for Session Id {0}".FormatWith(sessionId);
                TraceFactory.Logger.Debug(msg);
                throw new EndpointNotFoundException(msg);
            }

            var controller = _proxyControllers[sessionId];

            if (controller.ProxyProcessStarted)
            {
                TraceFactory.Logger.Debug("CallProxy -> Reserve({0})".FormatWith(sessionId));

                Action retryAction = () => assetDetails = controller.Channel.Reserve(reservationKey);
                TraceFactory.Logger.Debug("Returned Reservation");
                try
                {
                    Retry.WhileThrowing
                    (
                        retryAction,
                        10,
                        TimeSpan.FromSeconds(1),
                        new List <Type>()
                    {
                        typeof(EndpointNotFoundException)
                    }
                    );
                }
                catch (Exception ex)
                {
                    var msg = "Error communicating with session proxy for {0} - 1".FormatWith(sessionId);
                    TraceFactory.Logger.Error(msg, ex);
                    var exception = new ApplicationException(msg, ex);
                    EventPublisher.PublishDispatcherException(exception);
                }
            }
            else
            {
                var msg       = "Proxy service not started for session {0} (1)".FormatWith(sessionId);
                var exception = new ApplicationException(msg);
                EventPublisher.PublishDispatcherException(exception);
            }

            TraceFactory.Logger.Debug("Returning asset details");

            return(assetDetails);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the wizard page with the specified <see cref="WizardConfiguration"/>.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public bool Initialize(WizardConfiguration configuration)
        {
            _assets = configuration.SessionAssets;

            AvailableDeviceSet <AssetDetail> assetSet = new AvailableDeviceSet <AssetDetail>(_assets);
            var printDevices = assetSet.Devices.OfType <PrintDeviceDetail>().ToList();

            deviceSetup_GridView.DataSource = printDevices;
            //deviceSetup_GridView.BestFitColumns();

            return(printDevices.Any());
        }
Ejemplo n.º 4
0
        private bool AllAssetsAvailable(AssetDetailCollection assetDetails)
        {
            bool result = true;

            string display = string.Empty;

            foreach (AssetDetail asset in assetDetails)
            {
                display = "{0} - {1}".FormatWith(asset.AssetId, asset.Availability);
                UpdateStatus(display);
                TraceFactory.Logger.Debug(display);
                result = result && (asset.Availability == AssetAvailability.Available);
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WizardConfiguration"/> class.
        /// </summary>
        public WizardConfiguration()
        {
            // Add the user credentials to the ticket which will be used to interact with VCenter
            // for VM operations.  The assumption is that the user has a VCenter login with the same
            // username as their HP LR0 domain username.
            var credential = new UserCredential(UserManager.LoggedInUser.UserName, UserManager.LoggedInUser.Domain)
            {
                Role     = UserManager.LoggedInUser.Role,
                Password = UserManager.LoggedInUser.Password
            };

            Ticket = new SessionTicket()
            {
                SessionOwner = credential
            };

            SessionAssets = new AssetDetailCollection();
        }
Ejemplo n.º 6
0
        private void RefreshReservations(string reservationKey)
        {
            // Call the dispatcher service to make reservations
            AssetDetailCollection assets = null;

            if (!string.IsNullOrWhiteSpace(reservationKey))
            {
                assets = SessionClient.Instance.Reserve(_configuration.Ticket.SessionId, reservationKey);
            }
            else
            {
                assets = SessionClient.Instance.Reserve(_configuration.Ticket.SessionId);
            }

            _configuration.SessionAssets.Replace(assets);

            // Display the results
            assetReservation_GridView.DataSource = null;
            assetReservation_GridView.DataSource = assets.Select(n => new AssetReservationRow(n));
            assetReservation_GridView.BestFitColumns();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// adc is the active list. Returns true if the AssetDetail is already in the list. Will
        /// check to see if the asset detail is active or not. If not active in list and the given is active,
        /// will reset the list.
        /// </summary>
        /// <param name="adc">AssetDetailCollection</param>
        /// <param name="ad">AssetDetail</param>
        /// <returns>bool</returns>
        private bool FoundAssetDetail(AssetDetailCollection adc, AssetDetail ad)
        {
            bool bFound = false;

            foreach (AssetDetail item in adc)
            {
                if (item.AssetId.Equals(ad.AssetId))
                {
                    bFound = true;
                    if (!AssetAvailable(item) && AssetAvailable(ad))
                    {
                        // ID's and descriptions are the same so just reset the availability information for the device in the primary list.
                        item.Availability          = ad.Availability;
                        item.AvailabilityStartTime = ad.AvailabilityStartTime;
                        item.AvailabilityEndTime   = ad.AvailabilityEndTime;

                        break;
                    }
                }
            }

            return(bFound);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reserves all assets associated with this session using the specified key.
        /// If the reservationKey is a comma separated list, will process multiple values but only
        /// returns one Asset ID in the collection with priority being Available.
        /// </summary>
        /// <param name="sessionId">The session unique identifier.</param>
        /// <param name="reservationKey">The reservation key.</param>
        /// <returns>AssetDetailCollection</returns>
        public AssetDetailCollection Reserve(string sessionId, string reservationKey)
        {
            TraceFactory.Logger.Debug("SessionId: {0}, Key: {1}".FormatWith(sessionId, reservationKey));

            AssetDetailCollection scenarioAssets = new AssetDetailCollection();
            List <string>         rkList         = new List <string> {
                reservationKey
            };

            if (reservationKey.IndexOf(',') > 0)
            {
                rkList = reservationKey.Split(',').Select(r => r.Trim()).ToList();
            }

            foreach (string rk in rkList)
            {
                AssetDetailCollection adcTemp = GetConnection().Channel.Reserve(sessionId, rk);

                if (scenarioAssets.Count.Equals(0))
                {
                    scenarioAssets = adcTemp;
                }
                else
                {
                    foreach (AssetDetail ad in adcTemp)
                    {
                        if (!FoundAssetDetail(scenarioAssets, ad))
                        {
                            scenarioAssets.Add(ad);
                        }
                    }
                }
            }

            TraceFactory.Logger.Debug("Returning...");
            return(scenarioAssets);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Starts the session.
        /// If the startup args were not successfully validated, an exception is thrown.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Invalid State.  Unable to start session.</exception>
        public void StartSession()
        {
            if (_state != SessionState.Available)
            {
                throw new InvalidOperationException("Unable to start session. State: {0}.".FormatWith(_state));
            }

            if (HandleSessionClientEvents)
            {
                SessionClient.Instance.DispatcherExceptionReceived      += SessionClient_DispatcherErrorReceived;
                SessionClient.Instance.SessionStateReceived             += SessionClient_StateChanged;
                SessionClient.Instance.SessionStartupTransitionReceived += SessionClient_StartupTransitionReceived;
                SessionClient.Instance.SessionMapElementReceived        += SessionClient_MapElementReceived;
            }
            else
            {
                FreeConsole();
            }

            string reservationKey = _arguments["reservation"]?.ToString();

            UpdateStatus(string.Empty);
            UpdateStatus($"Starting session '{_ticket.SessionName}'");
            UpdateStatus(string.Empty);

            UpdateStatus("Created ticket {0}".FormatWith(_ticket.SessionId));

            TraceFactory.Logger.Debug("Initializing");
            SessionClient.Instance.Initialize(_arguments["dispatcher"]);

            SessionClient.Instance.InitiateSession(_ticket);

            UpdateStatus("Reserving Assets...");
            AssetDetailCollection assetDetails = null;

            if (string.IsNullOrEmpty(reservationKey))
            {
                assetDetails = SessionClient.Instance.Reserve(_ticket.SessionId);
            }
            else
            {
                UpdateStatus("Reservation Key: {0}".FormatWith(reservationKey));
                assetDetails = SessionClient.Instance.Reserve(_ticket.SessionId, reservationKey);
            }

            //Check asset availability
            if (!AllAssetsAvailable(assetDetails))
            {
                string message = "Not all assets are available.  Unable to continue.";
                UpdateStatus(message);
                TraceFactory.Logger.Error(message);
                ShutDown();
                return;
            }

            // This call to Stage() will kick off the process and as each event arrives to indicate
            // a step in the process has completed, the next step will automatically continue.
            SessionClient.Instance.Stage(_ticket.SessionId, assetDetails);
            UpdateStatus("Staged...{0}".FormatWith(_ticket.SessionId));

            if (HandleSessionClientEvents)
            {
                //Keep the console open
                Console.ReadLine();
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Starts the enterprise scenario based on the provided configuration.
 /// </summary>
 /// <param name="sessionId">The session unique identifier.</param>
 /// <param name="assets">The assets.</param>
 public void Stage(string sessionId, AssetDetailCollection assets)
 {
     SetTraceSessionContext(sessionId);
     TraceFactory.Logger.Debug("CallProxy -> Stage({0})".FormatWith(sessionId));
     CallSessionProxy(sessionId, (c) => c.Stage(assets));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Starts the enterprise scenario based on the provided configuration.
 /// </summary>
 /// <param name="sessionId">The session id.</param>
 /// <param name="assets">The assets.</param>
 public void Stage(string sessionId, AssetDetailCollection assets)
 {
     TraceFactory.Logger.Debug("SessionId: {0}".FormatWith(sessionId));
     CallDispatcher((c) => c.Stage(sessionId, assets));
 }