コード例 #1
0
        /// <summary>
        /// Jurisdiction rule
        /// </summary>
        /// <param name="knowledge"></param>
        private void jurisdiction(Knowledge knowledge)
        {
            for (int i = 0; i < knowledges.Count; i++)
            {
                if (knowledges[i].knowledgeType == KnowledgeType.believes && knowledges[i].statement is Knowledge)
                {
                    Knowledge secondKnowledge = (Knowledge)knowledges[i].statement;

                    if (secondKnowledge.agent.Equals(knowledge.agent) && secondKnowledge.knowledgeType.Equals(KnowledgeType.believes) &&
                        secondKnowledge.statement.Equals(knowledge.statement))
                    {
                        addKnowledge(new Knowledge(this, KnowledgeType.believes, knowledge.statement));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Nonce-verification rule
        /// </summary>
        /// <param name="statement"></param>
        private void nonceVerificationRule(IStatement statement)
        {
            for (int i = 0; i < knowledges.Count; i++)
            {
                if (knowledges[i].knowledgeType == KnowledgeType.believes && knowledges[i].statement is Knowledge)
                {
                    Knowledge knowledge = (Knowledge)knowledges[i].statement;

                    if (!knowledge.agent.Equals(this) && knowledge.knowledgeType.Equals(KnowledgeType.said) &&
                        knowledge.statement.Equals(statement))
                    {
                        addKnowledge(new Knowledge(this, KnowledgeType.believes,
                                                   new Knowledge(((Knowledge)knowledges[i].statement).agent, KnowledgeType.believes, ((Knowledge)knowledges[i].statement).statement)));
                    }
                }
            }
        }
コード例 #3
0
        public void addKnowledge(Knowledge newKnowledge)
        {
            bool isNewKnowledge = true;

            foreach (Knowledge knowledge in knowledges)
            {
                if (knowledge.Equals(newKnowledge))
                {
                    isNewKnowledge = false;
                }
            }

            if (isNewKnowledge)
            {
                knowledges.Add(newKnowledge);
            }
        }
コード例 #4
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Knowledge))
            {
                return(false);
            }

            Knowledge objKnowledge = (Knowledge)obj;

            if (agent.Id.Equals(objKnowledge.agent.Id) && knowledgeType.Equals(objKnowledge.knowledgeType) &&
                statement.Equals(objKnowledge.statement))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: radusecrieru/BanVerifier
        private Protocol Parse(string jProtocol)
        {
            protocol = new Protocol();

            /** Parse the contents of the json-formatted protocol */
            dynamic jsonProtocol   = JsonConvert.DeserializeObject(jProtocol);
            dynamic jsonAgents     = jsonProtocol.agents;
            dynamic jsonPhases     = jsonProtocol.phases;
            dynamic jsonKeys       = jsonProtocol.keys;
            dynamic jsonKnowledges = jsonProtocol.knowledges;

            foreach (dynamic jsonAgent in jsonAgents)
            {
                Agent   newAgent = new Agent();
                JObject jAgent   = new JObject(jsonAgent);
                newAgent.Id = jAgent.Properties().Select(p => p.Name).ElementAt(0);
                JObject jAgentValue = (JObject)jAgent.Properties().Select(p => p.Value).ElementAt(0);
                protocol.Agents.Add(newAgent);
            }

            foreach (dynamic jsonKey in jsonKeys)
            {
                Key key = new Key();

                Agent a1 = protocol.Agents.Where(p => p.Id == jsonKey.a1.ToString()).ElementAt(0);
                Agent a2 = protocol.Agents.Where(p => p.Id == jsonKey.a2.ToString()).ElementAt(0);

                key.agents.Add(a1);
                key.agents.Add(a2);

                protocol.Keys.Add(key);
            }

            foreach (dynamic jsonKnowledge in jsonKnowledges)
            {
                Knowledge knowledge = ParseKnowledge(jsonKnowledge);
                knowledge.agent.addKnowledge(knowledge);
            }

            foreach (dynamic jsonPhase in jsonPhases)
            {
                Phase phase = new Phase();

                JObject jPhase      = new JObject(jsonPhase);
                JObject jPhaseValue = (JObject)jPhase.Properties().Select(p => p.Value).ElementAt(0);

                if (jPhaseValue.Property("sender") != null)
                {
                    JObject jSender    = new JObject(jPhaseValue.Property("sender"));
                    string  id         = (string)jSender.Properties().Select(p => p.Value).ElementAt(0);
                    Agent   foundAgent = protocol.Agents.Where(p => p.Id == id).ElementAt(0);

                    phase.Sender = foundAgent;
                }

                if (jPhaseValue.Property("receiver") != null)
                {
                    JObject jReceiver  = new JObject(jPhaseValue.Property("receiver"));
                    string  id         = (string)jReceiver.Properties().Select(p => p.Value).ElementAt(0);
                    Agent   foundAgent = protocol.Agents.Where(a => a.Id == id).ElementAt(0);

                    phase.Receiver = foundAgent;
                }

                if (jPhaseValue.Property("message") != null)
                {
                    JObject jMessage      = new JObject(jPhaseValue.Property("message"));
                    JObject jMessageValue = (JObject)jMessage.Properties().Select(p => p.Value).ElementAt(0);

                    phase.message = this.ParseMessage(jMessageValue);
                }

                protocol.Phases.Add(phase);
            }

            return(protocol);
        }