예제 #1
0
        public PersonSearch(Session Session, string Forname, string Surname, int HierarchyId, Course Course, PersonType PersonType)
        {
            HttpWebRequest InitialLoginRequest = Session.GetHttpWebRequest("/search/search_person.aspx");
            HtmlDocument initialLoginScreen = new HtmlDocument();
            HttpWebResponse FirstResponse = (HttpWebResponse)InitialLoginRequest.GetResponse();
            initialLoginScreen.Load(FirstResponse.GetResponseStream());

            Dictionary<string, string> LoginFormData = new Dictionary<string, string>();

            LoginFormData.Add("FirstName", Forname);
            LoginFormData.Add("Lastname", Surname);
            LoginFormData.Add("CourseID", Course.Id.ToString());
            LoginFormData.Add("HierarchyId", HierarchyId.ToString());

            LoginFormData.Add("idProfileID_7", (((PersonType & PersonType.sysadmin) > 0) ? 7 : 0).ToString());
            LoginFormData.Add("idProfileID_14", (((PersonType & PersonType.examinator) > 0) ? 14 : 0).ToString());
            LoginFormData.Add("idProfileID_8", (((PersonType & PersonType.administrator) > 0) ? 8 : 0).ToString());
            LoginFormData.Add("idProfileID_9", (((PersonType & PersonType.employee) > 0) ? 9 : 0).ToString());
            LoginFormData.Add("idProfileID_10", (((PersonType & PersonType.student) > 0) ? 10 : 0).ToString());
            LoginFormData.Add("idProfileID_62007", (((PersonType & PersonType.parent) > 0) ? 62007 : 0).ToString());
            LoginFormData.Add("idProfileID_11", (((PersonType & PersonType.guest) > 0) ? 11 : 0).ToString());

            LoginFormData.Add("Search", "Søk");
            LoginFormData.Add("Advanced", "0");

            foreach (var Form in initialLoginScreen.DocumentNode.Descendants("form"))
            {
                if (Form.GetAttributeValue("name", "") == "form")
                {
                    foreach (var inp in initialLoginScreen.DocumentNode.Descendants("input"))
                    {
                        if (!LoginFormData.ContainsKey(inp.GetAttributeValue("name", ""))) LoginFormData.Add(inp.GetAttributeValue("name", ""), inp.GetAttributeValue("value", ""));
                    }
                    HtmlDocument doc = Session.PostData("/search/search_person.aspx", LoginFormData);
                    _Result = new List<Person>(10);
                    foreach (var row in (from element in doc.DocumentNode.DescendantNodes() where element.GetAttributeValue("id", "").StartsWith("row_") select element))
                    {
                        string href = row.ChildNodes[1].FirstChild.GetAttributeValue("href", "");
                        _Result.Add(new Person(Session, uint.Parse(HttpUtility.ParseQueryString(new Uri(Properties.Settings.Default.urlBase + href.Substring(href.IndexOf('/'))).Query).Get("PersonID"))));
                    }
                }
            }
        }
예제 #2
0
        private static void Main(string[] args)
        {
            Session sess = new Session();  //Create a new Session object
            Console.WriteLine("ASP.NET_Id: [" + sess.Id + "]"); //Output the value of the ASP.NET_SessionId cookie
            Console.Write("CustomerId? ");          //Get the customer id from the user
            uint CustomerId = uint.Parse(Console.ReadLine());
            sess.Customer = new Customer(sess, CustomerId);

            Console.WriteLine("Customer: " + sess.Customer.Name); //Output the customer's name
            System.Diagnostics.Debug.Assert((new Customer(sess, sess.Customer.Name).Id == CustomerId) && (new Customer(sess, sess.Customer.Name).Name == sess.Customer.Name));  //Check that creating a customer from that name, gives the same customer as creating one with the CustomerId

            Console.Write("Username: "******"Password: "******"Welcome, " + Me.Name + "!");//Print my name

            while (true) //Until the user exits
            {
                try
                {
                    Console.Write("."); //Print prompt
                    string order = Console.ReadLine(); //Get command
                    string[] orders = order.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);   //Split command into parts
                    orders[0] = orders[0].ToLower();//Make part one lowercase (to simplify the if's in our code)
                    if ((orders[0] == "exit") || (orders[0] == "quit") || (orders[0] == "break")) break;
                    if (orders[0] == "project")
                    {
                        if (orders[1] == "set-active") new Project(sess, uint.Parse(orders[2])).setActive();//Set the active context to the project with this id
                        if (orders[1] == "get-active") //Get project id of active context
                        {
                            if (sess.ActiveContext.StartsWith("P")) Console.WriteLine(sess.ActiveContext);
                            else Console.WriteLine("Active context is not a project");
                        }
                        if (orders[1] == "get-root")    //Get the root directory of the active context if it's a project
                        {
                            if (sess.ActiveContext.StartsWith("P"))
                            {
                                Console.WriteLine((new Project(sess, uint.Parse(sess.ActiveContext.Substring(1))).getRootDirectory()).Name);
                            }
                            else Console.WriteLine("Active context is not a project");
                        }
                        if (orders[1] == "active-toggle-archive") //send project in active context to archive
                        {
                            if (sess.ActiveContext.StartsWith("P")) new Project(sess, uint.Parse(sess.ActiveContext.Substring(1))).toArchive();
                            else Console.WriteLine("Active context is not a project");
                        }
                    }
                    if (orders[0] == "course")
                    {
                        if (orders[1] == "set-active") new Course(sess, int.Parse(orders[2])).setActive(); //Set active context course id
                        if (orders[1] == "get-active") //Get the active context course id
                        {
                            if (sess.ActiveContext.StartsWith("C")) Console.WriteLine(sess.ActiveContext);
                            else Console.WriteLine("Active context is not a course");
                        }
                        if (orders[1] == "get-root")        //Get the root directory of the course
                        {
                            if (sess.ActiveContext.StartsWith("C"))
                            {
                                new Course(sess, int.Parse(sess.ActiveContext.Substring(1))).getRootDirectory();
                            }
                            else Console.WriteLine("Active context is not a course");
                        }
                    }
                    if (orders[0] == "keepalive")
                    {
                        if (orders[1] == "get-messenger-status")        //Show as online
                        {
                            Console.WriteLine(sess.KeepAlive.MessengerStatus);
                        }
                        if (orders[1] == "set-messenger-status")        //Show as offline
                        {
                            sess.KeepAlive.MessengerStatus = uint.Parse(orders[2]);
                        }
                    }
                    if (orders[0] == "make-http-request") sess.GetHttpWebRequest(orders[1]).GetResponse().Close();  //Make a HTTP-GET request, with the session cookies
                    if (orders[0] == "session")
                    {
                        if (orders[1] == "logout") sess.Logout();           //Log out
                        if (orders[1] == "login") sess.Login(orders[2], orders[3]); //login <user> <password>
                    }
                    if (orders[0] == "mail")
                    {
                        if (orders[1] == "get-in-folder")       //Get mails in folder by id
                        {
                            itsLib.Messaging.MailBox mb = new itsLib.Messaging.MailBox(sess, int.Parse(orders[2]));
                            Console.WriteLine("Messages in folder \"" + mb.Name + "\"");    //Print folder name
                            List<Mail> mails = mb.GetMails();   //Get the mails in message folder
                            foreach (Mail Mail in mails)
                            {
                                Console.Write("From: " + Mail.From.Username + "\t\t");  //Output who sent the mail
                                foreach (Person Person in Mail.To)
                                {
                                    if (Person != null) Console.Write(Person.Username + "\t\t"); //And all recipients
                                }
                                Console.WriteLine(Mail.Subject);    //And lastly the subject
                            }
                        }
                        if (orders[1] == "create")
                        {
                            MailCreator NewMail = new MailCreator();
                            do
                            {
                                Console.Write("To: ");
                                order = Console.ReadLine().Trim();
                                if (order != "") NewMail.To.Add(new Person(sess, uint.Parse(order)));
                                else break;
                                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
                                Console.WriteLine("To: " + NewMail.To[NewMail.To.Count - 1].Name);
                            } while (true);
                            do
                            {
                                Console.Write("Cc: ");
                                order = Console.ReadLine().Trim();
                                if (order != "") NewMail.Cc.Add(new Person(sess, uint.Parse(order)));
                                else break;
                                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
                                Console.WriteLine("Cc: " + NewMail.Cc[NewMail.Cc.Count - 1].Name);
                            } while (true);
                            do
                            {
                                Console.Write("Bcc: ");
                                order = Console.ReadLine().Trim();
                                if (order != "") NewMail.Bcc.Add(new Person(sess, uint.Parse(order)));
                                else break;
                                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
                                Console.WriteLine("Bcc " + NewMail.Bcc[NewMail.Bcc.Count - 1].Name);
                            } while (true);
                            Console.Write("Subject: ");
                            NewMail.Subject = Console.ReadLine();
                            do
                            {
                                Console.Write("Text: ");
                                order = Console.ReadLine();
                                if (order != "") NewMail.Text += order + '\n'.ToString();
                                else break;
                            } while (true);
                            NewMail.SendMessage(sess);
                        }
                    }
                    if (orders[0] == "bulletin")
                    {
                        if (orders[1] == "in-active")   //Get bulletin (by id) in the currently active context (project or course)
                        {
                            List<Bulletin> bulletins;
                            if (sess.ActiveContext.StartsWith("C")) bulletins = Bulletin.inCP(sess, new Course(sess, int.Parse(sess.ActiveContext.Substring(1))));
                            else bulletins = Bulletin.inCP(sess, new Project(sess, uint.Parse(sess.ActiveContext.Substring(1))));
                            foreach (Bulletin bulletin in bulletins)
                            {
                                Console.WriteLine(bulletin.By.Username + ":" + bulletin.Title + ":" + bulletin.Text);
                            }
                        }
                    }
                    if (orders[0] == "find-person")
                    {
                        if (orders[1] == "any")         //List all persons
                        {
                            PersonSearch ps = PersonSearch.GetAll(sess);
                            foreach (Person Person in ps.Result)
                            {
                                Console.WriteLine(Person.Name);
                            }
                        }
                    }
                }
                catch (Exception e) { Console.WriteLine(e.Message); }
            }
        }