コード例 #1
0
        public async Task MoveFile(File file, string url, string sharedSecret)
        {
            var         callUrl     = $"{url}/{file.FileKey}";
            FileSyncDTO fileSyncDTO = new FileSyncDTO
            {
                creationTime = file.CreationTime.ToString(),
                expireTime   = file.ExpireTime.ToString(),
                siteId       = file.SiteId.ToString(),
            };

            try
            {
                LogHelper.Debug($"{DateTime.UtcNow} Begin call api: {file.FileKey}");
                var httpstatusCode = await CallApiHelper.UploadFile(callUrl, sharedSecret, file.Content.Name, file.Content.Content, fileSyncDTO);

                LogHelper.Debug($"{DateTime.UtcNow} End call api: {file.FileKey}");

                if (httpstatusCode == HttpStatusCode.OK)
                {
                    using (_container.BeginScope())
                    {
                        LogHelper.Debug($"{DateTime.UtcNow} Begin delete: {file.FileKey}");
                        IFileDomainService fileDomainService = _container.Resolve <IFileDomainService>();
                        await fileDomainService.Delete(file);

                        LogHelper.Debug($"{DateTime.UtcNow} End delete: {file.FileKey}");
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex, ex.Message);
            }
        }
コード例 #2
0
        public async Task <UpsertBlogOutput> UpsertBlogAsync(UpsertBlogInput input)
        {
            #region Validation

            if (input.Title.IsNullOrEmpty())
            {
                throw new UserFriendlyException("لطفا نام دسته بندی را وارد نمائید !!!");
            }

            #endregion

            var pc = new Blog();

            int?blogId = null;

            if (input.Id == 0)
            {
                if (_blogRepo.GetAll().Any(p => p.Title == input.Title || p.EnTitle == input.EnTitle))
                {
                    throw new UserFriendlyException("این دسته بندی در سیستم موجود می باشد !!!!");
                }

                pc.Title       = input.Title;
                pc.Description = input.Description;


                blogId = _blogRepo.InsertAndGetId(pc);
            }
            else
            {
                pc = _blogRepo.GetAll()
                     .SingleOrDefault(p => p.Id == input.Id);

                if (pc == null)
                {
                    throw new UserFriendlyException("آیتم مورد نظر وجود ندارد ویا حذف شده است !!!");
                }

                blogId = pc.Id;

                _fileDomainService.Delete(SystemConsts.DefaultPathBlog, blogId + ".jpg");


                pc.Title       = input.Title;
                pc.Description = input.Description;
            }
            _fileDomainService.Upload(SystemConsts.DefaultPathBlog, blogId + ".jpg", input.Based64BinaryString);

            pc.Labels        = input.Labels;
            pc.EnDescription = input.EnDescription;
            pc.EnTitle       = input.EnTitle;


            return(new UpsertBlogOutput());
        }
コード例 #3
0
        public async Task <UpsertCertificateOutput> UpsertCertificateAsync(UpsertCertificateInput input)
        {
            #region Validation

            if (input.Name.IsNullOrEmpty())
            {
                throw new UserFriendlyException("لطفا نام  را وارد نمائید !!!");
            }

            #endregion

            var pc = new Certificate();

            int cerId = 0;

            if (input.Id == 0)
            {
                if (_CertificateRepo.GetAll().Any(p => p.Name == input.Name || p.EnName == input.EnName))
                {
                    throw new UserFriendlyException("این موضوع در سیستم موجود می باشد !!!!");
                }

                pc.Name        = input.Name;
                pc.Description = input.Description;


                cerId = _CertificateRepo.InsertAndGetId(pc);
            }
            else
            {
                pc = _CertificateRepo.GetAll()
                     .SingleOrDefault(p => p.Id == input.Id);

                if (pc == null)
                {
                    throw new UserFriendlyException("آیتم مورد نظر وجود ندارد ویا حذف شده است !!!");
                }

                cerId = pc.Id;
                _fileDomainService.Delete(SystemConsts.DefaultPathCertificate, cerId + ".jpg");

                pc.Name        = input.Name;
                pc.Description = input.Description;
            }

            _fileDomainService.Upload(SystemConsts.DefaultPathCertificate, cerId + ".jpg", input.Based64BinaryString);
            pc.Labels        = input.Labels;
            pc.EnDescription = input.EnDescription;
            pc.EnName        = input.EnName;


            return(new UpsertCertificateOutput());
        }
コード例 #4
0
        public void MoveToMain()
        {
            var n     = _configService.GetInt("StandbyToMainWorkerNum");
            var files = this._fileDomainService.GetList(new FileFilterSpecification(n, null));
            var tasks = files.Select((f) =>
                                     Task.Run(() =>
            {
                // should have try-catch
                MoveFie(f);
                _fileDomainService.Delete(f.FileKey);
            })).ToArray();

            // wait until all finish
            Task.WaitAll(tasks);

            throw new NotImplementedException();
        }
コード例 #5
0
        public async Task <UpsertProductOutput> UpsertProductAsync(UpsertProductInput input)
        {
            #region Validation

            if (input.Name.IsNullOrEmpty())
            {
                throw new UserFriendlyException("لطفا نام کالا را وارد نمائید !!!");
            }
            if (input.ProductCategoryId == 0)
            {
                throw new UserFriendlyException("لطفا دسته بندی را وارد نمائید !!!");
            }

            if (input.Price == 0)
            {
                throw new UserFriendlyException("لطفا قیمت را وارد نمائید !!!");
            }
            if (input.Count == 0)
            {
                throw new UserFriendlyException("لطفا تعداد را وارد نمائید !!!");
            }
            #endregion

            var pc = new Product();

            int?productId = null;

            if (input.Id == 0)
            {
                if (_productRepo.GetAll().Any(p => p.Name == input.Name & p.ProductCategoryId == input.ProductCategoryId))
                {
                    throw new UserFriendlyException("این محصول در سیستم موجود می باشد !!!!");
                }

                pc.Name              = input.Name;
                pc.Description       = input.Description;
                pc.Count             = input.Count;
                pc.Labels            = input.Labels;
                pc.Price             = input.Price;
                pc.ProductCategoryId = input.ProductCategoryId;
                pc.SendPriceInRange  = input.SendPriceInRage;
                pc.SendPriceOutRange = input.SendPriceOutRage;
                pc.Weight            = input.Weight;
                pc.Unit              = input.Unit;

                productId = _productRepo.InsertAndGetId(pc);
            }
            else
            {
                pc = _productRepo.GetAll()
                     .SingleOrDefault(p => p.Id == input.Id);

                if (pc == null)
                {
                    throw new UserFriendlyException("آیتم مورد نظر وجود ندارد ویا حذف شده است !!!");
                }

                productId = pc.Id;
                _fileDomainService.Delete(SystemConsts.DefaultPathProduct, productId + ".jpg");

                pc.Name              = input.Name;
                pc.Description       = input.Description;
                pc.Count             = input.Count;
                pc.Labels            = input.Labels;
                pc.Price             = input.Price;
                pc.ProductCategoryId = input.ProductCategoryId;
                pc.SendPriceInRange  = input.SendPriceInRage;
                pc.SendPriceOutRange = input.SendPriceOutRage;
                pc.Weight            = input.Weight;
                pc.Unit              = input.Unit;
            }

            _fileDomainService.Upload(SystemConsts.DefaultPathProduct, productId + ".jpg", input.Based64BinaryString);

            pc.EnName        = input.EnName;
            pc.EnDescription = input.EnDescription;


            return(new UpsertProductOutput());
        }