public Models.VideoExportResponseModel CreateVideoExportTask(Models.VideoExportRequestModel request) { ExportKey exportKey = null; string audioFile = string.Empty; Models.VideoExportResponseModel ret = null; string exportsPhysicalPath = string.Empty, presentationExportsPhysicalPath = string.Empty, fullPhysicalPath = string.Empty; if (request != null && request.PresentationId > 0 && request.Width > 0) { exportKey = new ExportKey(request.PresentationId); exportsPhysicalPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Exports"); if (!Directory.Exists(exportsPhysicalPath)) { Directory.CreateDirectory(exportsPhysicalPath); } presentationExportsPhysicalPath = Path.Combine(exportsPhysicalPath, request.PresentationId.ToString()); if (!Directory.Exists(presentationExportsPhysicalPath)) { Directory.CreateDirectory(presentationExportsPhysicalPath); } fullPhysicalPath = Path.Combine(presentationExportsPhysicalPath, string.Format("{0}.mp4", exportKey.ToString())); audioFile = !string.IsNullOrEmpty(request.Audio) ? Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Uploads"), request.Audio) : string.Empty; if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ExportProviderUrl"])) { fullPhysicalPath = string.Format(@"C:\Apps\Ifly\Ifly.ExportProvider\App_Data\Exports\{0}.mp4", exportKey.ToString()); if (!string.IsNullOrEmpty(audioFile)) { audioFile = string.Format(@"C:\Apps\Ifly\Ifly.ExportProvider\App_Data\Uploads\{0}", System.IO.Path.GetFileName(audioFile)); } } ret = new Models.VideoExportResponseModel() { Key = exportKey.ToString() }; MessageQueueManager.Current.GetQueue(MessageQueueType.Export).AddMessages(new Message[] { new Message() { Id = System.Guid.NewGuid().ToString(), Body = new GenericMessageBody ( new Tuple <string, string>("PresentationId", request.PresentationId.ToString()), new Tuple <string, string>("Width", request.Width.ToString()), new Tuple <string, string>("OutputFile", fullPhysicalPath), new Tuple <string, string>("AudioFile", audioFile) ).ToString() } }); NotifyAboutVideoExport(request.PresentationId); } return(ret); }
public Models.ImageExportStatusResponseModel GetImageExportStatus(string key) { bool completed = false; ExportKey exportKey = null; string extension = string.Empty; string extraData = string.Empty; string providerUrl = string.Empty; string fullPhysicalPath = string.Empty; Models.ImageExportStatusResponseModel ret = null; if (ExportKey.TryParse(key, out exportKey)) { if (DateTime.UtcNow.Subtract(exportKey.Created).TotalSeconds >= 1000) { ret = new Models.ImageExportStatusResponseModel() { Key = exportKey.ToString(), Success = false }; } else { extension = Enum.GetName(typeof(Models.ImageExportFormat), exportKey.Format).ToLowerInvariant(); providerUrl = System.Configuration.ConfigurationManager.AppSettings["ExportProviderUrl"]; if (!string.IsNullOrEmpty(providerUrl) && Ifly.Utils.WebResource.QueryStatus(string.Format("{0}/status?key={1}", providerUrl.TrimEnd('/'), System.Web.HttpContext.Current.Server.UrlEncode(exportKey.ToString())), out extraData) == HttpStatusCode.OK) { completed = true; } else { fullPhysicalPath = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/App_Data/Exports/{0}/{1}.{2}", exportKey.PresentationId, exportKey.ToString(), extension)); if (File.Exists(fullPhysicalPath)) { completed = true; } } if (completed) { ret = new Models.ImageExportStatusResponseModel() { Key = exportKey.ToString(), Success = true }; } } } return(ret); }
public Models.ImageExportResponseModel CreateImageExportTask(Models.ImageExportRequestModel request) { ExportKey exportKey = null; Models.ImageExportResponseModel ret = null; string extension = Enum.GetName(typeof(Models.ImageExportFormat), request.Format).ToLowerInvariant(); string exportsPhysicalPath = string.Empty, presentationExportsPhysicalPath = string.Empty, fullPhysicalPath = string.Empty; if (request != null && request.PresentationId > 0 && request.Slide >= 0 && request.Width > 0) { exportKey = new ExportKey(request.PresentationId, request.Format); exportsPhysicalPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Exports"); if (!Directory.Exists(exportsPhysicalPath)) { Directory.CreateDirectory(exportsPhysicalPath); } presentationExportsPhysicalPath = Path.Combine(exportsPhysicalPath, request.PresentationId.ToString()); if (!Directory.Exists(presentationExportsPhysicalPath)) { Directory.CreateDirectory(presentationExportsPhysicalPath); } fullPhysicalPath = Path.Combine(presentationExportsPhysicalPath, string.Format("{0}.{1}", exportKey.ToString(), extension)); if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ExportProviderUrl"])) { fullPhysicalPath = string.Format(@"C:\Apps\Ifly\Ifly.ExportProvider\App_Data\Exports\{0}.{1}", exportKey.ToString(), extension); } ret = new Models.ImageExportResponseModel() { Key = exportKey.ToString() }; MessageQueueManager.Current.GetQueue(MessageQueueType.Export).AddMessages(new Message[] { new Message() { Id = System.Guid.NewGuid().ToString(), Body = new GenericMessageBody ( new Tuple <string, string>("PresentationId", request.PresentationId.ToString()), new Tuple <string, string>("Slide", request.Slide.ToString()), new Tuple <string, string>("TotalSlides", request.TotalSlides.ToString()), new Tuple <string, string>("Width", request.Width.ToString()), new Tuple <string, string>("OutputFile", fullPhysicalPath) ).ToString() } }); NotifyAboutImageExport(request.PresentationId, request.Slide); } return(ret); }
/// <summary> /// Tries to parse the given key. /// </summary> /// <param name="input">Input string.</param> /// <param name="result">Result.</param> /// <returns>Value indicating whether key was parsed.</returns> public static bool TryParse(string input, out ExportKey result) { bool ret = false; long created = 0; int presentationId = -1; string[] components = null; Guid correlationId = Guid.Empty; Models.ImageExportFormat format = Models.ImageExportFormat.JPG; result = null; if (string.IsNullOrWhiteSpace(input) || string.Compare(input, "null", true) == 0) { ret = true; result = new ExportKey(-1, Models.ImageExportFormat.JPG) { CorrelationId = string.Empty, Created = DateTime.MinValue }; } else { components = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (components != null && components.Length > 3) { if (long.TryParse(components[0], out created) && int.TryParse(components[1], out presentationId) && Guid.TryParse(components[2], out correlationId) && Enum.TryParse <Models.ImageExportFormat>(components[3], out format)) { ret = true; result = new ExportKey(presentationId, format) { CorrelationId = correlationId.ToString(), Created = new DateTime(created, DateTimeKind.Utc) }; } } } return(ret); }
public Models.VideoExportStatusResponseModel GetVideoExportStatus(string key, string continuation = null, string task = null) { bool completed = false; ExportKey exportKey = null; string extraData = string.Empty; string providerUrl = string.Empty; string fullPhysicalPath = string.Empty; Models.VideoExportStatusResponseModel ret = null; if (ExportKey.TryParse(key, out exportKey)) { if (DateTime.UtcNow.Subtract(exportKey.Created).TotalSeconds >= 1000 && string.Compare(task ?? string.Empty, "publish", true) != 0) { ret = new Models.VideoExportStatusResponseModel() { Key = exportKey.ToString(), Success = false }; } else { providerUrl = System.Configuration.ConfigurationManager.AppSettings["ExportProviderUrl"]; if (!string.IsNullOrEmpty(providerUrl) && Ifly.Utils.WebResource.QueryStatus(string.Format("{0}/status?key={1}", providerUrl.TrimEnd('/'), System.Web.HttpContext.Current.Server.UrlEncode(exportKey.ToString())), out extraData) == HttpStatusCode.OK) { if (string.IsNullOrEmpty(continuation)) { completed = true; } else { Ifly.Utils.WebResource.FireAndForget(string.Format("{0}/continue?key={1}&continuation={2}", providerUrl.TrimEnd('/'), System.Web.HttpContext.Current.Server.UrlEncode(exportKey.ToString()), System.Web.HttpContext.Current.Server.UrlEncode(continuation))); ret = new Models.VideoExportStatusResponseModel() { Task = "publish" }; } } else { fullPhysicalPath = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/App_Data/Exports/{0}/{1}.mp4", exportKey.PresentationId, exportKey.ToString())); if (File.Exists(fullPhysicalPath)) { if (string.IsNullOrEmpty(continuation)) { completed = true; } else { Ifly.ServiceAdapter.VideoPublishBroker.CreateVideoPublishTask(fullPhysicalPath, continuation); ret = new Models.VideoExportStatusResponseModel() { Task = "publish" }; } } else { if (!string.IsNullOrEmpty((extraData = Ifly.ServiceAdapter.VideoPublishBroker.GetVideoPublishStatus(fullPhysicalPath)))) { completed = true; } } } if (completed) { ret = new Models.VideoExportStatusResponseModel() { Key = exportKey.ToString(), ExtraData = extraData, Success = true }; } } } return(ret); }