コード例 #1
0
        public MainWindow()
        {
            InitializeComponent();

            bool exceptionCaught = true;

            while (exceptionCaught)
            {
                exceptionCaught = false;
                try
                {
                    this.programList = comm.PipeProxy.GetProgramList();
                    //this.websiteList = new List<WebsiteSpec>();
                    this.websiteList = comm.PipeProxy.GetWebsiteList();
                }
                catch (EndpointNotFoundException e)
                {
                    MessageBox.Show("Could not connect to service. Program will now crash.\n\n" +
                                    e.ToString(), "Study Locker Init Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    exceptionCaught = true;
                }
            }



            //this.programList.Programs.Add(new StudyLockerProtocol.ProgramSpec() { FileName = "Notepad.exe" });
            this.dataGrid.CanUserAddRows = true;
            this.dataGrid.ItemsSource    = programList.Programs;



            this.dataGrid1.ItemsSource    = this.websiteList.Sites;
            this.dataGrid1.CanUserAddRows = true;
        }
コード例 #2
0
        public WebsiteList SetWebsiteList(WebsiteList list)
        {
            eventLog1.WriteEntry("Received websites: " + string.Join(",", list.Sites));
            using (StreamReader hostsFile = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\Drivers\etc\hosts"))
            {
                using (StreamWriter newHostsFile = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\Drivers\etc\hosts_new"))
                {
                    bool studyLocker = false;
                    while (true)
                    {
                        string line = hostsFile.ReadLine();

                        if (line == null)
                        {
                            break;
                        }
                        else
                        {
                            if (line == "# STUDY LOCKER START")
                            {
                                studyLocker = true;
                            }
                            else if (line == "# STUDY LOCKER END")
                            {
                                studyLocker = false;
                            }
                            else
                            {
                                if (!studyLocker)
                                {
                                    newHostsFile.WriteLine(line);
                                }
                            }
                        }
                    }
                    newHostsFile.WriteLine("# STUDY LOCKER START");
                    foreach (WebsiteSpec site in list.Sites)
                    {
                        newHostsFile.WriteLine("0.0.0.0 " + site.Website);
                    }
                    newHostsFile.WriteLine("# STUDY LOCKER END");
                }
            }
            System.IO.File.Copy(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\Drivers\etc\hosts_new", Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\Drivers\etc\hosts", true);
            this.activeWebsites = list;
            return(list);
        }
コード例 #3
0
        public WebsiteList GetWebsiteList()
        {
            List <WebsiteSpec> websiteList = new List <WebsiteSpec>();

            using (StreamReader hostsFile = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\Drivers\etc\hosts"))
            {
                bool studyLocker = false;
                while (true)
                {
                    string line = hostsFile.ReadLine();

                    if (line == null)
                    {
                        break;
                    }
                    else
                    {
                        if (line == "# STUDY LOCKER START")
                        {
                            studyLocker = true;
                        }
                        else if (line == "# STUDY LOCKER END")
                        {
                            studyLocker = false;
                        }
                        else if (studyLocker)
                        {
                            string[] lineSplit = line.Split(new string[] { " " }, 3, StringSplitOptions.RemoveEmptyEntries);
                            if (!lineSplit[0].StartsWith("#"))
                            {
                                websiteList.Add(new WebsiteSpec(lineSplit[1]));
                            }
                        }
                    }
                }
            }
            this.activeWebsites = new WebsiteList(websiteList);
            eventLog1.WriteEntry("Sending website list: " + string.Join(",", websiteList));
            return(new WebsiteList(websiteList));
        }
コード例 #4
0
        private void AddWebsiteList()
        {
            if (ToolbarItems.Count != 0)
            {
                return;
            }

            if (_websiteList == null)
            {
                _websiteList = WebsiteList.GetWebsiteList();
            }

            foreach (var url in _websiteList)
            {
                var item = new ToolbarItem
                {
                    Order            = ToolbarItemOrder.Secondary,
                    Text             = url,
                    CommandParameter = url
                };
                item.SetBinding(MenuItem.CommandProperty, new Binding(nameof(_viewModel.PageLoadCommand)));
                ToolbarItems.Add(item);
            }
        }