Esempio n. 1
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;
                }
            }
        }