/// <summary>
 /// add as an asynchronous operation.
 /// </summary>
 /// <param name="obj">The object.</param>
 /// <returns>Task&lt;MethodReturnResult&gt;.</returns>
 public async Task <MethodReturnResult> AddAsync(PointDetail obj)
 {
     return(await Task.Run <MethodReturnResult>(() =>
     {
         return base.Channel.Add(obj);
     }));
 }
 public static string PointDetailHumanReadableType(PointDetail detail)
 {
     return(detail.DataType switch
     {
         "Campground" => "Campground",
         "Parking" => "Parking",
         "Peak" => "Peak",
         "Restroom" => "Restroom",
         "TrailJunction" => "Trail Junction",
         "Feature" => JsonSerializer.Deserialize <Feature>(detail.StructuredDataAsJson)?.Type ?? string.Empty,
         _ => string.Empty
     });
Exemple #3
0
        /// <summary>
        /// 修改采集点设置明细。
        /// </summary>
        /// <param name="obj">采集点设置明细数据。</param>
        /// <returns><see cref="MethodReturnResult" />.</returns>
        public MethodReturnResult Modify(PointDetail obj)
        {
            MethodReturnResult result = new MethodReturnResult();

            if (!this.PointDetailDataEngine.IsExists(obj.Key))
            {
                result.Code    = 1002;
                result.Message = String.Format(StringResource.PointDetailService_IsNotExists, obj.Key);
                return(result);
            }
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    Point p = this.PointDataEngine.Get(obj.Key.PointKey);
                    //根据采集设置组名获取记录
                    PagingConfig cfg = new PagingConfig()
                    {
                        IsPaging = false,
                        Where    = string.Format(@"EXISTS(From Point as p 
                                                       WHERE p.Key=self.Key.PointKey 
                                                       AND p.GroupName='{0}')
                                              AND Key.ParameterName='{1}'"
                                                 , p.GroupName
                                                 , obj.Key.ParameterName)
                    };
                    IList <PointDetail> lstPointDetail = this.PointDetailDataEngine.Get(cfg);
                    foreach (PointDetail item in lstPointDetail)
                    {
                        PointDetail itemUpdate = obj.Clone() as PointDetail;
                        itemUpdate.Key = new PointDetailKey()
                        {
                            PointKey      = item.Key.PointKey,
                            ParameterName = item.Key.ParameterName
                        };
                        itemUpdate.Creator    = item.Creator;
                        itemUpdate.CreateTime = item.CreateTime;
                        this.PointDetailDataEngine.Update(itemUpdate);
                    }
                    this.PointDetailDataEngine.Update(obj);
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = String.Format(StringResource.OtherError, ex.Message);
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 添加采集点设置明细。
        /// </summary>
        /// <param name="obj">采集点设置明细数据。</param>
        /// <returns><see cref="MethodReturnResult" />.</returns>
        public MethodReturnResult Add(PointDetail obj)
        {
            MethodReturnResult result = new MethodReturnResult();

            if (this.PointDetailDataEngine.IsExists(obj.Key))
            {
                result.Code    = 1001;
                result.Message = String.Format(StringResource.PointDetailService_IsExists, obj.Key);
                return(result);
            }
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    Point p = this.PointDataEngine.Get(obj.Key.PointKey);

                    //根据采集设置组名获取记录
                    PagingConfig cfg = new PagingConfig()
                    {
                        IsPaging = false,
                        Where    = string.Format("GroupName='{0}'", p.GroupName)
                    };
                    IList <Point> lstPoint = this.PointDataEngine.Get(cfg);

                    foreach (Point item in lstPoint)
                    {
                        PointDetail itemNew = obj.Clone() as PointDetail;
                        itemNew.Key = new PointDetailKey()
                        {
                            PointKey      = item.Key,
                            ParameterName = obj.Key.ParameterName
                        };
                        this.PointDetailDataEngine.Insert(itemNew);
                    }
                    this.PointDetailDataEngine.Insert(obj);

                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = String.Format(StringResource.OtherError, ex.Message);
            }
            return(result);
        }
 /// <summary>
 /// 添加采集点设置明细。
 /// </summary>
 /// <param name="obj">采集点设置明细数据。</param>
 /// <returns><see cref="MethodReturnResult" />.</returns>
 public MethodReturnResult Add(PointDetail obj)
 {
     return(base.Channel.Add(obj));
 }
 /// <summary>
 /// 修改采集点设置明细。
 /// </summary>
 /// <param name="obj">采集点设置明细数据。</param>
 /// <returns><see cref="MethodReturnResult" />.</returns>
 public ServiceCenter.Model.MethodReturnResult Modify(PointDetail obj)
 {
     return(base.Channel.Modify(obj));
 }
Exemple #7
0
        /// <summary>
        /// 添加采集点设置。
        /// </summary>
        /// <param name="obj">采集点设置数据。</param>
        /// <returns><see cref="MethodReturnResult" />.</returns>
        public MethodReturnResult Add(Point obj)
        {
            MethodReturnResult result = new MethodReturnResult();

            if (this.PointDataEngine.IsExists(obj.Key))
            {
                result.Code    = 1001;
                result.Message = String.Format(StringResource.PointService_IsExists, obj.Key);
                return(result);
            }
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    //根据采集设置组名获取记录
                    PagingConfig cfg = new PagingConfig()
                    {
                        PageNo   = 0,
                        PageSize = 1,
                        Where    = string.Format("GroupName='{0}'", obj.GroupName)
                    };
                    IList <Point>       lstPoint       = this.PointDataEngine.Get(cfg);
                    IList <PointDetail> lstPointDetail = new List <PointDetail>();
                    if (lstPoint.Count > 0)
                    {
                        Point p = lstPoint[0];
                        obj.SamplingPlanName = p.SamplingPlanName;
                        obj.CategoryName     = p.CategoryName;
                        obj.ActionName       = p.ActionName;
                        cfg = new PagingConfig()
                        {
                            IsPaging = false,
                            Where    = string.Format("Key.PointKey='{0}'", p.Key)
                        };
                        lstPointDetail = this.PointDetailDataEngine.Get(cfg);
                    }
                    //新增采集点设置。
                    this.PointDataEngine.Insert(obj);

                    //曾经有设置过该组采集点,则直接复制原有采集参数点设置。
                    if (lstPointDetail.Count > 0)
                    {
                        foreach (PointDetail item in lstPointDetail)
                        {
                            PointDetail itemNew = item.Clone() as PointDetail;
                            itemNew.Key = new PointDetailKey()
                            {
                                PointKey      = obj.Key,
                                ParameterName = item.Key.ParameterName
                            };
                            this.PointDetailDataEngine.Insert(itemNew);
                        }
                    }
                    else
                    {//之前没有设置采集参数明细,则插入参数。
                        cfg = new PagingConfig()
                        {
                            IsPaging = false,
                            Where    = string.Format("Key.CategoryName='{0}'", obj.CategoryName)
                        };
                        IList <CategoryDetail> lstDetail = this.CategoryDetailDataEngine.Get(cfg);
                        foreach (CategoryDetail item in lstDetail)
                        {
                            Parameter p = this.ParameterDataEngine.Get(item.Key.ParameterName);

                            PointDetail pointdetailItem = new PointDetail()
                            {
                                Key = new PointDetailKey()
                                {
                                    ParameterName = item.Key.ParameterName,
                                    PointKey      = obj.Key
                                },
                                CreateTime     = obj.CreateTime,
                                Creator        = obj.Creator,
                                DataType       = p != null ? p.DataType : EnumDataType.String,
                                DerivedFormula = p != null ? p.DerivedFormula : string.Empty,
                                DeviceType     = p != null ? p.DeviceType : EnumDeviceType.None,
                                Editor         = obj.Editor,
                                EditTime       = obj.EditTime,
                                IsDerived      = p != null ? p.IsDerived : false,
                                ItemNo         = item.ItemNo,
                                Mandatory      = p != null ? p.Mandatory : true,
                                ParameterCount = 1,
                                ParameterType  = EnumParameterType.EDC
                            };
                            this.PointDetailDataEngine.Insert(pointdetailItem);
                        }
                    }
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = String.Format(StringResource.OtherError, ex.Message);
            }
            return(result);
        }
Exemple #8
0
        public static List <ExcelValueParse <PointDetail> > GetPointDetails(ExcelHeaderRow headerInfo,
                                                                            IXLRangeRow toProcess)
        {
            var contentColumns = headerInfo.Columns.Where(x => x.ColumnHeader.StartsWith("PointDetail"));

            var returnList = new List <ExcelValueParse <PointDetail> >();

            foreach (var loopColumns in contentColumns)
            {
                var stringValue = toProcess.Worksheet.Cell(toProcess.RowNumber(), loopColumns.ExcelSheetColumn)
                                  .GetString();

                if (string.IsNullOrWhiteSpace(stringValue))
                {
                    continue;
                }

                var toAdd = new ExcelValueParse <PointDetail> {
                    StringValue = stringValue
                };
                returnList.Add(toAdd);


                var splitList = stringValue.RemoveNewLines().TrimNullToEmpty().Split("||")
                                .Select(x => x.TrimNullToEmpty()).ToList();

                if (splitList.Count != 3)
                {
                    toAdd.ParsedValue = null;
                    toAdd.ValueParsed = false;
                    continue;
                }

                PointDetail pointDetail;

                //
                // Content Id - new or db retrieved PointDetail()
                //
                if (splitList[0].Length <= 10 || !splitList[0].StartsWith("ContentId:"))
                {
                    pointDetail = new PointDetail {
                        ContentId = Guid.NewGuid(), CreatedOn = DateTime.Now
                    };
                }
                else
                {
                    var contentIdString = splitList[0].Substring(10, splitList[0].Length - 10).TrimNullToEmpty();

                    if (!Guid.TryParse(contentIdString, out var contentId))
                    {
                        toAdd.ParsedValue = null;
                        toAdd.ValueParsed = false;
                        continue;
                    }

                    var db            = Db.Context().Result;
                    var possiblePoint = db.PointDetails.Single(x => x.ContentId == contentId);

                    //Content Id specified but no db entry - error, exit
                    if (possiblePoint == null)
                    {
                        toAdd.ParsedValue = null;
                        toAdd.ValueParsed = false;
                        continue;
                    }

                    pointDetail = possiblePoint;
                    pointDetail.LastUpdatedOn = DateTime.Now;
                }

                //
                //Get the data type first so it can be used to create a new point if needed
                //
                if (splitList[1].Length <= 5 || !splitList[1].StartsWith("Type:"))
                {
                    toAdd.ParsedValue = null;
                    toAdd.ValueParsed = false;
                    continue;
                }

                var dataTypeString = splitList[1].Substring(5, splitList[1].Length - 5).TrimNullToEmpty();

                if (!Db.PointDetailDataTypeIsValid(dataTypeString))
                {
                    toAdd.ParsedValue = null;
                    toAdd.ValueParsed = false;
                    continue;
                }

                pointDetail.DataType = dataTypeString;


                //
                // Point Detail Data
                //
                if (splitList[2].Length <= 5 || !splitList[2].StartsWith("Data:"))
                {
                    //Empty Data - error
                    toAdd.ParsedValue = null;
                    toAdd.ValueParsed = false;
                    continue;
                }

                try
                {
                    var jsonString       = splitList[2].Substring(5, splitList[2].Length - 5);
                    var detailData       = Db.PointDetailDataFromIdentifierAndJson(dataTypeString, jsonString);
                    var validationResult = detailData.Validate();

                    if (!validationResult.isValid)
                    {
                        toAdd.ParsedValue = null;
                        toAdd.ValueParsed = false;
                        continue;
                    }

                    pointDetail.StructuredDataAsJson = jsonString;
                }
                catch
                {
                    toAdd.ParsedValue = null;
                    toAdd.ValueParsed = false;
                    continue;
                }

                toAdd.ParsedValue = pointDetail;
                toAdd.ValueParsed = true;
            }

            return(returnList);
        }