コード例 #1
0
        /// <summary>
        /// Retrieves all entities
        /// </summary>
        /// <returns>The response object</returns>
        public async Task <ContextResponses> GetAllEntitiesAsync()
        {
            RESTClient <ContextResponses> client = new RESTClient <ContextResponses>(OrionConfig.AuthHeaderKey, _config.Token);
            string           uri = string.Format(OrionConfig.UrlFormat, _config.BaseUrl, _config.Version1Path, OrionConfig.ContextEntitiesPath);
            ContextResponses contextResponses = await client.GetAsync(uri);

            if (contextResponses.Responses == null)
            {
                contextResponses.Responses = new List <ContextResponse>();
            }

            return(contextResponses);
        }
コード例 #2
0
        /// <summary>
        /// Queries the Context Broker for the specified query
        /// </summary>
        /// <param name="contextQuery">The context query</param>
        /// <returns>The response object</returns>
        public async Task <ContextResponses> QueryAsync(ContextQuery contextQuery)
        {
            RESTClient <ContextResponses> client = new RESTClient <ContextResponses>(OrionConfig.AuthHeaderKey, _config.Token);
            string uri  = string.Format(OrionConfig.UrlFormat, _config.BaseUrl, _config.Version1Path, OrionConfig.QueryContextPath);
            string body = JsonConvert.SerializeObject(contextQuery, jsonSettings);

            ContextResponses contextResponses = await client.PostAsync(uri, body);

            if (contextResponses.Responses == null)
            {
                contextResponses.Responses = new List <ContextResponse>();
            }

            return(contextResponses);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: smart-fi/core
        static void Main(string[] args)
        {
            string token = ConfigurationSettings.AppSettings["Token"];

            OrionClient.OrionConfig config = new OrionClient.OrionConfig()
            {
                Token = token,
            };

            OrionClient client = new OrionClient(config);

            OrionVersion version = client.GetOrionVersionAsync().Result;

            Debug.WriteLine(version.Orion.Version);

            ContextUpdate create = new ContextUpdate()
            {
                UpdateAction    = UpdateActionTypes.APPEND,
                ContextElements = new List <ContextElement>()
                {
                    new ContextElement()
                    {
                        Type       = "User",
                        IsPattern  = false,
                        Id         = "76afe5ed-a2b1-49f8-ba53-92eef732d265",
                        Attributes = new List <SMARTFI.OrionContextBroker.Client.Models.ContextAttribute>()
                        {
                            new SMARTFI.OrionContextBroker.Client.Models.ContextAttribute()
                            {
                                Name  = "userlocation",
                                Type  = "string",
                                Value = "23",
                            }
                        }
                    },
                }
            };

            ContextResponses createResponses = client.UpdateContextAsync(create).Result;

            Debug.WriteLine(createResponses.Responses.First().StatusCode.ReasonPhrase);

            ContextUpdate update = new ContextUpdate()
            {
                UpdateAction    = UpdateActionTypes.UPDATE,
                ContextElements = new List <ContextElement>()
                {
                    new ContextElement()
                    {
                        Type       = "Room",
                        IsPattern  = false,
                        Id         = "Room-S-123",
                        Attributes = new List <SMARTFI.OrionContextBroker.Client.Models.ContextAttribute>()
                        {
                            new SMARTFI.OrionContextBroker.Client.Models.ContextAttribute()
                            {
                                Name     = "temperature",
                                Type     = "float",
                                Value    = "230",
                                Metadata = new List <ContextAttributeMetadata>()
                                {
                                    new ContextAttributeMetadata()
                                    {
                                        Name  = "AcquisitionKey",
                                        Type  = "string",
                                        Value = "user.app.iphone"
                                    }
                                }
                            }
                        }
                    },
                }
            };

            StatusCode setAttributeResult = client.SetAttributeValueForEntityAsync("Room-S-123", "temperature", new Random().Next(-30, 45).ToString()).Result;

            ContextResponses updateResponses = client.UpdateContextAsync(update).Result;

            Debug.WriteLine(updateResponses.Responses.First().StatusCode.ReasonPhrase);

            ContextQuery query = new ContextQuery()
            {
                Entities = new List <ContextQueryEntity>()
                {
                    new ContextQueryEntity()
                    {
                        Type      = "Room",
                        IsPattern = true,
                        Id        = "Room.*",
                    },
                },
            };

            ContextResponses queryResponses = client.QueryAsync(query).Result;

            foreach (var item in queryResponses.Responses)
            {
                Debug.WriteLine(item.ContextElement.Id);
            }

            ContextQuery query2 = new ContextQuery()
            {
                Entities = new List <ContextQueryEntity>()
                {
                    new ContextQueryEntity()
                    {
                        Type      = "Room",
                        IsPattern = true,
                        Id        = "Room.*",
                    },
                },
                Attributes = new List <string>()
                {
                    "temperature",
                }
            };

            ContextResponses queryResponses2 = client.QueryAsync(query2).Result;

            foreach (var item in queryResponses2.Responses)
            {
                Debug.WriteLine(item.ContextElement.Id);
            }

            ContextSubscription subscription = new ContextSubscription()
            {
                Entities = new List <ContextQueryEntity>()
                {
                    new ContextQueryEntity()
                    {
                        Type      = "Room",
                        IsPattern = true,
                        Id        = "Room.*"
                    },
                },
                Attributes = new List <string>()
                {
                    "temperature"
                },
                Reference        = "http://smarthome.cloudapp.net/api/UserContext/Broker",
                Duration         = SubscriptionDurations.OneMonth,
                NotifyConditions = new List <NotifyCondition>()
                {
                    new NotifyCondition()
                    {
                        Type            = NotifyConditionTypes.ONCHANGE,
                        ConditionValues = new List <string>()
                        {
                            "temperature"
                        }
                    }
                },
                Throttling = SubscriptionThrottlingTypes.PT5S
            };

            ContextSubscriptionResponse subscriptionResponse = client.SubscribeAsync(subscription).Result;

            Debug.WriteLine(subscriptionResponse.SubscribeResponse.SubscriptionId);

            ContextResponses allEntities = client.GetAllEntitiesAsync().Result;

            foreach (var entity in allEntities.Responses)
            {
                Debug.WriteLine(entity.ContextElement.Id);
            }

            ContextResponse car1 = client.GetEntityAsync("Car1").Result;

            Debug.WriteLine(car1.ContextElement.Id);

            ContextTypesResponse types = client.GetTypesAsync().Result;

            foreach (var type in types.Types)
            {
                Debug.WriteLine(type.Name);
            }

            ContextAttributesResponse attributes = client.GetAttributesForTypeAsync("User").Result;

            foreach (var attribute in attributes.attributes)
            {
                Debug.WriteLine(attribute.Name);
            }

            ContextUnsubscribeResponse unsubscribe = client.UnsubscribeAsync(subscriptionResponse.SubscribeResponse.SubscriptionId).Result;

            Debug.WriteLine(unsubscribe.SubscriptionId);
        }