private void Button_Click(object sender, RoutedEventArgs e) { if (IsInputValid()) { var number = new PhoneNumber(PhoneNumberTextBox.Text, OwnerTextBox.Text); PhoneNumberManager.Instance().AddPhoneNumber(number); IsValid.Text = "number succesfuly added."; } }
public ListNumber() { this.InitializeComponent(); if (!isPhoneNumberManagerEmpty()) { NumberTextBlock.Text = PhoneNumberManager.Instance().getAllNumber().ElementAt(0).number; OwnerTextBlock.Text = PhoneNumberManager.Instance().getAllNumber().ElementAt(0).owner; } }
public void LoadAll() { // Arrange Mock <IDbService> mock = new Mock <IDbService>(); IPhoneNumberManager manager = new PhoneNumberManager(mock.Object); // Act manager.LoadAll(); // Assert mock.Verify(m => m.LoadAll(), Times.Once); }
public void FindByCustomerId() { // Arrange Mock <IDbService> mock = new Mock <IDbService>(); Guid customerId = Guid.NewGuid(); IPhoneNumberManager manager = new PhoneNumberManager(mock.Object); // Act manager.FindByCustomer(customerId); // Assert mock.Verify(m => m.FindByCustomerId(customerId), Times.Once); }
public void Activate() { // Arrange Mock <IDbService> mock = new Mock <IDbService>(); PhoneNumberDto fixture = new PhoneNumberDto(); IPhoneNumberManager manager = new PhoneNumberManager(mock.Object); // Act manager.Activate(fixture); // Assert mock.Verify(m => m.AddorUpdate(fixture), Times.Once); }
private void Button_Click_OK(object sender, RoutedEventArgs e) { //get the selected extension string SelectedExtension = (string)Extensions.SelectedValue; CallForwardingTypes ft = CallForwardingTypes.CallForwardNone; if (ForwardTypes.SelectedIndex == 1) { ft = CallForwardingTypes.CallForwardNone; } else if (rb_VoiceMail.IsChecked == true) { ft = CallForwardingTypes.CallForwardVoiceMail; } else if (rb_Destination.IsChecked == true) { ft = CallForwardingTypes.CallForwardDestination; } Globals.ForwardManager.CallForwardingSet(SelectedExtension, ft, PhoneNumberManager.Int32Parse(Voicemail.Text, 0), PhoneNumberManager.Int32Parse(DestinationExtension.Text, 0)); this.Close(); }
private bool isPhoneNumberManagerEmpty() { return(PhoneNumberManager.Instance().getAllNumber().Count() == 0); }
public LocalphoneNumberApiController() { _phoneNumberManager = new PhoneNumberManager(); _userManager = new UserManager(); }
public void importFile(string path, bool withNumbersOnly) { /* Read the initial time. */ DateTime startTime = DateTime.Now; TextReader tr = new StreamReader(path); string output = ""; int count = 0; //Get number of lines so we can update the progress bar output = tr.ReadLine(); while (output != null) { count++; output = tr.ReadLine(); } //after "count" should be the total number of lines in the contacts file //display Progress Bar form loader.miLoaderProgress.Maximum = count; loader.miLoaderProgress.Step = 1; loader.Show(); // create reader & open file //tofix try catch tr = new StreamReader(path); // read a line of text output = tr.ReadLine(); // set the header Regex regexAdditionals = new Regex(":::", RegexOptions.None); Regex regex = new Regex(",", RegexOptions.None); string[] headers = regex.Split(output); // Next Line output = tr.ReadLine(); ContactManager contactManager = new ContactManager(_connectionString, _provider); PhoneNumberManager phoneManager = new PhoneNumberManager(_connectionString, _provider); while (output != null) { string name = "", email = "", numbers = "", desc = ""; List <contactNumber> contactNumbers = new List <contactNumber>(); //get the current line output string[] csv = regex.Split(output); for (int i = 0; i < headers.Length; i++) { if (csv[i] != String.Empty) { if (headers[i] == "Name") { name = csv[i] + " "; } //Emails else if (headers[i].StartsWith("E-mail") && headers[i].EndsWith("Value")) { if (csv[i].Contains(":::")) { string[] splitEmails = regexAdditionals.Split(csv[i]); foreach (string eAddress in splitEmails) { email += eAddress + ", "; } } else { email += csv[i]; } } //Phone numbers else if ((headers[i].StartsWith("Phone")) && (headers[i].EndsWith("Type"))) { if (csv[i + 1].Contains(":::")) { string[] splitNumbers = regexAdditionals.Split(csv[i + 1]); foreach (string number in splitNumbers) { if (csv[i] != String.Empty) { contactNumbers.Add(new contactNumber(csv[i], number)); } numbers += " " + csv[i] + ": " + number; } } else { if (csv[i] != String.Empty) { contactNumbers.Add(new contactNumber(csv[i], csv[i + 1])); } numbers += " " + csv[i] + ": " + csv[i + 1]; } } //description info else if ((headers[i] == "Organization 1 - Name") || (headers[i] == "Organization 1 - Title") || (headers[i] == "Notes")) { if (desc == String.Empty) { desc += csv[i]; } else { desc += " - " + csv[i]; } } } } //Clean the data name = name.Trim().Replace("\"", "").Replace("'", ""); desc = desc.Trim().Replace("\"", "").Replace("'", ""); email = email.Trim().Replace("\"", "").Replace("'", ""); //Create a new Contact List <ValidationError> errors = new List <ValidationError>(); // Add the contact into the database if ((!withNumbersOnly) || (contactNumbers.Count > 0)) { errors = contactManager.AddContact(name, desc, email); } //tofix throw errors loader.miLoaderProgress.PerformStep(); foreach (contactNumber cont in contactNumbers) { cont.id = contactManager._lastid; cont.type = "External"; //#### Option 1 - 23.73 seconds //ThreadPool.QueueUserWorkItem(new WaitCallback(phoneManager.AddPhoneNumberNoReturn), cont); //#### Option 2 - 20.76 seconds try { errors = phoneManager.AddPhoneNumber(cont.id, cont.number, cont.description, cont.type); } catch (Exception ex) { errors.Add(new ValidationError(ex.ToString())); } if (errors.Count > 0) { MessageBox.Show("Error occured when importing the phone numbers"); foreach (ValidationError err in errors) { loader.showMsg(err.GetMesssage()); } } //#### Option 3 - 22.93 seconds //ThreadedContactAdder fetcher = new ThreadedContactAdder(cont,_connectionString,_provider); //new Thread(new ThreadStart(fetcher.AddNumber)).Start(); } // Next Line output = tr.ReadLine(); } /* Read the end time. */ DateTime stopTime = DateTime.Now; /* Compute the duration between the initial and the end time. */ TimeSpan duration = stopTime - startTime; loader.showMsg(duration.ToString()); loader.Close(); // close the stream tr.Close(); }
public List <ValidationError> ReadCsv(string path, bool withNumbersOnly) { /* Read the initial time. */ DateTime startTime = DateTime.Now; List <ValidationError> errors = new List <ValidationError>(); int _i = 0; // open the file "data.csv" which is a CSV file with headers using (CsvReader csv = new CsvReader(new StreamReader(path), true)) { int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); Regex regexAdditionals = new Regex(":::", RegexOptions.None); loader.miLoaderProgress.Maximum = fieldCount; loader.miLoaderProgress.Step = 1; loader.Show(); ContactManager contactManager = new ContactManager(_connectionString, _provider); PhoneNumberManager phoneManager = new PhoneNumberManager(_connectionString, _provider); while (csv.ReadNextRecord()) { string name = "", email = "", numbers = "", desc = ""; List <contactNumber> contactNumbers = new List <contactNumber>(); for (int i = 0; i < fieldCount; i++) { //Console.Write(string.Format("{0} = {1};", headers[i], csv[i])); _i = i; if (csv[i] != String.Empty) { if (headers[i] == "Name") { name = csv[i] + " "; } //Emails else if (headers[i].StartsWith("E-mail") && headers[i].EndsWith("Value")) { if (csv[i].Contains(":::")) { string[] splitEmails = regexAdditionals.Split(csv[i]); foreach (string eAddress in splitEmails) { email += eAddress + ", "; } } else { email += csv[i]; } } //Phone numbers else if ((headers[i].StartsWith("Phone")) && (headers[i].EndsWith("Type"))) { if (csv[i + 1].Contains(":::")) { string[] splitNumbers = regexAdditionals.Split(csv[i + 1]); foreach (string number in splitNumbers) { if (csv[i] != String.Empty) { contactNumbers.Add(new contactNumber(csv[i], number)); } numbers += " " + csv[i] + ": " + number; } } else { if (csv[i] != String.Empty) { contactNumbers.Add(new contactNumber(csv[i], csv[i + 1])); } numbers += " " + csv[i] + ": " + csv[i + 1]; } } //description info else if ((headers[i] == "Organization 1 - Name") || (headers[i] == "Organization 1 - Title") || (headers[i] == "Notes")) { if (desc == String.Empty) { desc += csv[i]; } else { desc += " - " + csv[i]; } } } } //Clean the data name = name.Trim().Replace("\"", "").Replace("'", ""); desc = desc.Trim().Replace("\"", "").Replace("'", ""); email = email.Trim().Replace("\"", "").Replace("'", ""); // Add the contact into the database if ((!withNumbersOnly) || (contactNumbers.Count > 0)) { //Create a new error list List <ValidationError> contactErrors = new List <ValidationError>(); try { contactErrors = contactManager.AddContact(name, desc, email); } catch (Exception ex) { contactErrors.Add(new ValidationError(ex.ToString())); } if (errors.Count > 0) { foreach (ValidationError err in contactErrors) { errors.Add(err); } } else { foreach (contactNumber cont in contactNumbers) { cont.id = contactManager._lastid; cont.type = "External"; if (cont.id != String.Empty) { List <ValidationError> newErrors = phoneManager.AddPhoneNumber(cont.id, cont.number, cont.description, cont.type); if (newErrors.Count > 0) { foreach (ValidationError err in newErrors) { errors.Add(err); } } } } } } //tofix throw errors loader.miLoaderProgress.PerformStep(); } } /* Read the end time. */ DateTime stopTime = DateTime.Now; /* Compute the duration between the initial and the end time. */ TimeSpan duration = stopTime - startTime; loader.showMsg(duration.ToString() + " and i=" + _i); loader.Close(); return(errors); }
public SMSPhoneNumberController() { _PhoneNumberManager = new PhoneNumberManager(); _SMSPhoneNumberManager = new SMSPhoneNumberManager(); }