コード例 #1
0
        void LoadLinks()
        {
            _AllLinks.Clear();
            string[] xmlFiles = Directory.GetFiles(Path, "*.xml");
            foreach (string xml in xmlFiles)
            {
                if (System.IO.Path.GetFileName(xml).ToLower().StartsWith("_infos"))
                {
                    continue;
                }

                XmlSerializer deserializer = new XmlSerializer(typeof(ImagesLinks));
                TextReader    reader       = new StreamReader(xml);
                try
                {
                    object obj = deserializer.Deserialize(reader);
                    reader.Close();
                    ImagesLinks list = obj as ImagesLinks;
                    list.Filename      = xml;
                    list.Id            = list.Filename.GetStableHashCode();
                    _AllLinks[list.Id] = list;
                }
                catch { }
            }
        }
コード例 #2
0
        //-----------------------------------------------------------------------------------------
        void ConvertCsvToXml(string _path)
        {
            ImagesLinks datas = new ImagesLinks();

            using (StreamReader tr = new StreamReader(_path))
            {
                string line = tr.ReadLine()?.Trim();
                //while ((line = tr.ReadLine()) != null)
                while (line != null)
                {
                    string nextLine = tr.ReadLine()?.Trim();
                    while (nextLine != null && nextLine.StartsWith("http"))
                    {
                        line     = line + nextLine;
                        nextLine = tr.ReadLine()?.Trim();
                    }

                    string[] parts = line.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length < 2 || string.IsNullOrWhiteSpace(parts[0]))
                    {
                        continue;
                    }
                    string name = parts[0].Trim(" \t\"".ToCharArray());

                    for (int i = 1; i < parts.Length; i++)
                    {
                        string url = parts[i].Trim(" \t\"".ToCharArray());
                        if (!string.IsNullOrEmpty(url) && url.Substring(0, 4).ToLower() == "http")
                        {
                            datas.Add(new ImageLink()
                            {
                                Key = name, Link = url
                            });
                        }
                    }

                    /*if (parts[1].ToLower().StartsWith("http:"))
                     *  parts[1] = parts[1].Remove(0, 5);
                     * if (parts[1].StartsWith("\""))
                     * {
                     *  parts[1] = parts[1].Remove(0, 1);
                     *  int index = parts[1].IndexOf("\"");
                     *  if (index != -1) parts[1] = parts[1].Remove(index);
                     * }
                     * datas.Add(new ImageLink() { Key = parts[0], Link = parts[1] });*/

                    line = nextLine;
                }
            }

            string        xml        = System.IO.Path.ChangeExtension(_path, ".xml");
            XmlSerializer serializer = new XmlSerializer(typeof(ImagesLinks));

            using (TextWriter writer = new StreamWriter(xml))
            {
                serializer.Serialize(writer, datas);
            }
        }