コード例 #1
0
ファイル: WSBConfigModel.cs プロジェクト: fcenobi/WSBManager
 /// <summary>
 /// Creates a new instance of the <see cref="WSBConfigModel"/> class from an existing instance.
 /// </summary>
 /// <param name="wSBConfigModel">A existing instance of the <see cref="WSBConfigModel"/> class</param>
 public WSBConfigModel(WSBConfigModel wSBConfigModel)
 {
     VGpu          = wSBConfigModel.VGpu;
     Networking    = wSBConfigModel.Networking;
     MappedFolders = new List <MappedFolder>(wSBConfigModel.MappedFolders);
     LogonCommand  = new LogonCommand(wSBConfigModel.LogonCommand);
 }
コード例 #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="WSBConfigManagerModel"/> class from a <see cref="WSBConfigModel"> existing instance.
 /// </summary>
 /// <param name="wSBConfigModel">A existing instance of the <see cref="WSBConfigModel"/> class</param>
 public WSBConfigManagerModel(WSBConfigModel wSBConfigModel)
 {
     VGpu                 = wSBConfigModel.VGpu;
     Networking           = wSBConfigModel.Networking;
     MappedFolders        = new List <MappedFolder>(wSBConfigModel.MappedFolders);
     LogonCommand         = new LogonCommand(wSBConfigModel.LogonCommand);
     AudioInput           = wSBConfigModel.AudioInput;
     VideoInput           = wSBConfigModel.VideoInput;
     ProtectedClient      = wSBConfigModel.ProtectedClient;
     PrinterRedirection   = wSBConfigModel.PrinterRedirection;
     ClipboardRedirection = wSBConfigModel.ClipboardRedirection;
     MemoryInMB           = wSBConfigModel.MemoryInMB;
 }
コード例 #3
0
ファイル: WSBConfigModel.cs プロジェクト: fcenobi/WSBManager
        /// <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);
        }
コード例 #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);
        }