Exemple #1
0
        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="input">条件参数</param>
        /// <returns></returns>
        public async Task <bool> CreatePptCustomerAsync(Ppt_Customer_AppCreateInputDto input)
        {
            try
            {
                string errMsg = await _manager.CreateValidateAsync(input);

                if (!string.IsNullOrWhiteSpace(errMsg))
                {
                    throw new Exception(errMsg);
                }
                var result = await base.Create(input);

                input.CustomerConsigneeList.ForEach(d => d.Customerid = result.Id);
                input.CustomerWarehouseList.ForEach(d => d.Customerid = result.Id);

                await _customerConsigneeAppService.CreateDescCustomerConsigneeAsync(result.Id, input.CustomerConsigneeList);

                await _customerWarehouseAppService.CreateDescCustomerWarehouseAsync(result.Id, input.CustomerWarehouseList);

                //日志
                var queueLog = QueueUtils.BuildQueueLog(LogType.OPERATION, string.Format($"客户 {input.Name}"), input.OperaterUserId, input.OperaterUserName, input.TenantId, result.Id, input.Warehouseid, OperationType.CREATE, TitleType.CREATE, input.Systemtype);
                await _capPublisher.PublishAsync(CapQueueName.Log_Basis, queueLog);

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            var study    = context.GetValue(this.Study);
            var duration = context.GetValue(this.Duration);
            var topics   = context.GetValue(this.Topics);
            var employee = context.GetValue(this.Employee);

            var queue = QueueUtils.GetOrCreateQueue("TwitterSpyQueueConString", QueuesContansts.TwitterSpyQueueName);

            study.CurrentState = TwitterStudyStates.Started;
            study.EmployeeId   = employee.Id;
            study.Duration     = duration;
            study.Topics       = topics;

            queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(study)));
        }
        /// <summary>
        /// 删除收货人
        /// </summary>
        /// <param name="input">条件参数</param>
        /// <returns></returns>
        public override async Task Delete(Ppt_Consignee_AppDeleteInputDto input)
        {
            try
            {
                var dataEntity = await _dataRepository.SingleAsync(d => d.Id == input.Id);

                await base.Delete(input);

                //日志
                var queueLog = QueueUtils.BuildQueueLog(LogType.OPERATION, string.Format($"客户 {dataEntity.Consigneename}"), input.OperaterUserId, input.OperaterUserName, input.TenantId, dataEntity.Id, input.WarehouseId, OperationType.DELETE, TitleType.DELETE, input.Systemtype);
                await _capPublisher.PublishAsync(CapQueueName.Log_Basis, queueLog);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            _queue       = QueueUtils.GetOrCreateQueue("QueueConnectionString", QueuesContansts.TwitterSpyQueueName);
            _reportQueue = QueueUtils.GetOrCreateQueue("BrandeAnalyticsQueueConnectionString", QueuesContansts.BrandAnalyticsQueueName);

            _cts             = new CancellationTokenSource();
            _poolingWaitTime = int.Parse(CloudConfigurationManager.GetSetting("PoolingWaitTime"));

            ConfigureTwitterClient();



            return(base.OnStart());
        }
 /// <summary>
 /// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
 /// after it has injected all of an object's dependencies.
 /// </summary>
 /// <remarks>
 ///     <p>
 /// This method allows the object instance to perform the kind of
 /// initialization only possible when all of it's dependencies have
 /// been injected (set), and to throw an appropriate exception in the
 /// event of misconfiguration.
 /// </p>
 ///     <p>
 /// Please do consult the class level documentation for the
 /// <see cref="Spring.Objects.Factory.IObjectFactory"/> interface for a
 /// description of exactly <i>when</i> this method is invoked. In
 /// particular, it is worth noting that the
 /// <see cref="Spring.Objects.Factory.IObjectFactoryAware"/>
 /// and <see cref="Spring.Context.IApplicationContextAware"/>
 /// callbacks will have been invoked <i>prior</i> to this method being
 /// called.
 /// </p>
 /// </remarks>
 /// <exception cref="System.Exception">
 /// In the event of misconfiguration (such as the failure to set a
 /// required property) or if initialization fails.
 /// </exception>
 public void AfterPropertiesSet()
 {
     if (messageQueueFactory == null)
     {
         DefaultMessageQueueFactory mqf = new DefaultMessageQueueFactory();
         mqf.ApplicationContext = applicationContext;
         messageQueueFactory    = mqf;
     }
     if (messageConverterObjectName == null)
     {
         messageConverterObjectName = QueueUtils.RegisterDefaultMessageConverter(applicationContext);
     }
     if (messageQueueTemplate == null)
     {
         messageQueueTemplate = new MessageQueueTemplate();
         messageQueueTemplate.ApplicationContext = ApplicationContext;
         messageQueueTemplate.AfterPropertiesSet();
     }
 }
        protected override void Execute(CodeActivityContext context)
        {
            if (_messageListenerTask != null)
            {
                return;
            }

            _messageListenerTask = Task.Factory.StartNew(async() =>
            {
                var queue = QueueUtils.GetOrCreateQueue("BrandAnalyticsQueueConString", QueuesContansts.BrandAnalyticsQueueName);

                do
                {
                    var msg = await queue.GetMessageAsync();

                    if (msg == null)
                    {
                        await Task.Delay(TimeToDelay);
                        continue;
                    }
                    var report = JsonConvert.DeserializeObject <TwitterStudyReport>(msg.AsString);

                    var study = BrandAnalyticsDatabaseFactory.Instance.Studies.GetAll()
                                .FirstOrDefault(s => s.Id.Equals(report.Studyid));


                    if (study == null)
                    {
                        Trace.WriteLine("Could not find study to set the report with id" + report.Studyid);
                        continue;
                    }

                    if (study.CurrentState != TwitterStudyStates.Canceled)
                    {
                        study.Report       = report;
                        study.CurrentState = TwitterStudyStates.Revision;
                    }

                    await queue.DeleteMessageAsync(msg);
                } while (true);
            }, TaskCreationOptions.LongRunning);
        }
        /// <summary>
        /// 修改收货人
        /// </summary>
        /// <param name="input">条件参数</param>
        /// <returns></returns>
        public override async Task <Ppt_Consignee_AppOutputDto> Update(Ppt_Consignee_AppUpdateInputDto input)
        {
            try
            {
                string errMsg = await _manager.UpdateValidateAsync(input);

                if (!string.IsNullOrWhiteSpace(errMsg))
                {
                    throw new Exception(errMsg);
                }
                var result = await base.Update(input);

                //日志
                var queueLog = QueueUtils.BuildQueueLog(LogType.OPERATION, string.Format($"客户 {input.Consigneename}"), input.OperaterUserId, input.OperaterUserName, input.TenantId, input.Id, input.Warehouseid, OperationType.UPDATE, TitleType.MODIFY, input.Systemtype);
                await _capPublisher.PublishAsync(CapQueueName.Log_Basis, queueLog);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Does the recieve and execute using message queue transaction manager.
        /// </summary>
        /// <param name="mq">The message queue.</param>
        /// <param name="status">The transactional status.</param>
        /// <returns>true if should continue peeking, false otherise</returns>
        protected virtual bool DoRecieveAndExecuteUsingMessageQueueTransactionManager(MessageQueue mq,
                                                                                      ITransactionStatus status)
        {
            #region Logging

            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Executing DoRecieveAndExecuteUsingMessageQueueTransactionManager");
            }

            #endregion Logging

            Message message;

            #region Receive message

            try
            {
                message = mq.Receive(TimeSpan.Zero, QueueUtils.GetMessageQueueTransaction(null));
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                {
                    //expected to occur occasionally
                    if (LOG.IsTraceEnabled)
                    {
                        LOG.Trace("IOTimeout: Message to receive was already processed by another thread.");
                    }
                    status.SetRollbackOnly();
                    return(false); // no more peeking unless this is the last listener thread
                }
                else
                {
                    // A real issue in receiving the message

                    #region Logging

                    if (LOG.IsErrorEnabled)
                    {
                        LOG.Error("Error receiving message from DefaultMessageQueue [" + mq.Path +
                                  "], closing queue and clearing connection cache.");
                    }

                    #endregion

                    lock (messageQueueMonitor)
                    {
                        mq.Close();
                        MessageQueue.ClearConnectionCache();
                    }
                    throw; // will cause rollback in MessageQueueTransactionManager and log exception
                }
            }

            #endregion

            if (message == null)
            {
                #region Logging

                if (LOG.IsTraceEnabled)
                {
                    LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]");
                }

                #endregion

                status.SetRollbackOnly();
                return(false); // no more peeking unless this is the last listener thread
            }

            try
            {
                #region Logging

                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]");
                }

                #endregion

                MessageReceived(message);
                DoExecuteListener(message);

                #region Logging

                if (LOG.IsTraceEnabled)
                {
                    LOG.Trace("MessageListener executed");
                }

                #endregion
            }
            catch (Exception ex)
            {
                //Exception may indicate rollback of database transaction in service layer.
                //Let the handler determine if the message should be removed from the queue.
                TransactionAction action =
                    HandleTransactionalListenerException(ex, message, QueueUtils.GetMessageQueueTransaction(null));
                if (action == TransactionAction.Rollback)
                {
                    #region Logging

                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(
                            "Exception handler's TransactionAction has rolled back MessageQueueTransaction for queue [" +
                            mq.Path + "]");
                    }

                    #endregion

                    status.SetRollbackOnly();
                    return(false); // no more peeking unless this is the last listener thread
                }
                else
                {
                    LOG.Info("Committing MessageQueueTransaction due to explicit commit request by exception handler.");
                }
            }
            finally
            {
                message.Dispose();
            }
            return(true);
        }