public static void CreateDefaultUserInfoDataCacheIfNotExists() { try { lock (CCacheData._CreateDefaultUserInfoDataCacheIfNotExistsLocker) { string path = ConfigurationManager.AppSettings["cacheLocation"].ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string str = string.Format("{0}DataUserTable.xml", (object)path); if (System.IO.File.Exists(str)) { return; } //string codeDataFilePath = Settings.Default.DummyUserCodeDataFilePath; //if (codeDataFilePath != null && System.IO.File.Exists(codeDataFilePath)) //{ // System.IO.File.Copy(codeDataFilePath, str, true); //} //else // { DataTable table = new DataTable("Table1"); DataSet dataSet = new DataSet(); DataTable dataforCacheUserInfo = new CGetVehicleDataForCache().GetDataforCacheUserInfoFromConfig(); //table.Columns.Add(new DataColumn("username", typeof (string))); //table.Columns.Add(new DataColumn("passcode", typeof (string))); //table.Columns.Add(new DataColumn("userInformationID", typeof (int))); //DataRow row = table.NewRow(); //row["username"] = (object) "Test"; //row["passcode"] = (object) "0450"; //row["UserInformationID"] = (object) "9999"; //table.Rows.Add(row); //if (table.Rows.Count == 0) // return; dataSet.Tables.Add(dataforCacheUserInfo); dataSet.WriteXml(path + "DataUserTable.xml", XmlWriteMode.WriteSchema); //} } } catch (Exception ex) { Log.Write(ex); } }
public static void CacheUserInfoDataFromDatabase() { try { lock (CCacheData._CacheUserInfoDataFromDatabaseLocker) { Console.WriteLine("Caching user info data."); // DataTable dataforCacheUserInfo = new CGetVehicleDataForCache().GetDataforCacheUserInfoFromConfig(); DataTable dataforCacheUserInfo = new CGetVehicleDataForCache().GetDataforCacheUserInfo(); DataSet dataSet = new DataSet(); string path = ConfigurationManager.AppSettings["cacheLocation"].ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (dataforCacheUserInfo != null && dataforCacheUserInfo.Rows.Count != 0) { string str = string.Format("{0}DataUserTable.xml", (object)path); if (System.IO.File.Exists(str)) { Console.WriteLine("User info data file exists already. Deleting."); System.IO.File.Delete(str); Console.WriteLine("Deleted. "); } dataSet.Tables.Add(dataforCacheUserInfo); dataSet.WriteXml(str, XmlWriteMode.WriteSchema); Console.WriteLine("Cached User Info Data...OK [{0}] records written to cache [{1}].", (object)dataforCacheUserInfo.Rows.Count, (object)str); } else { Console.WriteLine("Cached data not written to, no records found in db to write!"); } } } catch (Exception ex) { Log.Write(ex); } }