Esempio n. 1
0
        public static void Values(this GoogleStorageAdFileDto fileModel, IConfiguration _configuration, Guid attachedAssetsInCloudStorageGuId)
        {
            string googleStorageBucketName  = _configuration["AdBucketNameInGoogleCloudStorage"];
            string htmlFileName             = _configuration["AdHtmlTemplateFileNameWithExt"];
            string GoogleStorageFileExtType = Path.GetExtension(htmlFileName);

            fileModel.CacheExpiryDateTimeForHtmlTemplate = Utility.GetCacheExpireDateTime(_configuration["CacheExpireDays"]);
            fileModel.HtmlFileTemplateFullPathWithExt    = Path.Combine(Directory.GetCurrentDirectory(), htmlFileName);
            fileModel.GoogleStorageBucketName            = googleStorageBucketName;
            fileModel.CACHE_KEY = Constants.AD_HTML_FILE_TEMPLATE;
            fileModel.GoogleStorageObjectNameWithExt = string.Format("{0}{1}", attachedAssetsInCloudStorageGuId, GoogleStorageFileExtType);
            fileModel.ContentType = Utility.GetMimeTypes()[GoogleStorageFileExtType];
        }
Esempio n. 2
0
        private void UploadObjectInGoogleStorage(GoogleStorageAdFileDto model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(GoogleStorageAdFileDto));
            }
            if (model.AdAnonymousDataObjectForHtmlTemplate == null)
            {
                throw new ArgumentNullException(nameof(model.AdAnonymousDataObjectForHtmlTemplate));
            }
            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.AdAnonymousDataObjectForHtmlTemplate);
            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);
        }