示例#1
0
        /// <summary>
        /// The recent mails
        /// </summary>
        /// <param name="account">With the account data to use on the query</param>
        private void GetRecentEmails(Account account)
        {
            TimelineManager.ReportProgress(new Status(account.ID, "Loading account..."));

            LinkedList <Frame> frames   = new LinkedList <Frame>();
            BackgroundWorker   bgWorker = new BackgroundWorker();

            this.workers.AddLast(bgWorker);

            bgWorker.WorkerReportsProgress      = true;
            bgWorker.WorkerSupportsCancellation = true;
            bgWorker.DoWork += new DoWorkEventHandler(delegate(object wsender, DoWorkEventArgs args)  {
                // Load the remote data
                try {
                    pop3 popClient   = new pop3();
                    String popserver = (account.getOption("popserver"));
                    String port      = (account.getOption("popport"));
                    String email     = (account.getOption("email"));
                    String password  = ConfigurationManager.AuthenticatedUser.Decrypt(account.getOption("password"));
                    Boolean ssl      = Convert.ToBoolean((account.getOption("ssl")));

                    popClient.connect(email, password, popserver, port, ssl);

                    if (popClient.isConnected())
                    {
                        List <pop3.emailInfo> emails = popClient.getEmail();
                        foreach (pop3.emailInfo item in emails)
                        {
                            frames.AddLast(new Frame(account, "[" + account.Name + "] From: " + item.from + ": " + item.subject, item.text, item.mailDate, null, account.ID));
                        }
                    }
                } catch {
                    //MessageBox.Show(ex.Message+ ex.StackTrace);
                }
            });

            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object wsender, RunWorkerCompletedEventArgs args)  {
                foreach (Frame frame in frames)
                {
                    TimelineManager.AddFrame(frame);
                }
                TimelineManager.RegisterEvent(account);
                ConfigurationManager.UpdateUserAccount(account);

                TimelineManager.ReportProgress(new Status(account.ID, frames.Count + " mails loaded."));
                this.workers.Remove(bgWorker);
            });
            bgWorker.RunWorkerAsync(account);
        }
示例#2
0
        /// <summary>
        /// Instanciates a new TimelineUpdate object
        /// </summary>
        public override void TimelineUpdate()
        {
            foreach (BackgroundWorker bgWorker in workers)
            {
                if (bgWorker.IsBusy)
                {
                    bgWorker.CancelAsync();
                }
                this.workers.Remove(bgWorker);
            }

            LinkedList <Account> accounts = ConfigurationManager.GetUserAccountsFromType(Account.MOODLETYPE);

            foreach (Account account in accounts)
            {
                if (account.Enabled)
                {
                    TimelineManager.ReportProgress(new Status(account.ID, "Loading account..."));
                    this.GetCachedModificationsForAccount(account);
                    this.GetRecentModificationsForAccount(account);
                }
            }
        }
示例#3
0
        /// <summary>
        /// The recent modifications for a course
        /// </summary>
        /// <param name="account">With the account data to use on the query</param>
        private void GetRecentModificationsForAccount(Account account)
        {
            LinkedList <Frame> frames   = new LinkedList <Frame>();
            BackgroundWorker   bgWorker = new BackgroundWorker();

            this.workers.AddLast(bgWorker);

            bgWorker.WorkerReportsProgress      = true;
            bgWorker.WorkerSupportsCancellation = true;
            bgWorker.DoWork += new DoWorkEventHandler(delegate(object wsender, DoWorkEventArgs args)  {
                // Load the remote data
                try {
                    UedWs.UEDWSPortTypeClient client = new UedWs.UEDWSPortTypeClient();
                    client.Endpoint.Address          = new EndpointAddress(account.getOption(Properties.Settings.Default.MoodleServiceUrlSettingName));

                    UedWs.UedCredentials credentials = new UedWs.UedCredentials();
                    credentials.username             = account.getOption(Properties.Settings.Default.MoodleServiceUsernameSettingName);
                    credentials.autorizationKey      = account.getOption(Properties.Settings.Default.MoodleServiceAutorizationKeySettingName);

                    UedWs.UedDate beginDate = MoodleTimeline.DateTimeToUedDate(account.LastUpdate);

                    if (client.validateCredentials(credentials))
                    {
                        UedWs.UedCourse[] courses = client.getMyCourses(credentials);

                        int courseCount = 0;
                        bgWorker.ReportProgress(courseCount++);

                        foreach (UedWs.UedCourse course in courses)
                        {
                            UedWs.UedRecentModification[] recentModifications = client.getCourseRecentModifications(credentials, course.id, beginDate);

                            foreach (UedWs.UedRecentModification modification in recentModifications)
                            {
                                frames.AddLast(new Frame(account, "[" + account.Name + "] @" + course.fullName, modification.text + " " + modification.modulename, MoodleTimeline.UedDateToDateTime(modification.date), (modification.url.Equals("") ? null : new Uri(modification.url)), course.id));
                            }
                            bgWorker.ReportProgress(((courseCount++) * 100) / courses.Length);
                        }
                    }
                } catch (Exception) {
                    //MessageBox.Show(ex.Message+ ex.StackTrace);
                }
            });

            bgWorker.ProgressChanged += new ProgressChangedEventHandler(delegate(object s, ProgressChangedEventArgs args) {
                TimelineManager.ReportProgress(new Status(account.ID, "Checking for course events. " + args.ProgressPercentage + "% completed."));
            });

            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object wsender, RunWorkerCompletedEventArgs args)  {
                this.CacheModificationsForAccount(account, frames);

                foreach (Frame frame in frames)
                {
                    this.AddFrame(frame);
                }
                this.workers.Remove(bgWorker);
                TimelineManager.RegisterEvent(account);
                ConfigurationManager.UpdateUserAccountLastUpdate(account.ID);
                TimelineManager.ReportProgress(new Status(account.ID, frames.Count + " account events loaded."));
            });
            bgWorker.RunWorkerAsync(account);
        }
示例#4
0
        /// <summary>
        /// The recent modifications for a course
        /// </summary>
        /// <param name="account">With the account data to use on the query</param>
        private void GetRecentTweetsForAccount(Account account)
        {
            TimelineManager.ReportProgress(new Status(account.ID, "Loading account..."));

            // Load the cached data
            LinkedList <Frame> frames = TimelineManager.GetCachedFramesFromDB(account);

            foreach (Frame frame in frames)
            {
                this.AddFrame(frame);
            }

            frames.Clear();

            BackgroundWorker bgWorker = new BackgroundWorker();

            this.workers.AddLast(bgWorker);

            bgWorker.WorkerReportsProgress      = true;
            bgWorker.WorkerSupportsCancellation = true;
            bgWorker.DoWork += new DoWorkEventHandler(delegate(object wsender, DoWorkEventArgs args)  {
                // Load the remote data
                try {
                    Twitterizer.OAuthTokens authToken = TwitterTimeline.getTwitterAuthToken(account);

                    Twitterizer.TimelineOptions options = new Twitterizer.TimelineOptions();
                    String sinceStatusId = account.getOption("SinceStatusId");
                    if (sinceStatusId != null)
                    {
                        options.SinceStatusId = Convert.ToDecimal(sinceStatusId);
                    }
                    else
                    {
                        options.Count = 10;
                    }

                    Twitterizer.TwitterResponse <TwitterStatusCollection> timeline = Twitterizer.TwitterTimeline.HomeTimeline(authToken, options);

                    if (sinceStatusId != null && timeline.Result == Twitterizer.RequestResult.Success && timeline.ResponseObject.Count < 10)
                    {
                        options       = new Twitterizer.TimelineOptions();
                        options.Count = 10;
                        timeline      = Twitterizer.TwitterTimeline.HomeTimeline(authToken, options);
                    }

                    if (timeline.Result == Twitterizer.RequestResult.Success)
                    {
                        frames.Clear();
                        Frame frame;
                        foreach (Twitterizer.TwitterStatus status in timeline.ResponseObject)
                        {
                            frame          = new Frame(account, "[" + account.Name + "] @" + status.User.ScreenName, status.Text, status.CreatedDate, ((status.User.Website != null) ? new Uri(status.User.Website) : null), Convert.ToInt64(status.Id));
                            frame.ImageUrl = new Uri(status.User.ProfileImageLocation);
                            frames.AddLast(frame);
                        }
                        if (timeline.ResponseObject[0] != null)
                        {
                            sinceStatusId = Convert.ToString(timeline.ResponseObject[0].Id);
                        }
                        args.Result = Convert.ToString(sinceStatusId);
                    }
                } catch {
                    //MessageBox.Show(ex.Message+ ex.StackTrace);
                }
            });

            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object wsender, RunWorkerCompletedEventArgs args)  {
                TimelineManager.CacheFramesOnDB(account, frames);
                int totalFramesAdded = 0;
                foreach (Frame frame in frames)
                {
                    if (TimelineManager.AddFrame(frame))
                    {
                        totalFramesAdded++;
                    }
                }
                TimelineManager.RegisterEvent(account);

                if (!args.Cancelled && args.Error == null)
                {
                    String sinceStatusId = args.Result as String;
                    account.setOption("SinceStatusId", sinceStatusId);
                }
                account.LastUpdate = DateTime.Now;
                ConfigurationManager.UpdateUserAccount(account);

                TimelineManager.ReportProgress(new Status(account.ID, totalFramesAdded + " new twitts loaded."));
                this.workers.Remove(bgWorker);
            });
            bgWorker.RunWorkerAsync(account);
        }