示例#1
0
 internal static void OpenNoInterpretersHelpPage(System.IServiceProvider serviceProvider, string page = null)
 {
     OpenVsWebBrowser(serviceProvider, page ?? PythonToolsInstallPath.GetFile("NoInterpreters.html"));
 }
示例#2
0
        private void OnSurveyNewsDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var br = (WebBrowser)sender;
            var warnIfNoneAvailable = (bool)br.Tag;

            if (br.Url == e.Url)
            {
                List <string> available = null;

                string json = br.DocumentText;
                if (!string.IsNullOrEmpty(json))
                {
                    int startIndex = json.IndexOf("<PRE>");
                    if (startIndex > 0)
                    {
                        int endIndex = json.IndexOf("</PRE>", startIndex);
                        if (endIndex > 0)
                        {
                            json = json.Substring(startIndex + 5, endIndex - startIndex - 5);

                            try {
                                // Example JSON data returned by the server:
                                //{
                                // "cannotvoteagain": [],
                                // "notvoted": [
                                //  "http://ptvs.azurewebsites.net/news/141",
                                //  "http://ptvs.azurewebsites.net/news/41",
                                // ],
                                // "canvoteagain": [
                                //  "http://ptvs.azurewebsites.net/news/51"
                                // ]
                                //}

                                // Description of each list:
                                // voted: cookie found
                                // notvoted: cookie not found
                                // canvoteagain: cookie found, but multiple votes are allowed
                                JavaScriptSerializer serializer = new JavaScriptSerializer();
                                var results = serializer.Deserialize <Dictionary <string, List <string> > >(json);
                                available = results["notvoted"];
                            } catch (ArgumentException) {
                            } catch (InvalidOperationException) {
                            }
                        }
                    }
                }

                if (available != null && available.Count > 0)
                {
                    BrowseSurveyNews(available[0]);
                }
                else if (warnIfNoneAvailable)
                {
                    if (available != null)
                    {
                        BrowseSurveyNews(_serviceProvider.GetPythonToolsService().GeneralOptions.SurveyNewsIndexUrl);
                    }
                    else
                    {
                        BrowseSurveyNews(PythonToolsInstallPath.GetFile("NoSurveyNewsFeed.html"));
                    }
                }

                Application.ExitThread();
            }
        }