/// <summary>
        /// Converts a <see cref="XElement"/> instance to a <see cref="WSBConfigManagerModel"/> instance.
        /// </summary>
        /// <param name="xElement">A <see cref="XElement"/> instance contains configuration</param>
        /// <returns>A <see cref="WSBConfigManagerModel"/> instance</returns>
        public new static WSBConfigManagerModel FromXElement(XElement xElement)
        {
            var wsbConfigManagerModel = new WSBConfigManagerModel();

            // Metadata
            if (xElement.Attribute(nameof(Name)) is XAttribute xName)
            {
                wsbConfigManagerModel.Name = xName.Value;
            }
            if (xElement.Attribute(nameof(CreatedAt)) is XAttribute xCreatedAt &&
                Utility.TryConvert(xCreatedAt.Value, TypeCode.DateTime) is DateTime createdAt)
            {
                wsbConfigManagerModel.CreatedAt = createdAt;
            }
            if (xElement.Attribute(nameof(UUID)) is XAttribute xUUID)
            {
                wsbConfigManagerModel.UUID = xUUID.Value;
            }
            if (xElement.Attribute(nameof(LastLaunchedAt)) is XAttribute xLastLaunchedAt &&
                Utility.TryConvert(xLastLaunchedAt.Value, TypeCode.DateTime) is DateTime lastLaunchedAt)
            {
                wsbConfigManagerModel.LastLaunchedAt = lastLaunchedAt;
            }

            // VGPU
            if (xElement.Element(nameof(VGpu)) is XElement xVGpu &&
                Utility.TryConvert(typeof(VGpu), xVGpu.Value) is VGpu vGpu)
            {
                wsbConfigManagerModel.VGpu = vGpu;
            }
            // Networking
            if (xElement.Element(nameof(Networking)) is XElement xNetworking &&
                Utility.TryConvert(typeof(Networking), xNetworking.Value) is Networking networking)
            {
                wsbConfigManagerModel.Networking = networking;
            }
            // Mapped Folders
            if (xElement.Element(nameof(MappedFolders)) is XElement xMappedFolders)
            {
                foreach (var xMappedFolder in xMappedFolders.Elements(nameof(MappedFolder)))
                {
                    var mf = new MappedFolder();
                    if (xMappedFolder.Element(nameof(mf.HostFolder)) is XElement xHostFolder &&
                        xMappedFolder.Element(nameof(mf.ReadOnly)) is XElement xReadOnly &&
                        Utility.TryConvert(xReadOnly.Value, TypeCode.Boolean) is bool readOnly)
                    {
                        mf.HostFolder = xHostFolder.Value;
                        mf.ReadOnly   = readOnly;
                    }
                    wsbConfigManagerModel.MappedFolders.Add(mf);
                }
            }
            // Logon Command
            if (xElement.Element(nameof(LogonCommand))?.Element(nameof(wsbConfigManagerModel.LogonCommand.Command)) is XElement xCommand)
            {
                wsbConfigManagerModel.LogonCommand.Command = xCommand.Value;
            }

            return(wsbConfigManagerModel);
        }
示例#2
0
        /// <summary>
        /// Converts a <see cref="XElement"/> instance to a <see cref="WSBConfigModel"/> instance.
        /// </summary>
        /// <param name="xElement">A <see cref="XElement"/> instance contains configuration</param>
        /// <returns>A <see cref="WSBConfigModel"/> instance</returns>
        public static WSBConfigModel FromXElement(XElement xElement)
        {
            var wsbConfigModel = new WSBConfigModel();

            // VGPU
            if (xElement.Element(nameof(VGpu)) is XElement xVGpu &&
                Utility.TryConvert(typeof(VGpu), xVGpu.Value) is VGpu vGpu)
            {
                wsbConfigModel.VGpu = vGpu;
            }
            // Networking
            if (xElement.Element(nameof(Networking)) is XElement xNetworking &&
                Utility.TryConvert(typeof(Networking), xNetworking.Value) is Networking networking)
            {
                wsbConfigModel.Networking = networking;
            }
            // Mapped Folders
            if (xElement.Elements(nameof(MappedFolders)) is XElement xMappedFolders)
            {
                foreach (var xMappedFolder in xElement.Elements(nameof(MappedFolder)))
                {
                    var mf = new MappedFolder();
                    if (xMappedFolder.Element(nameof(mf.HostFolder)) is XElement xHostFolder &&
                        xMappedFolder.Element(nameof(mf.ReadOnly)) is XElement xReadOnly &&
                        Utility.TryConvert(xReadOnly.Value, TypeCode.Boolean) is bool readOnly)
                    {
                        mf.HostFolder = xHostFolder.Value;
                        mf.ReadOnly   = readOnly;
                    }
                    wsbConfigModel.MappedFolders.Add(mf);
                }
            }
            // Logon Command
            if (xElement.Element(nameof(LogonCommand))?.Element(nameof(wsbConfigModel.LogonCommand.Command)) is XElement xCommand)
            {
                wsbConfigModel.LogonCommand.Command = xCommand.Value;
            }

            return(wsbConfigModel);
        }
        /// <summary>
        /// Converts a <see cref="XElement"/> instance to a <see cref="WSBConfigManagerModel"/> instance.
        /// </summary>
        /// <param name="xElement">A <see cref="XElement"/> instance contains configuration</param>
        /// <returns>A <see cref="WSBConfigManagerModel"/> instance</returns>
        public new static WSBConfigManagerModel FromXElement(XElement xElement)
        {
            var wsbConfigManagerModel = new WSBConfigManagerModel();

            // Metadata
            if (xElement.Attribute(nameof(Name)) is XAttribute xName)
            {
                wsbConfigManagerModel.Name = xName.Value;
            }
            if (xElement.Attribute(nameof(CreatedAt)) is XAttribute xCreatedAt &&
                Utility.TryConvert(xCreatedAt.Value, TypeCode.DateTime) is DateTime createdAt)
            {
                wsbConfigManagerModel.CreatedAt = createdAt;
            }
            if (xElement.Attribute(nameof(UUID)) is XAttribute xUUID)
            {
                wsbConfigManagerModel.UUID = xUUID.Value;
            }
            if (xElement.Attribute(nameof(LastLaunchedAt)) is XAttribute xLastLaunchedAt &&
                Utility.TryConvert(xLastLaunchedAt.Value, TypeCode.DateTime) is DateTime lastLaunchedAt)
            {
                wsbConfigManagerModel.LastLaunchedAt = lastLaunchedAt;
            }

            // VGPU
            if (xElement.Element(nameof(VGpu)) is XElement xVGpu &&
                Utility.TryConvert(typeof(ThreeState), xVGpu.Value) is ThreeState vGpu)
            {
                wsbConfigManagerModel.VGpu = vGpu;
            }
            // Networking
            if (xElement.Element(nameof(Networking)) is XElement xNetworking &&
                Utility.TryConvert(typeof(TwoState), xNetworking.Value) is TwoState networking)
            {
                wsbConfigManagerModel.Networking = networking;
            }
            // Mapped Folders
            if (xElement.Element(nameof(MappedFolders)) is XElement xMappedFolders)
            {
                foreach (var xMappedFolder in xMappedFolders.Elements(nameof(MappedFolder)))
                {
                    var mf = new MappedFolder();
                    if (xMappedFolder.Element(nameof(mf.HostFolder)) is XElement xHostFolder &&
                        xMappedFolder.Element(nameof(mf.ReadOnly)) is XElement xReadOnly &&
                        Utility.TryConvert(xReadOnly.Value, TypeCode.Boolean) is bool readOnly)
                    {
                        mf.HostFolder = xHostFolder.Value;
                        mf.ReadOnly   = readOnly;
                    }
                    wsbConfigManagerModel.MappedFolders.Add(mf);
                }
            }
            // Logon Command
            if (xElement.Element(nameof(LogonCommand))?.Element(nameof(wsbConfigManagerModel.LogonCommand.Command)) is XElement xCommand)
            {
                wsbConfigManagerModel.LogonCommand.Command = xCommand.Value;
            }

            // Audio Input
            if (xElement.Element(nameof(AudioInput)) is XElement xAudioInput &&
                Utility.TryConvert(typeof(ThreeState), xAudioInput.Value) is ThreeState audioInput)
            {
                wsbConfigManagerModel.AudioInput = audioInput;
            }

            // Video Input
            if (xElement.Element(nameof(VideoInput)) is XElement xVideoInput &&
                Utility.TryConvert(typeof(ThreeState), xVideoInput.Value) is ThreeState videoInput)
            {
                wsbConfigManagerModel.VideoInput = videoInput;
            }

            // Protected Client
            if (xElement.Element(nameof(ProtectedClient)) is XElement xProtectedClient &&
                Utility.TryConvert(typeof(ThreeState), xProtectedClient.Value) is ThreeState protectedClient)
            {
                wsbConfigManagerModel.ProtectedClient = protectedClient;
            }

            // Printer Redirection
            if (xElement.Element(nameof(PrinterRedirection)) is XElement xPrinterRedirection &&
                Utility.TryConvert(typeof(ThreeState), xPrinterRedirection.Value) is ThreeState printerRedirection)
            {
                wsbConfigManagerModel.PrinterRedirection = printerRedirection;
            }

            // Clipboard Redirection
            if (xElement.Element(nameof(ClipboardRedirection)) is XElement xClipboardRedirection &&
                Utility.TryConvert(typeof(TwoState), xClipboardRedirection.Value) is TwoState clipboardRedirection)
            {
                wsbConfigManagerModel.ClipboardRedirection = clipboardRedirection;
            }

            // Memory in MB
            if (xElement.Element(nameof(MemoryInMB)) is XElement xMemoryInMB)
            {
                if (xMemoryInMB.Element(nameof(wsbConfigManagerModel.MemoryInMB.AmountInMB)) is XElement xAmountInMB &&
                    xMemoryInMB.Element(nameof(wsbConfigManagerModel.MemoryInMB.Enabled)) is XElement xEnabled &&
                    Utility.TryConvert(xAmountInMB.Value, TypeCode.Int32) is int amountInMB &&
                    Utility.TryConvert(xEnabled.Value, TypeCode.Boolean) is bool enabled)
                {
                    wsbConfigManagerModel.MemoryInMB.AmountInMB = amountInMB;
                    wsbConfigManagerModel.MemoryInMB.Enabled    = enabled;
                }
            }

            return(wsbConfigManagerModel);
        }
示例#4
0
        /// <summary>
        /// Converts a <see cref="XElement"/> instance to a <see cref="WSBConfigModel"/> instance.
        /// </summary>
        /// <param name="xElement">A <see cref="XElement"/> instance contains configuration</param>
        /// <returns>A <see cref="WSBConfigModel"/> instance</returns>
        public static WSBConfigModel FromXElement(XElement xElement)
        {
            var wsbConfigModel = new WSBConfigModel();

            // VGPU
            if (xElement.Element(nameof(VGpu)) is XElement xVGpu &&
                Utility.TryConvert(typeof(ThreeState), xVGpu.Value) is ThreeState vGpu)
            {
                wsbConfigModel.VGpu = vGpu;
            }
            // Networking
            if (xElement.Element(nameof(Networking)) is XElement xNetworking &&
                Utility.TryConvert(typeof(TwoState), xNetworking.Value) is TwoState networking)
            {
                wsbConfigModel.Networking = networking;
            }
            // Mapped Folders
            if (xElement.Elements(nameof(MappedFolders)) is XElement xMappedFolders)
            {
                foreach (var xMappedFolder in xElement.Elements(nameof(MappedFolder)))
                {
                    var mf = new MappedFolder();
                    if (xMappedFolder.Element(nameof(mf.HostFolder)) is XElement xHostFolder &&
                        xMappedFolder.Element(nameof(mf.ReadOnly)) is XElement xReadOnly &&
                        Utility.TryConvert(xReadOnly.Value, TypeCode.Boolean) is bool readOnly)
                    {
                        mf.HostFolder = xHostFolder.Value;
                        mf.ReadOnly   = readOnly;
                    }
                    wsbConfigModel.MappedFolders.Add(mf);
                }
            }
            // Logon Command
            if (xElement.Element(nameof(LogonCommand))?.Element(nameof(wsbConfigModel.LogonCommand.Command)) is XElement xCommand)
            {
                wsbConfigModel.LogonCommand.Command = xCommand.Value;
            }

            // Audio Input
            if (xElement.Element(nameof(AudioInput)) is XElement xAudioInput &&
                Utility.TryConvert(typeof(ThreeState), xAudioInput.Value) is ThreeState audioInput)
            {
                wsbConfigModel.AudioInput = audioInput;
            }

            // Video Input
            if (xElement.Element(nameof(VideoInput)) is XElement xVideoInput &&
                Utility.TryConvert(typeof(ThreeState), xVideoInput.Value) is ThreeState videoInput)
            {
                wsbConfigModel.VideoInput = videoInput;
            }

            // Protected Client
            if (xElement.Element(nameof(ProtectedClient)) is XElement xProtectedClient &&
                Utility.TryConvert(typeof(ThreeState), xProtectedClient.Value) is ThreeState protectedClient)
            {
                wsbConfigModel.ProtectedClient = protectedClient;
            }

            // Printer Redirection
            if (xElement.Element(nameof(PrinterRedirection)) is XElement xPrinterRedirection &&
                Utility.TryConvert(typeof(ThreeState), xPrinterRedirection.Value) is ThreeState printerRedirection)
            {
                wsbConfigModel.PrinterRedirection = printerRedirection;
            }

            // Clipboard Redirection
            if (xElement.Element(nameof(ClipboardRedirection)) is XElement xClipboardRedirection &&
                Utility.TryConvert(typeof(TwoState), xClipboardRedirection.Value) is TwoState clipboardRedirection)
            {
                wsbConfigModel.ClipboardRedirection = clipboardRedirection;
            }

            // Memory in MB
            if (xElement.Element(nameof(MemoryInMB)) is XElement xMemoryInMB &&
                Utility.TryConvert(typeof(int), xMemoryInMB.Value) is int memoryInMB &&
                memoryInMB > 0)
            {
                wsbConfigModel.MemoryInMB.AmountInMB = memoryInMB;
                wsbConfigModel.MemoryInMB.Enabled    = true;
            }

            return(wsbConfigModel);
        }