public TaskRegisterViewModel GetTask(Guid?idCampaign, Guid idTask, Guid idAccount) { var itemResult = new TaskRegisterViewModel(); //Creo Tarea if (idTask == Guid.Empty && idCampaign != null) { var campaign = _campaignDao.GetOne(idCampaign.Value, idAccount); itemResult.CampaignName = campaign.Name; itemResult.IdCampaign = idCampaign.Value; } //Recupero Tarea else if (idTask != Guid.Empty) { var task = _taskCampaignDao.GetTaskByIdForRegisterPage(idTask, idAccount); var campaign = _campaignDao.GetOne(task.IdCampaign, idAccount); itemResult = ConvertTask.ToTaskRegisterViewModel(task); itemResult.CampaignName = campaign.Name; itemResult.IdCampaign = task.IdCampaign; } //Mala Invocación de método else { throw new ExceptionMardis("Se ha invocado de manera incorrecta a la tarea"); } return(itemResult); }
public void Convert(ConvertTask task) { string fileName = HttpUtility.UrlDecode(task.Docx.Split('/').Last()); string localPath = $@"{_path}\{fileName}"; task.Path = localPath; _mongoRepository.Create(task); try { using (WebClient webClient = new WebClient()) { webClient.DownloadFile(task.Docx, localPath); } var targetPath = WordProcess(task, localPath, fileName); if (File.Exists(targetPath) && !string.IsNullOrEmpty(targetPath)) { _mongoRepository.ConvertSuccese(task); DeleteFile(localPath); task.Result = RetryHelper.Do(() => _s3Repository.UploadFile(targetPath, task.TaskId), TimeSpan.FromSeconds(5)); DeleteFile(targetPath); UploadSuccess(task); SendResponse(task); } } catch (Exception ex) { task.ExceptionLog = ex.Message; _mongoRepository.ConvertFailed(task); } }
private List <MyTaskItemViewModel> GetTaskList(int pageIndex, int pageSize, List <FilterValue> filters, Guid idAccount, string statusTask) { var tasks = _taskCampaignDao.GetPaginatedTasksByCampaignAndStatus(statusTask, pageIndex, pageSize, filters, idAccount); return(ConvertTask.ConvertTaskToMyTaskViewItemModel(tasks)); }
private string WordProcess(ConvertTask task, string localPath, string fileName) { string targetPath = ""; var wordApp = new Word.Application { Visible = true, DisplayAlerts = Word.WdAlertLevel.wdAlertsNone }; try { var docx = wordApp.Documents.Open(localPath); if (task.TaskType == "Doc") { targetPath = $"{_path}\\{fileName.Split('.').First()}.doc"; docx.SaveAs(targetPath, Word.WdSaveFormat.wdFormatDocument); } else if (task.TaskType == "Pdf") { targetPath = $"{_path}\\{fileName.Split('.').First()}.pdf"; docx.SaveAs(targetPath, Word.WdSaveFormat.wdFormatPDF); } } catch (Exception e) { task.ExceptionLog = e.ToString(); SendResponse(task); } finally { wordApp.Documents.Close(); wordApp.Quit(); } return(targetPath); }
public TaskPerCampaignViewModel GetTaskPerCampaignViewModel(Guid idCampaign, Guid idAccount, List <FilterValue> filters) { filters = filters ?? new List <FilterValue>(); var itemResult = new TaskPerCampaignViewModel(); filters = AddHiddenFilter("IdCampaign", idCampaign.ToString(), filters, itemResult.FilterName); itemResult = new TaskPerCampaignViewModel { IdCampaign = idCampaign, ImplementedTasksList = ConvertTask.ConvertTaskToMyTaskViewItemModel(_taskCampaignDao.GetPaginatedTasksByCampaignAndStatus( CTask.StatusImplemented, 1, int.MaxValue, filters, idAccount)), NotImplementedTasksList = ConvertTask.ConvertTaskToMyTaskViewItemModel(_taskCampaignDao.GetPaginatedTasksByCampaignAndStatus( CTask.StatusNotImplemented, 1, int.MaxValue, filters, idAccount)), PendingTasksList = ConvertTask.ConvertTaskToMyTaskViewItemModel(_taskCampaignDao.GetPaginatedTasksByCampaignAndStatus( CTask.StatusPending, 1, int.MaxValue, filters, idAccount)), StartedTasksList = ConvertTask.ConvertTaskToMyTaskViewItemModel(_taskCampaignDao.GetPaginatedTasksByCampaignAndStatus( CTask.StatusStarted, 1, int.MaxValue, filters, idAccount)) }; return(ConfigurePagination(itemResult, 1, int.MaxValue, filters, int.MaxValue)); }
public DashBoardViewModel GetDashBoard(DashBoardViewModel model, List <FilterValue> filters, int pageIndex, int pageSize, Guid idAccount, IDataProtector protector) { var idCampaign = string.IsNullOrEmpty(model.IdCampaign) ? Guid.Empty : Guid.Parse(protector.Unprotect(model.IdCampaign)); var totalTasks = 0; if (idCampaign != Guid.Empty) { var merchants = _userBusiness.GetMerchantsByCampaign(idCampaign, idAccount, filters, pageIndex, pageSize); //model.MerchantList = DashBoardConvert.ConvertUserListToDashBoardMerchantViewModelList(merchants); model.MerchantList = GetMerchantInformation(merchants); var campaign = _campaignBusiness.GetCampaignById(idCampaign, idAccount); var campaignDetails = _campaignBusiness.GetCampaignTaskDetails(idCampaign, idAccount); model = ConvertDashBoard.FromCampaign(model, campaign, campaignDetails); var tasks = _taskCampaignDao.GetPaginatedTasksByCampaign(pageIndex, pageSize, filters, idAccount); model.BranchList = ConvertTask.ConvertTaskListToCampaignBranchesViewModelList(tasks); totalTasks = _taskCampaignDao.GetPaginatedTasksCount(idAccount, filters); } return(ConfigurePagination(model, pageIndex, pageSize, filters, totalTasks)); }
public string ConvertToDoc([FromBody] ConvertTask task) { task.TaskType = "Doc"; MqHelper.Publish(task); return(task.TaskId); }
public bool Save(TaskRegisterViewModel model, Guid idAccount) { var task = ConvertTask.FromTaskRegisterViewModel(model); if (model.Id == Guid.Empty) { var status = _statusTaskBusiness.GeStatusTaskByName(CTask.StatusPending); task.IdStatusTask = status.Id; } task.IdAccount = idAccount; task.Branch = null; task.Campaign = null; task.Merchant = null; task.Answers = null; if (string.IsNullOrEmpty(task.Code)) { var code = _sequenceBusiness.NextSequence(CTask.SequenceCode, idAccount).ToString(); task.Code = code; } _taskCampaignDao.InsertOrUpdate(task); //SaveTask(task, idAccount); return(true); }
public object BytesToMessage(string typeName, byte[] bytes) { dynamic target = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(bytes)); ConvertTask task = new ConvertTask(target.TaskId.ToString(), target.Docx.ToString(), target.CallBack.ToString(), target.TaskType.ToString()); return(task); }
private void UploadSuccess(ConvertTask task) { if (!string.IsNullOrEmpty(task.Result)) { task.ConvertSuccess = true; _mongoRepository.Update(task); } }
public string GetBranchesByCampaign(Guid idCampaign) { var taskList = _taskCampaignBusiness.GetTasksBranchesByCampaign(idCampaign, ApplicationUserCurrent.AccountId); var resultList = ConvertTask.ConvertTaskListToCampaignBranchesViewModelList(taskList); return(JSonConvertUtil.Convert(resultList)); }
public void ConvertFailed(ConvertTask task) { var filter = Builders <ConvertTask> .Filter.Eq(c => c.TaskId, task.TaskId); var update = Builders <ConvertTask> .Update.Set(c => c.ConvertSuccess, false); _collection.UpdateOne(filter, update); }
public void HookSuccess(ConvertTask task) { var filter = Builders <ConvertTask> .Filter.Eq(c => c.TaskId, task.TaskId); var update = Builders <ConvertTask> .Update.Set(c => c.HookSuccess, true); _collection.UpdateOne(filter, update); }
public void Create(ConvertTask task) { try { _collection.InsertOne(task); } catch (Exception) { Delete(task.TaskId); Create(task); } }
private void SendResponse(ConvertTask task) { WebRequest request = WebRequest.Create(task.GetCallBackUrl()); request.ContentType = "application/json"; request.Method = "GET"; WebResponse response = RetryHelper.Do(() => request.GetResponse(), TimeSpan.FromMinutes(3)); task.HookSuccess = true; _mongoRepository.HookSuccess(task); response.Dispose(); }
//發送訊息 public static void Publish(ConvertTask task) { IBus bus = BusBuilder.CreateMessageBus(); try { bus.Publish(task); } catch (EasyNetQException ex) { throw ex; } bus.Dispose(); }
public IHttpActionResult PostTask([FromBody] TaskModel task) { if (task == null) { return(BadRequest("Task cannot be null.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _db.T_Tasks.Add(ConvertTask.T_Tasks(task)); _db.SaveChanges(); return(Ok("Task Added")); }
static void Main(string[] args) { LogManager.Instance.PutMessage("Application started"); ExcelApp.Instance.CreateWorkbook(); ExcelApp.Instance.FillHead(); ConvertTask task = new ConvertTask(); task.Execute("rates.txt"); task.Execute("rates1.txt"); task.Execute("rates2.txt"); LogManager.Instance.PutMessage("Application ended"); System.Console.ReadKey(); }
private static void BatchMergeVA(string path, bool deleteSource, string videoPattern, string[] audioPatterns, string[] resultPatterns) { var videoMatcher = new Regex(videoPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); var queue = new LinkedList <Tuple <string, string, string> > (from p in Directory.EnumerateFiles(FileHelper.GetFilePath(path), "*", SearchOption.AllDirectories) let input = p.Substring(6) let match = videoMatcher.Match(input) where match.Success let audio = (from ap in audioPatterns let ar = match.Result(ap) where File.Exists(FileHelper.GetFilePath(ar)) select ar).FirstOrDefault() where audio != null let output = (from op in resultPatterns let or = match.Result(op) where !File.Exists(FileHelper.GetFilePath(or)) select or).FirstOrDefault() where output != null select new Tuple <string, string, string>(input, audio, output)); while (queue.Count > 0) { var node = queue.First; while (node != null) { if (!FileHelper.IsReady(FileHelper.GetDataFilePath(node.Value.Item1)) || !FileHelper.IsReady(FileHelper.GetDataFilePath(node.Value.Item2))) { node = node.Next; continue; } ConvertTask.Create(node.Value.Item1, node.Value.Item3, null, "copy", "copy", null, node.Value.Item2).Execute(); if (deleteSource) { FileHelper.Delete(node.Value.Item1); FileHelper.Delete(node.Value.Item2); } var previous = node; node = node.Next; queue.Remove(previous); } Thread.Sleep(1000); } }
protected void Page_Load(object sender, EventArgs e) { if (!Request.GetUser().OperateTasks) { Response.StatusCode = 401; return; } Response.Clear(); Response.ContentType = "application/xml"; var result = new XElement("result"); var path = RouteData.GetRelativePath(); try { GeneralTask task; switch (RouteData.GetRouteString("Type").ToLowerInvariant()) { case "offline": OfflineDownloadTask.Create(Rbase64.Decode(Request.QueryString["Url"]), path); break; case "ftpupload": result.SetAttributeValue("id", (task = new FtpUploadTask(path, Request.QueryString["Files"].Split('|').Select(file => file.UrlDecode()), Request.QueryString["Target"].UrlDecode()))); task.Start(); break; case "compress": new CompressTask(path, Request.QueryString["Files"].Split('|').Select(file => file.UrlDecode()), Request.QueryString["BaseFolder"].UrlDecode(), Request.QueryString["CompressionLevel"]).Start(); break; case "decompress": result.SetAttributeValue("id", (task = new DecompressTask (path, Request.QueryString["Target"].UrlDecode())).ID); task.Start(); break; case "convert": ConvertTask.Create(path, Request.QueryString["Target"].UrlDecode(), Request.QueryString["Size"].UrlDecode(), Request.QueryString["VCodec"].UrlDecode(), Request.QueryString["ACodec"].UrlDecode(), Request.QueryString["SCodec"].UrlDecode(), Request.QueryString["AudioPath"].UrlDecode(), Request.QueryString["Start"].UrlDecode(), Request.QueryString["End"].UrlDecode()).Start(); break; case "crossappcopy": result.SetAttributeValue("id", (task = new CrossAppCopyTask( Request.QueryString["Domain"].UrlDecode(), Request.QueryString["Path"].UrlDecode(), path, Request.QueryString["Password"].UrlDecode() ?? Request.GetPassword()))); task.Start(); break; case "batchmergeva": TaskHelper.StartRunner(string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}", TaskType.BatchMergeVATask, path, Request.QueryString["DeleteSource"], Request.QueryString["VideoPattern"], Request.QueryString["ResultPattern"], Request.QueryString["AudioPatterns"])); break; default: throw new FormatException("无法识别的 Type!"); } result.SetAttributeValue("status", "ok"); } catch (Exception exc) { result.SetAttributeValue("status", "error"); result.SetAttributeValue("message", exc.GetMessage()); } Response.Write(result.ToString()); }
public void Update(ConvertTask task) { Delete(task.TaskId); Create(task); }
private static IEnumerable <ITask> ParseChildren(XmlNode parent) { if (parent == null || parent.ChildNodes.Count == 0) { return(null); } var tasks = new List <ITask>(); foreach (XmlNode child in parent.ChildNodes) { if (child.NodeType != XmlNodeType.Element) { continue; } var children = ParseChildren(child); ITask task = null; var transliteratePath = child.Attributes["transliteratePath"] != null && bool.Parse(child.Attributes["transliteratePath"].Value); switch (child.Name) { case "copy": var copy = new CopyTask(null, children, child.Attributes["target"].Value, transliteratePath); var overrideMode = OverwriteMode.Rename; if (child.Attributes["overwriteMode"] != null) { overrideMode = (OverwriteMode)Enum.Parse(typeof(OverwriteMode), child.Attributes["overwriteMode"].Value, true); } copy.OverrideMode = overrideMode; task = copy; break; case "xslt": task = new XsltTask(child.Attributes["filePathKey"].Value, null, children); break; case "crop": task = new CropTask(child.Attributes["xKey"].Value, child.Attributes["yKey"].Value, child.Attributes["widthKey"].Value, child.Attributes["heightKey"].Value, null, children); break; case "watermark": task = new WatermarkTask(child.Attributes["textKey"].Value, child.Attributes["textPositionKey"].Value, null, children); break; case "temp": task = new TempTask(null, children); break; case "delete": task = new DeleteTask(null, children, bool.Parse(child.Attributes["deleteEmptyFolders"].Value)); break; case "dpof": var targetDirectory = child.Attributes["targetDirectory"].Value; var channelDirectoryName = child.Attributes["channelDirectoryName"].Value; var copyCountKey = child.Attributes["copyCountKey"].Value; var paperSizeKey = child.Attributes["paperSizeKey"].Value; var channelKey = child.Attributes["printChannelKey"].Value; task = new DpofTask(null, children, copyCountKey, paperSizeKey, channelDirectoryName, channelKey, targetDirectory, transliteratePath); break; case "convert": ConvertTask.ConvertFormat format; Enum.TryParse(child.Attributes["to"].Value, true, out format); task = new ConvertTask(format, null, children); break; } if (task != null) { if (children != null) { foreach (var ch in children) { ch.ParentTask = task; } } tasks.Add(task); } } return(tasks); }