Esempio n. 1
0
        /// <summary>
        /// when init, fill data to memory
        /// </summary>
        /// <param name="jsonPath"></param>
        IList <JsonFolder> ParseJsonData(string jsonPath)
        {
            IList <JsonFolder> result = new List <JsonFolder>();

            try
            {
                using (StreamReader streamReader = new StreamReader(new FileStream(jsonPath, FileMode.Open,
                                                                                   FileAccess.Read, FileShare.Read)))
                {
                    //first line is head info.
                    string headerStr = streamReader.ReadLine();
                    Header = ParseHeader(headerStr);
                    if (!Header.IsNull())
                    {
                        string rootPath = Header.RootPath;

                        //check version
                        double minorVersion = 0;
                        double.TryParse(Header.Header.Minor, out minorVersion);
                        //Debug.Assert(minorVersion >= 1.7, "Json File Minor version is less than 1.7, this is old file, maybe fail!");
                    }

                    StringBuilder sb = new StringBuilder();
                    while (!streamReader.EndOfStream)
                    {
                        //skip blank line
                        string line = streamReader.ReadLine();
                        if (line.IsNullOrEmpty())
                        {
                            line = sb.ToString();
                            if (line.Contains(tagCopyright) ||
                                line.Contains(tagDateDescriptor))
                            {
                                sb.Clear();
                                continue;
                            }

                            JsonFolder folder = GetFolders(line);
                            if (!folder.IsNull())
                            {
                                result.Add(folder);
                            }
                            sb.Clear();
                        }
                        else
                        {
                            sb.AppendLine(line);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug("Failed", ex);
            }
            return(result);
        }
Esempio n. 2
0
        public FileData(JsonFolder json)
        {
            Id   = json.Id;
            Name = json.Name;

            Path = json.Name;
            Type = FileType.Folder;
            Size = Default.Size;
        }
Esempio n. 3
0
        /// <summary>
        /// get folder from json
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        JsonFolder GetFolders(string content)
        {
            JsonFolder result = null;

            if (string.IsNullOrEmpty(content))
            {
                return(result);
            }
            JsonReader jsonReader = GetJsonReader(content);

            if (jsonReader.IsNull())
            {
                return(result);
            }

            try
            {
                while (jsonReader.Read())
                {
                    if (jsonReader.Token == JsonToken.ObjectStart)
                    {
                        result = new JsonFolder();
                        continue;
                    }

                    if (!jsonReader.Value.IsNull())
                    {
                        result.Name = jsonReader.Value.ToString();
                        continue;
                    }

                    if (jsonReader.Token == JsonToken.ArrayStart)
                    {
                        var subFiles = GetFiles(jsonReader);
                        if (!subFiles.IsNullOrEmpty())
                        {
                            result.Items = subFiles;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug("Failed", ex);
            }
            jsonReader.Close();
            return(result);
        }