/// <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 }); }
public static bool IsSerializedStringValid(string input, File parent) { if (!DeserializationTools.CheckStringFormat(input, true)) { return(false); } var stringList = DeserializationTools.SplitStringForBlock(input); if (stringList.Count != 4) { return(false); } if (!DeserializationTools.ValidateStartOfStrings(stringList)) { return(false); } if (!DeserializationTools.ValidateEndOfStrings(stringList, 3)) { return(false); } if ((new string(stringList[0].Skip(1).TakeWhile(x => x != ':').ToArray())) != "string") { return(false); } if ((new string(stringList[0].Skip(8).TakeWhile(x => x != ')').ToArray())) != "path") { return(false); } if ((new string(stringList[1].Skip(1).TakeWhile(x => x != ':').ToArray())) != "uint64") { return(false); } if ((new string(stringList[1].Skip(8).TakeWhile(x => x != ')').ToArray())) != "size") { return(false); } if ((new string(stringList[2].Skip(1).TakeWhile(x => x != ':').ToArray())) != "string") { return(false); } if ((new string(stringList[2].Skip(8).TakeWhile(x => x != ')').ToArray())) != "parent_path") { return(false); } if ((new string(stringList[3].Skip(1).TakeWhile(x => x != ':').ToArray())) != "string") { return(false); } if ((new string(stringList[3].Skip(8).TakeWhile(x => x != ')').ToArray())) != "hash") { return(false); } string parent_path = new string(stringList[2].Skip(21).TakeWhile(x => x != ',').ToArray()); if (!DeserializationTools.CheckParent(parent, parent_path, true)) { return(false); } return(true); }