Пример #1
0
        public async override Task <bool> Add()
        {
            var picker = new TSviewCloud.FormTreeSelect
            {
                Text = "Select encrypt root folder"
            };

            if (picker.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }
            if (picker.SelectedItem == null)
            {
                return(false);
            }
            if (picker.SelectedItem.ItemType == RemoteItemType.File)
            {
                return(false);
            }

            var pass = new FormInputPass();

            if (pass.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }
            CryptCarot = new CryptCarotDAV(pass.CryptNameHeader)
            {
                Password = pass.Password
            };
            DrivePassword   = pass.Password;
            cryptNameHeader = pass.CryptNameHeader;

            cryptRootPath  = picker.SelectedItem.FullPath;
            _dependService = picker.SelectedItem.Server;
            var root = new CarotCryptSystemItem(this, picker.SelectedItem, null);

            pathlist.AddOrUpdate("", (k) => root, (k, v) => root);
            await EnsureItem("", 1).ConfigureAwait(false);

            _IsReady = true;
            TSviewCloudConfig.Config.Log.LogOut("[Add] CarotCryptSystem {0} as {1}", cryptRootPath, Name);
            return(true);
        }
Пример #2
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;
            });
        }