Exemple #1
0
        public void Login(string username, string password)
        {
            fetcher.Username = username;
            fetcher.Password = password;

            try {
                bag = ContentCodeBag.ParseCodes(fetcher.Fetch("/content-codes"));
                ContentNode node = ContentParser.Parse(bag, fetcher.Fetch("/login"));
                ParseSessionId(node);

                FetchDatabases();
                Refresh();

                if (serverInfo.SupportsUpdate)
                {
                    updateRunning = true;
                    Thread thread = new Thread(UpdateLoop);
                    thread.Name         = "DAAP";
                    thread.IsBackground = true;
                    thread.Start();
                }
            } catch (WebException e) {
                if (e.Response != null && (e.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)
                {
                    throw new AuthenticationException("Username or password incorrect");
                }
                else
                {
                    throw new LoginException("Failed to login", e);
                }
            } catch (Exception e) {
                throw new LoginException("Failed to login", e);
            }
        }
Exemple #2
0
        public Client(IPAddress address, UInt16 port)
        {
            this.address = address;
            this.port    = port;
            fetcher      = new ContentFetcher(address, port);

            bag = ContentCodeBag.ParseCodes(fetcher.Fetch("/content-codes"));

            ContentNode node = ContentParser.Parse(ContentCodeBag.Default, fetcher.Fetch("/server-info"));

            serverInfo = ServerInfo.FromNode(node);
        }