private bool disposedValue; // To detect redundant calls protected async Task Init() { Amazon = await Authenticate(); if (Amazon == null) { throw new InvalidOperationException("Authentication failed"); } DeleteDir("TempCache"); Provider = new FSProvider(Amazon, (a, b, c) => Task.FromResult(0)) { CachePath = "TempCache", SmallFilesCacheSize = 20 * (1 << 20), SmallFileSizeLimit = 1 * (1 << 20) }; try { await Provider.DeleteDir("\\ACDDokanNetTest"); } catch (FileNotFoundException) { //Ignore } await Provider.CreateDir("\\ACDDokanNetTest"); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { Guid _siteActivityRuleId; if (Guid.TryParse(Request.QueryString["ID"], out _siteActivityRuleId)) { var link = dataManager.Links.SelectById(_siteActivityRuleId); IFileProvider fileProvider = new FSProvider(); var file = fileProvider.Get(link.SiteID, link.URL); if (file != null && file.Length > 0) { var fileName = link.URL; if (Request.Browser.Browser.ToLower() == "ie") { fileName = Server.UrlEncode(fileName); if (fileName != null) { fileName = fileName.Replace(@"+", @"%20"); } } Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(file); Response.End(); } else { Response.Write("This file does not exist."); } } }
/// <summary> /// Handles the OnClick event of the lbAddFile control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void lbAddFile_OnClick(object sender, EventArgs e) { var siteId = CurrentUser.Instance.SiteID; var fsp = new FileSystemProvider(); if (rauFile.UploadedFiles.Count > 0) { string fileName = null; if (rauFile.UploadedFiles.Count > 0) { IFileProvider fileProvider = new FSProvider(); fileName = fileProvider.GetFilename(siteId, rauFile.UploadedFiles[0].FileName); fsp.Upload(siteId, fileName, rauFile.UploadedFiles[0].InputStream); } var link = new tbl_Links(); link.SiteID = siteId; link.Name = fileName; link.RuleTypeID = (int)RuleType.File; link.URL = fileName; link.FileSize = rauFile.UploadedFiles[0].InputStream.Length; string code = String.Format("file_[{0}]_[{1}]", DateTime.Now.ToString("ddMMyyyy"), DateTime.Now.ToString("mmss")); int maxCode = DataManager.Links.SelectByCode(siteId, code); if (maxCode != 0) { maxCode++; } link.Code = code + (maxCode != 0 ? String.Format("[{0}]", maxCode >= 10 ? maxCode.ToString() : "0" + maxCode.ToString()) : ""); DataManager.Links.Add(link); BindFiles(); } }
protected void lbUpdateFile_OnClick(object sender, EventArgs e) { var a = FileId; var fsp = new FileSystemProvider(); if (rauFile.UploadedFiles.Count > 0) { string fileName = null; if (rauFile.UploadedFiles.Count > 0) { //fileName = fsp.Upload(CurrentUser.Instance.SiteID, "SiteActivityRules", // rauFile.UploadedFiles[0].FileName, rauFile.UploadedFiles[0].InputStream, // FileType.Attachment); IFileProvider fileProvider = new FSProvider(); fileName = fileProvider.GetFilename(CurrentUser.Instance.SiteID, rauFile.UploadedFiles[0].FileName); fsp.Upload(CurrentUser.Instance.SiteID, fileName, rauFile.UploadedFiles[0].InputStream); } var file = _dataManager.Links.SelectById(FileId) ?? new tbl_Links(); file.SiteID = ((LeadForceBasePage)Page).SiteId; file.Name = fileName; file.RuleTypeID = (int)RuleType.File; file.URL = fileName; file.FileSize = rauFile.UploadedFiles[0].InputStream.Length; file.Description = txtDescription.Text; string code = String.Format("file_[{0}]_[{1}]", DateTime.Now.ToString("ddMMyyyy"), DateTime.Now.ToString("mmss")); int maxCode = _dataManager.Links.SelectByCode(((LeadForceBasePage)Page).SiteId, code); if (maxCode != 0) { maxCode++; } file.Code = code + (maxCode != 0 ? String.Format("[{0}]", maxCode >= 10 ? maxCode.ToString() : "0" + maxCode.ToString()) : ""); if (file.ID == Guid.Empty) { _dataManager.Links.Add(file); } else { _dataManager.Links.Update(file); } ((Labitec.UI.BaseWorkspace.Grid)FindControl("gridLinks", Page.Controls)).Rebind(); } else { var file = _dataManager.Links.SelectById(FileId); if (file != null) { file.Description = txtDescription.Text; _dataManager.Links.Update(file); ((Labitec.UI.BaseWorkspace.Grid)FindControl("gridLinks", Page.Controls)).Rebind(); } } }
private bool disposedValue = false; // To detect redundant calls protected FSProviderTestsBase() { Amazon = Authenticate().Result; if (Amazon == null) { throw new InvalidOperationException("Authentication failed"); } DeleteDir("TempCache"); Provider = new FSProvider(Amazon); Provider.CachePath = "TempCache"; Provider.SmallFilesCacheSize = 20 * (1 << 20); Provider.SmallFileSizeLimit = 1 * (1 << 20); Provider.DeleteDir("\\ACDDokanNetTest"); Provider.CreateDir("\\ACDDokanNetTest"); }
/// <summary> /// Handles the OnClick event of the lbAddFile control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void lbAddFile_OnClick(object sender, EventArgs e) { var btnAddFile = (RadButton)sender; var editFormTableCell = FindControlParent(btnAddFile, typeof(GridEditFormItem.EditFormTableCell)) as GridEditFormItem.EditFormTableCell; var rauFile = (RadAsyncUpload)editFormTableCell.FindControl("rauFile"); var siteId = CurrentUser.Instance.SiteID; var fsp = new FileSystemProvider(); if (rauFile.UploadedFiles.Count > 0) { string fileName = null; if (rauFile.UploadedFiles.Count > 0) { IFileProvider fileProvider = new FSProvider(); fileName = fileProvider.GetFilename(siteId, rauFile.UploadedFiles[0].FileName); fsp.Upload(siteId, fileName, rauFile.UploadedFiles[0].InputStream); } var link = new tbl_Links(); link.SiteID = siteId; link.Name = fileName; link.RuleTypeID = (int)RuleType.File; link.URL = fileName; link.FileSize = rauFile.UploadedFiles[0].InputStream.Length; string code = String.Format("file_[{0}]_[{1}]", DateTime.Now.ToString("ddMMyyyy"), DateTime.Now.ToString("mmss")); int maxCode = _dataManager.Links.SelectByCode(siteId, code); if (maxCode != 0) { maxCode++; } link.Code = code + (maxCode != 0 ? String.Format("[{0}]", maxCode >= 10 ? maxCode.ToString() : "0" + maxCode.ToString()) : ""); _dataManager.Links.Add(link); ((DictionaryOnDemandComboBox)editFormTableCell.FindControl("dcbFile")).BindData(); } }
protected void lbAddFile_OnClick(object sender, EventArgs e) { var fsp = new FileSystemProvider(); if (rauFile.UploadedFiles.Count > 0) { string fileName = null; if (rauFile.UploadedFiles.Count > 0) { //fileName = fsp.Upload(CurrentUser.Instance.SiteID, "Links", // rauFile.UploadedFiles[0].FileName, rauFile.UploadedFiles[0].InputStream, // FileType.Attachment); IFileProvider fileProvider = new FSProvider(); fileName = fileProvider.GetFilename(siteID, rauFile.UploadedFiles[0].FileName); fsp.Upload(siteID, fileName, rauFile.UploadedFiles[0].InputStream); } var file = new tbl_Links(); file.SiteID = siteID; file.Name = fileName; file.RuleTypeID = (int)RuleType.File; file.URL = fileName; file.FileSize = rauFile.UploadedFiles[0].InputStream.Length; file.Description = txtDescription.Text; file.OwnerID = CurrentUser.Instance.ContactID; string code = String.Format("file_[{0}]_[{1}]", DateTime.Now.ToString("ddMMyyyy"), DateTime.Now.ToString("mmss")); int maxCode = _dataManager.Links.SelectByCode(siteID, code); if (maxCode != 0) { maxCode++; } file.Code = code + (maxCode != 0 ? String.Format("[{0}]", maxCode >= 10 ? maxCode.ToString() : "0" + maxCode.ToString()) : ""); _dataManager.Links.Add(file); txtDescription.Text = ""; gridLinks.Rebind(); } }
internal async Task <char?> Mount(char driveLetter, bool readOnly, CancellationToken cs, bool interactiveAuth = true) { if (Interlocked.CompareExchange(ref mounted, 1, 0) != 0) { return(null); } var mountedEvent = new TaskCompletionSource <char>(); mountTask = Task.Factory.StartNew( async() => { try { lock (mountLock) { if (mountedLetter != null) { return; } mountedLetter = driveLetter; } AmazonDrive amazon = await Authenticate(cs, interactiveAuth); if (amazon == null) { Log.Error("Authentication failed"); mountedEvent.SetException(new InvalidOperationException("Authentication failed")); return; } provider = new FSProvider(amazon); provider.CachePath = Environment.ExpandEnvironmentVariables(Gui.Properties.Settings.Default.CacheFolder); provider.SmallFilesCacheSize = Gui.Properties.Settings.Default.SmallFilesCacheLimit * (1 << 20); provider.SmallFileSizeLimit = Gui.Properties.Settings.Default.SmallFileSizeLimit * (1 << 20); provider.OnStatisticsUpdated = ProviderStatisticsUpdated; cloudDrive = new VirtualDriveWrapper(provider); cloudDrive.Mounted = () => { mountedEvent.SetResult((char)mountedLetter); }; OnMountChanged?.Invoke(); try { cloudDrive.Mount(mountedLetter + ":\\", readOnly); mountedLetter = null; } catch (InvalidOperationException) { Log.Warn($"Drive letter {mountedLetter} is already used"); Exception lastException = null; foreach (char letter in VirtualDriveWrapper.GetFreeDriveLettes()) { try { mountedLetter = letter; cloudDrive.Mount(mountedLetter + ":\\", readOnly); break; } catch (InvalidOperationException ex) { lastException = ex; Log.Warn($"Drive letter {letter} is already used"); } } if (mountedLetter != null) { var message = "Could not find free letter"; if (lastException != null && lastException.InnerException != null) { message = lastException.InnerException.Message; } mountedEvent.SetException(new InvalidOperationException(message)); } } } catch (Exception ex) { mountedEvent.SetException(ex); } finally { mountedLetter = null; mounted = 0; OnMountChanged?.Invoke(); } }, TaskCreationOptions.LongRunning).Unwrap(); return(await mountedEvent.Task); }
private async Task <char> Mount(bool interactiveAuth = true) { try { Instance.OnAuthUpdated = this; var authenticated = await Authenticate(Instance, MountCancellation.Token, interactiveAuth); if (!authenticated) { Log.ErrorTrace("Authentication failed"); throw new InvalidOperationException("Authentication failed"); } var origProv = new FSProvider(instance, ProviderStatisticsUpdated) { VolumeName = CloudInfo.Name, CachePath = Environment.ExpandEnvironmentVariables(Properties.Settings.Default.CacheFolder), SmallFilesCacheSize = Properties.Settings.Default.SmallFilesCacheLimit * (1 << 20), SmallFileSizeLimit = Properties.Settings.Default.SmallFileSizeLimit * (1 << 20) }; var rfProv = new RootFolderFSProvider(origProv); await rfProv.SetRootFolder(CloudInfo.RootFolder); Provider = rfProv; var cloudDrive = new VirtualDriveWrapper(Provider); var mountedEvent = new TaskCompletionSource <char>(); cloudDrive.Mounted = letter => { mountedEvent.SetResult(letter); }; NotifyMount(); var task = Task.Factory.StartNew( () => { try { cloudDrive.Mount(CloudInfo.DriveLetter, CloudInfo.ReadOnly); unmountingEvent.Set(); } catch (InvalidOperationException) { Log.Warn($"Drive letter {CloudInfo.DriveLetter} is already used"); Exception lastException = null; var wasMounted = false; foreach (var letter in VirtualDriveWrapper.GetFreeDriveLettes()) { try { cloudDrive.Mount(letter, CloudInfo.ReadOnly); unmountingEvent.Set(); Instance.Dispose(); instance = null; wasMounted = true; break; } catch (InvalidOperationException ex) { lastException = ex; Log.Warn($"Drive letter {letter} is already used"); } } if (!wasMounted) { var message = "Could not find free letter"; if (lastException?.InnerException != null) { message = lastException.InnerException.Message; } mountedEvent.SetException(new InvalidOperationException(message)); } } catch (Exception ex) { mountedEvent.SetException(ex); } }, TaskCreationOptions.LongRunning); return(await mountedEvent.Task); } finally { NotifyMount(); } }