public static Return ClearAllCache() { try { ContextHelper.ClearAllMemoryCache(); FileCacheHelper.ClearAllCache(); RedisCacheHelper.ClearAllCache(); var webserviceRequests = FrameworkLibrary.WebserviceRequestsMapper.GetAll(); foreach (var item in webserviceRequests) { var context = BaseMapper.GetObjectFromContext(item); if (context != null) { BaseMapper.DeleteObjectFromContext(context); } } var returnObj = BaseMapper.SaveDataModel(); return(BaseMapper.GenerateReturn()); } catch (Exception ex) { return(BaseMapper.GenerateReturn(ex)); } }
public static Return RestoreDatabase(string backUpFilePath) { Return returnObj = BaseMapper.GenerateReturn(); if (!string.IsNullOrEmpty(backUpFilePath) && File.Exists(backUpFilePath)) { var databaseName = BaseMapper.GetDataModel().Database.Connection.Database; var sqlCommand = $@"ALTER DATABASE {databaseName} SET Single_User WITH Rollback Immediate; USE master; RESTORE DATABASE {databaseName} FROM DISK = '{backUpFilePath}'; ALTER DATABASE {databaseName} SET Multi_User"; try { var result = BaseMapper.GetDataModel(true).Database.ExecuteSqlCommand(transactionalBehavior: System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, sql: sqlCommand); returnObj.SetRawData(result); return(returnObj); } catch (Exception ex) { ErrorHelper.LogException(ex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } } return(returnObj); }
public Return Validate() { var returnObj = BaseMapper.GenerateReturn(); if (Roles.Count == 0) { returnObj.Error = ErrorHelper.CreateError(new System.Exception("Validation Error", new System.Exception("Must be assigned to at lease one role"))); } return(returnObj); }
public Return MoveToIndex(int insertAtIndex) { var returnObj = BaseMapper.GenerateReturn(); if (insertAtIndex < 0) { var ex = new System.Exception("Cant move to index: " + insertAtIndex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } var siblings = GetSiblings(); var currentIndex = GetIndex(siblings); if (currentIndex >= 0 && currentIndex <= siblings.Count) { siblings.RemoveAt(currentIndex); } if (siblings.Count < insertAtIndex) { var ex = new System.Exception("Cant move to index: " + insertAtIndex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } siblings.Insert(insertAtIndex, this); var index = 0; foreach (var media in siblings) { if (media.OrderIndex == index) { index++; continue; } var inContext = BaseMapper.GetObjectFromContext(media); media.OrderIndex = index; returnObj = MediasMapper.Update(media); index++; } MediasMapper.ClearCache(); MediaDetailsMapper.ClearCache(); return(returnObj); }
public Return CreateAndSendCampaign(string listId, string fromName, string fromEmailAddress, string subject, string title, string htmlMessage) { var returnObj = BaseMapper.GenerateReturn(); var campaign = new Campaign { Type = CampaignType.Regular, Recipients = new Recipient { ListId = listId }, Settings = new Setting { SubjectLine = subject, Title = title, FromName = fromName, ReplyTo = fromEmailAddress }, Tracking = new Tracking { Opens = true, HtmlClicks = true, TextClicks = true }, ReportSummary = new ReportSummary(), DeliveryStatus = new DeliveryStatus(), }; try { var mailChimpCampaign = MailChimpManager.Campaigns.AddOrUpdateAsync(campaign).Result; var ContentRequest = new ContentRequest { Html = htmlMessage }; var content = MailChimpManager.Content.AddOrUpdateAsync(mailChimpCampaign.Id, ContentRequest).Result; MailChimpManager.Campaigns.SendAsync(mailChimpCampaign.Id); return(returnObj); } catch (Exception ex) { ErrorHelper.LogException(ex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } }
public Return Validate() { var returnOnj = BaseMapper.GenerateReturn(); MediaTypeHandler = MediaTypeHandler.Trim(); if (!File.Exists(URIHelper.ConvertToAbsPath(URIHelper.ConvertAbsUrlToTilda(MediaTypeHandler)))) { var ex = new Exception("Media Type MediaTypeHandler is invalid", new Exception("File (" + MediaTypeHandler + ") does not exist")); returnOnj.Error = ErrorHelper.CreateError(ex); } return(returnOnj); }
public Return SetPassword(string password) { var returnObj = BaseMapper.GenerateReturn(); password = password.Trim(); var encryptedPassword = StringHelper.Encrypt(password); if (password != "") { this.Password = encryptedPassword; } else { returnObj = BaseMapper.GenerateReturn("Password cannot be blank"); } return(returnObj); }
public Return GenerateValidationReturn() { var returnObj = BaseMapper.GenerateReturn(); if (_validationErrors.Count == 0) { return(returnObj); } var validationMessages = ""; foreach (var validationError in _validationErrors) { validationMessages += validationError.Message + "<br />"; } returnObj.Error = ErrorHelper.CreateError(new System.Exception("Validation Error", new System.Exception(validationMessages))); return(returnObj); }
public static Return Send(string fromEmailAddress, IEnumerable <MailAddress> emailAddresses, string subject, string body, EmailMode emailMode = EmailMode.Both, bool bcc = true) { Return returnObj = new Return(); var emailLog = new EmailLog(); if (emailMode == EmailMode.Both || emailMode == EmailMode.Smtp) { try { MailMessage message = new MailMessage(); foreach (MailAddress address in emailAddresses) { if (bcc) { message.Bcc.Add(address); } else { message.To.Add(address); } } message.Sender = new MailAddress(fromEmailAddress); message.IsBodyHtml = true; message.Subject = subject; message.Body = body; emailLog = GetEmailLogFromMailMessage(message); System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Send(message); emailLog.ServerMessage = "Successfully sent email"; EmailsMapper.Insert(emailLog); return(returnObj); } catch (Exception ex) { ErrorHelper.LogException(ex); returnObj.Error = ErrorHelper.CreateError(ex); emailLog.ServerMessage = returnObj.Error.Message; EmailsMapper.Insert(emailLog); if (emailMode == EmailMode.Both) { var directSentReturn = SendDirectMessage(fromEmailAddress, emailAddresses, subject, body, bcc); if (directSentReturn.IsError) { return(directSentReturn); } else { returnObj = BaseMapper.GenerateReturn(); } } return(returnObj); } } else { return(SendDirectMessage(fromEmailAddress, emailAddresses, subject, body)); } }
public Return Validate() { var returnOnj = BaseMapper.GenerateReturn(); return(returnOnj); }
public static Return BackupDatabase() { Return returnObj = BaseMapper.GenerateReturn(); var databaseName = BaseMapper.GetDataModel().Database.Connection.Database; var sqlCommand = $@"BACKUP DATABASE {databaseName} TO DISK = '{DbBackupPath}{DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-tt")}-{databaseName}.bak'"; try { var result = BaseMapper.GetDataModel(true).Database.ExecuteSqlCommand(transactionalBehavior: System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, sql: sqlCommand); returnObj.SetRawData(result); return(returnObj); } catch (Exception ex) { ErrorHelper.LogException(ex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } /*SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); * string dbName = builder.InitialCatalog; * string backUpPath = URIHelper.BasePath + "App_Data/DBBackups/" + DateTime.Now.ToString("yyyy'-'MM'-'dd-HH'-'mm'-'ss'Z'") + "-" + dbName + ".bak"; * * using (SqlConnection cnn = new SqlConnection(connectionString)) * { * cnn.Open(); * dbName = cnn.Database.ToString(); * * ServerConnection sc = new ServerConnection(cnn); * Server sv = new Server(sc); * * // Create backup device item for the backup * BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File); * * // Create the backup informaton * Microsoft.SqlServer.Management.Smo.Backup bk = new Backup(); * * //bk.PercentComplete += new PercentCompleteEventHandler(percentComplete); * bk.Devices.Add(bdi); * bk.Action = BackupActionType.Database; * bk.PercentCompleteNotification = 1; * bk.BackupSetDescription = dbName; * bk.BackupSetName = dbName; * bk.Database = dbName; * * //bk.ExpirationDate = DateTime.Now.AddSeconds(10); * bk.LogTruncation = BackupTruncateLogType.Truncate; * bk.FormatMedia = false; * bk.Initialize = true; * bk.Checksum = true; * bk.ContinueAfterError = true; * bk.Incremental = false; * * try * { * // Run the backup * bk.SqlBackup(sv);//Exception * return returnObj; * } * catch (Exception ex) * { * ErrorHelper.LogException(ex); * * returnObj.Error = ErrorHelper.CreateError(ex); * * return returnObj; * } * }*/ }