示例#1
0
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record != null)
            {
                VM          = Record.VM;
                USBGroup    = Record.USB_group;
                OtherConfig = CommonCmdletFunctions.ConvertDictionaryToHashtable(Record.other_config);
            }
            else if (HashTable != null)
            {
                VM          = Marshalling.ParseRef <VM>(HashTable, "VM");
                USBGroup    = Marshalling.ParseRef <USB_group>(HashTable, "USB_group");
                OtherConfig = (Marshalling.ParseHashTable(HashTable, "other_config"));
            }
            if (!ShouldProcess(session.Url, "VUSB.create"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenServerCmdletDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VUSB.async_create(session, VM, USBGroup, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig));

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VUSB.create(session, VM, USBGroup, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig));

                    if (PassThru)
                    {
                        XenAPI.VUSB obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VUSB.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });

            UpdateSessions();
        }
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record != null)
            {
                NameLabel       = Record.name_label;
                NameDescription = Record.name_description;
                OtherConfig     = CommonCmdletFunctions.ConvertDictionaryToHashtable(Record.other_config);
            }
            else if (HashTable != null)
            {
                NameLabel       = Marshalling.ParseString(HashTable, "name_label");
                NameDescription = Marshalling.ParseString(HashTable, "name_description");
                OtherConfig     = (Marshalling.ParseHashTable(HashTable, "other_config"));
            }
            if (!ShouldProcess(session.Url, "GPU_group.create"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenServerCmdletDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.GPU_group.async_create(session, NameLabel, NameDescription, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig));

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.GPU_group.create(session, NameLabel, NameDescription, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig));

                    if (PassThru)
                    {
                        XenAPI.GPU_group obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.GPU_group.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });

            UpdateSessions();
        }
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record != null)
            {
                Mode       = Record.mode;
                Properties = CommonCmdletFunctions.ConvertDictionaryToHashtable(Record.properties);
            }
            else if (HashTable != null)
            {
                Mode       = (bond_mode)CommonCmdletFunctions.EnumParseDefault(typeof(bond_mode), Marshalling.ParseString(HashTable, "mode"));
                Properties = (Marshalling.ParseHashTable(HashTable, "properties"));
            }
            if (!ShouldProcess(session.Url, "Bond.create"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenServerCmdletDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.Bond.async_create(session, Network, Members, MAC, Mode, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(Properties));

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.Bond.create(session, Network, Members, MAC, Mode, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(Properties));

                    if (PassThru)
                    {
                        XenAPI.Bond obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.Bond.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });

            UpdateSessions();
        }
示例#4
0
 public void TestSerializeValidString()
 {
     var content = Marshalling.Serialize("bla");
 }
示例#5
0
 public string ReadString(IVariable variable)
 {
     return(Marshalling.GetString(Read(variable, new IntPtr(),
                                       (a, b, c, d) => _library.fmi2GetString(a, b, c, d))));
 }
示例#6
0
 public async void TestDeserializeNullInvalid()
 {
     await Assert.ThrowsAsync <Newtonsoft.Json.JsonSerializationException>(() => Marshalling.DeserializeAsync <int>(new StringContent("null", Encoding.UTF8, "application/json")));
 }
示例#7
0
        public async void TestDeserializeNull()
        {
            var ret = await Marshalling.DeserializeAsync <string>(new StringContent("null", Encoding.UTF8, "application/json"));

            Assert.Null(ret);
        }
示例#8
0
        public async void TestDeserializeValidString()
        {
            var ret = await Marshalling.DeserializeAsync <string>(new StringContent("\"bla\"", Encoding.UTF8, "application/json"));

            Assert.Equal("bla", ret);
        }
示例#9
0
 public async void TestDeserializeNonJsonThrows()
 {
     await Assert.ThrowsAsync <ArgumentException>(() => Marshalling.DeserializeAsync <string>(new ByteArrayContent(new byte[] { 0, 2, 3 })));
 }
示例#10
0
 public async void TestDeserializeThrowsOnNull()
 {
     await Assert.ThrowsAsync <ArgumentNullException>(() => Marshalling.DeserializeAsync <string>(null));
 }