Пример #1
0
        // NOTE: transaction has to implement or not , has to think more required.
        public AdDto CreateAd(AdDto dto)
        {
            #region Ad
            Share.Models.Ad.Entities.Ad ad = _mapper.Map <Share.Models.Ad.Entities.Ad>(dto);
            ad.UserPhoneNumber      = dto.UserPhoneNumber.ConvertToLongOrDefault();
            ad.UserPhoneCountryCode = dto.UserPhoneCountryCode.ConvertToShortOrDefault();
            int SRID = _configuration["SRID"].ConvertToInt();
            ad.AddressLocation = dto.IsValidLocation ? new Point(dto.Longitude, dto.Latitude)
            {
                SRID = SRID
            } : new Point(0.0, 0.0)
            {
                SRID = SRID
            };
            RepositoryResult result = _adRepository.Create(ad);
            if (!result.Succeeded)
            {
                throw new Exception(string.Join(Path.PathSeparator, result.Errors));
            }
            #endregion

            #region Google
            string content = _fileReadService.ReadFile(_configuration["FolderPathForGoogleHtmlTemplate"]);
            content = content.ToParseLiquidRender(dto);
            Stream stream  = new MemoryStream(Encoding.UTF8.GetBytes(content));
            string Dothtml = Path.GetExtension(_configuration["FolderPathForGoogleHtmlTemplate"]);

            var bucketName  = _configuration["AdBucketNameInGoogleCloudStorage"];
            var objectName  = string.Format("{0}{1}", dto.AttachedAssetsInCloudStorageId.Value, Dothtml);
            var contentType = Utility.GetMimeTypes()[Dothtml];
            _googleStorage.UploadObject(bucketName, stream, objectName, contentType);
            #endregion

            return(dto);
        }
Пример #2
0
        public void UploadObjectInGoogleStorage(string fileName, int inMemoryCachyExpireDays, string objectName, string bucketName, object anonymousDataObject, string contentType, string CACHE_KEY)
        {
            string content = _fileReadService.FileAsString(fileName, inMemoryCachyExpireDays, CACHE_KEY);

            content = _fileReadService.FillContent(content, anonymousDataObject);
            Stream stream = _fileReadService.FileAsStream(content);

            _googleStorage.UploadObject(bucketName, stream, objectName, contentType);
        }
Пример #3
0
        private void UploadObjectInGoogleStorage(GoogleStorageArticleFileDto model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(GoogleStorageArticleFileDto));
            }
            if (model.ArticleAnonymousDataObjectForHtmlTemplate == null)
            {
                throw new ArgumentNullException(nameof(model.ArticleAnonymousDataObjectForHtmlTemplate));
            }
            string content = _cacheService.Get <string>(model.CACHE_KEY);

            if (string.IsNullOrWhiteSpace(content))
            {
                content = System.IO.File.ReadAllText(model.HtmlFileTemplateFullPathWithExt);
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception(nameof(content));
                }
                content = _cacheService.GetOrAdd <string>(model.CACHE_KEY, () => content, model.CacheExpiryDateTimeForHtmlTemplate);
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception(nameof(content));
                }
            }
            content = _fileReadService.FillContent(content, model.ArticleAnonymousDataObjectForHtmlTemplate);
            if (string.IsNullOrEmpty(content))
            {
                throw new Exception(nameof(content));
            }
            Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(content));

            if (stream == null || stream.Length <= 0)
            {
                throw new Exception(nameof(stream));
            }
            _googleStorage.UploadObject(model.GoogleStorageBucketName, stream, model.GoogleStorageObjectNameWithExt, model.ContentType);
        }