Example #1
0
 private VolumePersistenceNode Save(VolumeNode volume)
 {
     return(new VolumePersistenceNode
     {
         Name = volume.Name,
         VolumeInfo = volume.VolumeInfo,
         Directories = volume.Directories?.Any() == true?volume.Directories.Select(Save).ToList() : null,
                           Files = volume.Files?.Any() == true?volume.Files.Select(Save).ToList() : null
     });
 }
        private VirtualFileSystem CreatePathInternal(string path, bool createChildrenFromPhysicalPath, DateTime?creationTime = null, DateTime?lastWriteTime = null)
        {
            VirtualFileSystem vfs = this;

            if (DirectorySeparatorChar == '\\')
            {
                path = Path.GetFullPath(path);
            }
            path = FileSystemUtility.SanitizePath(path, DirectorySeparatorChar);
            string[] pathNodes = FileSystemUtility.ParsePath(path, DirectorySeparatorChar);

            if (pathNodes.Length == 0)
            {
                throw new IOException("Path could not be parsed.");
            }

            VolumeNode     volume         = NodeNavigator.GetOrCreateVolume(Volumes, pathNodes[0], true);
            StringComparer stringComparer = volume.StringComparer;

            ContainerNode parent = volume;

            for (int i = 1; i < pathNodes.Length; i++)
            {
                string        fullName = string.Join(Path.DirectorySeparatorChar.ToString(), pathNodes, 0, i + 1);
                DirectoryNode existing = parent.Directories[pathNodes[i]];
                if (existing == null)
                {
                    DirectoryNode current = new DirectoryNode(NodeNavigator, pathNodes[i], stringComparer)
                    {
                        CreationTime  = createChildrenFromPhysicalPath ? new DirectoryInfo(fullName).CreationTime: creationTime?.ToLocalTime() ?? DateTime.Now,
                        LastWriteTime = createChildrenFromPhysicalPath ? new DirectoryInfo(fullName).LastWriteTime: lastWriteTime?.ToLocalTime() ?? DateTime.Now,
                    };
                    parent.Directories.Add(current);
                    parent = current;
                }
                else
                {
                    parent = existing;
                }
            }

            if (createChildrenFromPhysicalPath)
            {
                DirectoryInfo di = new DirectoryInfo(path);
                if (!(parent is VolumeNode))
                {
                    CreateChildrenFromPhysicalPath(di, parent);
                }
            }

            return(vfs);
        }
Example #3
0
    public atscQT()
        : base()
    {
        //gpstrategy = new QTStrategy();

        PriceNode pn = new PriceNode();

        pn = null;
        AgoNode an = new AgoNode();

        an = null;
        VolumeNode vn = new VolumeNode();

        vn = null;
    }
            public VolumeNode GetOrCreateVolume(List <VolumeNode> volumes, VolumeInfo volumeInfo, bool shouldCreate)
            {
                foreach (VolumeNode volume in volumes)
                {
                    if (volume.StringComparer.Equals(volume.Name, volumeInfo.RootPathName))
                    {
                        return(volume);
                    }
                }

                if (shouldCreate)
                {
                    VolumeNode volume = new VolumeNode(this, volumeInfo)
                    {
                        LastWriteTime = DateTime.Now
                    };
                    volumes.Add(volume);
                    return(volume);
                }

                return(null);
            }
        public override void update()
        {
            String UnitTypeList = String.Join( ",", CswNbtObjClassUnitOfMeasure.UnitTypes._All );

            _CswNbtSchemaModTrnsctn.createObjectClassProp(
                CswNbtMetaDataObjectClass.NbtObjectClass.UnitOfMeasureClass,
                CswNbtObjClassUnitOfMeasure.UnitTypePropertyName,
                CswNbtMetaDataFieldType.NbtFieldType.List,
                ServerManaged: true,
                ListOptions: UnitTypeList );

            CswNbtMetaDataNodeType WeightUnitNodeType = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( "Weight Unit" );
            if( WeightUnitNodeType != null )
            {
                CswNbtMetaDataNodeTypeProp WeightUnitTypeProp = WeightUnitNodeType.getNodeTypeProp( CswNbtObjClassUnitOfMeasure.UnitTypePropertyName );
                WeightUnitTypeProp.DefaultValue.AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Weight.ToString();

                foreach( CswNbtNode WeightNode in WeightUnitNodeType.getNodes( false, false ) )
                {
                    WeightNode.Properties[CswNbtObjClassUnitOfMeasure.UnitTypePropertyName].AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Weight.ToString();
                    WeightNode.postChanges( true );
                }
            }

            CswNbtMetaDataNodeType VolumeUnitNodeType = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( "Volume Unit" );
            if( VolumeUnitNodeType != null )
            {
                CswNbtMetaDataNodeTypeProp VolumeUnitTypeProp = VolumeUnitNodeType.getNodeTypeProp( CswNbtObjClassUnitOfMeasure.UnitTypePropertyName );
                VolumeUnitTypeProp.DefaultValue.AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Volume.ToString();

                foreach( CswNbtNode VolumeNode in VolumeUnitNodeType.getNodes( false, false ) )
                {
                    VolumeNode.Properties[CswNbtObjClassUnitOfMeasure.UnitTypePropertyName].AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Volume.ToString();
                    VolumeNode.postChanges( true );
                }
            }

            CswNbtMetaDataNodeType TimeUnitNodeType = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( "Time Unit" );
            if( TimeUnitNodeType != null )
            {
                CswNbtMetaDataNodeTypeProp TimeUnitTypeProp = TimeUnitNodeType.getNodeTypeProp( CswNbtObjClassUnitOfMeasure.UnitTypePropertyName );
                TimeUnitTypeProp.DefaultValue.AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Time.ToString();

                foreach( CswNbtNode TimeNode in TimeUnitNodeType.getNodes( false, false ) )
                {
                    TimeNode.Properties[CswNbtObjClassUnitOfMeasure.UnitTypePropertyName].AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Time.ToString();
                    TimeNode.postChanges( true );
                }
            }

            CswNbtMetaDataNodeType EachUnitNodeType = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( "Each Unit" );
            if( EachUnitNodeType != null )
            {
                CswNbtMetaDataNodeTypeProp EachUnitTypeProp = EachUnitNodeType.getNodeTypeProp( CswNbtObjClassUnitOfMeasure.UnitTypePropertyName );
                EachUnitTypeProp.DefaultValue.AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Each.ToString();

                foreach( CswNbtNode EachNode in EachUnitNodeType.getNodes( false, false ) )
                {
                    EachNode.Properties[CswNbtObjClassUnitOfMeasure.UnitTypePropertyName].AsList.Value = CswNbtObjClassUnitOfMeasure.UnitTypes.Each.ToString();
                    EachNode.postChanges( true );
                }
            }

        }//Update()
Example #6
0
        public MangaObject ParseMangaObject(string Content)
        {
            HtmlDocument MangaObjectDocument = new HtmlDocument();

            MangaObjectDocument.LoadHtml(Content);

            HtmlNode MangaNode = MangaObjectDocument.DocumentNode.SelectSingleNode(".//section[contains(@class, 'manga')]");
            String   Name      = HtmlEntity.DeEntitize(MangaNode.SelectSingleNode(".//div/div[1]/h1/a").InnerText);

            Name = Name.Substring(0, Name.LastIndexOf(' '));
            HtmlNode      AlternateNamesNode = MangaNode.SelectSingleNode(".//div/table/tr/td[2]/table/tr[4]/td");
            List <String> AlternateNames     = (from AltName in HtmlEntity.DeEntitize(AlternateNamesNode.InnerText).Split(';')
                                                select AltName.Trim()).ToList();
            List <String> Authors = (from Node in MangaNode.SelectNodes(".//div/table/tr/td[2]/table/tr[5]/td/a")
                                     select HtmlEntity.DeEntitize(Node.InnerText)).ToList();
            List <String> Artists = (from Node in MangaNode.SelectNodes(".//div/table/tr/td[2]/table/tr[6]/td/a")
                                     select HtmlEntity.DeEntitize(Node.InnerText)).ToList();
            List <String> Genres = (from Node in MangaNode.SelectNodes(".//div/table/tr/td[2]/table/tr[7]/td/a")
                                    select HtmlEntity.DeEntitize(Node.InnerText)).ToList();

            // Detect type
            MangaObjectType MangaType = MangaObjectType.Unknown;
            String          mType     = MangaNode.SelectSingleNode(".//div/table/tr/td[2]/table/tr[8]/td").InnerText.ToLower();

            if (mType.Contains("japanese manga"))
            {
                MangaType = MangaObjectType.Manga;
            }
            else if (mType.Contains("korean manhwa"))
            {
                MangaType = MangaObjectType.Manhwa;
            }

            // Get description
            String Description = HtmlEntity.DeEntitize(MangaNode.SelectSingleNode(".//div/p").InnerText);

            // Chapters
            List <ChapterObject> Chapters = new List <ChapterObject>();

            foreach (HtmlNode ChapterVersionNode in MangaNode.SelectNodes(".//*[@id='list']/div[starts-with(@id, 'stream_')]"))
            {
                foreach (HtmlNode VolumeNode in ChapterVersionNode.SelectNodes(".//div[contains(@class, 'volume')]"))
                {
                    UInt32   Volume         = 0;
                    HtmlNode VolumeNameNode = VolumeNode.SelectSingleNode(".//h4");
                    if (!Equals(VolumeNameNode, null))
                    {
                        String[] idParts = VolumeNameNode.GetAttributeValue("id", "v-1-").Split('-');
                        UInt32.TryParse(idParts[2], out Volume);
                    }

                    foreach (HtmlNode ChapterNode in ChapterVersionNode.SelectNodes(".//div/ul/li"))
                    {
                        HtmlNode InfoNode = ChapterNode.SelectSingleNode(".//a");
                        String   ChapterName = HtmlEntity.DeEntitize(InfoNode.InnerText),
                                 Url = InfoNode.GetAttributeValue("href", null);
                        UInt32 Chapter = 0, SubChapter = 0;

                        Match match = Regex.Match(ChapterName, @"(vol\.(?<Volume>\d+)\s)?ch\.(?<Chapter>\d+)(\.(?<SubChapter>\d+))?");
                        if (match.Success)
                        {
                            if (match.Groups["Volume"].Success)
                            {
                                UInt32.TryParse(match.Groups["Volume"].Value, out Volume);
                            }
                            if (match.Groups["Chapter"].Success)
                            {
                                UInt32.TryParse(match.Groups["Chapter"].Value, out Chapter);
                            }
                            if (match.Groups["SubChapter"].Success)
                            {
                                UInt32.TryParse(match.Groups["SubChapter"].Value, out SubChapter);
                            }
                        }

                        if (Equals(Url, null))
                        {
                            continue;
                        }
                        Url = String.Format("{0}{1}", ExtensionDescriptionAttribute.RootUrl, Url);

                        ChapterObject NewChapterObject = new ChapterObject()
                        {
                            Name       = ChapterName,
                            Volume     = Volume,
                            Chapter    = Chapter,
                            SubChapter = SubChapter,
                            Locations  =
                            {
                                new LocationObject()
                                {
                                    Enabled           = true,
                                    ExtensionName     = ExtensionDescriptionAttribute.Name,
                                    ExtensionLanguage = ExtensionDescriptionAttribute.Language,
                                    Url = Url
                                }
                            }
                        };
                        ChapterObject ExistingChapterObject = Chapters.FirstOrDefault(o =>
                        {
                            if (!Int32.Equals(o.Chapter, NewChapterObject.Chapter))
                            {
                                return(false);
                            }
                            if (!Int32.Equals(o.SubChapter, NewChapterObject.SubChapter))
                            {
                                return(false);
                            }
                            return(true);
                        });
                        if (Equals(ExistingChapterObject, null))
                        {
                            Chapters.Add(NewChapterObject);
                        }
                        else
                        {
                            ExistingChapterObject.Merge(NewChapterObject);
                        }
                    }
                }
            }
            Chapters = Chapters.OrderBy(c => c.Chapter).ThenBy(c => c.SubChapter).ThenBy(c => c.Volume).ToList();

            return(new MangaObject()
            {
                Name = Name,
                AlternateNames = AlternateNames,
                Description = Description,
                Authors = Authors,
                Artists = Artists,
                Genres = Genres,
                MangaType = MangaType,
                Chapters = Chapters
            });
        }
            private FileSystemNode GetOrCreateInternal(List <VolumeNode> volumes, string path, bool shouldCreate, bool isContextOfFile)
            {
                if (_directorySeparatorChar == '\\')
                {
                    if (!isContextOfFile)
                    {
                        path = path.TrimPath() + _directorySeparatorChar;
                    }
                    path = Path.GetFullPath(path);
                }
                if (!isContextOfFile)
                {
                    path = path.TrimPath();
                }
                string[] pathNodes = FileSystemUtility.ParsePath(path, _directorySeparatorChar);

                VolumeNode volume = GetOrCreateVolume(volumes, pathNodes[0], shouldCreate);

                if (volume == null)
                {
                    return(null);
                }
                StringComparer stringComparer = volume.StringComparer;

                ContainerNode current = volume;

                if (pathNodes.Length <= 1)
                {
                    return(current);
                }

                int i;

                for (i = 1; i < pathNodes.Length - 1; i++)
                {
                    bool found = false;

                    var child = current.Directories[pathNodes[i]];
                    if (child != null)
                    {
                        found   = true;
                        current = child;
                    }

                    if (!found)
                    {
                        if (!shouldCreate)
                        {
                            return(null);
                        }
                        break;
                    }
                }

                if (i >= pathNodes.Length && Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                var pathNode  = pathNodes[i];
                var directory = current.Directories[pathNode];

                if (directory != null)
                {
                    return(directory);
                }

                var file = current.Files[pathNode];

                if (file != null)
                {
                    return(file);
                }

                if (!shouldCreate)
                {
                    return(null);
                }

                for (int j = i; j < pathNodes.Length - 1; j++, i = j)
                {
                    var           directoryName     = pathNodes[j];
                    DirectoryNode existingDirectory = current.Directories[directoryName];
                    if (existingDirectory == null)
                    {
                        DirectoryNode newDirectory = new DirectoryNode(this, directoryName, stringComparer)
                        {
                            LastWriteTime = DateTime.Now,
                        };
                        current.Directories.Add(newDirectory);
                        current = newDirectory;
                    }
                    else
                    {
                        current = existingDirectory;
                    }
                }

                if (!isContextOfFile)
                {
                    var directoryName = pathNodes[i];
                    lock (current.Directories.SyncLock)
                    {
                        DirectoryNode existingDirectory = current.Directories[directoryName];
                        if (existingDirectory == null)
                        {
                            DirectoryNode newDirectory = new DirectoryNode(this, directoryName, stringComparer)
                            {
                                LastWriteTime = DateTime.Now,
                            };
                            current.Directories.Add(newDirectory);
                            return(newDirectory);
                        }

                        return(existingDirectory);
                    }
                }

                var fileName = pathNodes[i];

                lock (current.Files.SyncLock)
                {
                    FileNode existingFile = current.Files[fileName];
                    if (existingFile == null)
                    {
                        FileNode fileNode = new FileNode(this)
                        {
                            Name          = fileName,
                            LastWriteTime = DateTime.Now,
                        };
                        current.Files.Add(fileNode);
                        return(fileNode);
                    }

                    return(existingFile);
                }
            }