public static bool IsSameSource(FileSource left, FileSource right)
 {
     return(string.Equals(left.Url, right.Url, StringComparison.InvariantCultureIgnoreCase));
 }
Exemple #2
0
        /// <summary>
        /// 通过配置文件创建<see cref="LocalFileConfig"/>
        /// </summary>
        /// <param name="path">配置文件路径</param>
        /// <returns></returns>
        public static LocalFileConfig Load(string path)
        {
            XDocument xml;

            // 以UTF-8的格式加载配置文件
            using (var reader = new StreamReader(path, Encoding.UTF8))
            {
                xml = XDocument.Load(reader);
            }

            LocalFileConfig fileInfo = new LocalFileConfig();

            foreach (XElement field in xml.Root.Elements())
            {
                switch (field.Name.LocalName)
                {
                case "Source":
                {
                    if (string.IsNullOrEmpty(field.Value))
                    {
                        break;
                    }

                    fileInfo._mainSource = FileSource.CreateFromXElement(field);
                }
                break;

                case "Mirrors":
                {
                    List <FileSource> mirrors = new List <FileSource>();
                    foreach (var mirror in field.Elements())
                    {
                        mirrors.Add(FileSource.CreateFromXElement(mirror));
                    }

                    fileInfo._mirrors = mirrors;
                }
                break;

                case "RemoteInfo":
                {
                    if (string.IsNullOrEmpty(field.Value))
                    {
                        break;
                    }

                    fileInfo._remoteInfo = RemoteFileInfo.CreateFromXElement(field);
                }
                break;

                case "Segments":
                {
                    List <LocalSegment> segments = new List <LocalSegment>();
                    foreach (var segment in field.Elements())
                    {
                        segments.Add(LocalSegment.CreateFromXElement(segment));
                    }

                    fileInfo._segments = segments;
                }
                break;

                default:
                    break;
                }
            }// foreach

            return(fileInfo);
        }