/// <summary> /// Save Settings /// </summary> /// <param name="settings"></param> /// <returns></returns> public static bool SaveSettings(Settings settings) { bool iSuccess = false; try { if (settings != null) { //Persist Data into Database //connectionString = GetAppPath(@"\Zoiperdb.sdf"); //GetPath(@"..\..\SqlData\Zoiperdb.sdf"); dbContext = new ZoiperdbContext(AuthenticateConnectionToDB()); ApplicationLog.WriteEventToLog("Path to ZoiperDB from SaveSettings: " + AuthenticateConnectionToDB()); TblZoiperSetting zoiperSetting = new TblZoiperSetting() { Domain = settings.Domain, Username = settings.Username, CallerId = settings.CallerId, ServiceDuration = settings.ServiceDuration, IsRestart = Convert.ToInt32(settings.Restart), Password = SharedFunctions.Hash(settings.Password) }; ApplicationLog.WriteEventToLog(string.Format("Domain: {0}, Username: {1}, CallerId: {2}, Duration: {3}, Restart: {4}, Password: {5}", zoiperSetting.Domain, zoiperSetting.Username, zoiperSetting.CallerId, zoiperSetting.ServiceDuration, zoiperSetting.IsRestart, zoiperSetting.Password)); dbContext.TblZoiperSetting.InsertOnSubmit(zoiperSetting); dbContext.SubmitChanges(); iSuccess = true; ApplicationLog.WriteEventToLog("Settings saved into ZoiperDB"); } } catch (Exception ex) { ApplicationLog.WriteErrorToLog(ex.ToString()); } return(iSuccess); }
//public static bool TruncateTable() //{ // connectionString = GetAppPath(@"\Zoiperdb.sdf"); // string query = "DELETE from TblPhoneContact"; // string dropConstraint = @"ALTER TABLE [TblPhoneContact] DROP CONSTRAINT [PK__TblPhoneContact__0000000000000019]"; // string dropIdColumn = "ALTER TABLE[TblPhoneContact] DROP COLUMN[Id]"; // string addIdColumn = @"ALTER TABLE [TblPhoneContact] ADD [Id] int IDENTITY (1,1) NOT NULL"; // string addIdConstraint = "ALTER TABLE[TblPhoneContact] ADD CONSTRAINT[PK__TblPhoneContact__0000000000000019] PRIMARY KEY ([Id])"; // bool result = false; // try // { // dbContext = new ZoiperdbContext(connectionString); // if (dbContext.DatabaseExists()) // { // int idropConstraint = dbContext.ExecuteCommand(dropConstraint); // if (idropConstraint >= 0) // result = true; // int idropIdColumn = dbContext.ExecuteCommand(dropIdColumn); // if (idropIdColumn >= 0) // result = true; // int iQuery = dbContext.ExecuteCommand(query); // if (iQuery >= 0) // result = true; // int iaddIdColumn = dbContext.ExecuteCommand(addIdColumn); // int iaddIdConstraint = dbContext.ExecuteCommand(addIdConstraint); // } // } // catch (Exception ex) // { // LibraryLog.WriteErrorLog(ex); // } // return result; //} /// <summary> /// Get User account for calling /// </summary> /// <returns></returns> public static string GetSettings() { string account = string.Empty; try { //AuthenticateConnectionToDB(); dbContext = new ZoiperdbContext(AuthenticateConnectionToDB()); TblZoiperSetting tblSetting = dbContext.TblZoiperSetting.FirstOrDefault(); account = tblSetting.CallerId + "@" + tblSetting.Domain; } catch (Exception ex) { LibraryLog.WriteErrorLog(ex); } return(account); }
public static int GetServiceDuration() { connectionString = GetAppPath(@"\Zoiperdb.sdf"); //GetPath(@"..\..\SqlData\Zoiperdb.sdf"); dbContext = new ZoiperdbContext(connectionString); int duration = 0; try { TblZoiperSetting setting = dbContext.TblZoiperSetting.FirstOrDefault(); duration = setting.ServiceDuration; } catch (Exception ex) { logger.Error(ex, ex?.Message); LibraryLog.WriteErrorLog(ex); duration = Convert.ToInt32(false); } return(duration); }
public static Settings GetSIPAccount() { //bool iSuccess = false; Settings sipSetting = new Settings(); try { dbContext = new ZoiperdbContext(AuthenticateConnectionToDB()); TblZoiperSetting sipAccount = dbContext.TblZoiperSetting.FirstOrDefault(); sipSetting = new Settings(sipAccount.Domain, sipAccount.Username, sipAccount.Password, sipAccount.CallerId, sipAccount.RegistrationStatus); ApplicationLog.WriteErrorToLog("Success"); } catch (Exception ex) { ApplicationLog.WriteErrorToLog(ex); //iSuccess = false; } return(sipSetting); }