/// <summary> /// Creates and sends mail message using mailHelper property values. /// </summary> public void Send() { var bccAddresses = string.Empty; var ccAddresses = string.Empty; var toAddresses = string.Empty; try { var email = new MailMessage { Subject = Subject, Body = Body, From = new MailAddress(From) }; if (BccAddresses.Count > 0) { foreach (var addr in BccAddresses) { email.Bcc.Add(new MailAddress(addr)); bccAddresses = string.Format("{0}, {1},", bccAddresses, addr); } } if (CcAddresses.Count > 0) { foreach (var addr in CcAddresses) { email.CC.Add(new MailAddress(addr)); ccAddresses = string.Format("{0}, {1},", ccAddresses, addr); } } if (ToAddresses.Count > 0) { foreach (var addr in ToAddresses) { email.To.Add(new MailAddress(addr)); toAddresses = string.Format("{0}, {1},", toAddresses, addr); } } email.IsBodyHtml = true; Client.UseDefaultCredentials = true; Client.Send(email); } catch(Exception inner) { var errorLoggingService = new ErrorLoggingService(); var message = new StringBuilder(); message.AppendFormat("Error occurred when trying to send an email {0}{0}", Environment.NewLine); message.AppendFormat("To addresses: {0}{1}{1}", toAddresses, Environment.NewLine); message.AppendFormat("CC addresses: {0}{1}{1}", ccAddresses, Environment.NewLine); message.AppendFormat("BCC addresses: {0}{1}{1}", bccAddresses, Environment.NewLine); message.AppendFormat("Here is the inner exception message: {0}", inner.Message); var myException = new Exception(message.ToString(), inner); errorLoggingService.LogErrorNoContext(myException); throw myException; } finally { Client.Dispose(); } }
private static void GetLocationIdFromEquipmentDto(object dtoObject, string methodName, ref List<string> locationIdsToSync) { var equipementDto = (dtoObject.GetType().Name == "EquipmentDto") ? dtoObject as EquipmentDto : dtoObject as CableCardDto; if (equipementDto != null && !string.IsNullOrWhiteSpace(equipementDto.LocationId)) { locationIdsToSync.Add(equipementDto.LocationId); if (methodName == "UpdateEquipment") { try { using (var client = new RosettianClient()) { var equipments = client.SearchEquipment( new SearchFieldsDto() { EquipmentId = equipementDto.SerialNumber }, new UserDto() { Name = "SIMPL" }); if (equipments != null && equipments.FirstOrDefault() != null && equipments.Count > 0) { locationIdsToSync.Add(equipments.First().LocationId); } } } catch (FaultException<ValidationFault> fault) { var log = new ErrorLoggingService(); log.LogErrorNoContext(fault); } } } }
private static void GetLocationIdFromReturnToHeadend(object dtoObject, ref List<string> locationIdsToSync) { var serials = dtoObject as List<string>; var tempLocationsIdsToSync = locationIdsToSync; if (serials != null && serials.Count > 0) { try { Parallel.ForEach(serials, serial => { using (var client = new RosettianClient()) { var equipments = client.SearchEquipment(new SearchFieldsDto() { EquipmentId = serial }, new UserDto() { Name = "SIMPL" }); if (equipments != null && equipments.First() != null && equipments.Count > 0) { tempLocationsIdsToSync.Add(equipments.First().LocationId); } } }); } catch (AggregateException fault) { var log = new ErrorLoggingService(); log.LogErrorNoContext(fault); } } locationIdsToSync = tempLocationsIdsToSync; }
private static void GetLocationIdFromEquipmentCriteriaCollectionDto(object dtoObject, string methodName, ref List<string> locationIdsToSync) { var equipmentCollectionDto = dtoObject as EquipmentCriteriaCollectionDto; if (equipmentCollectionDto != null && equipmentCollectionDto.Count > 0) { foreach (var equipment in equipmentCollectionDto) { if (equipment != null && !string.IsNullOrWhiteSpace(equipment.LocationId)) { locationIdsToSync.Add(equipment.LocationId); } } if (methodName != "ActivateONT") return ; try { using (var client = new RosettianClient()) { var baseOntSerial = (equipmentCollectionDto.First().SerialNumber.Count() > 12) ? equipmentCollectionDto.First().SerialNumber.Substring(0, 12) : equipmentCollectionDto.First().SerialNumber; var equipments = client.SearchEquipment( new SearchFieldsDto() { EquipmentId = baseOntSerial }, new UserDto() { Name = "SIMPL" }); if (equipments != null && equipments.FirstOrDefault() != null && equipments.Count > 0) { foreach (var equipment in equipments) { if (equipment != null && !string.IsNullOrWhiteSpace(equipment.LocationId)) { locationIdsToSync.Add(equipment.LocationId); } } } } } catch (FaultException<ValidationFault> fault) { var log = new ErrorLoggingService(); log.LogErrorNoContext(fault); } } }