public static async Task LoadProfileMods(SortedDictionary <int, Mod> mods) { MainForm MainForm_Control = Application.OpenForms.OfType <MainForm>().First(); DataGridView modsGridView = (DataGridView)MainForm_Control.Controls.Find("modsListDataGridView", true).First(); modsGridView.Rows.Clear(); foreach (KeyValuePair <int, Mod> modsPair in mods) { Mod mod = modsPair.Value; string index = modsPair.Key.ToString(); string modSize; string modPath = Profiles.currentProfile.path + "\\ShooterGame\\Content\\Mods\\" + mod.Id.ToString(); if (System.IO.Directory.Exists(modPath)) { modSize = SpaceUsage.SizeSuffix(SpaceUsage.DirectorySize(new System.IO.DirectoryInfo(modPath), true), 2); } else { modSize = "N/A"; } string[] row = new string[] { index, mod.Id.ToString(), mod.Name, mod.LastDownload.ToString(), mod.LastUpdate.ToString(), modSize }; modsGridView.Rows.Add(row); } }
/// <summary> /// 获取文件相关信息 /// </summary> /// <param name="file">文件info</param> /// <param name="plies">层数</param> /// <returns></returns> public static RecordBean GetFileBean(FileInfo file, uint plies) { RecordBean bean = new RecordBean() { Path = file.FullName, Plies = plies, Size = file.Length, CerateTime = file.CreationTime, ModifyTime = file.LastWriteTime, VisitTime = file.LastAccessTime, ExceptionCode = (int)RecordExCode.Normal, FileCount = 1, IsFile = true, IsChange = false, }; // 获取文件占用空间 try { bean.SpaceUsage = SpaceUsage.Get(file.FullName); } catch (Win32Exception e) { bean.ExceptionCode = (int)RecordExCode.SpaceUsageException; Log.Warn(string.Format("获取文件占用空间失败。{0} {1}, [error code: {2}]", file.FullName, e.Message, bean.ExceptionCode)); } return(bean); }
public async Task <ActionResult> Update(int ID) { SetSessionVariable(); ServiceResult <SpaceUsage> result = null; SpaceUsage spaceUsage = null; SpaceUsageUpdateViewModel spaceUsageUpdateViewModel = null; try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Common.Instance.ApiSpaceUsageControllerName); var responsetask = await client.GetAsync(Common.Instance.ApiSpaceUsageGet + "/" + ID); result = await responsetask.Content.ReadAsAsync <ServiceResult <SpaceUsage> >(); spaceUsage = result.Result; spaceUsageUpdateViewModel = new SpaceUsageUpdateViewModel(); spaceUsageUpdateViewModel.SetView(spaceUsage); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Server error. Please contact administrator"); } return(View(spaceUsageUpdateViewModel)); }
public ActionResult Add(SpaceUsageAddViewModel spaceUsageVM) { SpaceUsage spaceUsage = spaceUsageVM.GetObject(); SetSessionVariable(); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Common.Instance.ApiSpaceUsageControllerName); var posttask = client.PostAsJsonAsync <SpaceUsage>(Common.Instance.ApiSpaceUsageAdd, spaceUsage); posttask.Wait(); var result = posttask.Result; if (result.IsSuccessStatusCode) { var rs = result.Content.ReadAsAsync <ServiceResult <SpaceUsage> >().Result; } } /*catch (Exception ex) * { * ModelState.AddModelError(string.Empty, "Server error. Please contact administrator"); * }*/ return(RedirectToAction("List")); }
public ActionResult Update(SpaceUsageUpdateViewModel spaceUsageVm) { spaceUsageVm.ModifyBy = GetSessionObject().UserID; spaceUsageVm.ModifyDateTime = DateTime.Now; SpaceUsage spaceUsage = spaceUsageVm.GetObject(); SetSessionVariable(); try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Common.Instance.ApiSpaceUsageControllerName); var posttask = client.PostAsJsonAsync <SpaceUsage>(Common.Instance.ApiSpaceUsageUpdate, spaceUsage); posttask.Wait(); var result = posttask.Result; if (result.IsSuccessStatusCode) { var rs = result.Content.ReadAsAsync <ServiceResult <SpaceUsage> >().Result; } } } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Server error. Please contact administrator"); } return(RedirectToAction("List")); }
public async Task <SpaceInfo> GetSpaceInfo() { SpaceUsage info = await client.Users.GetSpaceUsageAsync(); SpaceInfo res = new SpaceInfo(info.Allocation.AsIndividual.Value.Allocated, info.Used); return(res); }
public void SetView(SpaceUsage spaceUsage) { this.ID = spaceUsage.SpaceUsageID; this.MemberBookingSpaceID = spaceUsage.MemberBookingSpaceID; this.FromDateTime = spaceUsage.FromDateTime; this.ToDateTime = spaceUsage.ToDateTime; this.IsActive = spaceUsage.IsActive; }
public SpaceUsage GetObject() { SpaceUsage spaceUsage = new SpaceUsage(); spaceUsage.MemberBookingSpaceID = MemberBookingSpaceID; spaceUsage.FromDateTime = FromDateTime; spaceUsage.ToDateTime = ToDateTime; spaceUsage.IsActive = IsActive; return(spaceUsage); }
private async void getSpaceUsage() { SpaceUsage space = await client.Users.GetSpaceUsageAsync(); if (space != null) { label5.Text = "Используется: " + (space.Used / 1000000).ToString() + "MB"; label6.Text = "Всего: " + (space.Allocation.AsIndividual.Value.Allocated / 1000000).ToString() + "MB"; } }
//get storage status private async void button2_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "Refreshing storage space status..."; SpaceUsage space = await client.Users.GetSpaceUsageAsync(); if (space != null) { toolStripStatusLabel1.Text = "Refreshing succeed!"; } spaceInfo.Text = "Used space: " + (space.Used / 1000000).ToString() + "MB" + Environment.NewLine + "Free space: " + (space.Allocation.AsIndividual.Value.Allocated - space.Used) / 1000000 + "MB" + Environment.NewLine + "Allocated space: " + (space.Allocation.AsIndividual.Value.Allocated / 1000000).ToString() + "MB"; }
private async void LoadStorageCountAsync() { using (DropboxClient dropboxClient = new DropboxClient(AvoEx.AesEncryptor.DecryptString(PlayerPrefs.GetString("Token")))) { FullAccount fullAccount = await dropboxClient.Users.GetCurrentAccountAsync(); emailAddressText.text = fullAccount.Email; SpaceUsage spaceUsage = await dropboxClient.Users.GetSpaceUsageAsync(); IndividualSpaceAllocation individualSpace = spaceUsage.Allocation.AsIndividual.Value; double allocated = individualSpace.Allocated; allocated = allocated / 1024d / 1024d / 1024d; double used = spaceUsage.Used; used = used / 1024d / 1024d / 1024d; double percentage = used / allocated; storagePercentImage.fillAmount = (float)percentage; storagePercentText.text = used.ToString("n2") + "GB / " + allocated.ToString("n2") + "GB"; } }
private void refreshSpaceUsageButton_Click(object sender, EventArgs e) { serverSpaceUsageLabel.Text = "Server Space Usage: Calculating..."; Task.Factory.StartNew(async() => { string serverSpaceUsageString = "Server Space Usage: " + SpaceUsage.SizeSuffix(SpaceUsage.DirectorySize(new System.IO.DirectoryInfo(Utilities.Profiles.currentProfile.path), true), 2); if (serverSpaceUsageLabel.InvokeRequired) { this.Invoke(new MethodInvoker(delegate { serverSpaceUsageLabel.Text = serverSpaceUsageString; })); } else { serverSpaceUsageLabel.Text = serverSpaceUsageString; } }); }
private async void MainForm_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Properties.Settings.Default.AccessToken)) { Client = new DropboxClient(Properties.Settings.Default.AccessToken); if (await Client.CheckConnection()) { EnableUI(false); // get current account FullAccount currentAccount = await Client.Users.GetCurrentAccount(); // display account name and id connectionStatusLabel.Text = string.Format("Connected as {0} ({1})", currentAccount.Name.DisplayName, currentAccount.AccountId); // get space usage SpaceUsage usage = await Client.Users.GetSpaceUsage(); spaceUsageLabel.Text = string.Format("{0:0.00}% used ({1:n} of {2:n} GiB)", (float)usage.Used / (float)usage.Allocation.Allocated * 100f, usage.Used / 1073741824f, usage.Allocation.Allocated / 1073741824f); // refresh tree view await RefreshTreeView(); EnableUI(true); } else { MessageBox.Show("Unable to connect to Dropbox. Please try connecting again."); } } else { Client = new DropboxClient(appId, appSecret); } Client.Files.DownloadFileProgressChanged += Files_DownloadFileProgressChanged; Client.Files.UploadFileProgressChanged += Files_UploadFileProgressChanged; }