コード例 #1
0
        public RootFolder(PhysicalOverviewShellFolderServer server, ShellItemIdList idList)
            : base(idList)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            Hello = new HelloWorldItem(this);

            // get a path like C:\Users\<user>\AppData\Local\ShellBoost.Samples.PhysicalOverview\Root
            RootPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), GetType().Namespace), "Root");

            // ensure it exists
            var di = new DirectoryInfo(RootPath);

            if (!di.Exists)
            {
                di.Create();
            }

            RootPhysical = new PhysicalFolder(this, di);
            Server       = server;

            // we want to know when something changes in the real folder so we can update ours
            // note we don't use .NET's FileSystemWatcher but a Shell-oriented ShellBoost-provider tool instead base on native Shell's APIs.
            ChangeNotifier         = new ChangeNotifier(ShellUtilities.GetIdList(RootPath), true);
            ChangeNotifier.Notify += OnChangeNotifierNotify;
        }
コード例 #2
0
        public void Test()
        {
            var workDir    = Path.Combine(TestContext.CurrentContext.TestDirectory, TestContext.CurrentContext.Test.Name);
            var testFolder = PhysicalFolder.Create(workDir, PhysicalFolderDeleteType.NoDelete,
                                                   new Empty(),
                                                   new Folder("sub",
                                                              new Folder("subsub",
                                                                         new Empty(),
                                                                         new TextFile("test.txt", "test.txt"),
                                                                         new BinaryFile("a.dat", new byte[] { 0x01, 0x02 }),
                                                                         new ZipFile("a.zip",
                                                                                     new Folder("zip-sub",
                                                                                                new Empty(),
                                                                                                new TextFile("zip.txt", "zip.txt"),
                                                                                                new ZipFile("b.zip",
                                                                                                            new TextFile("c.txt", "c.txt")))))),
                                                   new TextFile("root.txt", "root.txt"),
                                                   new Folder("temp"));


            DirectoryAssert.Exists(workDir);
            FileAssert.Exists(Path.Combine(workDir, "root.txt"));
            FileAssert.Exists(Path.Combine(workDir, "sub", "subsub", "test.txt"));
            FileAssert.Exists(Path.Combine(workDir, "sub", "subsub", "a.dat"));
            FileAssert.Exists(Path.Combine(workDir, "sub", "subsub", "a.zip"));

            Path.Combine(workDir, "root.txt").IsFileContent("root.txt");
            Path.Combine(workDir, "sub", "subsub", "test.txt").IsFileContent("test.txt");
            Path.Combine(workDir, "sub", "subsub", "a.dat").IsFileContent(new byte[] { 0x01, 0x02 });

            using (var zip = System.IO.Compression.ZipFile.Open(Path.Combine(workDir, "sub", "subsub", "a.zip"), ZipArchiveMode.Read))
            {
                var paths = zip.Entries.Select(_ => _.FullName).ToArray();
                CollectionAssert.Contains(paths, "zip-sub/zip.txt");
                CollectionAssert.Contains(paths, "zip-sub/b.zip");

                zip.Entries.First(_ => _.FullName == "zip-sub/zip.txt").ExtractToFile(Path.Combine(workDir, "temp", "zip.txt"));
                zip.Entries.First(_ => _.FullName == "zip-sub/b.zip").ExtractToFile(Path.Combine(workDir, "temp", "b.zip"));
            }

            Path.Combine(workDir, "temp", "zip.txt").IsFileContent("zip.txt");

            using (var zip = System.IO.Compression.ZipFile.Open(Path.Combine(workDir, "temp", "b.zip"), ZipArchiveMode.Read))
            {
                Assert.That(zip.Entries.First().FullName, Is.EqualTo("c.txt"));
                using (var stream = zip.Entries.First().Open())
                {
                    Assert.That(new StreamReader(stream, Encoding.UTF8).ReadToEnd(), Is.EqualTo("c.txt"));
                }
            }
        }
コード例 #3
0
    private async Task <PhysicalFolder> FindSpecialFolder(List <PhysicalFolder> folders, string title, string viewName, string principalId)
    {
        var phFolder = folders.FirstOrDefault(x => x.ViewName == viewName && x.PrincipalId == principalId && x.IsDefaultFolder.HasValue && x.IsDefaultFolder.Value);

        //await _uow.Get<PhysicalFolder>().Get(x => x.ViewName == viewName && x.PrincipalId == principalId && x.IsDefaultFolder.HasValue && x.IsDefaultFolder.Value).FirstOrDefaultAsync();
        if (phFolder != null)
        {
            return(phFolder);
        }

        var folder = new PhysicalFolder
        {
            Title            = title,
            PrincipalId      = principalId,
            ViewName         = viewName,
            IsDefaultFolder  = true,
            TaskInstanceType = (byte)(viewName == WorkingFolderViewName || viewName == DraftFolderViewName ? TaskInstanceType.TaskInstance : TaskInstanceType.TaskInstanceCompleted)
        };

        _uow.Get <PhysicalFolder>().Add(folder);
        await _uow.SaveAsync();

        return(folder);
    }