Ejemplo n.º 1
0
        public bool AddToFileSystem(IFsiDirectoryItem rootItem, CancellationToken cancellationToken, string basePath = "")
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            try
            {
                // Add each file individually instead of using rootItem.AddTree so that all the streams are ManagedIStream
                var relativePath = System.IO.Path.Combine(basePath, DisplayName);
                rootItem.AddDirectory(relativePath);
                foreach (var item in mediaItems)
                {
                    item.AddToFileSystem(rootItem, cancellationToken, relativePath);
                    cancellationToken.ThrowIfCancellationRequested();
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void CreateFSIFolder(DirectoryInfo fsobject, IFsiDirectoryItem diritem)
        {
            if (fsobject == null || diritem == null || _cancel)
            {
                return;
            }
            DirectoryInfo pysicalFolder = null;

            pysicalFolder = new DirectoryInfo(UniqueListFileSystemInfo.GetPhysicalPath(fsobject.FullName.TrimEnd('\\')));
            IFsiDirectoryItem crtdiritem = null;

            if (diritem.FullPath.Length == 0)
            {
                try
                {
                    var newpath = string.Format("{0}\\{1}", diritem.FullPath, pysicalFolder.Name);
                    if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory)
                    {
                        diritem.AddDirectory(pysicalFolder.Name);
                    }
                }
                catch
                {
                }
                crtdiritem = diritem[pysicalFolder.Name] as IFsiDirectoryItem;
            }
            else
            {
                crtdiritem = diritem;
            }
            var files = pysicalFolder.GetFiles("*"); //all files

            foreach (var file in files)
            {
                if (_cancel)
                {
                    return;
                }
                CreateFSIFile(file, crtdiritem);
            }

            DirectoryInfo[] folders = null;
            folders = pysicalFolder.GetDirectories("*");
            if (folders != null && folders.Length > 0)
            {
                foreach (var folder in folders)
                {
                    if (_cancel)
                    {
                        return;
                    }
                    try
                    {
                        var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, folder.Name);
                        if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory)
                        {
                            crtdiritem.AddDirectory(folder.Name);
                        }
                    }
                    catch
                    {
                        Cancel = true;
                        throw;
                    }
                    var subdir = crtdiritem[folder.Name] as IFsiDirectoryItem;
                    CreateFSIFolder(folder, subdir);
                }
            }
        }