Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.Write("uri: ");
            remoteResources = new Uri(Console.ReadLine());
            Console.Write("user: "******"password: "******"domain: ");
            string domain = Console.ReadLine();

            //RemoteApp and Desktop Connections uses HTTPS to connect to the server.
            //In order to connect properly, the client operating system must trust the SSL certificate of the RD Web Access server.
            //Also, the server name in the URL must match the one in the server’s SSL certificate

            // User credentials to access the connection. Fill in <username>, <password>, <domainname> with your user credentials.
            NetworkCredential networkCredential = new NetworkCredential(user, pass, domain);

            string cookie = GetFormsAuthenticationCookie(remoteResources.ToString(), networkCredential);
            string xml    = GetConnectionXml(remoteResources.ToString(), cookie);

            //Fill in your code to parse the connection, and to download resource files and associated icon & image files. Use earlier cache cookie for authentication.
            XmlDocument xd = new XmlDocument();

            xd.LoadXml(xml);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable);

            nsmgr.AddNamespace("res", xmlns);

            var apps = xd.SelectNodes("//res:Resource[contains(@Type,'RemoteApp')]", nsmgr);

            foreach (XmlNode app in apps)
            {
                RemoteApp ra = new RemoteApp
                {
                    Id     = app.Attributes["ID"].InnerText,
                    Title  = app.Attributes["Title"].InnerText,
                    PngURI = app.SelectSingleNode("res:Icons/res:Icon32[contains(@FileType,'Png')]", nsmgr).Attributes["FileURL"].InnerText,
                    RdpURI = app.SelectSingleNode("res:HostingTerminalServers/res:HostingTerminalServer/res:ResourceFile[contains(@FileExtension,'.rdp')]", nsmgr).Attributes["URL"].InnerText
                };
                // place the rdp file + icon in the directory based on id
                var path  = Path.Combine(raPath, ra.Id);
                var ipath = Path.Combine(path, ra.Id + ".png");
                var rpath = Path.Combine(path, ra.Id + ".rdp");
                Directory.CreateDirectory(path);

                WriteFile(new Uri(remoteResources, ra.PngURI).ToString(), cookie, ipath);
                WriteFile(new Uri(remoteResources, ra.RdpURI).ToString(), cookie, rpath);
            }

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.Write("uri: ");
            remoteResources = new Uri(Console.ReadLine());
            Console.Write("user: "******"password: "******"domain: ");
            string domain = Console.ReadLine();

            //RemoteApp and Desktop Connections uses HTTPS to connect to the server.
            //In order to connect properly, the client operating system must trust the SSL certificate of the RD Web Access server.
            //Also, the server name in the URL must match the one in the server’s SSL certificate

            // User credentials to access the connection. Fill in <username>, <password>, <domainname> with your user credentials.
            NetworkCredential networkCredential = new NetworkCredential(user, pass, domain);

            string cookie = GetFormsAuthenticationCookie(remoteResources.ToString(), networkCredential);
            string xml = GetConnectionXml(remoteResources.ToString(), cookie);

            //Fill in your code to parse the connection, and to download resource files and associated icon & image files. Use earlier cache cookie for authentication.
            XmlDocument xd = new XmlDocument();
            xd.LoadXml(xml);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable);
            nsmgr.AddNamespace("res", xmlns);

            var apps = xd.SelectNodes("//res:Resource[contains(@Type,'RemoteApp')]", nsmgr);

            foreach (XmlNode app in apps)
            {
                RemoteApp ra = new RemoteApp
                {
                    Id = app.Attributes["ID"].InnerText,
                    Title = app.Attributes["Title"].InnerText,
                    PngURI = app.SelectSingleNode("res:Icons/res:Icon32[contains(@FileType,'Png')]", nsmgr).Attributes["FileURL"].InnerText,
                    RdpURI = app.SelectSingleNode("res:HostingTerminalServers/res:HostingTerminalServer/res:ResourceFile[contains(@FileExtension,'.rdp')]", nsmgr).Attributes["URL"].InnerText
                };
                // place the rdp file + icon in the directory based on id
                var path = Path.Combine(raPath, ra.Id);
                var ipath = Path.Combine(path, ra.Id + ".png");
                var rpath = Path.Combine(path, ra.Id + ".rdp");
                Directory.CreateDirectory(path);

                WriteFile(new Uri(remoteResources, ra.PngURI).ToString(), cookie, ipath);
                WriteFile(new Uri(remoteResources, ra.RdpURI).ToString(), cookie, rpath);
            }

            Console.ReadLine();
        }