/// <summary>
        ///   Deserializes passed string to file.
        /// </summary>
        /// <param name="input">
        ///   String to be deserialized.
        /// </param>
        /// <param name="parent">
        ///   Parent <see cref="IEntity">entity</see> for file.
        /// </param>
        /// <param name="encoding">
        ///   Encoding used for deserialization of file name.
        ///   Usually passed from parent <see cref="Hypermedia">hypermedia</see> where file resides during deserialization of parent hypermedia.
        /// </param>
        public static File DeserializeFromString(string input, IEntity parent, Encoding encoding)
        {
            string         path                 = null;
            string         name                 = null;
            string         extension            = null;
            FileAttributes?attributes           = null;
            long           lastModDateTime      = 0;
            DateTime?      lastModifiedDateTime = null;
            List <Block>   blocks               = new List <Block>();
            bool           isSingleBlock        = false;
            ulong          size                 = 0;
            string         parent_path          = null;
            string         hash                 = null;

            DeserializationTools.CheckStringFormat(input, false);

            string        blockList;
            int           count;
            List <string> stringList;

            DeserializationTools.SplitStringForSystemEntity(input, _startOfBlockListDeclaration, _endOfBlockListDeclaration, 13, out count, out blockList, out stringList, true);

            DeserializationTools.ParseStartBaseSystemEntitySerializationString(stringList, encoding, out path, out name);
            extension            = new string(stringList[2].Skip(19).TakeWhile(x => x != ',').ToArray());
            attributes           = FileAttributesDeserializer(new string(stringList[3].Skip(34).TakeWhile(x => x != ',').ToArray()));
            lastModDateTime      = long.Parse(new string(stringList[4].Skip(41).TakeWhile(x => x != ',').ToArray()));
            lastModifiedDateTime = DateTimeOffset.FromUnixTimeSeconds(lastModDateTime).UtcDateTime;
            isSingleBlock        = (new string(stringList[5].Skip(26).TakeWhile(x => x != ',').ToArray()) == "true") ? true : false;
            DeserializationTools.ParseEndBaseSerializationString(stringList, 6, out size, out parent_path, out hash);

            DeserializationTools.CheckParent(parent, parent_path, false);

            File file = new File
            {
                Path                 = path,
                Name                 = name,
                Extension            = extension,
                Attributes           = attributes,
                LastModifiedDateTime = lastModifiedDateTime,
                IsSingleBlock        = isSingleBlock,
                Size                 = size,
                Parent               = parent,
                Hash                 = hash
            };

            if (count != 0)
            {
                blocks = BlocksListDeserializer(blockList, file, count);
            }

            file.Blocks = blocks;
            return(file);
        }
        /// <summary>
        ///   Deserializes passed string to directory.
        /// </summary>
        /// <param name="input">
        ///   String to be deserialized.
        /// </param>
        /// <param name="parent">
        ///   Parent <see cref="IEntity">entity</see> for directory.
        /// </param>
        /// <param name="encoding">
        ///   Encoding used for deserialization of directory name.
        ///   Usually passed from parent <see cref="Hypermedia">hypermedia</see> where directory resides during deserialization of parent hypermedia.
        /// </param>
        public static Directory DeserializeFromString(string input, IEntity parent, Encoding encoding)
        {
            string               path                 = null;
            string               name                 = null;
            FileAttributes?      attributes           = null;
            long                 lastModDateTime      = 0;
            DateTime?            lastModifiedDateTime = null;
            List <ISystemEntity> entities             = new List <ISystemEntity>();
            ulong                size                 = 0;
            string               parent_path          = null;
            string               hash                 = null;

            DeserializationTools.CheckStringFormat(input, false);

            string        entitiesList;
            int           count;
            List <string> stringList;

            DeserializationTools.SplitStringForSystemEntity(input, _startOfSystemEntityListDeclaration, _endOfSystemEntityListDeclaration, 31, out count, out entitiesList, out stringList, false);

            DeserializationTools.ParseStartBaseSystemEntitySerializationString(stringList, encoding, out path, out name);
            attributes           = FileAttributesDeserializer(new string(stringList[2].Skip(34).TakeWhile(x => x != ',').ToArray()));
            lastModDateTime      = long.Parse(new string(stringList[3].Skip(41).TakeWhile(x => x != ',').ToArray()));
            lastModifiedDateTime = DateTimeOffset.FromUnixTimeSeconds(lastModDateTime).UtcDateTime;
            DeserializationTools.ParseEndBaseSerializationString(stringList, 4, out size, out parent_path, out hash);

            DeserializationTools.CheckParent(parent, parent_path, false);

            Directory directory = new Directory
            {
                Path                 = path,
                Name                 = name,
                Attributes           = attributes,
                LastModifiedDateTime = lastModifiedDateTime,
                Size                 = size,
                Parent               = parent,
                Hash                 = hash
            };

            if (count != 0)
            {
                entities = SystemEntitiesListDeserializer(entitiesList, directory, count, encoding);
            }

            directory.Entities = entities;
            return(directory);
        }
Beispiel #3
0
        /// <summary>
        ///   Deserializes passed string to block.
        /// </summary>
        /// <param name="input">
        ///   String to be deserialized.
        /// </param>
        /// <param name="parent">
        ///   Parent <see cref="File">file</see> for block.
        /// </param>
        public static Block DeserializeFromString(string input, File parent)
        {
            string path        = null;
            ulong  size        = 0;
            string parent_path = null;
            string hash        = null;

            DeserializationTools.CheckStringFormat(input, false);

            var stringList = DeserializationTools.SplitStringForBlock(input);

            path = new string(stringList[0].Skip(14).TakeWhile(x => x != ',').ToArray());
            DeserializationTools.ParseEndBaseSerializationString(stringList, 1, out size, out parent_path, out hash);

            DeserializationTools.CheckParent(parent, parent_path, false);

            return(new Block {
                Path = path, Size = size, Parent = parent, Hash = hash
            });
        }
Beispiel #4
0
        /// <summary>
        ///   Deserializes passed string to hypermedia.
        /// </summary>
        /// <param name="input">
        ///   String to be deserialized.
        /// </param>
        /// <param name="parent">
        ///   Parent <see cref="Hypermedia">hypermedia</see> for serialized hypermedia.
        ///   Default - null.
        /// </param>
        public Hypermedia DeserializeFromString(string input, Hypermedia parent)
        {
            string         path      = null;
            string         name      = null;
            string         comment   = null;
            Encoding       encoding  = null;
            long           cDateTime = 0;
            DateTime       createdDateTime;
            string         createdBy   = null;
            string         creatorPeer = null;
            List <IEntity> entities;
            bool           isDirectoryWrapped = false;
            bool           isRawIPFS          = false;
            string         topic = null;
            string         defaultSubscriptionMessage = null;
            string         defaultSeedingMessage      = null;
            string         version     = null;
            ulong          size        = 0;
            string         parent_path = null;
            string         hash        = null;

            input = input.Replace("\t", "");

            DeserializationTools.CheckStringFormat(input, false);

            int           count;
            string        entitiesList;
            List <string> stringList;

            DeserializationTools.SplitStringForHypermedia(input, _startOfEntityListDeclaration, _endOfEntityListDeclaration, 24, out count, out entitiesList, out stringList, false);

            DeserializationTools.ParseStartBaseHypermediaSerializationString(stringList, out path, out encoding, out name);
            comment            = EncodingTools.DecodeString(new string(stringList[2].Skip(17).TakeWhile(x => x != ',').ToArray()), encoding);
            cDateTime          = long.Parse(new string(stringList[4].Skip(30).TakeWhile(x => x != ',').ToArray()));
            createdDateTime    = DateTimeOffset.FromUnixTimeSeconds(cDateTime).UtcDateTime;
            createdBy          = new string(stringList[5].Skip(20).TakeWhile(x => x != ',').ToArray());
            creatorPeer        = new string(stringList[6].Skip(22).TakeWhile(x => x != ',').ToArray());
            isDirectoryWrapped = (new string(stringList[7].Skip(31).TakeWhile(x => x != ',').ToArray()) == "true") ? true : false;
            isRawIPFS          = (new string(stringList[8].Skip(22).TakeWhile(x => x != ',').ToArray()) == "true") ? true : false;
            topic = new string(stringList[9].Skip(15).TakeWhile(x => x != ',').ToArray());
            defaultSubscriptionMessage = new string(stringList[10].Skip(38).TakeWhile(x => x != ',').ToArray());
            defaultSeedingMessage      = new string(stringList[11].Skip(33).TakeWhile(x => x != ',').ToArray());
            version = new string(stringList[12].Skip(17).TakeWhile(x => x != ',').ToArray());
            DeserializationTools.ParseEndBaseSerializationString(stringList, 13, out size, out parent_path, out hash);

            if (parent != null)
            {
                DeserializationTools.CheckParent(parent, parent_path, false);
            }

            Hypermedia010 hypermedia = new Hypermedia010
            {
                Path                       = path,
                Name                       = name,
                Comment                    = comment,
                Encoding                   = encoding,
                CreatedDateTime            = createdDateTime,
                CreatedBy                  = createdBy,
                CreatorPeer                = creatorPeer,
                IsDirectoryWrapped         = isDirectoryWrapped,
                IsRawIPFS                  = isRawIPFS,
                Topic                      = topic,
                DefaultSubscriptionMessage = defaultSubscriptionMessage,
                DefaultSeedingMessage      = defaultSeedingMessage,
                Version                    = version,
                Size                       = size,
                Parent                     = parent,
                Hash                       = hash
            };

            entities = EntitiesListDeserializer(entitiesList, hypermedia, count);

            hypermedia.Entities = entities;
            return(hypermedia);
        }