//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);
            }
        }
Beispiel #2
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();
                }
            }
        }