Пример #1
0
        public ActionResult SubmitData(IncidentDetail model)
        {
            ApplicationUser applicationUser = new ApplicationUser();
            string          userId          = User.Identity.GetUserId();

            model.UserId = userId;

            //applicationUser.Id = userId;
            // applicationUser.UserName = context.Users.Where(x => x.Id == userId).Select(x => x.UserName).FirstOrDefault();
            //model.Users = new ApplicationUser()
            //{
            //    Id = userId,
            //    UserName = ""
            //    //context.Users.Where(x => x.Id == userId).Select(x => x.UserName).FirstOrDefault()
            //};
            var list = context.IncidentDetails.Add(model);

            list.FormState = "Submitted";
            context.SaveChanges();

            return(View("FormSubmitd"));
        }
Пример #2
0
        /// <summary>
        /// Reads in the xml
        /// </summary>
        /// <param name="xmlData">Xml as string</param>
        public void ReadXML(string xmlData)
        {
            if (string.IsNullOrEmpty(xmlData))
            {
                throw new ArgumentNullException("XMLData Can't Be Null!");
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(xmlData);
            }
            catch (XmlException)
            {
                throw new ArgumentException("Invalid XML String");
            }

            XmlNodeList denodelist = doc.GetElementsByTagName("Event", Constants.EmlcNamespace);

            if (denodelist.Count == 0)
            {
                throw new FormatException("No Event Element found!");
            }
            else if (denodelist.Count > 1)
            {
                throw new FormatException("Multiple Event Elements found!");
            }

            XmlNode deroot = denodelist[0];

            foreach (XmlNode node in deroot.ChildNodes)
            {
                if (string.IsNullOrEmpty(node.InnerText))
                {
                    continue;
                }

                switch (node.LocalName)
                {
                case "EventID":
                    this.EventID = node.InnerText;
                    break;

                case "EventTypeDescriptor":
                    EventTypeDescriptor.EventTypeCode = new ValueList(doc.GetElementsByTagName("EventTypeCode", Constants.EmeventNamespace)[0]);
                    //this.EventTypeDescriptor.SerialEventTypeCode = doc.GetElementsByTagName("EventTypeCode", Constants.EmeventNamespace)[0];//.InnerText; // 1/11/2017 changed property to "SerialEventTypeCode"
                    // to be consistent with LinkedEventCategory....should it be "EventTypeCode",
                    // or will XML be updated to be "SerialEventTypeCode"?
                    this.EventTypeDescriptor.EventTypeDescriptorExtension = new List <string>(0);
                    XmlNodeList extensions = doc.GetElementsByTagName("EventTypeDescriptorExtension", Constants.EmeventNamespace);
                    foreach (XmlNode extension in extensions)
                    {
                        this.EventTypeDescriptor.EventTypeDescriptorExtension.Add(extension.InnerText);
                    }
                    break;

                case "EventLocation":
                    this.EventLocation.LocationCylinder = new LocationCylinder();
                    this.EventLocation.LocationCylinder.LocationPoint               = new LocationPoint();
                    this.EventLocation.LocationCylinder.LocationPoint.Point         = new Point();
                    this.EventLocation.LocationCylinder.LocationPoint.Point.pos     = doc.GetElementsByTagName("Point", Constants.GmlNamespace)[0].InnerText;
                    this.EventLocation.LocationCylinder.LocationCylinderRadiusValue = decimal.Parse(doc.GetElementsByTagName("LocationCylinderRadiusValue", Constants.MofNamespace)[0].InnerText);
                    this.EventLocation.LocationCylinder.LocationCreationCode        = doc.GetElementsByTagName("LocationCreationCode", Constants.MofNamespace)[0].InnerText;
                    break;

                case "EventValidityDateTimeRange":
                    this.EventValidityDateTimeRange           = new EventValidityDateTimeRange();
                    this.EventValidityDateTimeRange.StartDate = Convert.ToDateTime(doc.GetElementsByTagName("StartDate", Constants.NiemcoreNamespace)[0].InnerText);
                    this.EventValidityDateTimeRange.EndDate   = Convert.ToDateTime(doc.GetElementsByTagName("EndDate", Constants.NiemcoreNamespace)[0].InnerText);
                    break;

                case "EventComment":
                    EventComment newComment     = new EventComment();
                    XmlNodeList  commentContent = node.ChildNodes;
                    foreach (XmlNode childNode in commentContent)
                    {
                        if (string.IsNullOrEmpty(childNode.InnerText))
                        {
                            continue;
                        }
                        switch (childNode.LocalName)
                        {
                        case "DateTime":
                            newComment.DateTime = Convert.ToDateTime(childNode.InnerText);
                            break;

                        case "CommentText":
                            newComment.CommentText = childNode.InnerText;
                            break;

                        case "OrganizationIdentification":
                            newComment.OrganizationIdentification = childNode.InnerText;
                            break;

                        case "PersonHumanResourceIdentification":
                            newComment.PersonHumanResourceIdentification = childNode.InnerText;
                            break;

                        default:
                            throw new ArgumentException("Unexpected Node Name: " + childNode.Name + " in NIEM Event Comment");
                        }
                    }
                    this.EventComment.Add(newComment);
                    break;

                case "EventMessageDateTime":
                    this.EventMessageDateTime = Convert.ToDateTime(node.FirstChild.InnerXml);
                    break;

                case "ResourceDetail":
                    ResourceDetail resource = new ResourceDetail();
                    this.Details = CreateResourceDetail(node, resource);
                    break;

                case "IncidentDetail":
                    IncidentDetail incident = new IncidentDetail();
                    this.Details = CreateIncidentDetail(node, incident);
                    break;

                case "InfrastructureDetail":
                    throw new NotImplementedException("ReadXML for " + node.Name + " not implemented yet");

                default:
                    throw new ArgumentException("Unexpected Node Name: " + node.Name + " in NIEM Event");
                }
            }
        }
Пример #3
0
        private EventDetails CreateIncidentDetail(XmlNode node, IncidentDetail incident)
        {
            incident.Status = new IncidentStatus();
            incident.Status.SecondaryStatus = new List <AltStatus>(0);
            incident.OwningOrg = new IncidentOrganization();
            XmlNodeList incidentChildNodes = node.ChildNodes;

            foreach (XmlNode childNode in incidentChildNodes)
            {
                XmlNodeList statusNodes = childNode.ChildNodes;
                if (string.IsNullOrEmpty(childNode.InnerText))
                {
                    continue;
                }
                switch (childNode.LocalName)
                {
                case "IncidentStatus":
                    foreach (XmlNode statusNode in statusNodes)
                    {
                        if (string.IsNullOrEmpty(statusNode.InnerText))
                        {
                            continue;
                        }
                        switch (statusNode.LocalName)
                        {
                        case "IncidentPrimaryStatus":
                            IncidentPrimaryStatusCodeList outputPrim = GetCode <IncidentPrimaryStatusCodeList>(statusNode.InnerText);
                            incident.Status.PrimaryStatus = outputPrim;
                            break;

                        case "IncidentEIDDStatus":
                            IncidentEIDDStatusCodeList outputEEID = GetCode <IncidentEIDDStatusCodeList>(statusNode.InnerText);
                            incident.AddEIDDStatus(outputEEID);
                            break;

                        case "IncidentPulsePointStatus":
                            IncidentPulsePointStatusCodeList outputPulsePoint = GetCode <IncidentPulsePointStatusCodeList>(statusNode.InnerText);
                            incident.AddPulsePointStatus(outputPulsePoint);
                            break;

                        case "IncidentSecondaryStatusText":
                            incident.AddSecondaryStatusText(statusNode.InnerText, "Freetext");
                            break;

                        default:
                            throw new ArgumentException("Unexpected Node Name: " + statusNode.Name + " in NIEM Incident Status");
                        }
                    }
                    break;

                case "IncidentOwningOrganization":
                    foreach (XmlNode orgNode in childNode.ChildNodes)
                    {
                        switch (orgNode.LocalName)
                        {
                        case "OrganizationIdentification":
                            incident.OwningOrg.OrgID = orgNode.InnerText;
                            break;

                        case "ResourceIdentifier":
                            incident.OwningOrg.IncidentID = orgNode.InnerText;
                            break;

                        default:
                            throw new ArgumentException("Unexpected Node Name: " + childNode.Name + " in NIEM Owning Organization");
                        }
                    }
                    break;

                default:
                    throw new ArgumentException("Unexpected Node Name: " + childNode.Name + " in NIEM Event");
                }
            }
            return(incident);
        }
        /// <summary>
        /// Deserializes Event object with it's proper event detail.
        /// Requires the xmlString which is used for the deserialization
        /// </summary>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            try
            {
                JObject obj  = JObject.Load(reader);
                Object  root = null;

                if (xmlString != null)
                {
                    //-- Deserializing Event without detail
                    XmlDocument xD = new XmlDocument();
                    xD.LoadXml(xmlString);
                    string eventString = "";

                    foreach (XmlNode child in xD.ChildNodes)
                    {
                        if (child.Name == "emlc:Event")
                        {
                            eventString = child.OuterXml;
                            break;
                        }
                    }

                    xD.LoadXml(eventString);


                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Event));
                    StringReader  xmlReader     = new StringReader(eventString);
                    Event         myEvent       = (Event)xmlSerializer.Deserialize(xmlReader);

                    //-- Deserializing EventDetails if it exists
                    JToken incTok = obj.SelectToken("emlc:Event.emlc:IncidentDetail");
                    JToken resTok = obj.SelectToken("emlc:Event.emlc:ResourceDetail");
                    JToken maTok  = obj.SelectToken("emlc:Event.maid:MutualAidDetail");
                    JToken infTok = obj.SelectToken("emlc:Event.emlc:InfrastructureDetail");


                    if (incTok != null) // If Details is an IncidentDetail
                    {
                        string elementName = "emlc:IncidentDetail";
                        Type   detailType  = typeof(IncidentDetail);
                        string detailXML   = "";

                        // Getting XML for just this detail
                        foreach (XmlNode child in xD.FirstChild.ChildNodes)
                        {
                            if (child.Name == elementName)
                            {
                                detailXML = child.OuterXml;
                                break;
                            }
                        }

                        // Deserializing
                        XmlSerializer detailSerializer = new XmlSerializer(detailType);
                        StringReader  detailReader     = new StringReader(detailXML);

                        IncidentDetail myDetail = (IncidentDetail)detailSerializer.Deserialize(detailReader);
                        myEvent.Details = myDetail;
                    }
                    else if (resTok != null) // If Details is a ResourceDetail
                    {
                        Type   detailType  = typeof(ResourceDetail);
                        JToken detailToken = resTok;
                        string elementName = "emlc:ResourceDetail";
                        string detailXML   = "";

                        // Getting XML for just this detail
                        foreach (XmlNode child in xD.FirstChild.ChildNodes)
                        {
                            if (child.Name == elementName)
                            {
                                detailXML = child.OuterXml;
                                break;
                            }
                        }

                        // Deserializing
                        XmlSerializer detailSerializer = new XmlSerializer(detailType);
                        StringReader  detailReader     = new StringReader(detailXML);

                        ResourceDetail myDetail = (ResourceDetail)detailSerializer.Deserialize(detailReader);
                        myEvent.Details = myDetail;
                    }
                    else if (infTok != null) // If Details is an InfrastructureDetail
                    {
                        Type   detailType  = typeof(InfrastructureDetail);
                        JToken detailToken = infTok;
                        string elementName = "emlc:InfrastructureDetail";
                        string detailXML   = "";

                        // Getting XML for just this detail
                        foreach (XmlNode child in xD.FirstChild.ChildNodes)
                        {
                            if (child.Name == elementName)
                            {
                                detailXML = child.OuterXml;
                                break;
                            }
                        }

                        // Deserializing
                        XmlSerializer detailSerializer = new XmlSerializer(detailType);
                        StringReader  detailReader     = new StringReader(detailXML);

                        InfrastructureDetail myDetail = (InfrastructureDetail)detailSerializer.Deserialize(detailReader);
                        myEvent.Details = myDetail;
                    }
                    else if (maTok != null) // If Details is a MutualAidDetail
                    {
                        JToken detailToken = maTok;
                        string elementName = "maid:MutualAidDetail";
                        string detailXML   = "";

                        // Getting XML for just this detail
                        foreach (XmlNode child in xD.FirstChild.ChildNodes)
                        {
                            if (child.Name == elementName)
                            {
                                detailXML = child.OuterXml;
                                break;
                            }
                        }

                        // Deserializing Mutual Aid Detail (requires MA Converter)
                        string json = detailToken.ToString();


                        NIEMUtil.setDefaultDeseralizeSetting();
                        MutualAidDetail myDetail = JsonConvert.DeserializeObject <MutualAidDetail>(json, new JsonConverter[] { new deserialMAConvert(detailXML) });


                        myEvent.Details = myDetail;
                    }
                    else
                    {
                        throw new JsonSerializationException("XML string must be specified");
                    }

                    return(myEvent);
                }
            } catch (Exception e)
            {
                string r = e.ToString();
            }

            return(null);
        }
        /// <summary>
        ///  Create a IncidentDetail
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public IncidentDetailVMDC CreateIncidentDetail(string currentUser, string user, string appID, string overrideID, IncidentDetailDC dc, IRepository <IncidentDetail> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dc)
                {
                    throw new ArgumentOutOfRangeException("dc");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Create a new ID for the IncidentDetail item
                    dc.Code = Guid.NewGuid();

                    // Map data contract to model
                    IncidentDetail destination = mappingService.Map <IncidentDetailDC, IncidentDetail>(dc);

                    // Add the new item
                    dataRepository.Add(destination);

                    // Commit unit of work
                    uow.Commit();

                    // Map model back to data contract to return new row id.
                    dc = mappingService.Map <IncidentDetail, IncidentDetailDC>(destination);
                }

                // Create aggregate data contract
                IncidentDetailVMDC returnObject = new IncidentDetailVMDC();

                // Add new item to aggregate
                returnObject.IncidentDetailItem = dc;

                return(returnObject);
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
        /// <summary>
        /// Retrieve a IncidentDetail with associated lookups
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public IncidentDetailVMDC GetIncidentDetail(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <IncidentDetail> dataRepository
                                                    , IExceptionManager exceptionManager, IMappingService mappingService)

        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    IncidentDetailDC destination = null;

                    // If code is null then just return supporting lists
                    if (!string.IsNullOrEmpty(code))
                    {
                        // Convert code to Guid
                        Guid codeGuid = Guid.Parse(code);

                        // Retrieve specific IncidentDetail
                        IncidentDetail dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                        // Convert to data contract for passing through service interface
                        destination = mappingService.Map <IncidentDetail, IncidentDetailDC>(dataEntity);
                    }



                    // Create aggregate contract
                    IncidentDetailVMDC returnObject = new IncidentDetailVMDC();

                    returnObject.IncidentDetailItem = destination;

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
        /// <summary>
        /// Update a IncidentDetail
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="lockID"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public void DeleteIncidentDetail(string currentUser, string user, string appID, string overrideID, string code, string lockID, IRepository <IncidentDetail> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (string.IsNullOrEmpty(code))
                {
                    throw new ArgumentOutOfRangeException("code");
                }
                if (string.IsNullOrEmpty(lockID))
                {
                    throw new ArgumentOutOfRangeException("lockID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Convert string to guid
                    Guid codeGuid = Guid.Parse(code);

                    // Find item based on ID
                    IncidentDetail dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                    // Delete the item
                    dataRepository.Delete(dataEntity);

                    // Commit unit of work
                    uow.Commit();
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);
            }
        }
Пример #8
0
 public Event(IncidentDetail det) : this()
 {
     this.Details = det;
 }