コード例 #1
0
 //This function gets the results from the google search and loops through
 //the database to set all the results that have been recommended
 private void SetRecommendationsFromDB()
 {
     if (!Program.connected_to_database)
     {
         return;
     }
     foreach (Result result in results)
     {
         result.RecommendationsNumber = DatabaseCommunicator.SetRecommendations(result.Link);
     }
 }
コード例 #2
0
        public static void Main()
        {
            DatabaseCommunicator.CheckIfConnected();
            System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware);
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            LoginForm form = new LoginForm();

            form.StartPosition = FormStartPosition.CenterScreen;
            System.Windows.Forms.Application.Run(form);
            form.Close();
        }
コード例 #3
0
        /** Logs the user into their Microsoft Live account using Microsoft Graphs API.
         *  To increase the number of permissions add to scopes array. Right now our graphs
         *  client has user email access and read/write permission to users onedrive.
         */
        public static async void Login()
        {
            var clientId = "1912fef8-e092-4702-8012-cb3e535138a8";        // microsoft graphs api ID.
            var app      = PublicClientApplicationBuilder.Create(clientId)
                           .WithRedirectUri("http://localhost")
                           .Build();

            string[] scopes = new string[]
            {
                // add more scopes here if you want more access to users data using graphs api.
                "https://graph.microsoft.com/user.read",
                "https://graph.microsoft.com/email",
                "https://graph.microsoft.com/Files.ReadWrite.AppFolder"
            };
            var result = await app.AcquireTokenInteractive(scopes)
                         .ExecuteAsync();

            InteractiveAuthenticationProvider authProvider = new InteractiveAuthenticationProvider(app, scopes);

            graphClient = new GraphServiceClient(authProvider);
            var user = await graphClient.Me.Request().GetAsync();

            email = user.Mail;
            DatabaseCommunicator.email = user.Mail;
            if (Program.connected_to_database)
            {
                if (!DatabaseCommunicator.CheckRegistration(email))
                {
                    // show registration box here.
                    RegisterForm register = new RegisterForm(email);
                    register.StartPosition = FormStartPosition.CenterScreen;
                    register.Show();
                }
                else
                {
                    // User is already registered so we don't show registration.
                    // get all the ticked whitelist categories. If it is first time user then we show messagebox asking to select categories.
                    LoadCSESettings();
                    LoadPrivacySettings();
                    Program.LoadWhitelist();
                    LoadCategories();
                }
            }
            else
            {
                // App isn't connected to database so we don't need to check if user is registered or not.
                LoadCSESettings();
                LoadPrivacySettings();
                Program.LoadWhitelist();
                LoadCategories();
            }
        }
コード例 #4
0
 //There are 2 cases for this function
 //If the label text is not enough links we open the email form
 //If the label is a title of a result we open the link and saving it to the history results array
 //@param lbl - label clicked
 //@param i - label index
 private void linkClicked(LinkLabel lbl, int i)
 {
     if (lbl.Text.Length > 0)
     {
         if (lbl.Text == "Not enough links?")
         {
             EmailForm form = new EmailForm();
             form.Show();
             return;
         }
         Program.OpenUrl(results[i + (pageNumber - 1) * 4].Link);
         historyResult hsr = new historyResult(link1.Text, results[i + (pageNumber - 1) * 4].Link, DateTime.Now);
         historyResults.Add(hsr);
         if ((Program.connected_to_database) && (Program.save_search))
         {
             DatabaseCommunicator.SaveURL(lbl.Text);
         }
     }
 }
コード例 #5
0
        /** We add the user to django database. We jsut send the corresponding
         *  code for the location they select to the database by calling Program.AddUser.
         */
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem == null)
            {
                return;
            }
            var choice = comboBox1.SelectedItem.ToString();

            switch (choice)
            {
            case "North East England":
                DatabaseCommunicator.AddUser(user, "1");
                break;

            case "North West England":
                DatabaseCommunicator.AddUser(user, "2");
                break;

            case "Yorkshire and The Humber":
                DatabaseCommunicator.AddUser(user, "3");
                break;

            case "East Midlands":
                DatabaseCommunicator.AddUser(user, "4");
                break;

            case "West Midlands":
                DatabaseCommunicator.AddUser(user, "5");
                break;

            case "East of England":
                DatabaseCommunicator.AddUser(user, "6");
                break;

            case "London":
                DatabaseCommunicator.AddUser(user, "7");
                break;

            case "South East England":
                DatabaseCommunicator.AddUser(user, "8");
                break;

            case "South West England":
                DatabaseCommunicator.AddUser(user, "9");
                break;

            case "Wales":
                DatabaseCommunicator.AddUser(user, "10");
                break;

            case "Scotland":
                DatabaseCommunicator.AddUser(user, "11");
                break;

            case "Northern Ireland":
                DatabaseCommunicator.AddUser(user, "12");
                break;

            default:
                DatabaseCommunicator.AddUser(user, "0");
                break;
            }
            this.Close();
        }
コード例 #6
0
        /** For each ticked category it searches that query for that whitelist. You can tick
         *  multiple categories. It also removes overlapping results. If no categories are ticked
         *  we should Nothing Found. The way this works is that it has to add sites to EXCLUDE in the
         *  request. So we need to do some preprocessing to obtain the sites to exclude.
         *  @param query is the search query e.g. "kidney disease".
         *  @return list of results from google
         */
        public static List <Result> Search(string query)
        {
            if (query == "")
            {
                // user hasnt typed in anything
                return(new List <Result>()
                {
                    new Result
                    {
                        Title = "Not enough links?",
                        Snippet = "",
                    }
                });
            }

            dynamic results;

            if (developer_mode)
            {
                string q = "https://www.googleapis.com/customsearch/v1?key=" + api_key + "&cx=" + search_engine_id + "&q=" + query;
                results = SendRequest(q);
            }
            else
            {
                string          q = "https://www.googleapis.com/customsearch/v1?key=" + default_api_key + "&cx=" + default_search_engine_id + "&q=" + query;
                bool            at_least_one_ticked = false;
                List <Category> ticked = new List <Category>();
                foreach (Category elem in Program.categories)
                {
                    // For each ticked category we add the site to exclude to list of sites then build query.
                    if (elem.Ticked)
                    {
                        ticked.Add(elem);
                        at_least_one_ticked = true;
                    }
                }

                if ((at_least_one_ticked == false))
                {
                    // User hasn't selected any categories so there is nothing to display
                    return(new List <Result>()
                    {
                        new Result
                        {
                            Title = "Not enough links?",
                            Snippet = "",
                        }
                    });
                }
                List <string> sites_to_include = new List <string>();
                foreach (Category elem in ticked)
                {
                    // we get all the sites that each category wants to include and save them.
                    IEnumerable <string> diff = Program.whitelist.Except(elem.Sites_to_exclude);
                    foreach (string site in diff)
                    {
                        if (!sites_to_include.Contains(site))
                        {
                            sites_to_include.Add(site);
                        }
                    }
                }

                IEnumerable <string> sites_to_exclude = Program.whitelist.Except(sites_to_include);
                if (sites_to_exclude.Count() != 0)
                {
                    // we specify sites to exclude in query so we take difference
                    q += "&siteSearch=";
                    foreach (int i in Enumerable.Range(0, sites_to_exclude.Count() - 1))
                    {
                        q += sites_to_exclude.ElementAt(i) + " ";
                    }
                    q += sites_to_exclude.ElementAt(sites_to_exclude.Count() - 1) + "&siteSearchFilter=e";
                }
                results = SendRequest(q);
            }
            var ret = CreateResults(results);

            // we save each query to database.
            if (Program.save_search && Program.connected_to_database)
            {
                DatabaseCommunicator.SaveQuery(query);
            }
            return(ret);
        }