Ejemplo n.º 1
0
        private void UploadRequest(HubRequest request)
        {
            NetWorkSetting networkSetting = Configuration.Instance.GetNetworkSetting(request.NetworkId);

            _log.Info(String.Format("BackgroundProcess:  Processing query {0} (RequestId: {3}, DataMartId: {1}, NetworkId: {2})", request.Source.Identifier, request.DataMartId, networkSetting.NetworkId, request.Source.ID));

            try
            {
                string requestId = request.Source.ID.ToString();

                Lpp.Dns.DataMart.Model.Document[] responseDocuments = request.Processor.Response(requestId);
                Guid[] documentIds = DnsServiceManager.PostResponseDocuments(requestId, request.DataMartId, responseDocuments, networkSetting);
                _log.Info("Number of portal document ids returned by PostResponseDocuments: " + documentIds.Length);
                for (int i = 0; i < documentIds.Length; i++)
                {
                    _log.Info("About to post content for portal document id: " + documentIds[i] + " corresponding to response document id: " + responseDocuments[i].DocumentID);
                    Stream contentStream = null;
                    try
                    {
                        request.Processor.ResponseDocument(requestId, responseDocuments[i].DocumentID, out contentStream, 60000);
                        DnsServiceManager.PostResponseDocumentContent(documentIds[i], contentStream, networkSetting)
                        .LogExceptions(_log.Error)
                        .Catch()
                        .SubscribeOn(Scheduler.Default)
                        .LastOrDefault();
                    }
                    finally
                    {
                        contentStream.CallDispose();
                    }
                }

                if (request.RoutingStatus == Lpp.Dns.DTO.DataMartClient.Enums.DMCRoutingStatus.Failed)
                {
                    HubRequestStatus hubRequestStatus = DnsServiceManager.ConvertModelRequestStatus(request.Processor.Status(requestId));
                    hubRequestStatus.Message = request.Processor.Status(requestId).Message;
                    DnsServiceManager.SetRequestStatus(request, hubRequestStatus, request.Properties, networkSetting);
                    _log.Info(String.Format("The following query {0} (ID: {3}) failed to execute on behalf of {1}:\n\n{2}",
                                            request.Source.Identifier, networkSetting.Profile.Username, hubRequestStatus.Message, request.Source.ID));
                }
                else
                {
                    //MantisID:6331:Zero out low-cell counts if they exist.
                    //string strReason = request.Processor.Status(requestId).Code == RequestStatus.StatusCode.CompleteWithMessage ? request.Processor.Status(requestId).Message : string.Empty;
                    //DnsServiceManager.SetRequestStatus(request, new HubRequestStatus(Lpp.Dns.DTO.DataMartClient.Enums.DMCRoutingStatus.Completed), request.Properties, networkSetting);
                    //if (string.IsNullOrEmpty(strReason))
                    //{
                    //DnsServiceManager.SetRequestStatus(request, new HubRequestStatus(HubRequestStatus.StatusCode.Completed), request.Properties, networkSetting);
                    _log.Info(String.Format("The following query {0} (ID: {2}) was executed and results were uploaded automatically on behalf of {1}",
                                            request.Source.Identifier, networkSetting.Profile.Username, request.Source.ID));
                    //}
                    //else
                    //{
                    //    //DnsServiceManager.SetRequestStatus(request, new HubRequestStatus(HubRequestStatus.StatusCode.Completed, strReason), request.Properties, networkSetting);
                    //    _log.Info(String.Format("The following query {0} (ID: {3}) was executed and results were uploaded automatically on behalf of {1}:\n\n{2}",
                    //        request.Source.Identifier, networkSetting.Profile.Username, strReason, request.Source.ID));
                    //}
                }
            }
            catch (Exception ex)
            {
                string message = string.Format("An error occurred while attempting unattended processing of the following query {0} (ID: {1})", request.Source.Identifier, request.Source.ID);
                _log.Error(message, ex);
                DnsServiceManager.SetRequestStatus(request, new HubRequestStatus(Lpp.Dns.DTO.DataMartClient.Enums.DMCRoutingStatus.Failed, message), request.Properties, networkSetting);
            }

            _log.Info(String.Format("BackgroundProcess:  Finished Processing / Uploading results for query {0} (RequestID: {3}, DataMartId: {1}, NetworkId: {2})", request.Source.Identifier, request.DataMartId, networkSetting.NetworkId, request.Source.ID));
        }
Ejemplo n.º 2
0
        private void UploadRequest(HubRequest request, Lib.Caching.DocumentCacheManager cache)
        {
            string requestId = request.Source.ID.ToString();

            Document[] responseDocuments;
            if (cache.Enabled)
            {
                responseDocuments = cache.GetResponseDocuments().ToArray();
            }
            else
            {
                responseDocuments = request.Processor.Response(requestId);
            }

            if (responseDocuments != null && responseDocuments.Length > 0)
            {
                Log.Info(string.Format("Uploading {4} documents for query: {0} (DataMart:{1}, Network:{2}, RequestID: {3:D})", request.Source.Identifier, request.DataMartName, request.NetworkName, request.Source.ID, responseDocuments.Length));

                //since the ID of the document returned from the API is not known when posting, and the order cannot be assumed in the response
                //loop over each document and post the metadata and the content as a single unit of work per document.

                for (int i = 0; i < responseDocuments.Length; i++)
                {
                    string uploadIdentifier     = ("[" + Utilities.Crypto.Hash(Guid.NewGuid()) + "]").PadRight(16);
                    Guid[] metaDataPostResponse = DnsServiceManager.PostResponseDocuments(uploadIdentifier, requestId, request.DataMartId, new[] { responseDocuments[i] }, _networkSetting);

                    System.IO.Stream contentStream = null;
                    try
                    {
                        if (cache.Enabled)
                        {
                            contentStream = cache.GetDocumentStream(Guid.Parse(responseDocuments[i].DocumentID));
                        }
                        else
                        {
                            request.Processor.ResponseDocument(requestId, responseDocuments[i].DocumentID, out contentStream, 60000);
                        }

                        DnsServiceManager.PostResponseDocumentContent(uploadIdentifier, requestId, request.DataMartId, metaDataPostResponse[0], responseDocuments[i].Filename, contentStream, _networkSetting)
                        .LogExceptions(Log.Error)
                        .Catch()
                        .Wait();
                    }
                    finally
                    {
                        contentStream.CallDispose();
                    }
                }
            }
            else
            {
                Log.Info(string.Format("No documents to upload for query: {0} (DataMart:{1}, Network:{2}, RequestID: {3:D})", request.Source.Identifier, request.DataMartName, request.NetworkName, request.Source.ID, responseDocuments.Length));
            }

            if (request.RoutingStatus == Lpp.Dns.DTO.DataMartClient.Enums.DMCRoutingStatus.Failed)
            {
                HubRequestStatus hubRequestStatus = DnsServiceManager.ConvertModelRequestStatus(request.Processor.Status(requestId));
                hubRequestStatus.Message = request.Processor.Status(requestId).Message;
                DnsServiceManager.SetRequestStatus(request, hubRequestStatus, request.Properties, _networkSetting);
                Log.Info(string.Format("The following query {0} (ID: {3}, DataMart: {4}, Network: {5}) failed to execute on behalf of {1}:\n\n{2}", request.Source.Identifier, _networkSetting.Profile.Username, hubRequestStatus.Message, request.Source.ID, request.DataMartName, request.NetworkName));
            }
            else
            {
                Log.Info(string.Format("The following query {0} (ID: {2}, DataMart: {3}, Network: {4}) was executed and results were uploaded automatically on behalf of {1}", request.Source.Identifier, _networkSetting.Profile.Username, request.Source.ID, request.DataMartName, request.NetworkName));
            }
        }
Ejemplo n.º 3
0
        private void UploadRequest(HubRequest request, Lib.Caching.DocumentCacheManager cache)
        {
            string requestId = request.Source.ID.ToString();

            Document[] responseDocuments;
            if (cache.Enabled)
            {
                responseDocuments = cache.GetResponseDocuments().ToArray();
            }
            else
            {
                responseDocuments = request.Processor.Response(requestId);
            }

            if (responseDocuments != null && responseDocuments.Length > 0)
            {
                Log.Info(string.Format("Uploading {4} documents for query: {0} (DataMart:{1}, Network:{2}, RequestID: {3:D})", request.Source.Identifier, request.DataMartName, request.NetworkName, request.Source.ID, responseDocuments.Length));

                if (_networkSetting.SupportsUploadV2)
                {
                    Log.Debug($"Network settings indicate document upload v2 supported for query: {request.Source.Identifier}, (DataMart: {request.DataMartName}, Network: { request.NetworkName }, RequestID: { request.Source.ID }");
                    try
                    {
                        Parallel.ForEach(responseDocuments,
                                         new ParallelOptions {
                            MaxDegreeOfParallelism = 4
                        },
                                         (doc) =>
                        {
                            string uploadIdentifier = ("[" + Utilities.Crypto.Hash(Guid.NewGuid()) + "]").PadRight(16);

                            System.IO.Stream stream = null;
                            try
                            {
                                if (cache.Enabled)
                                {
                                    stream = cache.GetDocumentStream(Guid.Parse(doc.DocumentID));
                                }
                                else
                                {
                                    request.Processor.ResponseDocument(requestId, doc.DocumentID, out stream, doc.Size);
                                }

                                var dto = new DTO.DataMartClient.Criteria.DocumentMetadata
                                {
                                    ID                = Guid.Parse(doc.DocumentID),
                                    DataMartID        = request.DataMartId,
                                    RequestID         = Guid.Parse(requestId),
                                    IsViewable        = doc.IsViewable,
                                    Size              = doc.Size,
                                    MimeType          = doc.MimeType,
                                    Kind              = doc.Kind,
                                    Name              = doc.Filename,
                                    CurrentChunkIndex = 0
                                };

                                DnsServiceManager.PostDocumentChunk(uploadIdentifier, dto, stream, _networkSetting);
                            }
                            finally
                            {
                                stream.Dispose();
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"An error occurred during concurrent uploading of response documents for query: {request.Source.Identifier}, (DataMart: {request.DataMartName}, Network: { request.NetworkName }, RequestID: { request.Source.ID }", ex);
                        throw;
                    }
                }
                else
                {
                    //since the ID of the document returned from the API is not known when posting, and the order cannot be assumed in the response
                    //loop over each document and post the metadata and the content as a single unit of work per document.
                    Log.Debug($"Network settings indicates document upload v2 IS NOT supported for query: {request.Source.Identifier}, (DataMart: {request.DataMartName}, Network: { request.NetworkName }, RequestID: { request.Source.ID }");
                    for (int i = 0; i < responseDocuments.Length; i++)
                    {
                        string uploadIdentifier     = ("[" + Utilities.Crypto.Hash(Guid.NewGuid()) + "]").PadRight(16);
                        Guid[] metaDataPostResponse = DnsServiceManager.PostResponseDocuments(uploadIdentifier, requestId, request.DataMartId, new[] { responseDocuments[i] }, _networkSetting);

                        System.IO.Stream contentStream = null;
                        try
                        {
                            if (cache.Enabled)
                            {
                                contentStream = cache.GetDocumentStream(Guid.Parse(responseDocuments[i].DocumentID));
                            }
                            else
                            {
                                request.Processor.ResponseDocument(requestId, responseDocuments[i].DocumentID, out contentStream, 60000);
                            }

                            DnsServiceManager.PostResponseDocumentContent(uploadIdentifier, requestId, request.DataMartId, metaDataPostResponse[0], responseDocuments[i].Filename, contentStream, _networkSetting)
                            .LogExceptions(Log.Error)
                            .Catch()
                            .Wait();
                        }
                        finally
                        {
                            contentStream.CallDispose();
                        }
                    }
                }
            }
            else
            {
                Log.Info(string.Format("No documents to upload for query: {0} (DataMart:{1}, Network:{2}, RequestID: {3:D})", request.Source.Identifier, request.DataMartName, request.NetworkName, request.Source.ID, responseDocuments.Length));
            }

            if (request.RoutingStatus == Lpp.Dns.DTO.DataMartClient.Enums.DMCRoutingStatus.Failed)
            {
                HubRequestStatus hubRequestStatus = DnsServiceManager.ConvertModelRequestStatus(request.Processor.Status(requestId));
                hubRequestStatus.Message = request.Processor.Status(requestId).Message;
                DnsServiceManager.SetRequestStatus(request, hubRequestStatus, request.Properties, _networkSetting);
                Log.Info(string.Format("The following query {0} (ID: {3}, DataMart: {4}, Network: {5}) failed to execute on behalf of {1}:\n\n{2}", request.Source.Identifier, _networkSetting.Profile.Username, hubRequestStatus.Message, request.Source.ID, request.DataMartName, request.NetworkName));
            }
            else
            {
                Log.Info(string.Format("The following query {0} (ID: {2}, DataMart: {3}, Network: {4}) was executed and results were uploaded automatically on behalf of {1}", request.Source.Identifier, _networkSetting.Profile.Username, request.Source.ID, request.DataMartName, request.NetworkName));
            }
        }