Example #1
0
        //Load Clouds in another thread
        private void backgroundWorkerLoadClouds_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Cloud> clouds = databaseService.GetAllClouds();

            foreach (var c in clouds)
            {
                CloudControl control = new CloudControl();
                switch (c.cloudType)
                {
                case "dropbox":
                    try
                    {
                        CloudUserInfo cloudUserInfoDropBox = dropBoxController.GetAccountInfo(c.token);
                        control.LabelTotalSpace.Text = MyUtils.GetFormatedSpaceInGB(cloudUserInfoDropBox.total_space) + " GB";
                        control.LabelFreeSpace.Text  = MyUtils.GetFormatedSpaceInGB(cloudUserInfoDropBox.free_space) + " GB";
                        int progress = (int)((cloudUserInfoDropBox.used_space * 100) / cloudUserInfoDropBox.total_space);
                        control.SetAvaible(progress);
                    }
                    catch (Exception)
                    {
                        Logger.Log("Error loading clouds, please check internet connection!");
                    }
                    control.LabelCloudName.Text        = c.name;
                    control.PictureBoxCloudImage.Image = mainWindowinstance.ImageListClouds.Images[0];
                    control.LabelId.Text = c.id.ToString();
                    break;

                case "box":
                    try
                    {
                        CloudUserInfo cloudUserInfoBox = boxController.GetAccountInfo(c.token);
                        control.LabelTotalSpace.Text = MyUtils.GetFormatedSpaceInGB(cloudUserInfoBox.total_space) + " GB";
                        control.LabelFreeSpace.Text  = MyUtils.GetFormatedSpaceInGB(cloudUserInfoBox.free_space) + " GB";
                        int progress = (int)((cloudUserInfoBox.used_space * 100) / cloudUserInfoBox.total_space);
                        control.SetAvaible(progress);
                    }
                    catch (Exception)
                    {
                        Logger.Log("Error loading clouds, please check internet connection!");
                    }
                    control.LabelCloudName.Text        = c.name;
                    control.PictureBoxCloudImage.Image = mainWindowinstance.ImageListClouds.Images[1];
                    control.LabelId.Text = c.id.ToString();
                    break;
                }
                control.OnUserControlDeleteCloudButtonClicked += (s, eve) => DeleteCloudButtonClicked(s, eve);
                backgroundWorkerLoadClouds.ReportProgress(1, control);
            }
        }
Example #2
0
        public CloudUserInfo GetAccountInfo(String accessToken)
        {
            var client = new WebClient();

            client.Headers["Authorization"] = "Bearer " + accessToken;
            string        source        = client.DownloadString("https://www.dropbox.com/1/account/info");
            dynamic       data          = JObject.Parse(source);
            CloudUserInfo cloudUserInfo = new CloudUserInfo();

            cloudUserInfo.uid         = data.uid;
            cloudUserInfo.total_space = data.quota_info.quota;
            cloudUserInfo.used_space  = data.quota_info.normal + data.quota_info.shared;
            cloudUserInfo.free_space  = cloudUserInfo.total_space - cloudUserInfo.used_space;
            return(cloudUserInfo);
        }
Example #3
0
        public CloudUserInfo GetAccountInfo(string accessToken)
        {
            accessToken = RefreshToken(accessToken);
            CloudUserInfo cloudUserInfo = new CloudUserInfo();
            var           client        = new WebClient();

            client.Headers["Authorization"] = "Bearer " + accessToken;
            string  source = client.DownloadString("https://api.onedrive.com/v1.0/drive");
            dynamic data   = JObject.Parse(source);

            cloudUserInfo.uid         = data.id;
            cloudUserInfo.total_space = data.quota.total;
            cloudUserInfo.used_space  = data.quota.used;
            cloudUserInfo.free_space  = data.quota.remaining;
            return(cloudUserInfo);
        }
Example #4
0
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            string accessToken;
            string refresh_token = null;
            var    result        = cloudController.ParseUriForToken(e.Url);

            if (result != null)
            {
                if (cloudType == (int)CloudsEnum.OneDrive)
                {
                    dynamic data1 = JObject.Parse(result);
                    refresh_token = data1.refresh_token;
                    accessToken   = data1.access_token;
                }
                else
                {
                    accessToken = result;
                }
                CloudUserInfo cloudUserInfo = cloudController.GetAccountInfo(accessToken);

                if (dbService.IsCloudAlreadyInsered(cloudUserInfo.uid))
                {
                    DialogResult dialogResult = MessageBox.Show("This cloud is already inserted.", "Error", MessageBoxButtons.OK);
                    this.Close();
                }
                else
                {
                    Cloud cloud = new Cloud();
                    cloud.id           = cloudUserInfo.uid;
                    cloud.name         = textBoxCloudName.Text;
                    cloud.cloudType    = (cloudType == (int)CloudsEnum.DropBox) ? "dropbox" : "box";
                    cloud.token        = accessToken;
                    cloud.refreshToken = refresh_token;
                    cloud.date         = DateTime.Now;
                    dbService.InsertCloud(cloud);
                    DialogResult dialogResult = MessageBox.Show("Cloud inserted successfuly.", "Succes", MessageBoxButtons.OK);
                    Logger.Log("The cloud " + cloud.name + " was inserted successfuly!");
                    this.Close();
                }
            }
        }