示例#1
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.ChangeContent(App.StartupView);

            string sitesUri = StackApi.CreateRequestUri("sites", new Dictionary <string, string>
            {
                { "pagesize", "999" }
            });
            SiteResponse response = StackApi.FireCacheableRequest <SiteResponse>(sitesUri, 3600 * 24);

            if (response == null)
            {
                this.ChangeContent(new ErrorReport("An error occurred while fetching site names.", App.GetExceptionMessage("LoadingSites"), App.GetExceptionTechDetails("LoadingSites")));
                return;
            }

            _sites = response.Sites.ToList <Site>();

            foreach (Site site in response.Sites.OrderBy(x => x.Name))
            {
                this.SitesPanel.Children.Add(this.CreateSiteDisplay(site));
            }

            if (App.SignedInUser != null)
            {
                this.UserFrame.Children.Add(new UserSidebar(App.SignedInUser));
            }
            else
            {
                App.AuthenticatingGuid = Guid.NewGuid();
                this.UserFrame.Children.Add(new AuthSidebar(string.Format("https://stackexchange.com/oauth/dialog?client_id={0}&scope={1}&redirect_uri={2}&state={3}",
                                                                          App.ClientId, "read_inbox,no_expiry,write_access,private_info",
                                                                          "https://auth.artofcode.co.uk/auth/redirect", App.AuthenticatingGuid)));
            }
        }
示例#2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            StackApi.RequestKey    = "WmNN*LGf5mFL9JYq9Q3hnQ((";
            ApiCache.BaseCachePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "ExchangeStats", "Cache"
                );
            StartupView = new WelcomeScreen();

            if (!Directory.Exists(ApiCache.BaseCachePath))
            {
                Directory.CreateDirectory(ApiCache.BaseCachePath);
                using (FileStream stream = File.Create(Path.Combine(ApiCache.BaseCachePath, "CacheInfo.dat")))
                {
                    stream.Close();
                    stream.Dispose();
                }
            }

            BaseResourcePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "ExchangeStats", "Resources"
                );

            if (!Directory.Exists(BaseResourcePath))
            {
                Directory.CreateDirectory(BaseResourcePath);
            }

            AutoloadResources();

            JObject userSignedIn = GetResourceObject("User") as JObject;

            if (userSignedIn == null)
            {
                SignedInUser = null;
                return;
            }

            JToken uid = userSignedIn.GetValue("UserId");

            if (uid == null)
            {
                SignedInUser = null;
                return;
            }

            string userUri = StackApi.CreateRequestUri("users/{id}", new Dictionary <string, string>
            {
                { "id", uid.ToString() }
            });
            UserResponse resp = StackApi.FireRequest <UserResponse>(userUri);

            SignedInUser = resp.Users.First();
        }