public static void AddItemMenu(IContactModel model) { list.AddContact(model); // AddessBook.dataGridView1.Update(); }
public ContactViewModel(IContactModel model) { SaveModel = model; Name = model.Name; Email = model.Email; Phone = model.Phone; }
/// <summary> /// Connect the model to the controller /// </summary> public void ConnectModel(IContactModel model) { // Save the model in a local variable _contactModel = model; // Subscribe the model's events to our event proxy handlers _contactModel.ContactCreated += new ContactCreatedHandler(_eventProxy.HandleContactCreated); _contactModel.ContactCreationFailed += new EventHandler(_eventProxy.HandleContactCreationFailed); }
public bool DeleteContact(string email) { IContactModel item = contacts.Find(x => x.Email == email); if (item != null) { return(contacts.Remove(item)); } return(false); }
public void RowSelect(IContactModel row) { WindowManager windowManager = new WindowManager(); ContactViewModel vm = new ContactViewModel(row); // SearchViewModel vm1 = new SearchViewModel(); vm.Flag = false; windowManager.ShowDialog(vm); // MessageBox.Show(""); //now how to access the selected row after the double click event? }
public bool CreateEmailFromTemplate(IContactModel contact, Incident incident, string registrationName, Template template) { try { _log.Info($"Creating email message from template {template.Title}..."); _contactId = contact.Id ?? Guid.Empty; // Create the 'From:' activity party for the email ActivityParty fromParty = new ActivityParty { PartyId = new EntityReference(SystemUser.EntityLogicalName, _userId) }; // Create the 'To:' activity party for the email ActivityParty toParty = new ActivityParty { PartyId = new EntityReference(Contact.EntityLogicalName, _contactId), AddressUsed = contact.Email }; _log.Info("Created activity parties."); // Create an e-mail message. Email email = new Email { To = new ActivityParty[] { toParty }, From = new ActivityParty[] { fromParty }, Subject = GetDataFromXml(template.Subject, "match"), Description = GetDataFromXml(template.Body, "match"), DirectionCode = true, RegardingObjectId = new EntityReference(Contact.EntityLogicalName, _contactId) }; _log.Info("Start modifying the email description with dynamic values..."); email.Description = email.Description.Replace("#LastName#", contact.LastName); email.Description = email.Description.Replace("#caseNumber#", incident.TicketNumber); email.Description = email.Description.Replace("#RegistrationName#", registrationName); Guid emailId = _service.Create(email); if (emailId == Guid.Empty) { _log.Error("Email not sent successfully"); return(false); } _log.Info($"Created email message with id {emailId} with the following information: " + $"Template {template.Title}, Subject {email.Subject}, Description {email.Description}"); return(true); //bool emailSent = SendEmailFromTemplate(email, template.Id); } catch (Exception ex) { _log.Error($"An error occurred during creating email. Exception: {ex.Message}"); return(false); } }
public bool Decrypt(EncryptedMessage encryptedMessage, int senderId, out string messageText) { if (encryptedMessage == null) { throw new ArgumentException("Encrypted message cannot be null"); } if (encryptedMessage.Body == null || encryptedMessage.DigitalSignature == null || encryptedMessage.SymmetricKey == null || encryptedMessage.Iv == null) { throw new ArgumentException("Not all encrypted message fields are initialized"); } IContactModel senderContact = _storageService.GetContacts().FirstOrDefault(c => c.Id == senderId); if (senderContact == null) { throw new ArgumentException("Contact with id of senderId does not exist"); } string receiverKeyPair = _storageService.GetUser().KeyPair; string senderPublicKey = senderContact.PublicKey; try { // decrypt symmetric key with receivers private key RsaCipher rsa = new RsaCipher(receiverKeyPair); byte[] encryptedSymmetricKeyBytes = FormatConverter.String64ToBytes(encryptedMessage.SymmetricKey); byte[] decryptedSymmetricKeyBytes = rsa.Decrypt(encryptedSymmetricKeyBytes); // decrypt message text with jsut decrypted symmetric key byte[] ivBytes = FormatConverter.String64ToBytes(encryptedMessage.Iv); AesCipher aes = new AesCipher(decryptedSymmetricKeyBytes, ivBytes); byte[] encryptedMessageBytes = FormatConverter.String64ToBytes(encryptedMessage.Body); byte[] decryptedMessageBytes = aes.Decrypt(encryptedMessageBytes); // set message text out parameter messageText = FormatConverter.BytesToString(decryptedMessageBytes); // verify digital signature rsa = new RsaCipher(senderPublicKey); byte[] digitalSignatureBytes = FormatConverter.String64ToBytes(encryptedMessage.DigitalSignature); bool signatureOk = rsa.VerifyDigitalSignature(decryptedMessageBytes, digitalSignatureBytes); return(signatureOk); } catch (Exception ex) { messageText = null; return(false); } }
public static string checkEmail(string email) { var flag = Regex.IsMatch(email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); if (!flag) { throw new AddressException("Email not valid"); } IContactModel cm = AddressBook.list.SearchFirst(email); if (cm != null) { throw new AddressException("Email already used, try another"); } return(email); }
public EncryptedMessage Encrypt(string messageText, int recieverId) { if (messageText == null) { throw new ArgumentException("Message text cannot be null"); } IContactModel receiverContact = _storageService.GetContacts().FirstOrDefault(c => c.Id == recieverId); if (receiverContact == null) { throw new ArgumentException("Contact with id of receiverId does not exist"); } EncryptedMessage encMsg = new EncryptedMessage(); AesCipher aes = new AesCipher(); // set initiazlization vector encMsg.Iv = FormatConverter.BytesToString64(aes.IV); // enccrypt message text symmetrically byte[] messageBytes = FormatConverter.StringToBytes(messageText); byte[] encryptedMessageBytes = aes.Encrypt(messageBytes); encMsg.Body = FormatConverter.BytesToString64(encryptedMessageBytes); // encrypt symmetric key with receivers public key string receiverPublicKey = receiverContact.PublicKey; RsaCipher rsa = new RsaCipher(receiverPublicKey); byte[] encryptedSymmetricKeyBytes = rsa.Encrypt(aes.Key); encMsg.SymmetricKey = FormatConverter.BytesToString64(encryptedSymmetricKeyBytes); // create digital signature of message text (using senders private key) string senderKeyPair = _storageService.GetUser().KeyPair; rsa = new RsaCipher(senderKeyPair); byte[] digitalSignatureBytes = rsa.CreateDigitalSignature(messageBytes); encMsg.DigitalSignature = FormatConverter.BytesToString64(digitalSignatureBytes); return(encMsg); }
public static void EditItemMenu(string email, IContactModel model) { IContactModel oldData = list.SearchFirst(email); list.EditContact(model, oldData); }
public static IContactModel GetItemByEmail(string email) { IContactModel oldData = list.SearchFirst(email); return(oldData); }
public IContactModel SearchFirst(string email) { IContactModel item = contacts.Find(x => x.Email == email); return(item); }
public bool EditContact(IContactModel add, IContactModel delete) { contacts.Remove(delete); contacts.Add(add); return(true); }
public int AddContact(IContactModel contact) { contacts.Add(contact); return(contacts.Count); }