示例#1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="message"></param>
        /// <returns>是否发送成功,true/false</returns>
        public static Task <Boolean> Send(string topic, MessageBody message)
        {
            return(Task.Run(() => {
                if (string.IsNullOrWhiteSpace(message.SysCode))
                {
                    message.SysCode = GuidUtil.NewGuid();
                }
                // 发送之前先持久化
                MessageColl messageCollection = new MessageColl
                {
                    SysCode = message.SysCode,
                    From = message.From,
                    To = message.To,
                    ChannelType = (int)message.ChannelType,
                    MsgType = (int)message.MessageType,
                    Payload = message.Payload,
                    SendTime = DateUtil.CurrentTimeMillis,
                    Delivered = (int)EnumDeliverType.UNDELIVERED,
                    Read = (int)EnumReadType.UNREAD
                };

                MongodbHelper <MessageColl> .Add(ServiceFactory.MongoDatabase, messageCollection);

                var dr = producer.ProduceAsync(topic, null, JsonConvert.SerializeObject(message));
                if (dr.Result.Error.HasError)
                {
                    LOG.Error($" 发送失败,详情[{dr.Result.Error.Reason}]");
                    return false;
                }
                messageCollection.Delivered = (int)EnumDeliverType.DELIVERED;
                MongodbHelper <MessageColl> .Update(ServiceFactory.MongoDatabase, messageCollection, messageCollection._id);
                LOG.Info($"成功发送 '{dr.Result.Value}' to: {dr.Result.TopicPartitionOffset}");
                return true;
            }));
        }
示例#2
0
        public void MongoSetData(BugModel model)
        {
            MongodbHelper h = new MongodbHelper();

            model.BrowserInfo = JsonConvert.SerializeObject(model.BrowserInfo);
            model.exception = JsonConvert.SerializeObject(model.exception);
            var task = h.Add(model);
            //task.Wait();
        }
示例#3
0
        /// <summary>
        /// 异步保存输出
        /// </summary>
        /// <param name="outputParams"></param>
        protected void SaveOutput(IDictionary <string, Property> outputParams)
        {
            // 保存计算结果
            foreach (var item in outputParams)
            {
                DmeTaskResult taskResult = new DmeTaskResult
                {
                    TaskId     = this.taskId,
                    RuleStepId = this.step.Id,
                    ResultCode = item.Key,
                    ResultType = EnumUtil.GetEnumName <EnumValueMetaType>(item.Value.DataType)
                };
                switch (item.Value.DataType)
                {
                case (int)EnumValueMetaType.TYPE_BIGNUMBER:
                case (int)EnumValueMetaType.TYPE_BINARY:
                case (int)EnumValueMetaType.TYPE_BOOLEAN:
                case (int)EnumValueMetaType.TYPE_INTEGER:
                case (int)EnumValueMetaType.TYPE_NUMBER:
                case (int)EnumValueMetaType.TYPE_SERIALIZABLE:
                case (int)EnumValueMetaType.TYPE_STRING:
                case (int)EnumValueMetaType.TYPE_TIMESTAMP:
                case (int)EnumValueMetaType.TYPE_MDB_FEATURECLASS:
                    taskResult.ResultValue = item.Value.Value;
                    break;

                case (int)EnumValueMetaType.TYPE_JSON:
                    // 存储到mongodb
                    TaskResultColl taskResultColl = new TaskResultColl
                    {
                        TaskId       = this.taskId,
                        TaskCode     = this.task.SysCode,
                        RuleStepId   = this.step.Id,
                        RuleStepCode = this.step.SysCode,
                        Code         = item.Key,
                        Value        = JsonConvert.SerializeObject(item.Value.Value)
                    };
                    MongodbHelper <TaskResultColl> .Add(ServiceFactory.MongoDatabase, taskResultColl);

                    //taskResult.ResultValue = JsonConvert.SerializeObject(item.Value.Value);
                    break;

                case (int)EnumValueMetaType.TYPE_DATE:
                    // 日期类型,转换成毫秒存储
                    taskResult.ResultValue = ((DateTime)item.Value.Value).Millisecond;
                    break;

                default:
                    break;
                }
                this.repository.GetDbContext().Insertable <DmeTaskResult>(taskResult).ExecuteCommand();
            }
        }
        public Result Run()
        {
            IDictionary <string, Property> attributes = this.ruleStepMeta.ReadAttributes();
            string database   = Convert.ToString(attributes[nameof(this.ruleStepMeta.Database)].Value);
            string collection = Convert.ToString(attributes[nameof(this.ruleStepMeta.Collection)].Value);
            IList <MongoFieldDTO> mongoFields = (IList <MongoFieldDTO>)attributes[nameof(this.ruleStepMeta.MongoFields)].Value;

            if (0 == mongoFields?.Count)
            {
                return(new Result(EnumSystemStatusCode.DME_FAIL, "没有输出的字段信息,停止计算", null));
            }
            DmeDataSource dmeDataSource = (DmeDataSource)attributes[nameof(this.ruleStepMeta.Source)].Value;
            MongodbHost   mongodbHost   = JsonConvert.DeserializeObject <MongodbHost>(dmeDataSource.Connection);

            if (!string.IsNullOrEmpty(database))
            {
                mongodbHost.DataBase = database;
            }
            mongodbHost.Collection = collection;
            JObject json = new JObject
            {
                { new JProperty("TaskId", this.taskId) },
                { new JProperty("RuleStepId", this.step.Id) }
            };

            foreach (var item in mongoFields)
            {
                string fieldName = item.Name;
                if (0 == item.IsNeedPrecursor)
                {
                    LOG.Info($"当前[{item.Name}]为非前驱参数");
                    if (0 == item.IsUseName)
                    {
                        LOG.Info($"IsUseName为[{item.IsUseName}],将会使用NewName");
                        fieldName = item.NewName;
                    }
                    LOG.Info($"fieldName值为[{fieldName}]");
                    if (string.IsNullOrEmpty(fieldName))
                    {
                        LOG.Error("mongo输出字段名称为空,不能构建");
                        continue;
                    }
                    if (null == item.ConstantValue)
                    {
                        LOG.Error($"mongo输出字段[{fieldName}]的值不能为NULL");
                        continue;
                    }
                    json.Add(new JProperty(fieldName, item.ConstantValue));
                }
                else
                {
                    LOG.Info($"当前[{item.Name}]为前驱参数");
                    // 前驱参数
                    if (string.IsNullOrEmpty(item.Name) ||
                        !item.Name.ToString().Contains(":"))
                    {
                        throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤[{step.SysCode}]的前驱参数[{item.Name}]无效");
                    }
                    string   preStepName      = item.Name.Split(":")[0];
                    string   preAttributeName = item.Name.Split(":")[1];
                    Property property         = base.GetStepAttributeValue(preStepName, preAttributeName);
                    if (null == property)
                    {
                        throw new BusinessException((int)EnumSystemStatusCode.DME_ERROR, $"步骤名[{preStepName}]的参数[{preAttributeName}]无效");
                    }
                    if (0 == item.IsUseName)
                    {
                        fieldName = item.NewName;
                    }
                    else
                    {
                        fieldName = preAttributeName;
                    }
                    if (string.IsNullOrEmpty(fieldName))
                    {
                        LOG.Error("mongo输出字段名称为空,不能构建");
                        continue;
                    }
                    if (null == property.Value)
                    {
                        LOG.Error($"mongo输出字段[{fieldName}]的值不能为NULL");
                        continue;
                    }
                    json.Add(new JProperty(fieldName, property.Value));
                }
            }
            // LOG.Info("JSON对象,方法ToJson:" + json.ToJson());
            // LOG.Info("JSON对象,方法ToString:" + json.ToString());
            // PS:不能使用json.ToJson()和json.ToBsonDocument构建一个BsonDocument,否则插入进去的实体对象不对;
            //      需要使用json.ToString()
            BsonDocument document = BsonDocument.Parse(json.ToString());

            MongodbHelper <BsonDocument> .Add(mongodbHost, document);

            return(new Result(EnumSystemStatusCode.DME_SUCCESS, $"模型[{step.ModelId}]的步骤[{step.SysCode}]运算完毕", null));
        }