static void Main(string[] args) { Polygon2D poly = new Polygon2D(); poly.AddVertex(new Vec2D(1,1)); poly.AddVertex(new Vec2D(4, 1)); poly.AddVertex(new Vec2D(2.5, 3)); poly.AddVertex(new Vec2D(4, 3)); poly.AddVertex(new Vec2D(4, 4)); poly.AddVertex(new Vec2D(2, 3.5)); bool r; r = Polygon2D.IsPointInside(poly,new Vec2D(5, 3)); //false r = Polygon2D.IsPointInside(poly, new Vec2D(2, 2)); //true r = Polygon2D.IsPointInside(poly, new Vec2D(3.5, 3.5)); //true r = Polygon2D.IsPointInside(poly, new Vec2D(1, 3.5)); //false r = Polygon2D.IsPointInside(poly, new Vec2D(3, 2.5)); //false r = Polygon2D.DoLinesIntersect(new Vec2D(0, 2), new Vec2D(3, 0), new Vec2D(1, 1), new Vec2D(3, 3)); //true r = Polygon2D.DoLinesIntersect(new Vec2D(0, 2), new Vec2D(3, 0), new Vec2D(2, 1), new Vec2D(3, 3)); //false DataValue dv = DataValueFactory.BuildValue("CapabilityType"); ((CapabilityValue)dv).effects.Add(new CapabilityValue.Effect("foo",45,10,.50)); ((CapabilityValue)dv).effects.Add(new CapabilityValue.Effect("foo", 100, 5, .25)); string s = DataValueFactory.XMLSerialize(dv); DataValue dv2 = DataValueFactory.XMLDeserialize(s); DataValue dv3 = DataValueFactory.BuildValue("VulnerabilityType"); VulnerabilityValue.Transition t = new VulnerabilityValue.Transition("dead"); t.conditions.Add(new VulnerabilityValue.TransitionCondition("foo",50,0,0)); t.conditions.Add(new VulnerabilityValue.TransitionCondition("bar", 20,0,0)); ((VulnerabilityValue)dv3).transitions.Add(t); t = new VulnerabilityValue.Transition("hurt"); t.conditions.Add(new VulnerabilityValue.TransitionCondition("foo", 25,0,0)); ((VulnerabilityValue)dv3).transitions.Add(t); s = DataValueFactory.XMLSerialize(dv3); DataValue dv4 = DataValueFactory.XMLDeserialize(s); System.Console.WriteLine(s == DataValueFactory.XMLSerialize(dv4)); DataValue dv5 = DataValueFactory.BuildValue("StateTableType"); DataValue dv6 = DataValueFactory.BuildValue("AttributeCollectionType"); ((StateTableValue)dv5).states["foo"] = DataValueFactory.BuildValue("DoubleType"); ((AttributeCollectionValue)dv6).attributes["foo2"] = DataValueFactory.BuildValue("DoubleType"); ((StateTableValue)dv5).states["bar"] = dv6; s = DataValueFactory.XMLSerialize(dv5); DataValue dv7 = DataValueFactory.XMLDeserialize(s); DataValue dv8 = DataValueFactory.BuildValue("StringListType"); ((StringListValue)dv8).strings.Add("Foo"); ((StringListValue)dv8).strings.Add("Bar"); s = DataValueFactory.XMLSerialize(dv8); dv8 = DataValueFactory.XMLDeserialize(s); DataValue dv9 = DataValueFactory.BuildValue("PolygonType"); ((PolygonValue)dv9).points.Add(new PolygonValue.PolygonPoint(0, 0)); ((PolygonValue)dv9).points.Add(new PolygonValue.PolygonPoint(10.234, 34.097)); ((PolygonValue)dv9).points.Add(new PolygonValue.PolygonPoint(10.234, 1.2)); s = DataValueFactory.XMLSerialize(dv9); DataValue dv10 = DataValueFactory.XMLDeserialize(s); }
/// <summary> /// Sends an event to the server which updates a single object's Vulnerability object. /// This is a very complicated data structure. It contains a list of states to transition to. /// The index of these states should be used to index into the dictionaries for Capabilities, Ranges, Intensities, and Probabilities. /// Within each state, there are a series of Capabilities, Ranges, Intensities, and Probabilities. The index of each of these /// collections should correlate such that Capabilities[1], Ranges[1], Intensities[1] and Probabilities[1] are all /// for a single transition. As these are TIGHTLY correlated, you cannot skip inserting any values into this collection. /// </summary> /// <param name="objectID">The object's ID</param> /// <param name="states">Simple list of state names to transition to</param> /// <param name="capabilities">Dictionary whose index is related to the index of it's corresponding state. The value list index relates to the other Dictionary/List collections passed in as parameters.</param> /// <param name="ranges">Dictionary whose index is related to the index of it's corresponding state. The value list index relates to the other Dictionary/List collections passed in as parameters.</param> /// <param name="intensities">Dictionary whose index is related to the index of it's corresponding state. The value list index relates to the other Dictionary/List collections passed in as parameters.</param> /// <param name="probabilities">Dictionary whose index is related to the index of it's corresponding state. The value list index relates to the other Dictionary/List collections passed in as parameters.</param> public void UpdateObjectVulnerabilities(String objectID, List<String> states, Dictionary<int, List<String>> capabilities, Dictionary<int, List<Double>> ranges, Dictionary<int, List<int>> intensities, Dictionary<int, List<Double>> probabilities) { VulnerabilityValue dv = new VulnerabilityValue(); //construct list of conditions -> CapName/Range/Effect/Probability; //conditions map to a state to change to. state index in "states" corresponds to key of dictionary in other dictionaries try { for (int x = 0; x < states.Count; x++) { if ((capabilities[x].Count == ranges[x].Count) && (ranges[x].Count == intensities[x].Count) && (intensities[x].Count == probabilities[x].Count)) { VulnerabilityValue.Transition tr = new VulnerabilityValue.Transition(states[x]); for (int y = 0; y < capabilities[x].Count; y++) { VulnerabilityValue.TransitionCondition tc = new VulnerabilityValue.TransitionCondition(capabilities[x][y], intensities[x][y], ranges[x][y], probabilities[x][y]); tr.conditions.Add(tc); } if (tr.conditions.Count > 0) { dv.transitions.Add(tr); } } else { Console.WriteLine("In UpdateObjectVulnerabilities: Lists of Capabilities, Ranges, Intensities and Probabilities for state "+states[x]+" have different counts"); } } } catch (Exception e) { return; } if(dv.transitions.Count > 0) SendObjectAttributeUpdateEvent(objectID, "Vulnerability", dv); }
private static DataValue DefineVulnerabilityValue(Dictionary<string, SingletonVulnerabilityType> singletons, List<ComboVulnerabilityType> combo) { DataValue returnVulnerabilityValue = (VulnerabilityValue)DataValueFactory.BuildValue("VulnerabilityType"); VulnerabilityValue.Transition t; VulnerabilityValue.TransitionCondition tc; string state; int effect; double range; double probability; foreach (ComboVulnerabilityType c in combo) { state = c.NewState; t = new VulnerabilityValue.Transition(state); foreach (ContributionType cont in c.Contributions) { effect = cont.Effect; string capability = cont.Capability; range = cont.Range; probability = cont.Probability; tc = new VulnerabilityValue.TransitionCondition(capability, effect, range, probability); t.conditions.Add(tc); } ((VulnerabilityValue)returnVulnerabilityValue).transitions.Add(t); } foreach (string capability in singletons.Keys) { singletons[capability].Transitions.Sort(); foreach (TransitionType transType in singletons[capability].Transitions) { effect = transType.Effect; state = transType.State; range = transType.Range; probability = transType.Probability; tc = new VulnerabilityValue.TransitionCondition(capability, effect, range, probability); t = new VulnerabilityValue.Transition(state); t.conditions.Add(tc); ((VulnerabilityValue)returnVulnerabilityValue).transitions.Add(t); } } return returnVulnerabilityValue; }