Ejemplo n.º 1
0
 /// <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);
 }
Ejemplo n.º 2
0
        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;
        }