/// <summary>
		/// Initializes this object from the given from baseline distributing request to data
		/// container.
		/// </summary>
		/// <param name="processBaselineDistributingRequest">The process baseline distributing request.</param>
		/// <returns>Data container instance filled with converted data</returns>
		public static DataContainer fromBaselineDistributingRequestToDataContainer(RequestMgt.BaselineDistributingRequestContext processBaselineDistributingRequest)
		{
			DataContainer baselineDistributingTask = new DataContainer();
			baselineDistributingTask.Columns = new List<string>();
			baselineDistributingTask.Rows = new List<string>();
			baselineDistributingTask.Columns.Add("ElementID");
			baselineDistributingTask.Columns.Add("RequestID");
			baselineDistributingTask.Columns.Add("TransferMode");
			baselineDistributingTask.Columns.Add("FileCompression");
			baselineDistributingTask.Columns.Add("TransferDate");
			baselineDistributingTask.Columns.Add("TransferExpirationDate");
			baselineDistributingTask.Columns.Add("Priority");
			baselineDistributingTask.Columns.Add("Incremental");
			baselineDistributingTask.Columns.Add("BaselineVersion");
			baselineDistributingTask.Columns.Add("BaselineActivationDate");
			baselineDistributingTask.Columns.Add("BaselineExpirationDate");

			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.ElementId);
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.RequestId.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.DistributionAttributes.TransferMode.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.DistributionAttributes.fileCompression.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.DistributionAttributes.transferDate.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.DistributionAttributes.transferExpirationDate.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.DistributionAttributes.priority.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.IsIncremental.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.BaselineVersion);
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.BaselineActivationDate.ToString());
			baselineDistributingTask.Rows.Add(processBaselineDistributingRequest.BaselineExpirationDate.ToString());
			
			return baselineDistributingTask;
		}
Beispiel #2
0
        /// <summary>Creates baseline distributing request context.</summary>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="elementId">Identifier for the element.</param>
        /// <param name="requestId">Identifier for the request.</param>
        /// <param name="sessionId">Identifier for the session.</param>
        /// <param name="distributionAttributes">The distribution attributes.</param>
        /// <param name="incremental">True if the request is incremental.</param>
        /// <param name="baselineVersion">The baseline version.</param>
        /// <param name="baselineActivationDate">Date of the baseline activation.</param>
        /// <param name="baselineExpirationDate">Date of the baseline expiration.</param>
        /// <returns>The new baseline distributing request context.</returns>
        public IRequestContext CreateBaselineDistributingRequestContext(string endpoint, string elementId, Guid requestId, Guid sessionId, BaselineDistributionAttributes distributionAttributes, bool incremental, string baselineVersion, DateTime baselineActivationDate, DateTime baselineExpirationDate)
        {
            BaselineDistributingRequestContext requestContext   = new BaselineDistributingRequestContext(endpoint, elementId, requestId, sessionId, distributionAttributes, incremental, baselineVersion, baselineActivationDate, baselineExpirationDate);
            IRequestContextProcessor           requestProcessor = new BaselineDistributingRequestContextProcessor(_remoteDataStoreFactory, _t2gManager, _baselineStatusUpdater);

            requestContext.RequestProcessor = requestProcessor;
            return(requestContext);
        }
Beispiel #3
0
        /// <summary>Creates baseline distributing request context.</summary>
        /// <param name="elementId">Identifier for the element.</param>
        /// <param name="requestId">Identifier for the request.</param>
        /// <param name="transferMode">The transfer mode.</param>
        /// <param name="fileCompression">True if file compression is used.</param>
        /// <param name="isIncremental">True if this request is incremental.</param>
        /// <param name="transferDate">Date of the transfer.</param>
        /// <param name="transferExpirationDate">Date of the transfer expiration.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="baselineVersion">The baseline version.</param>
        /// <param name="baselineActivationDate">Date of the baseline activation.</param>
        /// <param name="baselineExpirationDate">Date of the baseline expiration.</param>
        /// <returns>The new baseline distributing request context.</returns>
        public IRequestContext CreateBaselineDistributingRequestContext(string elementId, Guid requestId, Core.Data.FileTransferMode transferMode, bool fileCompression, bool isIncremental, DateTime transferDate, DateTime transferExpirationDate, sbyte priority, string baselineVersion, DateTime baselineActivationDate, DateTime baselineExpirationDate)
        {
            BaselineDistributionAttributes distributionAttributes = new BaselineDistributionAttributes();

            distributionAttributes.fileCompression        = fileCompression;
            distributionAttributes.priority               = priority;
            distributionAttributes.transferDate           = transferDate;
            distributionAttributes.transferExpirationDate = transferExpirationDate;
            distributionAttributes.TransferMode           = transferMode;

            BaselineDistributingRequestContext requestContext   = new BaselineDistributingRequestContext(null, elementId, requestId, Guid.Empty, distributionAttributes, isIncremental, baselineVersion, baselineActivationDate, baselineExpirationDate);
            IRequestContextProcessor           requestProcessor = new BaselineDistributingRequestContextProcessor(_remoteDataStoreFactory, _t2gManager, _baselineStatusUpdater);

            requestContext.RequestProcessor = requestProcessor;
            return(requestContext);
        }
        /// <summary>Adds a request.</summary>
        /// <exception cref="ArgumentNullException">Thrown when a value was unexpectedly null.</exception>
        /// <param name="requestContext">Context for the request.</param>
        public virtual void AddRequest(PIS.Ground.Core.Data.IRequestContext requestContext)
        {
            if (requestContext != null)
            {
                BaselineDistributingRequestContext processBaselineDistributingRequest = requestContext as BaselineDistributingRequestContext;
                if (null != processBaselineDistributingRequest)
                {
                    DataPackageService.saveBaselineDistributingRequest(processBaselineDistributingRequest);
                }

                lock (_lock)
                {
                    _newRequests.Add(requestContext);
                }

                _TransmitEvent.Set();
            }
            else
            {
                throw new ArgumentNullException("requestContext");
            }
        }
Beispiel #5
0
        /// <summary>Process the distribute request described by request.</summary>
        /// <exception cref="NotSupportedException">Thrown when the requested operation is not supported.</exception>
        /// <param name="request">The request.</param>
        private void ProcessDistributeRequest(IRequestContext request)
        {
            BaselineDistributingRequestContext requestContext = request as BaselineDistributingRequestContext;

            if (requestContext == null)
            {
                throw new ArgumentException(Logs.ERROR_INVALID_BASELINE_DISTRIBUTE_REQUEST_CONTEXT, "request");
            }

            List <string> parametersList = new List <string>()
            {
                requestContext.ElementId,
                requestContext.BaselineVersion
            };

            using (StringWriter stringWriter = new StringWriter())
            {
                _stringListXmlSerializer.Serialize(stringWriter, parametersList);

                if (requestContext.TransferAttemptsDone == 1)
                {
                    DataPackageService.sendNotificationToGroundApp(
                        request.RequestId,
                        PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionPending,
                        stringWriter.ToString());
                }

                if (_trainToGroundManager.IsElementOnlineAndPisBaselineUpToDate(requestContext.ElementId))
                {
                    ServiceInfo serviceInfo;
                    if (T2GManagerErrorEnum.eSuccess == _trainToGroundManager.GetAvailableServiceData(requestContext.ElementId, (int)Core.Common.eServiceID.eSrvSIF_DataPackageServer, out serviceInfo))
                    {
                        // Rebuild the url of the service in case that it has changed since the last invocation.
                        requestContext.Endpoint = "http://" + serviceInfo.ServiceIPAddress + ":" + serviceInfo.ServicePortNumber;
                        try
                        {
                            using (PIS.Ground.DataPackage.DataPackageTrainServiceClient lTrainDataPackageClient = new PIS.Ground.DataPackage.DataPackageTrainServiceClient("DataPackageEndpoint", requestContext.Endpoint))
                            {
                                try
                                {
                                    List <RecipientId> recipients = new List <RecipientId>()
                                    {
                                        new RecipientId()
                                        {
                                            ApplicationId = ConfigurationSettings.AppSettings["ApplicationId"],
                                            SystemId      = requestContext.ElementId,
                                            MissionId     = string.Empty
                                        }
                                    };

                                    DataPackageService.mWriteLog(TraceType.INFO, System.Reflection.MethodBase.GetCurrentMethod().Name, null, Logs.INFO_FUTURE_BASELINE, requestContext.ElementId, requestContext.BaselineVersion);

                                    if (!string.IsNullOrEmpty(requestContext.BaselineVersion))
                                    {
                                        List <PackageParams> packagesParamsList;
                                        List <string>        filesUrlsList;
                                        if (GetBaselineFilesURLs(requestContext.RequestId, requestContext.ElementId, requestContext.BaselineVersion, requestContext.IsIncremental, true, out filesUrlsList, out packagesParamsList))
                                        {
                                            try
                                            {
                                                using (IRemoteDataStoreClient remoteDataStore = _remoteDataStoreFactory.GetRemoteDataStoreInstance())
                                                {
                                                    filesUrlsList.Add(ConfigurationSettings.AppSettings["RemoteDataStoreUrl"]
                                                                      + remoteDataStore.createBaselineFile(
                                                                          requestContext.RequestId,
                                                                          requestContext.ElementId,
                                                                          requestContext.BaselineVersion,
                                                                          requestContext.BaselineActivationDate.ToString(),
                                                                          requestContext.BaselineExpirationDate.ToString()));
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                DataPackageService.mWriteLog(TraceType.EXCEPTION, System.Reflection.MethodBase.GetCurrentMethod().Name, ex, Logs.ERROR_REMOTEDATASTORE_FAULTED);
                                            }

                                            if (filesUrlsList.Count > 0)
                                            {
                                                UploadFileDistributionRequest uploadFilesRequestContext = new UploadFileDistributionRequest(
                                                    requestContext.RequestId,
                                                    requestContext.RequestId.ToString(),
                                                    requestContext.DistributionAttributes.transferExpirationDate,
                                                    filesUrlsList,
                                                    requestContext.DistributionAttributes.fileCompression,
                                                    recipients,
                                                    requestContext.DistributionAttributes.transferDate,
                                                    "Distribute baseline for element " + requestContext.ElementId,
                                                    requestContext.DistributionAttributes.TransferMode,
                                                    requestContext.DistributionAttributes.priority,
                                                    new EventHandler <FileDistributionStatusArgs>(DataPackageService.OnFileDistributeNotification),
                                                    new EventHandler <FileDistributionTaskCreatedArgs>(_baselineStatusUpdater.OnFileDistributionTaskCreated));

                                                DataPackageService.sendNotificationToGroundApp(requestContext.RequestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageFutureBaselineDefinition, stringWriter.ToString());

                                                string logMessage = "Distribute baseline for element " + requestContext.ElementId;
                                                logMessage += ". Files to upload : ";
                                                foreach (string file in filesUrlsList)
                                                {
                                                    logMessage += file + ", ";
                                                }

                                                logMessage = logMessage.Substring(0, logMessage.Length - 2);
                                                DataPackageService.mWriteLog(TraceType.INFO, System.Reflection.MethodBase.GetCurrentMethod().Name, null, logMessage);

                                                AvailableElementData elementData;
                                                T2GManagerErrorEnum  lRqstResult = _trainToGroundManager.GetAvailableElementDataByElementNumber(requestContext.ElementId, out elementData);

                                                if (lRqstResult == T2GManagerErrorEnum.eSuccess &&
                                                    elementData != null && elementData.PisBaselineData != null)
                                                {
                                                    _baselineStatusUpdater.ProcessDistributeBaselineRequest(
                                                        elementData.ElementNumber,
                                                        requestContext.RequestId,
                                                        elementData.OnlineStatus,
                                                        elementData.PisBaselineData.CurrentVersionOut,
                                                        elementData.PisBaselineData.FutureVersionOut,
                                                        requestContext.BaselineVersion);
                                                }
                                                else
                                                {
                                                    DataPackageService.mWriteLog(TraceType.ERROR, System.Reflection.MethodBase.GetCurrentMethod().Name, null, Logs.ERROR_ELEMENT_INFO, requestContext.ElementId);
                                                }

                                                DataPackageService.mAddBaselineVersionToDictionary(requestContext.RequestId, requestContext.ElementId, requestContext.BaselineVersion);
                                                DataPackageService.mAddPackagesToUsedPackagesList(packagesParamsList);
                                                _trainToGroundManager.T2GFileDistributionManager.AddUploadRequest(uploadFilesRequestContext);
                                                requestContext.TransmissionStatus = true;
                                                DataPackageService.mRemovePackagesFromUsedPackagesList(packagesParamsList);
                                            }
                                        }
                                        else
                                        {
                                            requestContext.CompletionStatus = true;
                                            DataPackageService.sendNotificationToGroundApp(requestContext.RequestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionFailed, stringWriter.ToString());
                                            DataPackageService.mWriteLog(TraceType.ERROR, System.Reflection.MethodBase.GetCurrentMethod().Name, null, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED, requestContext.BaselineVersion, requestContext.ElementId, Logs.ERROR_GETTING_URL_LIST);
                                        }
                                    }
                                    else
                                    {
                                        requestContext.CompletionStatus = true;
                                        DataPackageService.sendNotificationToGroundApp(requestContext.RequestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionFailed, stringWriter.ToString());
                                        DataPackageService.mWriteLog(TraceType.ERROR, System.Reflection.MethodBase.GetCurrentMethod().Name, null, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED_UNKNOW_BASELINE_VERSION, requestContext.ElementId);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    if (false == requestContext.OnCommunicationError(ex))
                                    {
                                        requestContext.CompletionStatus = true;
                                        DataPackageService.sendNotificationToGroundApp(requestContext.RequestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionFailedRejectedByElement, stringWriter.ToString());
                                        DataPackageService.mWriteLog(TraceType.ERROR, System.Reflection.MethodBase.GetCurrentMethod().Name, ex, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED, requestContext.BaselineVersion, requestContext.ElementId, ex.Message);
                                    }
                                    else
                                    {
                                        DataPackageService.mWriteLog(TraceType.DEBUG, System.Reflection.MethodBase.GetCurrentMethod().Name, ex, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED, requestContext.BaselineVersion, requestContext.ElementId, ex.Message);
                                    }
                                }
                                finally
                                {
                                    if (lTrainDataPackageClient.State == CommunicationState.Faulted)
                                    {
                                        lTrainDataPackageClient.Abort();
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (false == requestContext.OnCommunicationError(ex))
                            {
                                requestContext.CompletionStatus = true;
                                DataPackageService.mWriteLog(TraceType.ERROR, System.Reflection.MethodBase.GetCurrentMethod().Name, ex, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED, requestContext.BaselineVersion, requestContext.ElementId, ex.Message);
                                DataPackageService.sendNotificationToGroundApp(requestContext.RequestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionFailed, stringWriter.ToString());
                            }
                            else
                            {
                                DataPackageService.mWriteLog(TraceType.DEBUG, System.Reflection.MethodBase.GetCurrentMethod().Name, ex, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED, requestContext.BaselineVersion, requestContext.ElementId, ex.Message);
                            }
                        }
                    }
                    else
                    {
                        DataPackageService.mWriteLog(TraceType.ERROR, System.Reflection.MethodBase.GetCurrentMethod().Name, null, Logs.ERROR_DISTRIBUTE_BASELINE_FAILED, requestContext.BaselineVersion, requestContext.ElementId, "Cannot get embedded DataPackage service data.");
                        requestContext.TransmissionStatus = false;
                    }
                }
                else
                {
                    requestContext.TransmissionStatus = false;
                }
            }
        }
        /// <summary>
        /// Processes the requests.
        /// </summary>
        /// <param name="currentRequests">The request to process.</param>
        protected virtual void ProcessRequests(List <IRequestContext> requests)
        {
            BaselineDistributingRequestContext processBaselineDistributingRequest = null;

            for (int i = 0; i < requests.Count && !_stopTransmitThread; ++i)
            {
                IRequestContext request = requests[i];

                switch (request.State)
                {
                case RequestState.Created:
                    Predicate <IRequestContext> comparisonPredicate;
                    if (request is BaselineDistributingRequestContext)
                    {
                        comparisonPredicate = c => { return(c is BaselineDistributingRequestContext && (string.Equals(c.ElementId, request.ElementId) && (c.RequestId != request.RequestId || c.RequestId == Guid.Empty))); };
                    }
                    else if (request is BaselineForcingRequestContext)
                    {
                        comparisonPredicate = c => { return(c is BaselineForcingRequestContext && (string.Equals(c.ElementId, request.ElementId) && (c.RequestId != request.RequestId || c.RequestId == Guid.Empty))); };
                    }
                    else
                    {
                        comparisonPredicate = c => { return(c is BaselineSettingRequestContext && (string.Equals(c.ElementId, request.ElementId) && (c.RequestId != request.RequestId || c.RequestId == Guid.Empty))); };
                    }

                    for (int j = requests.Count - 1; j >= 0; --j)
                    {
                        if (comparisonPredicate(requests[j]))
                        {
                            requests.RemoveAt(j);
                            if (j <= i)
                            {
                                --i;
                            }
                        }
                    }

                    break;

                case RequestState.ReadyToSend:
                    break;

                case RequestState.WaitingRetry:
                    break;

                case RequestState.Expired:
                    BaselineForcingRequestContext processBaselineCommandRequest = request as BaselineForcingRequestContext;
                    if (null != processBaselineCommandRequest)
                    {
                        if (processBaselineCommandRequest.CommandType == BaselineCommandType.CLEAR_FORCING)
                        {
                            SendNotificationToGroundApp(
                                request.RequestId,
                                PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageBaselineClearForcingTimedOut,
                                FormatNotificationParameter(processBaselineCommandRequest.ElementId));
                        }
                        else
                        {
                            SendNotificationToGroundApp(
                                request.RequestId,
                                PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageBaselineForcingTimedOut,
                                FormatNotificationParameter(processBaselineCommandRequest.ElementId));
                        }
                    }
                    else
                    {
                        processBaselineDistributingRequest = request as BaselineDistributingRequestContext;
                        if (null != processBaselineDistributingRequest)
                        {
                            DataPackageService.deleteBaselineDistributingRequest(processBaselineDistributingRequest.ElementId);
                            SendNotificationToGroundApp(
                                request.RequestId,
                                PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionTimedOut,
                                FormatNotificationParameter(processBaselineDistributingRequest.ElementId, processBaselineDistributingRequest.BaselineVersion));
                        }
                    }

                    break;

                case RequestState.Transmitted:
                    request.CompletionStatus           = true;
                    processBaselineDistributingRequest = request as BaselineDistributingRequestContext;
                    if (null != processBaselineDistributingRequest)
                    {
                        DataPackageService.deleteBaselineDistributingRequest(processBaselineDistributingRequest.ElementId);
                        SendNotificationToGroundApp(
                            request.RequestId,
                            PIS.Ground.GroundCore.AppGround.NotificationIdEnum.DataPackageDistributionTransferred,
                            FormatNotificationParameter(processBaselineDistributingRequest.ElementId, processBaselineDistributingRequest.BaselineVersion));
                        processBaselineDistributingRequest.CompletionStatus = true;
                    }

                    break;

                case RequestState.AllRetriesExhausted:
                    break;

                case RequestState.Completed:
                    break;

                case RequestState.Error:
                    break;
                }
            }

            if (!_stopTransmitThread)
            {
                requests.RemoveAll(c => c.IsStateFinal);
            }
        }