Пример #1
0
        public void Retrieve()
        {
            IBlobUtility  blobUtility  = new BlobUtility();
            IMySqlUtility mySqlUtility = new MySqlUtility();

            GdprUtility gdprUtility = new GdprUtility(blobUtility, mySqlUtility);

            gdprUtility.Retrieve(new AnonymizeToken(156001, "Want to be anonymized", true));
        }
 public HomeController(ApplicationDbContext db,
                       SignInManager <ApplicationUser> signInManager,
                       IConfigurationRoot config)
 {
     _db            = db;
     _signInManager = signInManager;
     _config        = config;
     utility        = new BlobUtility(_config["BlobDetails:AccountName"], _config["BlobDetails:Accountkey"]);
 }
 public BlobImagesController(
     IAuthorizationService authorizationService,
     IOptions <StorageAccountOptions> storageAccountOptions)
 {
     _authzService          = authorizationService;
     _storageAccountOptions = storageAccountOptions.Value;
     _blobUtility           = new BlobUtility(
         _storageAccountOptions.StorageAccountNameOption,
         _storageAccountOptions.StorageAccountKeyOption);
 }
        public async Task <string> Delete(string destinationPath)
        {
            string connectionStringRef = Configuration[ConfigSettingName_RuntimeStorageConnectionString];
            string connectionString    = await KeyVaultClient.ResolveSecretUriAsync(connectionStringRef);

            var filePath = NormalizeFilePath(destinationPath);
            await BlobUtility.DeleteBlob(connectionString, filePath);

            return(destinationPath);
        }
Пример #5
0
        public void RemoveBlob()
        {
            AnonymizeUser.BlobUtility blobUtility = new BlobUtility();

            if (blobUtility.BlobExists(CONTAINER, FILENAME))
            {
                blobUtility.DeleteBlob(CONTAINER, FILENAME);
            }

            Assert.IsFalse(blobUtility.BlobExists(CONTAINER, FILENAME));
        }
 public SignShopController(
     IHttpClientFactory clientFactory,
     IOptions <StorageAccountOptions> storageAccountOptions)
 {
     _clientFactory         = clientFactory;
     _httpClient            = _clientFactory.CreateClient(ApiClient);
     _storageAccountOptions = storageAccountOptions.Value;
     _blobUtility           = new BlobUtility(
         _storageAccountOptions.StorageAccountNameOption,
         _storageAccountOptions.StorageAccountKeyOption);
 }
Пример #7
0
        public void AddBlob()
        {
            string path = string.Concat(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, @"\data\test.jpg");

            AnonymizeUser.BlobUtility blobUtility = new BlobUtility();

            blobUtility.DeleteBlob(CONTAINER, FILENAME);
            Assert.IsFalse(blobUtility.BlobExists(CONTAINER, FILENAME));

            blobUtility.AddBlob(CONTAINER, path);
            Assert.IsTrue(blobUtility.BlobExists(CONTAINER, FILENAME));
        }
        public void OnGet(string projectname, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                Response.Redirect(Startup.ErrorImage);
            }
            else
            {
                if (Startup.MemCacheUrlPool.ContainsKey("0_0_" + id))
                {
                    try
                    {
                        var tmpSign = Startup.MemCacheUrlPool.GetValueOrDefault("0_0_" + id);

                        if (tmpSign.UTCExpire > DateTime.UtcNow)
                        {
                            Response.Redirect(tmpSign.Url);
                        }
                        else
                        {
                            Startup.MemCacheUrlPool.TryRemove("0_0_" + id, out _);
                        }
                    }
                    catch
                    {
                    }
                }


                var res          = BlobUtility.IsFileExisted(id + ".gif", projectname.Trim().ToUpper());
                var _keepseconds = Startup.GetProjectKeepSeconds(projectname.Trim().ToUpper());
                if (res)
                {
                    var      path      = "";
                    var      para      = "";
                    DateTime checkDate = DateTime.UtcNow;
                    BlobUtility.GetUriAndPermission(id + ".gif", out path, out para, out checkDate, _keepseconds, projectname);

                    Startup.MemCacheUrlPool.TryRemove("0_0_" + id, out _);
                    var tmpCache = new Models.CacheInfo {
                        Url = path + para, UTCExpire = checkDate
                    };
                    Startup.MemCacheUrlPool.TryAdd("0_0_" + id, tmpCache);

                    Response.Redirect(path + para);
                }
                else
                {
                    Response.Redirect(Startup.NotFoundImage);
                }
            }
        }
Пример #9
0
        // TODO - add new cases for adhesive w/ and w/o corrplast, and plasticore options ---- Could have made option value property...

        public SalesController(
            SignInManager <IdentityUser> signInManager,
            UserManager <IdentityUser> userManager,
            IHttpClientFactory clientFactory,
            ISalesService salesService,
            IOptions <StorageAccountOptions> storageAccountOptions)
        {
            _signInManager         = signInManager;
            _userManager           = userManager;
            _clientFactory         = clientFactory;
            _httpClient            = _clientFactory.CreateClient(ApiClient);
            _salesService          = salesService;
            _storageAccountOptions = storageAccountOptions.Value;
            _blobUtility           = new BlobUtility(
                _storageAccountOptions.StorageAccountNameOption,
                _storageAccountOptions.StorageAccountKeyOption);
        }
        public async Task <string> DeleteAll(string destinationPath)
        {
            string connectionStringRef = Configuration[ConfigSettingName_RuntimeStorageConnectionString];
            string connectionString    = await KeyVaultClient.ResolveSecretUriAsync(connectionStringRef);

            var filePath = NormalizeFilePath(destinationPath);

            if (Uri.TryCreate(destinationPath, UriKind.Absolute, out var uri))
            {
                await BlobUtility.DeleteAllBlobsInAContainer(connectionString, uri.UserInfo, uri.PathAndQuery.TrimStart('/'));
            }
            else
            {
                throw new ArgumentException($"Malformed Uri for output:'{destinationPath}'");
            }
            return(destinationPath);
        }
Пример #11
0
        public void OnGet(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                Response.Body.Write(System.Text.Encoding.UTF8.GetBytes(
                                        JsonConvert.SerializeObject(new Models.ImageInfo {
                    Id = "ERROR", Tag = "NULL ID"
                })
                                        ));
            }
            else
            {
                var res = BlobUtility.IsFileExisted(id + ".gif");

                if (res)
                {
                    try
                    {
                        var info = BlobUtility.ReadInfoFromBlob(id);
                        Response.Body.Write(System.Text.Encoding.UTF8.GetBytes(
                                                JsonConvert.SerializeObject(info)
                                                ));
                    }
                    catch (Exception ex)
                    {
                        Response.Body.Write(System.Text.Encoding.UTF8.GetBytes(
                                                JsonConvert.SerializeObject(new Models.ImageInfo {
                            Id = "ERROR", Tag = ex.Message.Replace("\"", "").Replace("'", "")
                        })
                                                ));
                    }
                }
                else
                {
                    Response.Body.Write(System.Text.Encoding.UTF8.GetBytes(
                                            JsonConvert.SerializeObject(new Models.ImageInfo {
                        Id = "ERROR", Tag = "NOT EXISTED"
                    })
                                            ));
                }
            }
        }
        public void OnGet(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                Response.Redirect("https://upload.wikimedia.org/wikipedia/commons/thumb/5/57/Blue_Screen_of_Death.png/800px-Blue_Screen_of_Death.png");
            }
            else
            {
                var res = BlobUtility.IsFileExisted(id + ".gif");

                if (res)
                {
                    var path = "";
                    var para = "";
                    BlobUtility.GetUriAndPermission(id + ".gif", out path, out para, Startup.UserTokenLifeSeconds);
                    Response.Redirect(path + para);
                }
                else
                {
                    Response.Redirect("https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/600px-No_image_available.svg.png");
                }
            }
        }
Пример #13
0
        public void OnGet(string projectname, string id)
        {
            var syncIOFeature = HttpContext.Features.Get <IHttpBodyControlFeature>();

            if (syncIOFeature != null)
            {
                syncIOFeature.AllowSynchronousIO = true;
            }


            if (string.IsNullOrEmpty(id))
            {
                Response.Body.Write(System.Text.Encoding.UTF8.GetBytes(
                                        JsonConvert.SerializeObject(new Models.ImageInfo {
                    Id = "ERROR", Tag = "NULL ID"
                })
                                        ));


                return;
            }

            if (string.IsNullOrEmpty(projectname))
            {
                Response.Body.Write(System.Text.Encoding.UTF8.GetBytes(
                                        JsonConvert.SerializeObject(new Models.ImageInfo {
                    Id = "ERROR", Tag = "NULL PROJECTNAME"
                })
                                        ));

                return;
            }


            Response.Redirect(BlobUtility.GetImageInfo(projectname.Trim().ToUpper(), id));
        }
Пример #14
0
 public ImagesController(IOptions <StorageAccountOptions> options)
 {
     _blobUtility = new BlobUtility(options.Value.StorageAccountNameOption, options.Value.StorageAccountKeyOption);
 }
 public PersonController()
 {
     utility = new BlobUtility(AccountName, AccountKey);
 }
 public UserMediaController(UserManager <ApplicationUser> userManager, ApplicationDbContext context)
 {
     _userManager = userManager;
     _context     = context;
     utility      = new BlobUtility(accountName, accountKey);
 }
Пример #17
0
        public void OnGet(string id, string w, string h)
        {
            if (string.IsNullOrEmpty(id))
            {
                Response.Redirect("https://upload.wikimedia.org/wikipedia/commons/thumb/5/57/Blue_Screen_of_Death.png/800px-Blue_Screen_of_Death.png");
            }

            var res = BlobUtility.IsFileExisted(id + ".gif");

            if (res)
            {
                int.TryParse(w, out _w);
                int.TryParse(h, out _h);


                #region  原圖處理 : _w=0 , _h=0


                if (_w == 0 && _h == 0)
                {
                    Response.Redirect("/source/" + id);
                    return;
                }

                #endregion



                if (BlobUtility.IsFileExisted(id + ".gif", "thumbs/" + w + "_" + h))
                {
                    var path = "";
                    var para = "";
                    BlobUtility.GetUriAndPermission(id + ".gif", out path, out para, Startup.UserTokenLifeSeconds, "thumbs/" + w + "_" + h);
                    Response.Redirect(path + para);
                }

                #region  寬圖處理 : _w>0 , _h=0

                var source = BlobUtility.DownloadFileFromBlob(id + ".gif");
                var info   = BlobUtility.ReadInfoFromBlob(id);

                var random = NUlid.Ulid.NewUlid().ToString().ToLower();

                System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "thumbswap");
                if (_w > 0 && _h == 0)
                {
                    var thumbHandler = new ImageUtility();
                    var source2      = thumbHandler.MakeThumbnail(source, _w, _h, "W");
                    thumbHandler.ImageSaveFile(source2, AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", info.Extension);
                    BlobUtility.UpoloadImage(id, AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", "thumbs/" + w + "_" + h);
                    source.Dispose();
                    source2.Dispose();
                }

                #endregion


                #region  高圖處理 : _w=0 , _h>0

                else if (_w == 0 && _h > 0)
                {
                    var thumbHandler = new ImageUtility();
                    var source2      = thumbHandler.MakeThumbnail(source, _w, _h, "H");
                    thumbHandler.ImageSaveFile(source2, AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", info.Extension);
                    BlobUtility.UpoloadImage(id, AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", "thumbs/" + w + "_" + h);
                    source.Dispose();
                    source2.Dispose();
                }

                #endregion

                #region  強迫處理 : _w>0 , _h>0

                else if (_w > 0 && _h > 0)
                {
                    var thumbHandler = new ImageUtility();
                    var source2      = thumbHandler.MakeThumbnail(source, _w, _h, "WH");
                    thumbHandler.ImageSaveFile(source2, AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", info.Extension);
                    BlobUtility.UpoloadImage(id, AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", "thumbs/" + w + "_" + h);
                    source.Dispose();
                    source2.Dispose();
                }


                var tmpPath = "";
                var tmpPara = "";
                BlobUtility.GetUriAndPermission(id + ".gif", out tmpPath, out tmpPara, Startup.UserTokenLifeSeconds, "thumbs/" + w + "_" + h);

                System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif");
                Response.Redirect(tmpPath + tmpPara);

                #endregion
            }
            else
            {
                Response.Redirect("https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/600px-No_image_available.svg.png");
            }
        }
Пример #18
0
 public ContractController()
 {
     manager = new UserManager <ContractUser>(new UserStore <ContractUser>(db));
     //Mosaab: ....Files Blob
     utility = new BlobUtility(accountName, accountKey);
 }
        public string Post([FromForm] string token, [FromForm] string tag, [FromForm] string filename, IFormFile file)
        {
            if (string.IsNullOrEmpty(token))
            {
                return("error:token null");
            }

            if (token != Startup.ServerToekn)
            {
                return("error:token error");
            }

            var    myulid      = NUlid.Ulid.NewUlid();
            string newFileName = myulid.ToString();

            if (!string.IsNullOrEmpty(filename))
            {
                newFileName = filename;
            }
            newFileName = newFileName.ToLower();

            Stream readStream = file.OpenReadStream();

            byte[] fileData = new byte[file.Length];

            readStream.Read(fileData, 0, fileData.Length);


            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "swapupload");
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "info");

            System.IO.File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "swapupload" + Path.DirectorySeparatorChar + newFileName + ".gif", fileData);
            readStream.Dispose();
            Image source;

            try
            {
                source = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "swapupload" + Path.DirectorySeparatorChar + newFileName + ".gif");
            }
            catch
            {
                return("error:not image source");
            }

            try
            {
                //JSON
                var imgInfo = new Models.ImageInfo();
                imgInfo.Id        = newFileName;
                imgInfo.Width     = source.Width;
                imgInfo.Height    = source.Height;
                imgInfo.Extension = ImageUtility.GetImageFormat(source).ToString().ToLower();

                if (!string.IsNullOrEmpty(tag))
                {
                    imgInfo.Tag = tag;
                }
                System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "info" + Path.DirectorySeparatorChar + newFileName + ".json", JsonConvert.SerializeObject(imgInfo));
                source.Dispose();
            }
            catch (Exception ex)
            {
                return("error:" + ex.Message.Replace("\"", "").Replace("'", ""));
            }

            try
            {
                BlobUtility.UpoloadImageSource(AppDomain.CurrentDomain.BaseDirectory + "swapupload" + Path.DirectorySeparatorChar + newFileName + ".gif", newFileName);
                BlobUtility.UpoloadImageInfoSource(AppDomain.CurrentDomain.BaseDirectory + "info" + Path.DirectorySeparatorChar + newFileName + ".json", newFileName);
            }
            catch (Exception ex)
            {
                return("error:" + ex.Message.Replace("\"", "").Replace("'", ""));
            }
            try
            {
                System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + "swapupload" + Path.DirectorySeparatorChar + newFileName + ".gif");
                System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + "info" + Path.DirectorySeparatorChar + newFileName + ".json");
            }
            catch (Exception ex)
            {
                return("error:" + ex.Message.Replace("\"", "").Replace("'", ""));
            }


            return("success:" + newFileName);
        }
Пример #20
0
 public ReviewController()
 {
     utility = new BlobUtility();
 }
Пример #21
0
 public ReviewController(ITrekStoriesContext context)
 {
     db      = context;
     utility = new BlobUtility();
 }
 public HomeController()
 {
     utility = new BlobUtility(accountName, accountKey);
     db      = new ApplicationDbContext();
 }
 public PicturesController(BlobUtility blobUtility)
 {
     BlobUtility = blobUtility;
 }
        public void OnGet(string projectname, string id, string w, string h)
        {
            if (string.IsNullOrEmpty(id))
            {
                Response.Redirect(Startup.ErrorImage);
            }
            if (string.IsNullOrEmpty(projectname))
            {
                Response.Redirect(Startup.ErrorImage);
            }
            _projectname = projectname.Trim().ToUpper();

            var res = BlobUtility.IsFileExisted(id + ".gif", _projectname);

            if (res)
            {
                _keepseconds = Startup.GetProjectKeepSeconds(_projectname);
                int.TryParse(w, out _w);
                int.TryParse(h, out _h);



                #region  原圖處理 : _w=0 , _h=0


                if (_w == 0 && _h == 0)
                {
                    if (_keepseconds <= 0)
                    {
                        Response.Redirect("/source/" + _projectname + id);
                        return;
                    }
                    else
                    {
                        Response.Redirect("/source/" + _projectname + "/" + id + "/" + _keepseconds);
                        return;
                    }
                }

                #endregion

                #region PreHanlder Check Cache

                if (Startup.MemCacheUrlPool.ContainsKey(w + "_" + h + "_" + id))
                {
                    try
                    {
                        var tmpSign = Startup.MemCacheUrlPool.GetValueOrDefault(w + "_" + h + "_" + id);

                        if (tmpSign.UTCExpire > DateTime.UtcNow)
                        {
                            Response.Redirect(tmpSign.Url);
                        }
                        else
                        {
                            Startup.MemCacheUrlPool.TryRemove(w + "_" + h + "_" + id, out _);
                        }
                    }
                    catch
                    {
                    }
                }

                #endregion


                if (BlobUtility.IsFileExisted(id + ".gif", _projectname, "thumbs/" + w + "_" + h))
                {
                    var      path      = "";
                    var      para      = "";
                    DateTime checkDate = DateTime.UtcNow;
                    BlobUtility.GetUriAndPermission(id + ".gif", out path, out para, out checkDate, _keepseconds, _projectname, "thumbs/" + w + "_" + h);

                    //Create Cache
                    Startup.MemCacheUrlPool.TryRemove(w + "_" + h + "_" + id, out _);
                    var tmpCache = new Models.CacheInfo {
                        Url = path + para, UTCExpire = checkDate
                    };
                    Startup.MemCacheUrlPool.TryAdd(w + "_" + h + "_" + id, tmpCache);

                    Response.Redirect(path + para);
                }

                #region  寬圖處理 : _w>0 , _h=0

                var source = BlobUtility.DownloadFileFromBlob(_projectname, id + ".gif");
                var info   = BlobUtility.ReadInfoFromBlob(_projectname, id);

                var random = NUlid.Ulid.NewUlid().ToString().ToLower();

                System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar);
                System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap");
                if (_w > 0 && _h == 0)
                {
                    var thumbHandler = new ImageUtility();
                    var source2      = thumbHandler.MakeThumbnail(source, _w, _h, "W");
                    thumbHandler.ImageSaveFile(source2, AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", info.Extension);
                    BlobUtility.UpoloadImage(id, AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", _projectname, "thumbs/" + w + "_" + h);
                    source.Dispose();
                    source2.Dispose();
                }

                #endregion


                #region  高圖處理 : _w=0 , _h>0

                else if (_w == 0 && _h > 0)
                {
                    var thumbHandler = new ImageUtility();
                    var source2      = thumbHandler.MakeThumbnail(source, _w, _h, "H");
                    thumbHandler.ImageSaveFile(source2, AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", info.Extension);
                    BlobUtility.UpoloadImage(id, AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", _projectname, "thumbs/" + w + "_" + h);
                    source.Dispose();
                    source2.Dispose();
                }

                #endregion

                #region  強迫處理 : _w>0 , _h>0

                else if (_w > 0 && _h > 0)
                {
                    var thumbHandler = new ImageUtility();
                    var source2      = thumbHandler.MakeThumbnail(source, _w, _h, "WH");
                    thumbHandler.ImageSaveFile(source2, AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", info.Extension);
                    BlobUtility.UpoloadImage(id, AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif", _projectname, "thumbs/" + w + "_" + h);
                    source.Dispose();
                    source2.Dispose();
                }


                var tmpPath = "";
                var tmpPara = "";


                DateTime checkDate2 = DateTime.UtcNow;
                BlobUtility.GetUriAndPermission(id + ".gif", out tmpPath, out tmpPara, out checkDate2, _keepseconds, _projectname, "thumbs/" + w + "_" + h);

                //Create Cache
                Startup.MemCacheUrlPool.TryRemove(w + "_" + h + "_" + id, out _);
                var tmpCache2 = new Models.CacheInfo {
                    Url = tmpPath + tmpPara, UTCExpire = checkDate2
                };
                Startup.MemCacheUrlPool.TryAdd(w + "_" + h + "_" + id, tmpCache2);


                System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + _projectname + Path.DirectorySeparatorChar + "thumbswap" + Path.DirectorySeparatorChar + id + "_" + random + ".gif");
                Response.Redirect(tmpPath + tmpPara);

                #endregion
            }
            else
            {
                Response.Redirect(Startup.NotFoundImage);
            }
        }
Пример #25
0
 public apiVideoController(TelemetryClient telemetryClient)
 {
     _telemetryClient = telemetryClient;
     blob             = new BlobUtility("container azure", "add your public key for your blob azure");
 }
Пример #26
0
 public AccommodationController(ITrekStoriesContext context)
 {
     db      = context;
     utility = new BlobUtility();
 }
Пример #27
0
 public AccommodationController()
 {
     utility = new BlobUtility();
 }
 public UploadController(ApplicationDbContext context)
 {
     _context = context;
     blob     = new BlobUtility("container azure", "add your public key for your blob azure");
 }
Пример #29
0
        /// <summary>
        /// This is the method that gets called when the job starts running
        /// </summary>
        /// <returns></returns>
        public async Task RunAsync()
        {
            if (string.IsNullOrWhiteSpace(_config.ServiceUrl))
            {
                string errorMessage = "Server URL is not available.";
                _logger.LogError(_scenario.Description, "JobRunner ScenarioTester", new Dictionary <string, string>()
                {
                    { "scenario.errorMessage", errorMessage }
                });

                throw new InvalidOperationException(errorMessage);
            }

            using (var context = new ScenarioContext())
            {
                context[Context.ServiceUrl]    = _config.ServiceUrl;
                context[Context.ApplicationId] = KeyVault.GetSecretFromKeyvault(_config.ApplicationId);

                // The flow config needs to be saved at this location
                string blobUri = $"{_config.BlobUri}";
                context[Context.FlowConfigContent] = await Task.Run(() => BlobUtility.GetBlobContent(KeyVault.GetSecretFromKeyvault(_config.BlobConnectionString), blobUri));

                context[Context.ApplicationIdentifierUri] = _config.ApplicationIdentifierUri;
                context[Context.SecretKey]          = KeyVault.GetSecretFromKeyvault(_config.SecretKey);
                context[Context.MicrosoftAuthority] = _config.MicrosoftAuthority;

                using (_logger.BeginScope <IReadOnlyCollection <KeyValuePair <string, object> > >(
                           new Dictionary <string, object> {
                    { "scenario.Description", _scenario.Description },
                    { "scenarioCount", _scenarioCount.ToString() },
                    { "scenario.Steps", $"[{string.Join(", ", _scenario.Steps.Select(s => s.Method.Name))}]" }
                }))
                {
                    // do actual logging inside the scope. All logs inside this will have the properties from the Dictionary used in begin scope.
                    _logger.LogInformation("JobRunner ScenarioTester: " + _scenario.Description);
                }

                var results = await ScenarioResult.RunAsync(_scenario, context, _scenarioCount);

                int iterationCount = 0;

                foreach (var result in results)
                {
                    string scenarioResult = result.Failed ? "failed" : "succeeded";

                    // log failed steps.
                    foreach (var stepResult in result.StepResults.Where(r => !r.Success))
                    {
                        using (_logger.BeginScope <IReadOnlyCollection <KeyValuePair <string, object> > >(
                                   new Dictionary <string, object> {
                            { "Scenario iteration", $"Scenario iteration {_scenario.Description}.{iterationCount} " },
                            { "ScenarioResult length", scenarioResult.Length }
                        }))
                        {
                            // do actual logging inside the scope. All logs inside this will have the properties from the Dictionary used in begin scope.
                            _logger.LogInformation(_scenario.Description);
                        }

                        if (stepResult.Exception != null)
                        {
                            _logger.LogError(stepResult.Exception, _scenario.Description);
                        }
                        _logger.LogError(stepResult.Value);
                    }

                    iterationCount++;
                }

                //emit metric on how many parallel executions passed.
                using (_logger.BeginScope <IReadOnlyCollection <KeyValuePair <string, object> > >(
                           new Dictionary <string, object> {
                    { $"SuccessRate:{_scenario.Description}", $"{(long)((double)results.Count(r => !r.Failed) / _scenarioCount * 100.0)}" }
                }))
                {
                    // do actual logging inside the scope. All logs inside this will have the properties from the Dictionary used in begin scope.
                    _logger.LogInformation(_scenario.Description);
                }
            }
        }
Пример #30
0
 public UsersController()
 {
     this._service = new UsersService();
     this.utility  = new BlobUtility(accountName, accountKey);
 }