示例#1
0
        private async Task <bool> DownloadVideosFromBlob()
        {
            da.UpdateVideoQueStatus(_renderParameters.VideoQueId, VideoQueueStatus.Downloading);
            try
            {
                foreach (var file in _videoFiles.AsParallel())
                {
                    Library.WriteServiceLog("Downloading File From Azure. File Name: " + file);
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AzureStorageAccount);
                    CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer  container      = blobClient.GetContainerReference("videos-in-queue");
                    CloudBlockBlob      blockBlob      = container.GetBlockBlobReference(file);
                    await blockBlob.DownloadToFileAsync(RawFileArchivePath + "\\" + file, FileMode.Create);
                }
                da.UpdateVideoQueStatus(_renderParameters.VideoQueId, VideoQueueStatus.Downloaded);
                return(true);
            }
            catch (Exception e)
            {
                Library.WriteServiceLog("Failed to download azure blobs!");
                Library.WriteServiceLog("Exception: " + e.Message);

                RenderErrors.ReportError(ErrorSeverity.Fatal, e, "RenderVideo", "DownloadVideosFromBlob", "63", _renderParameters.ServiceId, _renderParameters.FuneralHomeName);
                HandleErrors();
                return(false);
            }
        }
        public static void DeleteResourceGroupAsync(string groupName)
        {
            Library.WriteServiceLog("Begining to delete Resource Group.");
            var isAzureVM = ConfigurationManager.AppSettings["IsAzureVM"];

            if (isAzureVM != "false")
            {
                int retries = 0;
                while (true)
                {
                    try
                    {
                        string subscriptionId = "b77561f7-eb44-46d0-af75-fa61114f3255";
                        Library.WriteServiceLog("Getting Token for azure API");
                        var token = GetAccessTokenAsync();
                        if (token != null)
                        {
                            Library.WriteServiceLog("Got token;");
                        }
                        else
                        {
                            Library.WriteServiceLog("Error getting token;");
                        }

                        TokenCredentials credential = new TokenCredentials(token.Result.AccessToken);
                        Library.WriteServiceLog("Succesfully got credential");
                        var resourceManagementClient = new ResourceManagementClient(credential)
                        {
                            SubscriptionId = subscriptionId
                        };
                        Library.WriteServiceLog("Succesfully got resource management client");
                        Library.WriteServiceLog("Deleting resource group!");
                        resourceManagementClient.ResourceGroups.Delete(groupName);
                        Library.WriteServiceLog("Successfully deleted resource group! This file shouldn't exist. And you shouldn't be reading this");
                        break;
                    }
                    catch (Exception e)
                    {
                        retries++;
                        Library.WriteServiceLog("Error Deleting Resource Group! Resource Group Name: " + groupName);
                        Library.WriteServiceLog("Error: " + e.Message);
                        Library.WriteServiceLog("Inner Exception: " + e.InnerException);
                        Library.WriteServiceLog("Retry Count: " + retries.ToString());
                        if (retries > 4)
                        {
                            string vmMachineName = System.Environment.MachineName;
                            RenderErrors.ReportError(VideoManager.Code.ErrorSeverity.Severe, e, "Error deleting resource group", "ManageResourceGroup", "DeleteResourceGroup", 0, groupName);

                            break;
                        }
                    }
                }
            }
        }
示例#3
0
 private bool FinishRenderProcess()
 {
     try
     {
         if (File.Exists(BatchFilePath + "Converting.SEM"))
         {
             File.Delete(BatchFilePath + "Converting.SEM");
         }
     }
     catch (Exception e)
     {
         RenderErrors.ReportError(ErrorSeverity.Warning, e, "Error deleting Semi File", "RenderVideo", "FinishRenderProcess", "105", _renderParameters.ServiceId, _renderParameters.FuneralHomeName);
     }
     return(true);
 }
示例#4
0
        ///<summary>
        ///Log error in config file. If errored out 3 times in a row shutdown machine
        ///</summary>
        private void HandleErrors()
        {
            string vmMachineName = System.Environment.MachineName;

            RenderErrors.ReportError(ErrorSeverity.Severe, "Video Failed To Render. Machine Name: " + vmMachineName, "RenderVideo", "HandleErrors", "662", _renderParameters.ServiceId, _renderParameters.FuneralHomeName);

            int errorCount = GlobalVariables.ErrorCount;

            da.UpdateVideoQueStatus(_renderParameters.VideoQueId, VideoManager.Models.Data.Enums.VideoQueueStatus.Error);

            var isAzureVM = ConfigurationManager.AppSettings["IsAzureVM"];

            if (isAzureVM != "false")
            {
                ManageResourceGroup.StopVirtualMachine(_renderParameters.ResourceGroupName, vmMachineName);
            }
            else
            {
                CleanUpRenderEnviroment();
            }
        }
示例#5
0
 private void DeleteVideoFilesFromQue()
 {
     foreach (var file in _videoFiles)
     {
         try
         {
             Library.WriteServiceLog("Deleting Video File: " + file + " From Azure Que Container");
             CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AzureStorageAccount);
             CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
             CloudBlobContainer  container      = blobClient.GetContainerReference("videos-in-queue");
             CloudBlockBlob      blockBlob      = container.GetBlockBlobReference(file);
             blockBlob.Delete();
             Library.WriteServiceLog("Sucessfully deleted file!");
         }
         catch (Exception e)
         {
             string errorDescrip = "Failed to delete azure blobs from videos-in-queue container!";
             RenderErrors.ReportError(ErrorSeverity.Warning, e, errorDescrip, "RenderVideo", "DeleteVideoFilesFromQue", "565", _renderParameters.ServiceId, _renderParameters.FuneralHomeName);
         }
     }
 }
        public bool SendAdminEmail(string message)
        {
            var client = new RestClient(APIPath);

            client.AddDefaultHeader("api-key", ApiKey);
            var request = new RestRequest("sendadminemail", Method.POST);

            request.AddParameter("message", message);

            var response = client.Execute(request);

            if (response != null && response.Content != null)
            {
                if (response.Content == "{\"Success\":true}")
                {
                    return(true);
                }
                string errorDescription = "Error setting video status from API Status Code: " + response.StatusCode.ToString();
                RenderErrors.ReportError(VideoManager.Code.ErrorSeverity.Severe, errorDescription, "DataAccess", "SendAdminEmail", "210", 0);
            }
            return(false);
        }
        public bool NotifyFuneralHome(int serviceId)
        {
            var client = new RestClient(APIPath);

            client.AddDefaultHeader("api-key", ApiKey);
            var request = new RestRequest("notifyfuneralhome", Method.POST);

            request.AddParameter("id", serviceId);

            var response = client.Execute(request);

            if (response != null && response.Content != null)
            {
                if (response.Content == "{\"Success\":true}")
                {
                    return(true);
                }
                string errorDescription = "Error calling NotifyFuneralHome from API! Status Code: " + response.StatusCode.ToString();
                RenderErrors.ReportError(VideoManager.Code.ErrorSeverity.Severe, errorDescription, "DataAccess", "SetVideoThumbnail", "147", serviceId);
            }
            return(false);
        }
        public bool UpdateVideoQueStatus(int id, VideoQueueStatus status)
        {
            var client = new RestClient(APIPath);

            client.AddDefaultHeader("api-key", ApiKey);
            var request = new RestRequest("updatevideoquestatus", Method.POST);

            request.AddParameter("id", id);
            request.AddParameter("status", status);

            var response = client.Execute(request);

            if (response != null && response.Content != null)
            {
                if (response.Content == "{\"Success\":true}")
                {
                    return(true);
                }
                string errorDescription = "Error setting video que status from API! Status Code: " + response.StatusCode.ToString();
                RenderErrors.ReportError(VideoManager.Code.ErrorSeverity.Warning, errorDescription, "DataAccess", "UpdateVideoQueStatus", "228", id);
            }
            return(false);
        }