예제 #1
0
 public override void Execute()
 {
     if (Parameters.Count > 0)
     {
         FlowObjectResource flowObjectResource = _Client.GetResource("20000/0") as FlowObjectResource;
         if (flowObjectResource != null)
         {
             flowObjectResource.FCAP = Parameters[0];
             flowObjectResource.Changed();
         }
     }
 }
예제 #2
0
        public async void ReadStringResource()
        {
            // Arrange
            string expectedValue    = "Imagination Technologies 123";
            string objectTypeID     = "3";
            string objectInstanceID = "0";
            string resourceID       = "0";

            await _HttpClientFixture.Login();

            IResource resource = _TestClient.GetResource($"{objectTypeID}/{objectInstanceID}/{resourceID}");

            Assert.NotNull(resource);
            (resource as LWM2MResource).SetValue(expectedValue);

            // Act
            string actualValue = await _HttpClientFixture.GetClientResource(_TestClient.ClientID, objectTypeID, objectInstanceID, resourceID);

            // Assert
            Assert.Equal(expectedValue, actualValue);
        }
 public override void Execute()
 {
     if (Parameters.Count > 0)
     {
         IResource resource = _Client.GetResource(Parameters[0]);
         if (resource != null)
         {
             List <IResource> items = resource.Children.ToArray().ToList();
             items.Sort(CompareResources);
             foreach (IResource item in items)
             {
                 LWM2MResources resources = item as LWM2MResources;
                 if (resources == null)
                 {
                     LWM2MResource itemResource = item as LWM2MResource;
                     if (itemResource == null)
                     {
                         Console.Write(item.Name.PadRight(33, ' '));
                     }
                     else
                     {
                         Console.Write(item.Name.PadRight(3, ' '));
                         if (string.IsNullOrEmpty(itemResource.Description))
                         {
                             Console.Write(new string(' ', 30));
                         }
                         else
                         {
                             Console.Write(itemResource.Description.PadRight(30, ' '));
                         }
                     }
                     Console.Write(":");
                     Console.WriteLine(item.ToString());
                 }
                 else
                 {
                     Console.Write(item.Name.PadRight(3, ' '));
                     Console.Write(resources.Description);
                     Console.WriteLine();
                     List <IResource> children = resources.Children.ToArray().ToList();
                     children.Sort(CompareResources);
                     foreach (IResource childItem in children)
                     {
                         Console.Write("\t\t");
                         Console.Write(childItem.Name);
                         Console.Write("\t:");
                         Console.WriteLine(childItem.ToString());
                     }
                 }
             }
         }
     }
     else
     {
         IResource resource = _Client.GetResource(null);
         if (resource != null)
         {
             List <IResource> items = resource.Children.Where((e) => { return(e.Visible); }).ToArray().ToList();
             items.Sort(CompareResources);
             foreach (IResource item in items)
             {
                 List <IResource> children = item.Children.ToArray().ToList();
                 children.Sort(CompareResources);
                 if (children.Count > 0)
                 {
                     foreach (IResource childItem in children)
                     {
                         Console.Write("  ");
                         Console.Write(item.Name);
                         Console.Write("/");
                         Console.WriteLine(childItem.Name);
                     }
                 }
                 else
                 {
                     Console.Write("  ");
                     Console.WriteLine(item.Name);
                 }
             }
         }
     }
 }
예제 #4
0
        public override void Execute()
        {
            if (Parameters.Count > 1)
            {
                if (Parameters[0].StartsWith("/"))
                {
                    Parameters[0] = Parameters[0].Substring(1);
                }
                LWM2MResource resource = _Client.GetResource(Parameters[0]) as LWM2MResource;
                if (resource == null)
                {
                    IResource parentResource = _Client.GetParentResource(Parameters[0]);

                    resource = parentResource as LWM2MResource;

                    if (resource == null && parentResource.Parent != null && String.IsNullOrEmpty(parentResource.Parent.Path))
                    {
                        // object instance does not exist
                        LWM2MResources resources  = parentResource as LWM2MResources;
                        string         instanceID = Parameters[0].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        parentResource = resource = resources.CreateResource(instanceID);

                        resources.ModifiedResource = resource;

                        resources.Changed();
                        //(parentResource as LWM2MResource).Changed();
                        resource = null;
                    }

                    if (resource == null)
                    {
                        LWM2MResources resources = parentResource as LWM2MResources;

                        if (resources != null)
                        {
                            string[]         paths            = Parameters[0].Split('/');
                            string           name             = paths[paths.Length - 1];
                            LWM2MResource    childResource    = null;
                            BooleanResources booleanResources = resources as BooleanResources;
                            if (booleanResources == null)
                            {
                                DateTimeResources dateTimeResources = resources as DateTimeResources;
                                if (dateTimeResources == null)
                                {
                                    FloatResources floatResources = resources as FloatResources;
                                    if (floatResources == null)
                                    {
                                        IntegerResources integerResources = resources as IntegerResources;
                                        if (integerResources == null)
                                        {
                                            OpaqueResources opaqueResources = resources as OpaqueResources;
                                            if (opaqueResources == null)
                                            {
                                                StringResources stringResources = resources as StringResources;
                                                if (stringResources == null)
                                                {
                                                }
                                                else
                                                {
                                                    childResource = new StringResource(name);
                                                }
                                            }
                                            else
                                            {
                                                childResource = new OpaqueResource(name);
                                            }
                                        }
                                        else
                                        {
                                            childResource = new IntegerResource(name);
                                        }
                                    }
                                    else
                                    {
                                        childResource = new FloatResource(name);
                                    }
                                }
                                else
                                {
                                    childResource = new DateTimeResource(name);
                                }
                            }
                            else
                            {
                                childResource = new BooleanResource(name);
                            }


                            if (childResource != null)
                            {
                                childResource.SetValue(Parameters[1]);
                                resources.Add(childResource);
                            }
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    resource.SetValue(Parameters[1]);
                    resource.Changed();
                    LWM2MResource parent = resource.Parent as LWM2MResource;
                    if (parent != null)
                    {
                        parent.Changed();
                        LWM2MResources grandparent = parent.Parent as LWM2MResources;
                        if (grandparent != null)
                        {
                            grandparent.Changed();
                        }
                    }
                }
            }
        }