Exemplo n.º 1
0
        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.";
            });
        }
Exemplo n.º 2
0
 static public void Run()
 {
     if (TSviewCloud.ConsoleFunc.IsOutputRedirected)
     {
         return;
     }
     t = new System.Threading.Timer((o) =>
     {
         Console.Clear();
         var height  = Console.WindowHeight;
         var width   = Console.WindowWidth;
         var joblist = JobControler.JobList();
         var i       = 0;
         foreach (var j in joblist.Where(x => !x.IsHidden).OrderBy(x => x.Index))
         {
             Console.SetCursorPosition(0, i++);
             Console.Write(j.DisplayName);
             if (i > height - 1)
             {
                 break;
             }
             Console.SetCursorPosition(4, i++);
             Console.Write(j.ProgressStr);
             if (i > height - 1)
             {
                 break;
             }
         }
     }, null, 0, 1000);
 }
Exemplo n.º 3
0
 private void timer2_Tick(object sender, EventArgs e)
 {
     if (!Instance.Visible && (JobControler.JobList()?.Any(x => x.IsDelayShow) ?? false))
     {
         Instance.Show();
         Instance.BringToFront();
     }
 }
Exemplo n.º 4
0
 public virtual void Cancel()
 {
     cts.Cancel();
     if (!IsRunning)
     {
         _delete = true;
         Task.Delay(5000).ContinueWith((task) => JobControler.RemoveJob(this as Job));
         JobControler.joberaser.Set();
     }
 }
Exemplo n.º 5
0
        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;
            });
Exemplo n.º 6
0
        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;
            });
        }
Exemplo n.º 7
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            tic++;
            if (tic > 10000)
            {
                tic = 0;
            }
            listView1.Invalidate();
            if (tic % 10 != 0)
            {
                return;
            }

            var joblist = JobControler.JobList();

            if (joblist == null)
            {
                return;
            }
            var now = DateTime.Now;

            internalJobList = joblist.Where(x => !x.IsHidden)
                              .OrderBy(x => (x.IsInfo)? 0: (x.IsDone) ? 1 : (x.IsRunning) ? 2 : 3)
                              .ThenBy(x => x.Index)
                              .ThenBy(x => (x.StartTime == default(DateTime)) ? now : x.StartTime)
                              .ThenBy(x => x.QueueTime).ToArray();
            try
            {
                listView1.VirtualListSize = internalJobList.Length;
            }
            catch
            {
                return;
            }
            if (listView1.VirtualListSize > 0)
            {
                var str = new StringBuilder();
                str.AppendFormat("All:{0} ", internalJobList.Length);
                int d = JobControler.JobTypeCount(JobClass.Download);
                int u = JobControler.JobTypeCount(JobClass.Upload) + JobControler.JobTypeCount(JobClass.RemoteUpload);
                int p = JobControler.JobTypeCount(JobClass.PlayDownload);
                int o = internalJobList.Length - (d + u + p);
                if (d > 0)
                {
                    str.AppendFormat("Download:{0} ", d);
                }
                if (u > 0)
                {
                    str.AppendFormat("Upload:{0} ", u);
                }
                if (p > 0)
                {
                    str.AppendFormat("Play:{0} ", p);
                }
                if (o > 0)
                {
                    str.AppendFormat("Other:{0} ", o);
                }
                label1.Text = str.ToString();
            }
            else
            {
                label1.Text = "";
            }
            if (internalJobList.Length == 0)
            {
                Stop();
            }
        }
Exemplo n.º 8
0
 private void button1_Click(object sender, EventArgs e)
 {
     JobControler.CancelAllforUser();
     TSviewCloud.FormClosing.Instance.Show();
 }