private void PlaySoundEvidenceNearby(IEvidence e)
 {
     if (canPlaySound)
     {
         canPlaySound = false;
         e.SoundPlayerNearby.Play();
     }
 }
 public static UserAgent newDeviceUserAgent(IEvidence evidence)
 {
     String ua = evidence.Get("x-device-user-agent");
     if (ua == null || ua.Trim().Length < 2)
     {
         ua = evidence.Get("user-agent");
     }
     return newUserAgent(ua);
 }
 //XXX: to be refined, this should NOT be the main entry point, we should use a set of evidence derivation
 public BuiltObject Get(IEvidence evdnc, int threshold)
 {
     UserAgent ua = UserAgentFactory.newDeviceUserAgent(evdnc);
     if (ua != null)
     {
         return Get(ua, threshold);
     }
     return null;
 }
        private void Process()
        {
            if (!IsActive)
            {
                return;
            }

            if (!inspecting)
            {
                if (Evidence.Count < 1)
                {
                    return;
                }

                DisableCollectedEvidence();

                closest = GetClosestEvidence();

                if (closest == null)
                {
                    return;
                }

                if (closest.IsCollected)
                {
                    return;
                }

                if (!IsEvidenceWithinDetectionDistance(closest))
                {
                    canPlaySound = true;
                    return;
                }

                PlaySoundEvidenceNearby(closest);

                Game.DisplayHelp(closest.TextInteractWithEvidence, INFO_INTERACT_TIME);

                if (!Game.IsKeyDown(closest.KeyInteract))
                {
                    closest.PlaySoundPlayerNearby = false;
                    return;
                }

                closest.Interact();
                inspecting = true;
            }
            else
            {
                if (DoesPlayerQuitInspecting(closest))
                {
                    inspecting = false;
                }
            }
        }
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary <string, object> GetContextClaims(string aspectName)
        {
            using (new Tracer(aspectName))
            {
                if (_contextEngineClient == null)
                {
                    // Apparently an exception occurred in the class constructor; it should have logged the exception already.
                    throw new DxaException("Context Engine Client was not initialized. Check the log file for errors.");
                }

                // TODO: Not really nice to use HttpContext at this level.
                HttpContext httpContext = HttpContext.Current;
                if (httpContext == null)
                {
                    throw new DxaException("Cannot obtain HttpContext.");
                }
                HttpRequest httpRequest   = httpContext.Request;
                HttpCookie  contextCookie = httpRequest.Cookies["context"];

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", httpRequest.UserAgent);
                    if (contextCookie != null && !string.IsNullOrEmpty(contextCookie.Value))
                    {
                        evidenceBuilder.With("cookie", string.Format("{0}={1}", contextCookie.Name, contextCookie.Value));
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    contextMap = _contextEngineClient.Resolve(evidence);
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.", ex);
                }

                IDictionary <string, object> result = new Dictionary <string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return(result);
            }
        }
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="evidence"></param>
        public void Add(IEvidence evidence)
        {
            //ensure this evidence has not already been added
            foreach(object value in list)
            {
                Item i = (Item)value;
                if (i.evidenceId == evidence.ID)
                    return;
            }

            //make the evidence evaluatable
            evidence.IsEvaluatable = true;

            //add it to the list
            list.Add(new Item(evidence.Priority, evidence.ID));
            list.Sort(new RuleEngine.Decisions.ExecutionList.Comparer());
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="evidence"></param>
        public void Add(IEvidence evidence)
        {
            //ensure this evidence has not already been added
            foreach (object value in list)
            {
                Item i = (Item)value;
                if (i.evidenceId == evidence.ID)
                {
                    return;
                }
            }

            //make the evidence evaluatable
            evidence.IsEvaluatable = true;

            //add it to the list
            list.Add(new Item(evidence.Priority, evidence.ID));
            list.Sort(new RuleEngine.Decisions.ExecutionList.Comparer());
        }
Example #8
0
        /// <summary>
        /// 克隆
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            ROM rom = new ROM();

            rom.callback = new Dictionary <string, Delegate>(this.callback);

            rom.dependentEvidence = new Dictionary <string, List <string> >();
            foreach (string key in this.dependentEvidence.Keys)
            {
                rom.dependentEvidence.Add(key, new List <string>(this.dependentEvidence[key]));
            }

            rom.evidenceCollection = new Dictionary <string, IEvidence>();
            foreach (string key in this.evidenceCollection.Keys)
            {
                IEvidence evidence = (IEvidence)this.evidenceCollection[key].Clone();
                rom.evidenceCollection.Add(key, evidence);
            }

            rom.models = new Dictionary <string, XmlDocument>(this.models);

            return(rom);
        }
 private bool IsEvidenceWithinDetectionDistance(IEvidence e)
 => DistToPlayer(e.Position) <= e.DistanceEvidenceClose;
 public void SetPassed(IEvidence reason)
 {
     featureImplemented = true;
     GiveEvidence(reason);
 }
 private void GiveEvidence(IEvidence reason)
 {
     Evidence = reason;
 }
        public IPropertyValues GetPropertyValues(IEvidence evdnc)
        {
            Device deviceFound = null;
            Browser browserFound = null;
            OSModel.OperatingSystem osFound = null;
            bool deviceIdentified = false;
            bool browserIdentified = false;
            bool osIdentified = false;
            UserAgent deviceUA = null;
            UserAgent browserUA = null;

            ODDRPropertyValues ret = new ODDRPropertyValues();
            Dictionary<String, Vocabulary> vocabularies = vocabularyHolder.GetVocabularies();

            foreach (String vocabularyKey in vocabularies.Keys)
            {
                Vocabulary vocabulary = vocabularies[vocabularyKey];
                Dictionary<String, VocabularyProperty> properties = vocabulary.properties;

                foreach (String propertyKey in properties.Keys)
                {
                    IPropertyName propertyName = new ODDRPropertyName(propertyKey, vocabularyKey);

                    VocabularyProperty vocabularyProperty = properties[propertyKey];
                    string[] aspects = vocabularyProperty.aspects;

                    for (int i = 0; i < aspects.Length; i++)
                    {
                        IPropertyRef propertyRef = new ODDRPropertyRef(propertyName, aspects[i]);
                        if (ASPECT_DEVICE.Equals(propertyRef.AspectName()))
                        {
                            if (!deviceIdentified)
                            {
                                if (deviceUA == null)
                                {
                                    deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc);
                                }
                                if (evdnc is BufferedODDRHTTPEvidence)
                                {
                                    deviceFound = ((BufferedODDRHTTPEvidence)evdnc).deviceFound;
                                }
                                if (deviceFound == null)
                                {
                                    deviceFound = deviceIdentificator.Get(deviceUA, this.threshold) as Device;
                                }
                                if (evdnc is BufferedODDRHTTPEvidence)
                                {
                                    ((BufferedODDRHTTPEvidence)evdnc).deviceFound = deviceFound;
                                }
                                deviceIdentified = true;
                            }
                            String property = null;
                            if (deviceFound != null)
                            {
                                property = deviceFound.Get(propertyRef.LocalPropertyName());
                                ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef));

                            }
                            else
                            {
                                ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef));
                            }
                            continue;

                        }
                        else if (ASPECT_WEB_BROWSER.Equals(propertyRef.AspectName()))
                        {
                            if (!browserIdentified)
                            {
                                if (browserUA == null)
                                {
                                    browserUA = UserAgentFactory.newBrowserUserAgent(evdnc);
                                }
                                if (evdnc is BufferedODDRHTTPEvidence)
                                {
                                    browserFound = ((BufferedODDRHTTPEvidence)evdnc).browserFound;
                                }
                                if (browserFound == null)
                                {
                                    browserFound = browserIdentificator.Get(browserUA, this.threshold) as Browser;
                                }
                                if (evdnc is BufferedODDRHTTPEvidence)
                                {
                                    ((BufferedODDRHTTPEvidence)evdnc).browserFound = browserFound;
                                }

                                browserIdentified = true;
                            }
                            String property = null;
                            if (browserFound != null)
                            {
                                property = browserFound.Get(propertyRef.LocalPropertyName());
                                ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef));

                            }
                            else
                            {
                                ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef));
                            }
                            continue;

                        }
                        else if (ASPECT_OPERATIVE_SYSTEM.Equals(propertyRef.AspectName()))
                        {
                            if (!osIdentified)
                            {
                                if (deviceUA == null)
                                {
                                    deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc);
                                }
                                if (evdnc is BufferedODDRHTTPEvidence)
                                {
                                    osFound = ((BufferedODDRHTTPEvidence)evdnc).osFound;
                                }
                                if (osFound == null)
                                {
                                    osFound = osIdentificator.Get(deviceUA, this.threshold) as OSModel.OperatingSystem;
                                }
                                if (evdnc is BufferedODDRHTTPEvidence)
                                {
                                    ((BufferedODDRHTTPEvidence)evdnc).osFound = osFound;
                                }

                                osIdentified = true;
                            }
                            String property = null;
                            if (osFound != null)
                            {
                                property = osFound.Get(propertyRef.LocalPropertyName());
                                ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef));

                            }
                            else
                            {
                                ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef));
                            }
                            continue;

                        }
                    }
                }
            }

            return ret;
        }
Example #13
0
 public Classifier(IEvidence first, IEvidence second)
 {
     _classA = first;
     _classB = second;
 }
Example #14
0
        /// <summary>
        /// 执行计算
        /// </summary>
        /// <param name="evidenceCollection"></param>
        /// <param name="factRelationships"></param>
        public void Evaluate(Dictionary <string, IEvidence> evidenceCollection, Dictionary <string, List <string> > factRelationships)
        {
            #region register all evidences in this rom with this instance of decision
            // 在这个实例中注册所有的evidences与这个实例的决定
            foreach (IEvidence evidence in evidenceCollection.Values)
            {
                evidence.CallbackLookup += RaiseCallback;
                evidence.EvidenceLookup += RaiseEvidenceLookup;
                evidence.ModelLookup    += RaiseModelLookup;

                evidence.Changed += delegate(object sender, ChangedArgs args)
                {
                    IEvidence evidence1 = (IEvidence)sender;
                    if (!(evidence1 is IFact))
                    {
                        return; //exit if not IFact
                    }

                    // 找出这ifact模型
                    IFact          fact    = (IFact)evidence1;
                    IEvidenceValue value   = (IEvidenceValue)fact.ValueObject;
                    string         modelId = value.ModelId;

                    // 遍历所有ifacts并添加这些到相同的模型来执行列表
                    foreach (IEvidence evidence2 in evidenceCollection.Values)
                    {
                        // 排除所有不是IFact证据类型
                        if (!(evidence2 is IFact))
                        {
                            continue;
                        }
                        // 排除自己
                        if (evidence2.ID == evidence1.ID)
                        {
                            continue;
                        }

                        // 排除所有那些不同的ifacts模型
                        if (evidence2.ValueObject.ModelId != modelId)
                        {
                            continue;
                        }

                        executionList.Add(evidence2);
                    }
                };
            }
            #endregion

            #region load up the execution list with facts
            //load up the execution list with facts
            // 加载列表可执行事实
            foreach (IEvidence fact in evidenceCollection.Values)
            {
                if (!(fact is IFact))
                {
                    continue;
                }

                executionList.Add(fact);
                Debug.WriteLine("Added fact to execution list: " + fact.ID);
            }
            #endregion

            #region load up the execution list with chainable rules
            //load up the execution list with chainable rules
            // 加载列表可执行链式规则
            foreach (IEvidence rule in evidenceCollection.Values)
            {
                if (rule is IRule && ((IRule)rule).isChainable)
                {
                    executionList.Add(rule);
                    Debug.WriteLine("Added rule to execution list: " + rule.ID);
                }
            }
            #endregion

            #region execute list
            //execute list
            Debug.WriteLine("Iteration");
            Debug.IndentLevel++;
            while (executionList.HasNext)
            {
                Debug.WriteLine("Execution List: " + executionList.ToString());
                Debug.WriteLine("Processing");
                Debug.IndentLevel++;
                //evaluate first item on list, it will always be the one of the lowest priority
                // 计算list的第一个,它将永远是最低优先级的一个
                string    evidenceId = executionList.Read();
                IEvidence evidence   = evidenceCollection[evidenceId];
                Debug.WriteLine("EvidenceId: " + evidence.ID);

                //evaluate evidence计算证明
                evidence.Evaluate();

                //add its actions, if any, to executionList, for evidence that has clauses
                // /如果证明有子句的,增加它的行为
                if (evidence.ClauseEvidence != null)
                {
                    foreach (string clauseEvidenceId in evidence.ClauseEvidence)
                    {
                        Evidence.IEvidence clauseEvidence = (Evidence.IEvidence)evidenceCollection[clauseEvidenceId];
                        executionList.Add(clauseEvidence);
                        Debug.WriteLine("Added evidence to execution list: " + clauseEvidence.ID);
                    }
                }

                //add chainable dependent facts to executionList
                // /执行列表的链式的相关的事实
                if (factRelationships.ContainsKey(evidence.ID))
                {
                    List <string> dependentFacts = factRelationships[evidence.ID];
                    foreach (string dependentFact in dependentFacts)
                    {
                        Evidence.IEvidence dependentEvidence = (Evidence.IEvidence)evidenceCollection[dependentFact];
                        executionList.Add(dependentEvidence);
                        Debug.WriteLine("Added dependent evidence to execution list: " + dependentEvidence.ID);
                    }
                }

                Debug.IndentLevel--;
                Debug.WriteLine("End Processing");
                Debug.WriteLine("");
            }
            Debug.IndentLevel--;
            Debug.WriteLine("End Iteration");

            #endregion
            //complete
        }
 public static UserAgent newBrowserUserAgent(IEvidence evidence)
 {
     return newUserAgent(evidence.Get("user-agent"));
 }
Example #16
0
 /// <summary>
 /// Add a fact, action, or rule to the ROM.
 /// </summary>
 /// <param name="Action"></param>
 public void AddEvidence(IEvidence evidence)
 {
     //add evidence to collection
     evidenceCollection.Add(evidence.ID, evidence);
 }
Example #17
0
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <param name="localization">The context Localization.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary <string, object> GetContextClaims(string aspectName, Localization localization)
        {
            using (new Tracer(aspectName))
            {
                if (_contextEngineClient == null)
                {
                    // Apparently an exception occurred in the class constructor; it should have logged the exception already.
                    throw new DxaException("Context Engine Client was not initialized. Check the log file for errors.");
                }

                string      userAgent          = null;
                string      contextCookieValue = null;
                HttpContext httpContext        = HttpContext.Current; // TODO: Not really nice to use HttpContext at this level.
                if (httpContext != null)
                {
                    userAgent = httpContext.Request.UserAgent;
                    HttpCookie contextCookie = httpContext.Request.Cookies["context"];
                    if (contextCookie != null)
                    {
                        contextCookieValue = contextCookie.Value;
                    }
                }
                if (string.IsNullOrEmpty(userAgent))
                {
                    userAgent = DefaultUserAgent;
                }

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", userAgent);
                    if (_usePublicationEvidence)
                    {
                        evidenceBuilder.WithPublicationId(Convert.ToInt32(localization.Id)); // TODO: What about URI scheme?
                    }
                    if (!string.IsNullOrEmpty(contextCookieValue))
                    {
                        evidenceBuilder.With("cookie", string.Format("context={0}", contextCookieValue));
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    contextMap = _contextEngineClient.Resolve(evidence);
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.", ex);
                }

                IDictionary <string, object> result = new Dictionary <string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return(result);
            }
        }
Example #18
0
        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <param name="localization">The context Localization.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary <string, object> GetContextClaims(string aspectName, Localization localization)
        {
            using (new Tracer(aspectName))
            {
                var contextEngineClient = ODataContextEngineInstance.Instance;
                if (contextEngineClient == null)
                {
                    return(new Dictionary <string, object>());
                }

                string      userAgent          = null;
                string      contextCookieValue = null;
                HttpContext httpContext        = HttpContext.Current;
                // TODO: Not really nice to use HttpContext at this level.
                if (httpContext != null)
                {
                    userAgent = httpContext.Request.UserAgent;
                    HttpCookie contextCookie = httpContext.Request.Cookies["context"];
                    if (contextCookie != null)
                    {
                        contextCookieValue = contextCookie.Value;
                    }
                }
                if (string.IsNullOrEmpty(userAgent))
                {
                    userAgent = DefaultUserAgent;
                }

                IContextMap contextMap;
                try
                {
                    EvidenceBuilder evidenceBuilder = new EvidenceBuilder().With("user-agent", userAgent);
                    if (_usePublicationEvidence)
                    {
                        evidenceBuilder.WithPublicationId(Convert.ToInt32(localization.Id));
                        // TODO: What about URI scheme?
                    }
                    if (!string.IsNullOrEmpty(contextCookieValue))
                    {
                        evidenceBuilder.With("cookie", $"context={contextCookieValue}");
                    }
                    IEvidence evidence = evidenceBuilder.Build();
                    lock (_lock)
                    {
                        contextMap = contextEngineClient.Resolve(evidence);
                    }
                }
                catch (Exception ex)
                {
                    throw new DxaException("An error occurred while resolving evidence using the Context Service.",
                                           ex);
                }

                IDictionary <string, object> result = new Dictionary <string, object>();
                if (string.IsNullOrEmpty(aspectName))
                {
                    // Add claims for all aspects.
                    foreach (string aspectKey in contextMap.KeySet)
                    {
                        AddAspectClaims(aspectKey, contextMap, result);
                    }
                }
                else
                {
                    // Add claims for the given aspect.
                    AddAspectClaims(aspectName, contextMap, result);
                }

                return(result);
            }
        }
Example #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="evidenceCollection"></param>
        /// <param name="factRelationships"></param>
        public void Evaluate(Dictionary <string, IEvidence> evidenceCollection, Dictionary <string, List <string> > factRelationships)
        {
            #region register all evidences in this rom with this instance of decision
            foreach (IEvidence evidence in evidenceCollection.Values)
            {
                evidence.CallbackLookup += RaiseCallback;
                evidence.EvidenceLookup += RaiseEvidenceLookup;
                evidence.ModelLookup    += RaiseModelLookup;
                //evidence.Changed += delegate(object sender, ChangedArgs args) sarvesh
                //{
                //    IEvidence evidence1 = (IEvidence)sender;
                //    if (!(evidence1 is IFact))
                //        return; //exit if not IFact

                //    //find out the model of this ifact
                //    IFact fact = (IFact)evidence1;
                //    IEvidenceValue value = (IEvidenceValue)fact.ValueObject;
                //    string modelId = value.ModelId;

                //    //go through all ifacts and add those to of the same model to the execution list
                //    foreach(IEvidence evidence2 in evidenceCollection.Values)
                //    {
                //        //exclude all evidences not of IFact type
                //        if (!(evidence2 is IFact))
                //            continue;
                //        //exclude self
                //        if (evidence2.ID == evidence1.ID)
                //            continue;
                //        //exclude all ifacts who are of a different model
                //        if (evidence2.ValueObject.ModelId != modelId)
                //            continue;
                //        //we have a hit, add them to the list
                //        executionList.Add(evidence2);
                //    }
                //};
            }
            #endregion

            #region load up the execution list with facts
            //load up the execution list with facts
            foreach (IEvidence fact in evidenceCollection.Values)
            {
                if (!(fact is IFact))
                {
                    continue;
                }

                executionList.Add(fact);
                Debug.WriteLine("Added fact to execution list: " + fact.ID);
            }
            #endregion

            #region load up the execution list with chainable rules
            //load up the execution list with chainable rules
            foreach (IEvidence rule in evidenceCollection.Values)
            {
                if (rule is IRule && ((IRule)rule).isChainable)
                {
                    executionList.Add(rule);
                    Debug.WriteLine("Added rule to execution list: " + rule.ID);
                }
            }
            #endregion

            #region execute list
            //execute list
            Debug.WriteLine("Iteration");
            Debug.IndentLevel++;
            while (executionList.HasNext)
            {
                Debug.WriteLine("Execution List: " + executionList.ToString());
                Debug.WriteLine("Processing");
                Debug.IndentLevel++;
                //evaluate first item on list, it will always be the one of the lowest priority
                string    evidenceId = executionList.Read();
                IEvidence evidence   = evidenceCollection[evidenceId];
                Debug.WriteLine("EvidenceId: " + evidence.ID);

                //evaluate evidence
                evidence.Evaluate();

                //add its actions, if any, to executionList, for evidence that has clauses
                if (evidence.ClauseEvidence != null)
                {
                    foreach (string clauseEvidenceId in evidence.ClauseEvidence)
                    {
                        Evidence.IEvidence clauseEvidence = (Evidence.IEvidence)evidenceCollection[clauseEvidenceId];
                        executionList.Add(clauseEvidence);
                        Debug.WriteLine("Added evidence to execution list: " + clauseEvidence.ID);
                    }
                }

                //add chainable dependent facts to executionList
                if (factRelationships.ContainsKey(evidence.ID))
                {
                    List <string> dependentFacts = factRelationships[evidence.ID];
                    foreach (string dependentFact in dependentFacts)
                    {
                        Evidence.IEvidence dependentEvidence = (Evidence.IEvidence)evidenceCollection[dependentFact];
                        executionList.Add(dependentEvidence);
                        Debug.WriteLine("Added dependent evidence to execution list: " + dependentEvidence.ID);
                    }
                }

                Debug.IndentLevel--;
                Debug.WriteLine("End Processing");
                Debug.WriteLine("");
            }
            Debug.IndentLevel--;
            Debug.WriteLine("End Iteration");

            #endregion
            //complete
        }
Example #20
0
 /// <summary>
 /// Add a fact, action, or rule to the ROM.
 /// 添加一个,事实,动作,或者规则
 /// </summary>
 /// <param name="Action"></param>
 public void AddEvidence(IEvidence evidence)
 {
     //add evidence to collection
     evidenceCollection.Add(evidence.ID, evidence);
 }
 /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
 public IPropertyValue GetPropertyValue(IEvidence evdnc, string localPropertyName, string localAspectName, string vocabularyIRI)
 {
     return GetPropertyValue(evdnc, NewPropertyRef(NewPropertyName(localPropertyName, vocabularyIRI), localAspectName));
 }
 public void SetInconclusive(IEvidence reason)
 {
     featureImplemented = null;
     FeatureWeighting   = 0;
     Evidence           = reason;
 }
 /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
 public IPropertyValue GetPropertyValue(IEvidence evdnc, string localPropertyName)
 {
     return GetPropertyValue(evdnc, NewPropertyName(localPropertyName));
 }
 public void SetFailed(IEvidence reason)
 {
     featureImplemented = false;
     GiveEvidence(reason);
 }
 /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
 public IPropertyValue GetPropertyValue(IEvidence evdnc, IPropertyName pn)
 {
     return GetPropertyValue(evdnc, NewPropertyRef(pn));
 }
 public void AddEvidence(IEvidence evidence)
 {
     evidence.CanBeInspected        = false;
     evidence.PlaySoundPlayerNearby = false;
     Evidence.Add(evidence);
 }
 /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
 public IPropertyValue GetPropertyValue(IEvidence evdnc, IPropertyRef pr)
 {
     return GetPropertyValues(evdnc, new IPropertyRef[] { pr }).GetValue(pr);
 }
 private bool DoesPlayerQuitInspecting(IEvidence ev)
 => Game.IsKeyDown(closest.KeyCollect) ||
 Game.IsKeyDown(closest.KeyLeave);
        /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
        public IPropertyValues GetPropertyValues(IEvidence evdnc, string localAspectName, string vocabularyIRI)
        {
            VocabularyProperty vocabularyProperty = vocabularyHolder.ExistProperty(localAspectName, null, vocabularyIRI, true);

            IPropertyName propertyName = new ODDRPropertyName(localAspectName, vocabularyIRI);
            IPropertyRef propertyRef = new ODDRPropertyRef(propertyName, vocabularyProperty.defaultAspect);

            return GetPropertyValues(evdnc, new IPropertyRef[] { propertyRef });
        }
Example #30
0
 public Classifier(IEvidence first, IEvidence second)
 {
     _classA = first;
     _classB = second;
 }
 /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
 public IPropertyValues GetPropertyValues(IEvidence evdnc, string localAspectName)
 {
     return GetPropertyValues(evdnc, localAspectName, defaultVocabularyIRI);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="evdnc"></param>
        /// <param name="prs"></param>
        /// <returns></returns>
        /// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when...</exception>
        public IPropertyValues GetPropertyValues(IEvidence evdnc, IPropertyRef[] prs)
        {
            Device deviceFound = null;
            Browser browserFound = null;
            OSModel.OperatingSystem osFound = null;
            bool deviceIdentified = false;
            bool browserIdentified = false;
            bool osIdentified = false;
            UserAgent deviceUA = null;
            UserAgent browserUA = null;

            ODDRPropertyValues ret = new ODDRPropertyValues();
            Dictionary<String, Vocabulary> vocabularies = vocabularyHolder.GetVocabularies();

            foreach (IPropertyRef propertyRef in prs)
            {
                VocabularyProperty vocabularyProperty = vocabularyHolder.ExistProperty(propertyRef.LocalPropertyName(), propertyRef.AspectName(), propertyRef.Namespace(), true);

                Vocabulary vocabulary = null;
                string nameSpace = propertyRef.Namespace();
                if (vocabularies.TryGetValue(nameSpace, out vocabulary))
                {
                    if (ASPECT_DEVICE.Equals(propertyRef.AspectName()))
                    {
                        if (!deviceIdentified)
                        {
                            if (deviceUA == null)
                            {
                                deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc);
                            }
                            if (evdnc is BufferedODDRHTTPEvidence)
                            {
                                deviceFound = ((BufferedODDRHTTPEvidence)evdnc).deviceFound;
                            }
                            if (deviceFound == null)
                            {
                                deviceFound = deviceIdentificator.Get(deviceUA, this.threshold) as Device;
                            }
                            if (evdnc is BufferedODDRHTTPEvidence)
                            {
                                ((BufferedODDRHTTPEvidence)evdnc).deviceFound = deviceFound;
                            }

                            deviceIdentified = true;
                        }
                        String property = null;

                        if (deviceFound != null)
                        {
                            property = deviceFound.Get(propertyRef.LocalPropertyName());
                            ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef));

                        }
                        else
                        {
                            ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef));
                        }
                        continue;

                    }
                    else if (ASPECT_WEB_BROWSER.Equals(propertyRef.AspectName()))
                    {
                        //TODO: evaluate ua-pixels header in evidence
                        if (!browserIdentified)
                        {
                            if (browserUA == null)
                            {
                                browserUA = UserAgentFactory.newBrowserUserAgent(evdnc);
                            }
                            if (evdnc is BufferedODDRHTTPEvidence)
                            {
                                browserFound = ((BufferedODDRHTTPEvidence)evdnc).browserFound;
                            }
                            if (browserFound == null)
                            {
                                browserFound = browserIdentificator.Get(browserUA, this.threshold) as Browser;
                            }
                            if (evdnc is BufferedODDRHTTPEvidence)
                            {
                                ((BufferedODDRHTTPEvidence)evdnc).browserFound = browserFound;
                            }
                            browserIdentified = true;
                        }
                        String property = null;
                        if (browserFound != null)
                        {
                            property = browserFound.Get(propertyRef.LocalPropertyName());
                            ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef));

                        }
                        else
                        {
                            ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef));
                        }
                        continue;

                    }
                    else if (ASPECT_OPERATIVE_SYSTEM.Equals(propertyRef.AspectName()))
                    {
                        //TODO: evaluate ua-os header in evidence
                        if (!osIdentified)
                        {
                            if (deviceUA == null)
                            {
                                deviceUA = UserAgentFactory.newDeviceUserAgent(evdnc);
                            }
                            if (evdnc is BufferedODDRHTTPEvidence)
                            {
                                osFound = ((BufferedODDRHTTPEvidence)evdnc).osFound;
                            }
                            if (osFound == null)
                            {
                                osFound = osIdentificator.Get(deviceUA, this.threshold) as OSModel.OperatingSystem;
                            }
                            if (evdnc is BufferedODDRHTTPEvidence)
                            {
                                ((BufferedODDRHTTPEvidence)evdnc).osFound = osFound;
                            }
                            osIdentified = true;
                        }
                        String property = null;
                        if (osFound != null)
                        {
                            property = osFound.Get(propertyRef.LocalPropertyName());
                            ret.addProperty(new ODDRPropertyValue(property, vocabularyProperty.type, propertyRef));

                        }
                        else
                        {
                            ret.addProperty(new ODDRPropertyValue(null, vocabularyProperty.type, propertyRef));
                        }
                        continue;
                    }
                }

            }

            return ret;
        }
 private Classifier(IEvidence first, IEvidence second)
 {
     _classA = first;
     _classB = second;
 }