static void Main(string[] args) { List <NationalParkServiceJsonData> data = new List <NationalParkServiceJsonData>(); ApiDAO apiDao; SqlDAO sqlDao; string connectionString = ConfigurationManager.ConnectionStrings["NPGeek"].ConnectionString; string apiKey = ConfigurationManager.ConnectionStrings["npsApiKey"].ConnectionString; apiDao = new ApiDAO(apiKey); sqlDao = new SqlDAO(connectionString); Console.WriteLine($"Database has {sqlDao.GetDBParkCount()} parks stored"); bool auto = !GetYesOrNo("Manual fill? (more stable)"); try { if (auto) { Auto(sqlDao, apiDao, data); } else { Manual(sqlDao, apiDao, data); } } catch (System.Exception ex) { Console.WriteLine("An error was encountered, probably got timed out by NPS."); Console.WriteLine($"{ex.Message}\n{ex.StackTrace}\n{ex.InnerException}\n{ex.Source}"); } }
protected void onSave(object sender, EventArgs e) { save(); SqlDAO<Blog> sdao = new SqlDAO<Blog>(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); Loader.save(blog,sdao.emulate<DataObject>(typeof(Blog))); sdao.saveOrUpdate(blog); }
protected void Page_Load(object sender, EventArgs e) { SqlDAO<Blog> sdao = new SqlDAO<Blog>(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); List<Blog> results = sdao.get("", 0); Loader.load<Blog>(results, sdao.emulate<DataObject>(typeof(Blog))); rptExisting.DataSource = results; rptExisting.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { SqlDAO<Blog> blDao = new SqlDAO<Blog>(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); List<Blog> bls = blDao.get("ORDER BY PostDate DESC",0); Loader.load<Blog>(bls, blDao.emulate<DataObject>(typeof(Blog))); rptNews.DataSource = bls; rptNews.DataBind(); }
public void ProcessRequest(HttpContext context) { int id = int.Parse(context.Request["id"].ToString()); SqlDAO<BlogImage> bi = new SqlDAO<BlogImage>(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); BlogImage img = bi.getSingle("WHERE _dbId = " + id); if (img != null && img.ImageData != null) { using (System.IO.MemoryStream m = new System.IO.MemoryStream()) { img.ImageData.Save(m, img.ImageData.RawFormat); context.Response.BinaryWrite(m.ToArray()); context.Response.Flush(); } } }
/// <summary> /// Complete Registration for the user /// </summary> /// <returns>IResult the result of whole registration process</returns> public IResult RegisterUser() { string message = ""; string email = registrationRequest.Email; string fname = registrationRequest.Firstname; string lname = registrationRequest.Lastname; DateTime dob = registrationRequest.Dob; string password = registrationRequest.Password; // Generate salt and hash password Hasher hasher = new Hasher(algorithm); HashObject hash = hasher.GenerateSaltedHash(password); string hashedPw = hash.HashedValue; string salt = hash.Salt; Account newAccount = new Account(email, hashedPw, salt); ICreateAccountDAO newAccountDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User)); ICreateAccountDAO newMappingDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)); IMapperDAO mapperDAO = new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)); ICreateAccountDAO newUserDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)); CreateAccountDAOs daos = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO); ICreateAccountService cas = new SqlCreateAccountService(newAccount, daos); IResult checkResult = cas.Create(); message = message + checkResult.Message; bool ifSuccess = checkResult.IsSuccess; if (ifSuccess) { int sysID = mapperDAO.GetSysID(email); if (sysID != -1) { ISqlDAO DAO = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)); User newUser = new User(sysID, email, fname, lname, "Enable", dob, "male"); UpdateAccountSqlService updateAccount = new UpdateAccountSqlService(newUser, DAO); checkResult = updateAccount.Update(); message = message + checkResult.Message; ifSuccess = checkResult.IsSuccess; } else { ifSuccess = false; message = message + "failed to Retrieve sysID"; } } return(new CheckResult(message, ifSuccess)); }
static void Manual(SqlDAO sqlDao, ApiDAO apiDao, List <NationalParkServiceJsonData> data) { DateTime start = DateTime.Now; DateTime end; int querySize = 0; bool runAgain = false; int parkCount; do { parkCount = sqlDao.GetDBParkCount(); if (parkCount >= totalNumberOfNationalParks) { Console.WriteLine("Database already has every national park. Program will now close"); Console.ReadKey(); return; } Console.WriteLine($"Database has {parkCount}/{totalNumberOfNationalParks} parks stored"); while (querySize < 1) { Console.WriteLine("Enter number of entries to retrieve, (exceeding 75 causes instability)"); if (int.TryParse(Console.ReadLine(), out querySize)) { if (querySize < 1) { Console.WriteLine("Number must be positive."); } if (querySize > 100) { bool confirm = GetYesOrNo("Are you sure?"); if (!confirm) { querySize = 0; } } } } Console.WriteLine("Getting data from NPS... this may take some time"); data = new List <NationalParkServiceJsonData>(apiDao.GetParkData(querySize, sqlDao.GetDBParkCount())); end = DateTime.Now; Console.WriteLine($"Done. Execution took {(end - start).TotalSeconds} seconds.\nBeginning upload to SQL... this may also take some time"); start = DateTime.Now; sqlDao.InsertDataIntoSql(data); end = DateTime.Now; Console.WriteLine($"Done. Execution took {(end - start).TotalSeconds} seconds."); runAgain = GetYesOrNo("Run again?"); }while (runAgain); }
public static void InitDB() { SqlDAO DL = new SqlDAO(FlightCenterConfig.strConn); string SQL = "DELETE FROM Tickets"; DL.ExecuteSqlNonQuery(SQL); SQL = "DELETE FROM Customers"; DL.ExecuteSqlNonQuery(SQL); SQL = "DELETE FROM Flights"; DL.ExecuteSqlNonQuery(SQL); SQL = "DELETE FROM AirlineCompanies"; DL.ExecuteSqlNonQuery(SQL); SQL = "DELETE FROM Countries"; DL.ExecuteSqlNonQuery(SQL); }
public void UpdateTestException() { var dao = new SqlDAO("false"); try { dao.RunCommand(new List <SqlCommand>()); Assert.Fail(); } catch (Exception e) { Trace.WriteLine(e.ToString()); Assert.IsInstanceOfType(e, typeof(Exception)); } }
public UserManagementManager() { var sqlDao = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)); var createAccountDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User)); var newMappingDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)); var newUserDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)); var mapperDAO = new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)); var bunchedDaos = new CreateAccountDAOs(createAccountDAO, newMappingDAO, newUserDAO, mapperDAO); _updatePermissionService = new PermissionUpdateSqlService(new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)), new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User))); _updateAccountService = new UpdateAccountSqlService(new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User))); _createAccountService = new SqlCreateAccountService(bunchedDaos); _deleteAccountService = new DeleteAccountSQLService(new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)), new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)), new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User))); _authNService = new AuthenticationService(new GetUserDao(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User))); _authService = new JWTService(); }
static void Auto(SqlDAO sqlDao, ApiDAO apiDao, List <NationalParkServiceJsonData> data) { int parkCount = sqlDao.GetDBParkCount(); int actualMax = int.MaxValue; bool alreadyFull = true; DateTime totalStart = DateTime.Now; DateTime totalEnd; Console.WriteLine("BEGINNING AUTOFILL. YOLO"); while (parkCount < totalNumberOfNationalParks) { alreadyFull = false; int beforeCount = sqlDao.GetDBParkCount(); DateTime start = DateTime.Now; DateTime end; Console.WriteLine($"Pulling from NPS..."); data = new List <NationalParkServiceJsonData>(apiDao.GetParkData(25, sqlDao.GetDBParkCount())); end = DateTime.Now; Console.WriteLine($"Done. Execution took {(end - start).TotalSeconds} seconds.\nBeginning upload to SQL..."); start = DateTime.Now; sqlDao.InsertDataIntoSql(data); parkCount = sqlDao.GetDBParkCount(); end = DateTime.Now; if (beforeCount == parkCount) { actualMax = parkCount; Console.WriteLine($"Done. Execution took {(end - start).TotalSeconds} seconds. Database did not increase in size, assuming we have every national park now.\n Actual total: {actualMax} (Write this down. WRITE THIS DOWN)"); break; } Console.WriteLine($"Done. Execution took {(end - start).TotalSeconds} seconds. {parkCount}/{totalNumberOfNationalParks} have been processed."); } totalEnd = DateTime.Now; if (alreadyFull) { Console.WriteLine($"The database is already full dummy, if you really want it to run you can recreate the database and run this again."); } else { Console.WriteLine($"\n\n\n\nAuto fill completed with out errors? Wow I'm good. Execution took {(totalEnd - totalStart).Minutes} minutes."); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (id > 0) { SqlDAO<Blog> bldao = new SqlDAO<Blog>(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); Blog bl = bldao.getSingle("WHERE _dbId = " + id); if (bl != null) { Loader.load(bl, bldao.emulate<DataObject>(typeof(Blog))); blog = bl; } } else { Blog t = new Blog(); t.Sections = new List<BlogSection>(); t.Tags = new List<BlogTag>(); t.Attachments = new List<BlogAtachment>(); this.blog = t; } bind(); } }
protected void OnSave(object sender, EventArgs e) { if (!SaveData()) { try { SqlDAO<DataObject> dao = new SqlDAO<DataObject>("Data Source=REVLOCAL-54\\SQLEXPRESS;Initial Catalog=FileStoreTest;Integrated Security=True;", source.GetType()); dao.saveOrUpdate(source); } catch (Exception ex) { Log.getInst("UI").error(ex.ToString()); } Log.getInst("UI").write(Server.MapPath("DebugUI.html"), 4); } else { } }
public AccesEmp() { objSqlDAO = SqlDAO.GetInstance(); }