Example #1
0
        private void ButtonShowLast_Click(object sender, EventArgs e)
        {
            PictureViewerForm pvf = new PictureViewerForm("cache/" + Config.USER_ID + "/graph.jpg");

            if(!pvf.Disposing && !pvf.IsDisposed) {
                pvf.ShowDialog();
                ((IDisposable) pvf).Dispose();
            }
        }
Example #2
0
        private void ButtonShowLast_Click(object sender, EventArgs e)
        {
            PictureViewerForm pvf = new PictureViewerForm("cache/" + Config.USER_ID + "/graph.jpg");

            if (!pvf.Disposing && !pvf.IsDisposed)
            {
                pvf.ShowDialog();
                ((IDisposable)pvf).Dispose();
            }
        }
        /// <summary>
        /// Displaying the info through the progress bars depending on current stage.
        /// Progress is reported from the Generate() method (and from methods that Generate() calls).
        /// Everytime we reach 100% we change the stage and start over.
        /// </summary>
        private void backgroundLoader_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // stages are in order in which they are run
            // every stage adds a certain amount of % to the total progress
            switch (stage)
            {
            // This stage loads users friendlist, it is a short one.
            case Stage.UserInfo:
                LabelOperation.Text = "Getting friend information...";

                LabelOverallStage.Text        = "1/5";
                LabelOperationPercentage.Text = "0/" + e.UserState;

                ProgressBarOverall.Value = 5;                         // + 5% to the overall progress

                stage = Stage.FriendsInfo;

                break;


            // Downloading info about friends and mutual friends
            case Stage.FriendsInfo:
                if (e.ProgressPercentage == 100)                          // stage completed
                {
                    stage = Stage.ProfilePictures;

                    LabelOperation.Text = "Downloading profile pictures...";

                    LabelOverallStage.Text        = "2/5";
                    LabelOperationPercentage.Text = "0" + LabelOperationPercentage.Text.Substring(LabelOperationPercentage.Text.IndexOf('/'));
                }
                else
                {
                    LabelOperationPercentage.Text = e.UserState + LabelOperationPercentage.Text.Substring(LabelOperationPercentage.Text.IndexOf('/'));
                    ProgressBarOperation.Value    = e.ProgressPercentage;
                    ProgressBarOverall.Value      = 5 + e.ProgressPercentage * 7 / 20;                        // + up to 35% to the overall progress
                }

                break;


            // This stage is the longest - downloads the profile picture for every friend
            case Stage.ProfilePictures:
                if (e.ProgressPercentage == 100)                          // stage completed
                {
                    stage = Stage.Calculating;

                    LabelOperation.Text           = "Calculating graph...";
                    LabelOverallStage.Text        = "3/5";
                    LabelOperationPercentage.Text = "0%";
                    ProgressBarOperation.Value    = 0;
                }
                else
                {
                    LabelOperationPercentage.Text = e.UserState + LabelOperationPercentage.Text.Substring(LabelOperationPercentage.Text.IndexOf('/'));
                    ProgressBarOperation.Value    = e.ProgressPercentage;
                    ProgressBarOverall.Value      = 40 + e.ProgressPercentage / 5 * 2;                        // + up to 40% to the overall progress
                }

                break;


            // Here we calculate the graph (position of vertices)
            case Stage.Calculating:

                if (e.ProgressPercentage == 100)                          // stage completed
                {
                    stage = Stage.Drawing;

                    LabelOperation.Text = "Drawing graph...";

                    LabelOverallStage.Text        = "4/5";
                    LabelOperationPercentage.Text = "0%";
                }
                else
                {
                    LabelOperationPercentage.Text = e.ProgressPercentage + "%";
                    ProgressBarOperation.Value    = e.ProgressPercentage;
                    ProgressBarOverall.Value      = 80 + e.ProgressPercentage / 10;                        // + up to 10% to the overall progress
                }

                break;


            // In this stage we draw the result graph image (might take a sec too, if canvas large)
            case Stage.Drawing:

                if (e.ProgressPercentage == 100)                          // stage completed
                {
                    stage = Stage.Calculating;
                    LabelOperation.Text    = "Finished";
                    LabelOverallStage.Text = "5/5";

                    // at the end of the stage, we show the result window
                    PictureViewerForm pvf = new PictureViewerForm((string)e.UserState);
                    pvf.ShowDialog();
                    ((IDisposable)pvf).Dispose();
                }
                else
                {
                    LabelOperationPercentage.Text = e.ProgressPercentage + "%";
                    ProgressBarOperation.Value    = e.ProgressPercentage;
                    ProgressBarOverall.Value      = 90 + e.ProgressPercentage / 10;                        // + up to 10% to the overall progress
                }

                break;
            }
        }
Example #4
0
        /// <summary>
        /// Displaying the info through the progress bars depending on current stage.
        /// Progress is reported from the Generate() method (and from methods that Generate() calls).
        /// Everytime we reach 100% we change the stage and start over.
        /// </summary>
        private void backgroundLoader_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // stages are in order in which they are run
            // every stage adds a certain amount of % to the total progress
            switch(stage) {

                // This stage loads users friendlist, it is a short one.
                case Stage.UserInfo:
                    LabelOperation.Text = "Getting friend information...";

                    LabelOverallStage.Text = "1/5";
                    LabelOperationPercentage.Text = "0/" + e.UserState;

                    ProgressBarOverall.Value = 5; // + 5% to the overall progress

                    stage = Stage.FriendsInfo;

                    break;

                // Downloading info about friends and mutual friends
                case Stage.FriendsInfo:
                    if(e.ProgressPercentage == 100) { // stage completed
                        stage = Stage.ProfilePictures;

                        LabelOperation.Text = "Downloading profile pictures...";

                        LabelOverallStage.Text = "2/5";
                        LabelOperationPercentage.Text = "0" + LabelOperationPercentage.Text.Substring(LabelOperationPercentage.Text.IndexOf('/'));

                    } else {
                        LabelOperationPercentage.Text = e.UserState + LabelOperationPercentage.Text.Substring(LabelOperationPercentage.Text.IndexOf('/'));
                        ProgressBarOperation.Value = e.ProgressPercentage;
                        ProgressBarOverall.Value = 5 + e.ProgressPercentage * 7 / 20; // + up to 35% to the overall progress
                    }

                    break;

                // This stage is the longest - downloads the profile picture for every friend
                case Stage.ProfilePictures:
                    if(e.ProgressPercentage == 100) { // stage completed
                        stage = Stage.Calculating;

                        LabelOperation.Text = "Calculating graph...";
                        LabelOverallStage.Text = "3/5";
                        LabelOperationPercentage.Text = "0%";
                        ProgressBarOperation.Value = 0;

                    } else {
                        LabelOperationPercentage.Text = e.UserState + LabelOperationPercentage.Text.Substring(LabelOperationPercentage.Text.IndexOf('/'));
                        ProgressBarOperation.Value = e.ProgressPercentage;
                        ProgressBarOverall.Value = 40 + e.ProgressPercentage / 5 * 2; // + up to 40% to the overall progress
                    }

                    break;

                // Here we calculate the graph (position of vertices)
                case Stage.Calculating:

                    if(e.ProgressPercentage == 100) { // stage completed
                        stage = Stage.Drawing;

                        LabelOperation.Text = "Drawing graph...";

                        LabelOverallStage.Text = "4/5";
                        LabelOperationPercentage.Text = "0%";

                    } else {
                        LabelOperationPercentage.Text = e.ProgressPercentage + "%";
                        ProgressBarOperation.Value = e.ProgressPercentage;
                        ProgressBarOverall.Value = 80 + e.ProgressPercentage / 10; // + up to 10% to the overall progress
                    }

                    break;

                // In this stage we draw the result graph image (might take a sec too, if canvas large)
                case Stage.Drawing:

                    if(e.ProgressPercentage == 100) { // stage completed
                        stage = Stage.Calculating;
                        LabelOperation.Text = "Finished";
                        LabelOverallStage.Text = "5/5";

                        // at the end of the stage, we show the result window
                        PictureViewerForm pvf = new PictureViewerForm((string) e.UserState);
                        pvf.ShowDialog();
                        ((IDisposable) pvf).Dispose();

                    } else {
                        LabelOperationPercentage.Text = e.ProgressPercentage + "%";
                        ProgressBarOperation.Value = e.ProgressPercentage;
                        ProgressBarOverall.Value = 90 + e.ProgressPercentage / 10; // + up to 10% to the overall progress
                    }

                    break;
            }
        }