예제 #1
0
        /// <summary>
        /// POST api/source
        /// 图片目录数据保存接口
        /// </summary>
        public async Task <HttpResponseMessage> PostAsync()
        {
            string data = await Request.Content.ReadAsStringAsync();

            JavaScriptSerializer js = new JavaScriptSerializer();

            js.MaxJsonLength = int.MaxValue;
            Logger.Debug(data);
            SourceInputDto input = js.Deserialize <SourceInputDto>(data);

            srcOp.CreateBatchData(input.Images.Select(_ => new SourceEntity
            {
                SourceType       = (int)SourceTypeEnum.Picture,
                DeviceNo         = input.DeviceNo,
                SourceCameraNo   = input.SourceCameraNo,
                SavePathDir      = _.SavePathDir,
                SourceFiles      = string.Join(";", _.SourceFiles),
                CoverImageName   = _.SourceFiles[0],
                CreatedDate      = DateTime.Parse(_.CreatedDate),
                CreatedTimestamp = Convert.ToInt64(Commoncs.GetTimestamp(DateTime.Parse(_.CreatedDate))),
                CurrentStatus    = (int)RowStatusEnum.Enable
            }));
            return(new HttpResponseMessage
            {
                Content = new StringContent(Commoncs.SerializeJson(new ResponseViewModel
                {
                    Status = (int)HttpStatusCode.OK,
                    Msg = "保存成功!"
                }), Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
예제 #2
0
        private void InitData()
        {
            string imgExts = ".jpg,.bmp,.jpeg,.gif,.png";

            var path  = Server.MapPath("~/cameral_shara_1/");
            var dInfo = new DirectoryInfo(path);

            var dSub         = dInfo.GetDirectories();
            var imgExtsArray = imgExts.Split(',').ToList();

            BaseEntityOperation <SourceEntity> srcOp = EtOpManager.GetFactory().GetEntityOperation <SourceEntity>();

            var entities = new List <SourceEntity>();

            var now = DateTime.Now;

            dSub.ToList().ForEach(m =>
            {
                var createdDate = now.AddSeconds(Convert.ToInt16(m.Name));

                var entity = new SourceEntity
                {
                    SourceType       = (int)SourceTypeEnum.Picture,
                    SourceCameraNo   = "C001",
                    SavePathDir      = "/cameral_shara_1/" + m.Name + "/",
                    DeviceNo         = "D001",
                    CurrentStatus    = (int)RowStatusEnum.Enable,
                    CreatedDate      = createdDate,
                    CreatedTimestamp = Convert.ToInt64(Commoncs.GetTimestamp(createdDate)),
                };

                var sourceFiles = new List <string>();

                m.GetFiles().ToList().ForEach(x =>
                {
                    x.MoveTo(x.FullName.Replace(" ", ""));
                    if (imgExtsArray.Any(f => x.Name.EndsWith(f)))
                    {
                        sourceFiles.Add(x.Name.Replace(" ", ""));
                    }
                });

                entity.SourceFiles    = string.Join(";", sourceFiles);
                entity.CoverImageName = sourceFiles[0];
                entities.Add(entity);
            });
            srcOp.CreateBatchData(entities);
        }