public void Test_CCIItemWithReferenceDataIsValid()
        {
            CciItem cci = new CciItem();

            cci.cciId       = "CCI-2345";
            cci.status      = "myStatus";
            cci.publishDate = DateTime.Now.ToShortDateString();
            cci.contributor = "Cingulara";
            cci.definition  = "This is my definition";
            cci.type        = "thisType";
            cci.parameter   = "myParams";
            cci.note        = "man this is complicated!";

            CciReference cciRef = new CciReference();

            cciRef.creator  = "NIST";
            cciRef.title    = "This is my title here";
            cciRef.location = "My location";
            cciRef.index    = "AU-9 1.a(2)";
            cci.references.Add(cciRef);

            // test things out
            Assert.True(cci != null);
            Assert.True(!string.IsNullOrEmpty(cci.cciId));
            Assert.True(!string.IsNullOrEmpty(cci.status));
            Assert.True(!string.IsNullOrEmpty(cci.publishDate));
            Assert.True(!string.IsNullOrEmpty(cci.contributor));
            Assert.True(!string.IsNullOrEmpty(cci.definition));
            Assert.True(!string.IsNullOrEmpty(cci.type));
            Assert.True(!string.IsNullOrEmpty(cci.parameter));
            Assert.True(!string.IsNullOrEmpty(cci.note));
            Assert.True(cci.references != null);
            Assert.True(cci.references.Count == 1);
        }
        public void Test_CCIItemWithDataIsValid()
        {
            CciItem cci = new CciItem();

            cci.cciId       = "CCI-2345";
            cci.status      = "myStatus";
            cci.publishDate = DateTime.Now.ToShortDateString();
            cci.contributor = "Cingulara";
            cci.definition  = "This is my definition";
            cci.type        = "thisType";
            cci.parameter   = "myParams";
            cci.note        = "man this is complicated!";

            // test things out
            Assert.True(cci != null);
            Assert.True(!string.IsNullOrEmpty(cci.cciId));
            Assert.True(!string.IsNullOrEmpty(cci.status));
            Assert.True(!string.IsNullOrEmpty(cci.publishDate));
            Assert.True(!string.IsNullOrEmpty(cci.contributor));
            Assert.True(!string.IsNullOrEmpty(cci.definition));
            Assert.True(!string.IsNullOrEmpty(cci.type));
            Assert.True(!string.IsNullOrEmpty(cci.parameter));
            Assert.True(!string.IsNullOrEmpty(cci.note));
            Assert.True(cci.references != null);
            Assert.True(cci.references.Count == 0);
        }
        public void Test_CciItemWithDataIsValid()
        {
            CciItem cci = new CciItem();

            cci.cciId       = "cciId";
            cci.status      = "status";
            cci.publishDate = "mydate";
            cci.contributor = "mycontributor";
            cci.definition  = "mydefinition";
            cci.type        = "mytype";
            cci.parameter   = "param1";
            cci.note        = "mynote";
            CciReference ccir = new CciReference();

            ccir.creator      = "me";
            ccir.title        = "mytitle";
            ccir.version      = "v1";
            ccir.location     = "mylocation";
            ccir.index        = "2.3";
            ccir.majorControl = "AC-2";
            cci.references.Add(ccir);

            // test things out
            Assert.True(cci != null);
            Assert.True(cci.references != null);
            Assert.True(cci.references.Count == 1);
            Assert.True(cci.references[0] != null);
        }
        public void Test_NewCciItemIsValid()
        {
            CciItem cci = new CciItem();

            Assert.True(cci != null);
            Assert.True(cci.references != null);
            Assert.True(cci.references.Count == 0);
        }
Beispiel #5
0
        /// <summary>
        /// Return a CCI Item record with the title and references
        /// </summary>
        /// <returns></returns>
        public static CciItem GetCCIItemReferences(string cciId)
        {
            // get the result ready to receive the info and send on
            CciItem cciItem = new CciItem();

            // Create a new connection factory to create a connection.
            ConnectionFactory cf = new ConnectionFactory();
            // add the options for the server, reconnecting, and the handler events
            Options opts = ConnectionFactory.GetDefaultOptions();

            opts.MaxReconnect            = -1;
            opts.ReconnectWait           = 1000;
            opts.Name                    = "openrmf-api-compliance";
            opts.Url                     = Environment.GetEnvironmentVariable("NATSSERVERURL");
            opts.AsyncErrorEventHandler += (sender, events) =>
            {
                Console.WriteLine(string.Format("NATS client error. Server: {0}. Message: {1}. Subject: {2}", events.Conn.ConnectedUrl, events.Error, events.Subscription.Subject));
            };

            opts.ServerDiscoveredEventHandler += (sender, events) =>
            {
                Console.WriteLine(string.Format("A new server has joined the cluster: {0}", events.Conn.DiscoveredServers));
            };

            opts.ClosedEventHandler += (sender, events) =>
            {
                Console.WriteLine(string.Format("Connection Closed: {0}", events.Conn.ConnectedUrl));
            };

            opts.ReconnectedEventHandler += (sender, events) =>
            {
                Console.WriteLine(string.Format("Connection Reconnected: {0}", events.Conn.ConnectedUrl));
            };

            opts.DisconnectedEventHandler += (sender, events) =>
            {
                Console.WriteLine(string.Format("Connection Disconnected: {0}", events.Conn.ConnectedUrl));
            };

            // Creates a live connection to the NATS Server with the above options
            IConnection c = cf.CreateConnection(opts);

            // send the message with the subject, passing in the CCI number/id
            Msg reply = c.Request("openrmf.compliance.cci.references", Encoding.UTF8.GetBytes(cciId), 30000);

            // save the reply and get back the checklist to score
            if (reply != null)
            {
                cciItem = JsonConvert.DeserializeObject <CciItem>(Compression.DecompressString(Encoding.UTF8.GetString(reply.Data)));
                c.Close();
                return(cciItem);
            }
            c.Close();
            return(cciItem);
        }
        /// <summary>
        /// Generate the list of CCI items from the NIST listing in the XML file included
        /// </summary>
        /// <returns>The list of CCI items for use in filtering</returns>
        public static List <CciItem> LoadNistToCci()
        {
            List <CciItem> cciList = new List <CciItem>();
            CciItem        item;       // the CCI item
            CciReference   reference;  // list of references
            int            len    = 0; // the length to find the major control piece
            XmlDocument    xmlDoc = new XmlDocument();
            // get the file path for the CCI to NIST listing
            var ccipath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/U_CCI_List.xml";

            if (File.Exists(ccipath))
            {
                xmlDoc.LoadXml(File.ReadAllText(ccipath));
                XmlNodeList itemList = xmlDoc.GetElementsByTagName("cci_item");

                foreach (XmlElement child in itemList)
                {
                    item = new CciItem();
                    // get all the main pieces of the XML record for this
                    foreach (XmlElement ccidata in child.ChildNodes)
                    {
                        if (ccidata.Name == "status")
                        {
                            item.status = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "publishdate")
                        {
                            item.publishDate = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "contributor")
                        {
                            item.contributor = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "definition")
                        {
                            item.definition = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "type")
                        {
                            item.type = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "parameter")
                        {
                            item.parameter = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "note")
                        {
                            item.note = ccidata.InnerText;
                        }
                        else if (ccidata.Name == "references")
                        {
                            // cycle through all the references
                            foreach (XmlElement cciref in ccidata.ChildNodes)
                            {
                                reference = new CciReference();
                                foreach (XmlAttribute attr in cciref.Attributes)
                                {
                                    if (attr.Name == "creator")
                                    {
                                        reference.creator = attr.InnerText;
                                    }
                                    else if (attr.Name == "title")
                                    {
                                        reference.title = attr.InnerText;
                                    }
                                    else if (attr.Name == "version")
                                    {
                                        reference.version = attr.InnerText;
                                    }
                                    else if (attr.Name == "location")
                                    {
                                        reference.location = attr.InnerText;
                                    }
                                    else if (attr.Name == "index")
                                    {
                                        reference.index = attr.InnerText;
                                        len             = EndOfIndex(attr.InnerText);
                                        if (len > 0)
                                        {
                                            reference.majorControl = attr.InnerText.Substring(0, len);
                                        }
                                        else
                                        {
                                            reference.majorControl = reference.index;
                                        }
                                    }
                                }
                                item.references.Add(reference);
                            }
                        }
                    }
                    // get the CCI ID
                    if (child.Attributes.Count == 1)
                    {
                        item.cciId = child.Attributes[0].InnerText;
                    }
                    cciList.Add(item);
                }
            }
            return(cciList);
        }
        public void Test_NewCCIItemIsValid()
        {
            CciItem cci = new CciItem();

            Assert.True(cci != null);
        }