public void AppendModelAsync(Guid bmGuid, string bmFileName, string alias, string columnNameToImport, int columnIndexToImport, Guid userGuid, int allowImportAfterMinutes = 0) { var emails = _users.GetUserEmails(new Guid[] { userGuid }).ToArray(); var repeats = _contentManager.Query <BlockModelPart, BlockModelPartRecord>("BlockModel").Where(f => f.BmGuid == bmGuid && f.BmFileName == bmFileName && f.ColumnIndexToAdd == columnIndexToImport && f.ColumnNameToAdd == columnNameToImport && f.Processed > DateTime.UtcNow.AddMinutes(-allowImportAfterMinutes)).Count(); if (repeats == 0) { var m = _contentManager.New <BlockModelPart>("BlockModel"); m.BmGuid = bmGuid; m.Recipients = emails.FlattenStringArray(); m.BmFileName = bmFileName; m.Alias = alias; m.UserID = userGuid; m.ColumnNameToAdd = columnNameToImport; m.ColumnIndexToAdd = columnIndexToImport; m.Processed = DateTime.UtcNow; _contentManager.Create(m, VersionOptions.Published); _concurrentTasks.ExecuteAsyncTask(AppendModel, m.ContentItem); //_taskManager.AppendModelAsync(m.ContentItem); } else { Logger.Information(string.Format("Can't re-append file:{0} with the same settings within the currently selected time-frame", bmFileName)); } }
public void ProcessApiRequestAsync(MailApiCall apiMethod, string apiKey, string apiValue = null, string json = null, int status = 0, DateTime?processed = default(DateTime?), DateTime?completed = default(DateTime?), bool shortLived = true) { try { var m = _contentManager.New <MailApiPart>("MailApi"); m.Status = status; m.Processed = DateTime.UtcNow; m.ApiKey = apiKey; m.ApiValue = apiValue; m.Json = json; m.ApiMethod = EnumHelper.EnumToString(apiMethod); _contentManager.Create(m); if (!shortLived) { _concurrentTasks.ExecuteAsyncTask(ProcessApiRequest, m.ContentItem); } else { _taskManager.MailApiAsync(m.ContentItem); } } catch (Exception ex) { Logger.Debug(ex, string.Format("Failed Mail Api Request.\n\nKey:\n{0}\n\nValue:\n{1}\n\nJson:\n{2}\n\n", apiMethod, apiKey, apiValue, json)); } }