public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (!email.Subject.Contains("Parkland County Incident") && !email.Subject.Contains("Incident Message")) { return(null); } bool is2ndPage = false; string priorityChar = null; DateTime callTimeUtc = DateTime.UtcNow; var c = new Call(); c.Notes = email.Body; try { var data = new List <string>(); string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count > 0) { c.Name = data[1].Trim().Replace("Type: ", ""); var priorityString = c.Name.Substring(0, c.Name.IndexOf(char.Parse("-"))).Trim(); priorityChar = Regex.Replace(priorityString, @"\d", "").Trim(); TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(department.TimeZone); callTimeUtc = new DateTimeOffset(DateTime.Parse(data[0].Replace("Date:", "").Trim()), timeZone.BaseUtcOffset).UtcDateTime; is2ndPage = c.Notes.Contains("WCT2ndPage"); try { var location = data.FirstOrDefault(x => x.StartsWith("Location:")); if (!String.IsNullOrWhiteSpace(location)) { c.Address = location.Replace("//", "").Replace("Business Name:", ""); } var coordinates = data.FirstOrDefault(x => x.Contains("(") && x.Contains(")")); if (!String.IsNullOrWhiteSpace(coordinates)) { coordinates = coordinates.Replace("Common Place:", ""); coordinates = coordinates.Trim(); c.GeoLocationData = coordinates.Replace("(", "").Replace(")", ""); } } catch { } } } else { c.Name = "Call Import Type: Unknown"; } } catch { c.Name = "Call Import Type: Unknown"; } c.NatureOfCall = email.Body; c.LoggedOn = callTimeUtc; c.Priority = PriorityMapping(priorityChar, is2ndPage, priority); c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.UnitDispatches = new Collection <CallDispatchUnit>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } if (units != null && units.Any()) { foreach (var unit in units) { var ud = new CallDispatchUnit(); ud.UnitId = unit.UnitId; ud.LastDispatchedOn = DateTime.UtcNow; c.UnitDispatches.Add(ud); } } // Search for an active call if (activeCalls != null && activeCalls.Any()) { var activeCall = activeCalls.FirstOrDefault(x => x.Name == c.Name && x.LoggedOn == c.LoggedOn); if (activeCall != null) { activeCall.Priority = c.Priority; activeCall.Notes = c.Notes; activeCall.LastDispatchedOn = DateTime.UtcNow; activeCall.DispatchCount++; return(activeCall); } } return(c); }
public void SendUnitCall(Call call, CallDispatchUnit dispatch, string departmentNumber, string address = null) { var spc = new StandardPushCall(); spc.CallId = call.CallId; spc.Title = string.Format("Call {0}", call.Name); spc.Priority = call.Priority; spc.ActiveCallCount = 1; if (call.CallPriority != null && !String.IsNullOrWhiteSpace(call.CallPriority.Color)) { spc.Color = call.CallPriority.Color; } else { spc.Color = "#000000"; } string subTitle = String.Empty; if (String.IsNullOrWhiteSpace(address) && !String.IsNullOrWhiteSpace(call.Address)) { subTitle = call.Address; } else if (!String.IsNullOrWhiteSpace(address)) { subTitle = address; } else if (!string.IsNullOrEmpty(call.GeoLocationData)) { try { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { subTitle = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } } catch { } } if (!string.IsNullOrEmpty(subTitle)) { spc.SubTitle = subTitle.Truncate(200); } else { if (!string.IsNullOrEmpty(call.NatureOfCall)) { spc.SubTitle = call.NatureOfCall.Truncate(200); } } if (!String.IsNullOrWhiteSpace(spc.SubTitle)) { spc.SubTitle = StringHelpers.StripHtmlTagsCharArray(spc.SubTitle); } spc.Title = StringHelpers.StripHtmlTagsCharArray(spc.Title); try { #pragma warning disable 4014 Task.Run(async() => { await _pushService.PushCallUnit(spc, dispatch.UnitId, call.CallPriority); }).ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } }