public override void ClearCache() { _IsReady = false; pathlist.Clear(); var job = JobControler.CreateNewJob(); job.DisplayName = "Initialize CarotCrypt"; job.ProgressStr = "Initialize..."; JobControler.Run(job, async(j) => { job.Progress = -1; job.ProgressStr = "waiting for base system..."; while (!RemoteServerFactory.ServerList[_dependService].IsReady) { await Task.Delay(1000, j.Ct).ConfigureAwait(false); } job.ProgressStr = "loading..."; var host = await RemoteServerFactory.PathToItem(cryptRootPath, ReloadType.Reload).ConfigureAwait(false); if (host == null) { return; } var root = new CarotCryptSystemItem(this, host, null); pathlist.AddOrUpdate("", (k) => root, (k, v) => root); await EnsureItem("", 1).ConfigureAwait(false); _IsReady = true; job.Progress = 1; job.ProgressStr = "done."; }); }
public override Job <IRemoteItem> MakeFolder(string foldername, IRemoteItem remoteTarget, bool WeekDepend = false, params Job[] parentJob) { if (parentJob?.Any(x => x?.IsCanceled ?? false) ?? false) { return(null); } try { var check = CheckUpload(remoteTarget, foldername, null, WeekDepend, parentJob); if (check != null) { WeekDepend = false; parentJob = new[] { check }; } } catch { var mkjob = JobControler.CreateNewJob <IRemoteItem>( type: JobClass.RemoteOperation, depends: parentJob); mkjob.WeekDepend = WeekDepend; mkjob.ForceHidden = true; JobControler.Run <IRemoteItem>(mkjob, (j) => { j.Result = remoteTarget.Children.Where(x => x.Name == foldername).FirstOrDefault(); }); return(mkjob); } TSviewCloudConfig.Config.Log.LogOut("[MakeFolder(CarotCryptSystem)] " + foldername); var parent = pathlist[(remoteTarget.ID == cryptRootPath)? "": remoteTarget.ID]; var orgmakejob = parent.orgItem.MakeFolder(CryptCarot.EncryptFilename(foldername), WeekDepend, parentJob); var job = JobControler.CreateNewJob <IRemoteItem>( type: JobClass.RemoteOperation, depends: orgmakejob); job.DisplayName = "Make folder : " + foldername; job.ProgressStr = "wait for operation."; var ct = job.Ct; JobControler.Run <IRemoteItem>(job, (j) => { var result = j.ResultOfDepend[0]; if (result.TryGetTarget(out var item)) { j.ProgressStr = "Make folder..."; j.Progress = -1; var newitem = new CarotCryptSystemItem(this, item, remoteTarget); pathlist.AddOrUpdate(newitem.ID, (k) => newitem, (k, v) => newitem); remoteTarget.SetChildren(remoteTarget.Children.Concat(new[] { newitem })); j.Result = newitem; SetUpdate(remoteTarget); } j.ProgressStr = "Done"; j.Progress = 1; });
public void OnDeserialized(StreamingContext c) { TSviewCloudConfig.Config.Log.LogOut("[Restore] CarotCryptSystem {0} as {1}", cryptRootPath, Name); CryptCarot = new CryptCarotDAV(cryptNameHeader) { Password = DrivePassword }; loadinglist = new ConcurrentDictionary <string, ManualResetEventSlim>(); var job = JobControler.CreateNewJob(); job.DisplayName = "CryptCarotDAV"; job.ProgressStr = "waiting parent"; JobControler.Run(job, async(j) => { j.ProgressStr = "Loading..."; j.Progress = -1; try { int waitcount = 500; while (!(RemoteServerFactory.ServerList.Keys.Contains(_dependService) && RemoteServerFactory.ServerList[_dependService].IsReady)) { if (RemoteServerFactory.ServerList.Keys.Contains(_dependService)) { await Task.Delay(1, job.Ct).ConfigureAwait(false); } else { await Task.Delay(1000, job.Ct).ConfigureAwait(false); } if (waitcount-- == 0) { throw new FileNotFoundException("Depend Service is not ready.", _dependService); } } } catch { RemoteServerFactory.Delete(this); return; } if (pathlist == null) { pathlist = new ConcurrentDictionary <string, CarotCryptSystemItem>(); var root = new CarotCryptSystemItem(this, await RemoteServerFactory.PathToItem(cryptRootPath).ConfigureAwait(false), null); pathlist.AddOrUpdate("", (k) => root, (k, v) => root); await EnsureItem("", 1).ConfigureAwait(false); } else { Parallel.ForEach(pathlist.Values.ToArray(), new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.75) * 1.0)) }, (x) => x.FixChain(this)); } j.ProgressStr = "Done"; j.Progress = 1; _IsReady = true; }); }