コード例 #1
0
        protected override IMessage ToMessagingMessage(Message amqpMessage)
        {
            if (BatchingStrategy.CanDebatch(amqpMessage.MessageProperties))
            {
                if (ConverterAdapter.IsMessageList)
                {
                    var messages = new List <IMessage>();
                    BatchingStrategy.DeBatch(amqpMessage, fragment =>
                    {
                        messages.Add(base.ToMessagingMessage(fragment));
                    });
                    return(new GenericMessage(messages));
                }
                else
                {
                    var list = new List <object>();
                    BatchingStrategy.DeBatch(amqpMessage, fragment =>
                    {
                        list.Add(ConverterAdapter.ExtractPayload(fragment));
                    });
                    return(Messaging.Support.MessageBuilder.WithPayload(list)
                           .CopyHeaders(ConverterAdapter.HeaderMapper.ToHeaders(amqpMessage.MessageProperties))
                           .Build());
                }
            }

            return(base.ToMessagingMessage(amqpMessage));
        }
コード例 #2
0
        /// <summary>
        /// Версия с делегатом
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="convert">The convert.</param>
        /// <returns></returns>
        public static double CalculateAverage(IEnumerable <double> values,
                                              Converter <IEnumerable <double>, double> convert)
        {
            ValidateOnNull(convert);
            ConverterAdapter ca = new ConverterAdapter(convert);

            return(CalculateAverage(values, ca));
        }
コード例 #3
0
        // GET: Adapter
        public ActionResult Index()
        {
            ArrayCollAdaptee <string> array = new ArrayCollAdaptee <string>();

            array.AddItemtoCollection("Item 1");
            array.AddItemtoCollection("Item 2");



            ConverterAdapter <string> convertor = new ConverterAdapter <string>(array);

            List <string> listOfStrings = convertor.Convert();

            return(View());
        }
コード例 #4
0
        /// <summary>
        /// Reconvert document from import jobs
        /// </summary>
        /// <param name="docCollection">The documents</param>
        public void ImportReconvert(ConversionDocCollection docCollection)
        {
            // loop through documents to push each document for conversion
            var documentConversionLogBeo = new List <DocumentConversionLogBeo>();
            var validationList           = new List <ReconversionDocumentBEO>();

            foreach (var document in docCollection.Documents)
            {
                short reasonId;
                byte  status;
                int   fileSize = 0;
                try
                {
                    //if FileList does not exists, do not send for conversion
                    if (document.FileList == null)
                    {
                        //can not find file
                        LogMessage(false, "File paths null or Files does not exist");
                    }
                    else
                    {
                        //calculate file size; multiple images file will add them together
                        fileSize = 0;
                        foreach (var file in document.FileList)
                        {
                            if (String.IsNullOrEmpty(file))
                            {
                                continue;
                            }
                            var fileInfo = new FileInfo(file);
                            if (fileInfo.Exists)
                            {
                                fileSize += (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);
                            }
                        }
                    }
                    var filesWithReasonCodes = Utils.GetReasonCodes(document.FileList);
                    var heartbeatFilePath    = docCollection.GetDefaultHeartbeatFileFullPath(document);
                    var matterId             = docCollection.DataSet.Matter.FolderID;

                    ConverterAdapter.PushDocumentForConversionWithHearbeat(
                        matterId.ToString(CultureInfo.InvariantCulture), document.CollectionId,
                        document.DocumentId, filesWithReasonCodes.Item1,
                        heartbeatFilePath, CmgServiceConfigBO.GetServiceConfigurationsforConfig(Constants.PublishBlankPages));

                    reasonId = filesWithReasonCodes.Item2;
                    status   = filesWithReasonCodes.Item3;

                    document.ConversionCheckCounter = 0;
                    document.SubmittedTime          = DateTime.UtcNow;
                    document.ConversionEnqueueTime  = DateTime.UtcNow;

                    //only add submitted documents for validation, otherwise we might wait for heartbeat files that never exists.
                    validationList.Add(document);

                    IncreaseProcessedDocumentsCount(1);
                }
                catch (Exception ex)
                {
                    ReportToDirector(ex);
                    ex.Trace().Swallow();
                    if (ex is WebException)
                    {
                        reasonId = EVRedactItErrorCodes.FailedToSendFile;
                    }
                    else
                    {
                        reasonId = Utils.GetConversionErrorReason(ex.GetErrorCode());
                    }
                    status = EVRedactItErrorCodes.Failed;
                    LogMessage(false, ex.ToUserString());
                }

                var logBeo = ConvertToReoconversionDocumentBeo(document, status, reasonId);
                logBeo.Size = fileSize;
                documentConversionLogBeo.Add(logBeo);
            }

            docCollection.Documents = validationList;
            BulkUpdateProcessedDocuments(docCollection.DataSet.Matter.FolderID, documentConversionLogBeo);
        }