private bool GetDocument(string documentID, out SystemEvent systemEvent)
 {
     systemEvent = null;
     try
     {
         var storageMan = new AzureStorageManager(ConfigurationManager.AppSettings["AzureStorageConnectionString"]);
         var table      = storageMan.GetTableReference(ConfigurationManager.AppSettings["TableName"]);
         var splitID    = SystemEvent.DecodeIDToPartitionAndRowKey(documentID);
         var op         = TableOperation.Retrieve <SystemEvent>(splitID.Item1, splitID.Item2);
         var doc        = table.Execute(op);
         if (doc == null)
         {
             return(false);
         }
         systemEvent           = (SystemEvent)doc.Result;
         ViewBag.pageException = HelperMethods.FormatException(systemEvent.CaughtException);
         ViewBag.objectDump    = HelperMethods.GetObjectDump(systemEvent.OperationParameters);
         return(true);
     }
     catch (Exception ex)
     {
         ViewBag.pageException = HelperMethods.FormatException(ex);
         return(false);
     }
 }
 /// <summary>
 /// Delete current selected file
 /// </summary>
 public async void DeleteSelectedFile()
 {
     try
     {
         if (!info.CanModifyFile)
         {
             PopUpWarning("Please Select a file!");
             return;
         }
         requestMessage = "Send request: Delete selected file";
         if (await AzureStorageManager.DeleteBlob(info.Container, SelectedFile, LogEvent) == true)
         {
             PopUpWarning("Send request: Delete selected file\n" + "Delete successfully!");
             DeleteBlobOnDataBaseOnVersion(ParseFilenameToVersion(SelectedFile));
         }
         else
         {
             PopUpWarning("Failed to delete!");
         }
     }
     catch (StorageException ex)
     {
         PopUpWarning(ex.Message);
     }
     finally
     {
         ClearRightClickMenu();
         RefreshPage();
     }
 }
 /// <summary>
 /// Paste the file according to the infomation in main scriptable object info to the current directory.
 /// If current directory is container, the paste button is inactive.
 /// </summary>
 public async void PasteAfterCut()
 {
     try
     {
         requestMessage = "Send request: create a container";
         if (await AzureStorageManager.CopyAndPasteBlob(info.CopyedContainer, info.Container, info.CopyedFilePath + info.CopyedFileName, info.AbsolutePath + info.CopyedFileName, LogEvent) == true)
         {
             PopUpWarning("Paste file successfully. Notice: move files in Azure storage may lose track of file from database.");
         }
         else
         {
             PopUpWarning("Name is invalid or already existed.");
         }
     }
     catch (StorageException ex)
     {
         PopUpWarning(ex.Message);
     }
     finally
     {
         info.Pasted();
         ClearRightClickMenu();
         RefreshPage();
     }
 }
Beispiel #4
0
 public AccountController(IUserManager userManger, INationalityManager nationalityManger, IGenderManager genderManager, ISessionHelper sessionHelper)
 {
     _userManger         = userManger;
     _nationalityManager = nationalityManger;
     _genderManager      = genderManager;
     _sessionHelper      = sessionHelper;
     _azureManager       = new AzureStorageManager();
 }
        public async Task <IActionResult> Get(string id)
        {
            AzureStorageManager azStorageMgr = new AzureStorageManager(Globals.GetAppSetting("STORAGECONNECTIONSTRING"), "BdpFamilySanitizer");

            DesignAutomationRecord[] dar = await azStorageMgr.ReadAutomationRecord(_logTable, id);

            return(Ok(dar));
        }
Beispiel #6
0
        public async Task UpdateRouteFileAsync(string name, RouteModel route)
        {
            route.ProcessDate = DateTime.UtcNow;

            var storageConnectionString = Environment.GetEnvironmentVariable("StorageConnectionString");

            var azureStorageManager = new AzureStorageManager(storageConnectionString);

            await azureStorageManager.StoreObject("routes", name, route);
        }
        public async Task <IActionResult> Put(string id, [FromBody] string status)
        {
            AzureStorageManager azStorageMgr = new AzureStorageManager(Globals.GetAppSetting("STORAGECONNECTIONSTRING"), "BdpFamilySanitizer");

            DesignAutomationRecord[] dar = await azStorageMgr.ReadAutomationRecord(_logTable, id);

            IActionResult res = await azStorageMgr.UpdateLoggedWorkItemStatus(status, dar.First <DesignAutomationRecord>(), _logTable);

            return(res);
        }
Beispiel #8
0
        public override bool OnStart()
        {
            //Create Manager
            asManager = new AzureStorageManager(RoleEnvironment.GetConfigurationSettingValue(Constants.stringName));

            ServicePointManager.DefaultConnectionLimit = 12;

            Trace.TraceInformation("WorkerRole has been started");

            return(base.OnStart());
        }
Beispiel #9
0
        public FileStorageController()
        {
            CloudStorageAccount cloudStorageAccount;

            if (CloudStorageAccount.TryParse(
                    ConfigurationManager.ConnectionStrings["AzureStorage"].ConnectionString,
                    out cloudStorageAccount))
            {
                _azureStorageManager = new AzureStorageManager(cloudStorageAccount);
            }
        }
 /// <summary>
 /// Delete blob file on Azure storage
 /// </summary>
 /// <param name="name_Container">Name of container</param>
 /// <param name="Name_ZipPatch">Name of zipped patch file</param>
 /// <param name="onComplete">Delete OnComplete callback</param>
 public async void DeleteCloudFileByName(string name_Container, string Name_ZipPatch, Action <bool, string, string> onComplete)
 {
     try
     {
         await AzureStorageManager.DeleteBlob(name_Container, Name_ZipPatch,
                                              (bool result) => onComplete(result, "Successfully delete file " + Name_ZipPatch, "Failed to delete file " + Name_ZipPatch));
     }
     catch (Exception ex)
     {
         PrintError("Name of file is not specified. Error message: " + ex.Message);
     }
 }
 /// <summary>
 /// Delete container on Azure Storage
 /// </summary>
 /// <param name="name_Container">Name of container</param>
 /// <param name="onComplete">Delete OnComplete callback</param>
 public async void DeleteCloudDirectoryByName(string name_Container, Action <bool, string, string> onComplete)
 {
     try
     {
         await AzureStorageManager.DeleteContainer(name_Container,
                                                   (bool result) => onComplete(result, "Successfully delete directory " + name_Container, "Failed to delete directory " + name_Container));
     }
     catch (Exception ex)
     {
         PrintError("Name of container is not specified. Error message: " + ex.Message);
     }
 }
Beispiel #12
0
        private async void btnReadLog_Click(object sender, EventArgs e)
        {
            AzureStorageManager azStorageMgr = new AzureStorageManager(Environment.GetEnvironmentVariable("STORAGECONNECTIONSTRING"), "BdpFamilySanitizer");

            DesignAutomationRecord[] dars = await azStorageMgr.ReadAutomationRecord("DesignAutomationLog");

            logBox.Items.Clear();
            foreach (DesignAutomationRecord dar in dars)
            {
                logBox.Items.Add($"{dar.WorkItemId}  {dar.InputModelName} { dar.InputSource} {dar.WorkItemStatus}");
            }
        }
 /// <summary>
 /// Create a container by give name with callback when complete
 /// </summary>
 /// <param name="name_Container">name of container</param>
 /// <param name="onComplete">Error Message callback function</param>
 public async void CreateFolderOnCloud(string name_Container, Action <bool, string, string> onComplete)
 {
     try
     {
         await AzureStorageManager.CreateContainer(name_Container,
                                                   (bool result) => onComplete(result, "Create folder " + name_Container + " successfully.", "Failed to create folder " + name_Container));
     }
     catch (Exception ex)
     {
         PrintError("Name of container is not specified. Error message: " + ex.Message);
     }
 }
        private async Task CreateAudioFileInWowza(Guid hearingRefId)
        {
            var file = FileManager.CreateNewAudioFile("TestAudioFile.mp4", hearingRefId.ToString());

            _azureStorage = new AzureStorageManager()
                            .SetStorageAccountName(Context.Config.Wowza.StorageAccountName)
                            .SetStorageAccountKey(Context.Config.Wowza.StorageAccountKey)
                            .SetStorageContainerName(Context.Config.Wowza.StorageContainerName)
                            .CreateBlobClient(hearingRefId.ToString());

            await _azureStorage.UploadAudioFileToStorage(file);

            FileManager.RemoveLocalAudioFile(file);
        }
        public async Task TryToDeleteItemsFromAzure(params string[] filenames)
        {
            var azureManager = new AzureStorageManager();

            foreach (var filename in filenames)
            {
                try
                {
                    await azureManager.DeleteItemFromStorageIfExists(filename);
                }
                catch (Exception)
                {
                }
            }
        }
 /// <summary>
 /// Upload blob file with progress report callback and progress oncomplete callback but without updating database
 /// </summary>
 /// <param name="name_Container">Name of Container</param>
 /// <param name="Name_ZipPatchForUpload">Name of blob file</param>
 /// <param name="path_ZipPatchFiles">Path of blob file on local disk</param>
 /// <param name="blockSize">Size of datablock for uploading every excute time</param>
 /// <param name="onProgress">Upload Onprogress callback</param>
 /// <param name="OnComplete">Upload OnComplete callback</param>
 public async void UploadFileProgressivelyWithoutUpDate(string name_Container, string Name_ZipPatchForUpload, string path_ZipPatchFiles, int blockSize,
                                                        Action <double, string> onProgress, Action <string> OnComplete)
 {
     try
     {
         await AzureStorageManager.UploadFromFileProgressively(name_Container, Name_ZipPatchForUpload, path_ZipPatchFiles, blockSize,
                                                               (double percent) => onProgress(percent, "Uploading"),
                                                               () => {
             OnComplete("Uploading");
         });
     }
     catch (Exception ex)
     {
         PrintError("Name of container or Path of zip file is invalid. Error Message: " + ex.Message);
     }
 }
 /// <summary>
 /// UpateFile name by changing name in Inputfield
 /// </summary>
 public async void UpdateFileName()
 {
     try
     {
         requestMessage = "Send request: update filename";
         Debug.Log(await AzureStorageManager.UpdateBlob(info.Container, info.AbsolutePath + info.Filename, info.AbsolutePath + info.NewFilename,
                                                        LogEvent) == true ? "Update sucessfully!" : "Failed to Update!");
     }
     catch (StorageException ex)
     {
         PopUpWarning(ex.Message);
     }
     finally
     {
         RefreshPage();
     }
 }
        public async Task <IActionResult> Post([FromBody] DesignAutomationRecord dar)
        {
            //Persist the activity in Azure Table Storage
            Console.WriteLine("Saving record to Azure " + dar);

            //set the queueing time
            dar.TimeQueued = DateTime.UtcNow;

            //set a unique id
            dar.RowKey = Guid.NewGuid().ToString();

            //log the operation
            AzureStorageManager azStorageMgr = new AzureStorageManager(Globals.GetAppSetting("STORAGECONNECTIONSTRING"), "BdpFamilySanitizer");

            _ = await azStorageMgr.SaveAutomationRecord(_logTable, dar);

            return(Ok());
        }
 /// <summary>
 /// delete current selected container
 /// </summary>
 public async void DeleteContainer()
 {
     try
     {
         requestMessage = "Send request: Delete selected Container";
         PopUpWarning("Send request: 'Delete selected Container'\n" + (await AzureStorageManager.DeleteContainer(info.CurrentSelectedContainer,
                                                                                                                 LogEvent) == true ? "Delete sucessfully!" : "Failed to delete!"));
     }
     catch (StorageException ex)
     {
         PopUpWarning(ex.Message);
     }
     finally
     {
         info.CurrentSelectedContainer = "";
         RefreshPage();
         ResetNewContainer();
     }
 }
 /// <summary>
 /// Upload blob file with progress report callback and progress oncomplete callback
 /// </summary>
 /// <param name="name_Container">Name of Container</param>
 /// <param name="Name_ZipPatchForUpload">Name of blob file</param>
 /// <param name="path_ZipPatchFiles">Path of blob file on local disk</param>
 /// <param name="blockSize">Size of datablock for uploading every excute time</param>
 /// <param name="versionOne">Version number of old patch number</param>
 /// <param name="versionTwo">Version number of latest patch number</param>
 /// <param name="onProgress">Upload Onprogress callback</param>
 /// <param name="OnComplete">Upload OnComplete callback</param>
 public async void UploadFileProgressively(string name_Container, string Name_ZipPatchForUpload, string path_ZipPatchFiles, int blockSize,
                                           string versionOne, string versionTwo, Action <double, string> onProgress, Action <string> OnComplete)
 {
     try
     {
         await AzureStorageManager.UploadFromFileProgressively(name_Container, Name_ZipPatchForUpload, path_ZipPatchFiles, blockSize,
                                                               (double percent) => onProgress(percent, "Uploading"),
                                                               () => {
             OnComplete("Uploading");
             Debug.Log("Trying to update info on database, but links to database had been removed.");
             //AzureRestPatchAPI patchAPI = new AzureRestPatchAPI(AzureRestClient.UrlEndpoint + AzureRestClient.AddPatchEndpoint, AzureRestAPI.HttpVerb.POST);
             //patchAPI.UploadingPatch(versionOne, versionTwo, FileHelper.FindMD5(path_ZipPatchFiles), GetSizeOfFile(path_ZipPatchFiles), name_Container, Name_ZipPatchForUpload);
         });
     }
     catch (Exception ex)
     {
         PrintError("Name of container or Path of zip file is invalid. Error message: " + ex.Message);
     }
 }
        public static void RemoveAudioFiles(TestContext context, ScenarioContext scenario)
        {
            if (!scenario.ScenarioInfo.Tags.Contains("AudioRecording"))
            {
                return;
            }
            if (context?.VideoWebConfig == null)
            {
                return;
            }
            if (context.Test.NewHearingId == Guid.Empty)
            {
                return;
            }
            var storage = new AzureStorageManager()
                          .SetStorageAccountName(context.VideoWebConfig.Wowza.StorageAccountName)
                          .SetStorageAccountKey(context.VideoWebConfig.Wowza.StorageAccountKey)
                          .SetStorageContainerName(context.VideoWebConfig.Wowza.StorageContainerName)
                          .CreateBlobClient(context.Test.NewHearingId.ToString());

            storage.RemoveAudioFileFromStorage();
        }
Beispiel #22
0
        public async Task CaptureScreenshotAsync(string routeId, LinkModel link)
        {
            try
            {
                bool enableScreenshots = bool.Parse(Environment.GetEnvironmentVariable("EnableScreenshots"));

                if (enableScreenshots)
                {
                    var           applicationKey    = Environment.GetEnvironmentVariable("GrabzitApplicationKey");
                    var           applicationSecret = Environment.GetEnvironmentVariable("GrabzitApplicationSecret");
                    GrabzItClient grabzIt           = new GrabzItClient(applicationKey, applicationSecret);

                    var imageOptions = new ImageOptions
                    {
                        Format = ImageFormat.jpg
                    };

                    grabzIt.URLToImage(link.Target, imageOptions);

                    var file = grabzIt.SaveTo();

                    var azManager = new AzureStorageManager(Environment.GetEnvironmentVariable("StorageConnectionString"));

                    var screenshotFileName = $"{routeId}-{Guid.NewGuid()}.jpg";

                    await azManager.StoreFile("screenshots", screenshotFileName, file.Bytes);

                    link.ScreenshotFileName = screenshotFileName;

                    _logger.LogInformation($"Saved Link Screenshot: {screenshotFileName}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to process screenshot: {ex.Message}");

                throw ex;
            }
        }
 /// <summary>
 /// Create container from right click menu and pop-up window
 /// </summary>
 public async void CreateContainerOnAzure()
 {
     try
     {
         requestMessage = "Send request: create a container";
         if (await AzureStorageManager.CreateContainer(info.NewContainer, LogEvent) == true)
         {
             OpenInputPage();
         }
         else
         {
             PopUpWarning("Name is invalid or already existed.");
         }
     }
     catch (StorageException ex)
     {
         PopUpWarning(ex.Message);
     }
     finally
     {
         RefreshPageOnGoUp();
         ResetNewContainer();
     }
 }
        public async Task UploadToBlobStorage(IEnumerable <TemporaryPictureObject> picture)
        {
            var azureManager = new AzureStorageManager();

            await Task.WhenAll(picture.Select(pic => azureManager.UploadFile(pic.FileName, pic.Data)).ToList());
        }
            public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
            {
                EventProcInfo[id] = TimeStampThis("Processing");
                var parsedData = messages.Select(eventData => Encoding.UTF8.GetString(eventData.GetBytes())).Select(JsonConvert.DeserializeObject <SystemEvent>).ToList();

                if (Engine.EngineIsRunning)
                {
                    await Engine.AddToMainQueue(parsedData);

                    EventProcInfo[id] = TimeStampThis(parsedData.Count + " events added to engine");
                }
                else
                {
                    EventProcInfo[id] = TimeStampThis("Engine is not running. Cannot add events. Aborting.");
                    return;
                }
                try
                {
                    var        storageMan = new AzureStorageManager(CloudConfigurationManager.GetSetting("AzureStorageConnectionString"));
                    CloudTable Table      = storageMan.GetTableReference(ConfigurationManager.AppSettings["OperationStorageTable"]);

                    var       batches    = new Dictionary <string, TableBatchOperation>();
                    var       batchNames = new Dictionary <string, string>();
                    const int maxOps     = Microsoft.WindowsAzure.Storage.Table.Protocol.TableConstants.TableServiceBatchMaximumOperations;
                    foreach (var operationResult in parsedData)
                    {
                        string batchName;
                        if (!batchNames.TryGetValue(operationResult.PartitionKey, out batchName))
                        {
                            batchName = operationResult.PartitionKey;
                        }
                        TableBatchOperation batchOperation;
                        if (!batches.ContainsKey(batchName))
                        {
                            batchOperation = new TableBatchOperation();
                            batches.Add(batchName, batchOperation);
                        }
                        else
                        {
                            batches.TryGetValue(batchName, out batchOperation);
                        }
                        Debug.Assert(batchOperation != null, "Could not find batchOperation in Dictionary.");

                        if (batchOperation.Count == maxOps)
                        {
                            batchOperation = new TableBatchOperation();
                            batches.Add(GetNewBatchName(operationResult.PartitionKey, batchNames), batchOperation);
                        }
                        batchOperation.Insert(operationResult);
                    }
                    EventProcInfo[id] = TimeStampThis("Running batches");
                    foreach (var batch in batches)
                    {
                        await Table.ExecuteBatchAsync(batch.Value);
                    }
                }
                catch (Exception ex) when(ex.Message.Contains("The specified entity already exists"))
                {
                    Logger.AddRow("Duplicate entry tried to be added to table storage.");
                }
                catch (Exception ex)
                {
                    EventProcInfo[id] = TimeStampThis("!ERROR! " + ex.Message);
                    Logger.AddRow("!ERROR! In event processor");
                    Logger.AddRow(ex.ToString());
                }
                finally
                {
                    EventProcInfo[id] = TimeStampThis("Setting Checkpoint");
                    await context.CheckpointAsync();

                    EventProcInfo[id] = TimeStampThis("Checkpoint set");
                }
            }
Beispiel #26
0
 public HomeController()
 {
     asManager = new AzureStorageManager(RoleEnvironment.GetConfigurationSettingValue(Constants.stringName));
 }