Remove OPML.Net from dir struct

master
exsersewo 4 years ago
parent 4dcc1158e1
commit 715165f105
  1. 4
      .gitmodules
  2. 312
      src/submodules/OPMLCore.NET/.gitignore
  3. 29
      src/submodules/OPMLCore.NET/.vscode/launch.json
  4. 15
      src/submodules/OPMLCore.NET/.vscode/tasks.json
  5. 21
      src/submodules/OPMLCore.NET/LICENSE
  6. 53
      src/submodules/OPMLCore.NET/OPMLCoredotNET.sln
  7. 48
      src/submodules/OPMLCore.NET/README.md
  8. 52
      src/submodules/OPMLCore.NET/src/OPMLCore.NET/Body.cs
  9. 213
      src/submodules/OPMLCore.NET/src/OPMLCore.NET/Head.cs
  10. 7
      src/submodules/OPMLCore.NET/src/OPMLCore.NET/OPMLCore.NET.csproj
  11. 93
      src/submodules/OPMLCore.NET/src/OPMLCore.NET/Opml.cs
  12. 203
      src/submodules/OPMLCore.NET/src/OPMLCore.NET/Outline.cs
  13. 251
      src/submodules/OPMLCore.NET/test/UnitTest1.cs
  14. 20
      src/submodules/OPMLCore.NET/test/test.csproj

4
.gitmodules vendored

@ -1,4 +0,0 @@
[submodule "src/submodules/OPMLCore.NET"]
path = src/submodules/OPMLCore.NET
url = https://github.com/fnya/OPMLCore.NET
branch = master

@ -1,312 +0,0 @@
# Created by https://www.gitignore.io/api/visualstudio,visualstudiocode
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Uncomment the next line to ignore your web deploy settings.
# By default, sensitive information, such as encrypted password
# should be stored in the .pubxml.user file.
#*.pubxml
*.pubxml.user
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
### VisualStudio Patch ###
# By default, sensitive information, such as encrypted password
# should be stored in the .pubxml.user file.
# End of https://www.gitignore.io/api/visualstudio,visualstudiocode
# Mac
.DS_Store

@ -1,29 +0,0 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/test.xunit/bin/Debug/netcoreapp2.0/test.xunit.dll",
"args": [],
"cwd": "${workspaceFolder}/test.xunit",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}

@ -1,15 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/test.xunit/test.xunit.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018 fnya
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,53 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0DA6DFA3-972E-4B42-AF2C-67D226DCDD89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OPMLCore.NET", "src\OPMLCore.NET\OPMLCore.NET.csproj", "{74D51452-48A8-4F0F-82B5-F47826B4F1C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{15E07BD7-75A1-46F8-8697-F146915FC23F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Debug|x64.ActiveCfg = Debug|x64
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Debug|x64.Build.0 = Debug|x64
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Debug|x86.ActiveCfg = Debug|x86
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Debug|x86.Build.0 = Debug|x86
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Release|Any CPU.Build.0 = Release|Any CPU
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Release|x64.ActiveCfg = Release|x64
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Release|x64.Build.0 = Release|x64
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Release|x86.ActiveCfg = Release|x86
{74D51452-48A8-4F0F-82B5-F47826B4F1C9}.Release|x86.Build.0 = Release|x86
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Debug|x64.ActiveCfg = Debug|x64
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Debug|x64.Build.0 = Debug|x64
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Debug|x86.ActiveCfg = Debug|x86
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Debug|x86.Build.0 = Debug|x86
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Release|Any CPU.Build.0 = Release|Any CPU
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Release|x64.ActiveCfg = Release|x64
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Release|x64.Build.0 = Release|x64
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Release|x86.ActiveCfg = Release|x86
{15E07BD7-75A1-46F8-8697-F146915FC23F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{74D51452-48A8-4F0F-82B5-F47826B4F1C9} = {0DA6DFA3-972E-4B42-AF2C-67D226DCDD89}
EndGlobalSection
EndGlobal

@ -1,48 +0,0 @@
# OPMLCore.NET
OPMLCore.NET is OPML Parser which easy to use for .NET Core Applications.
It is written in C# and with Visual Studio Code.
It supports .NET Core 2.0.
# Setting
You shoud add project refference to your project.
The below is sample `.csproj` which is added project refference.
```
<ItemGroup>
<ProjectReference Include="..\src\OPMLCore.NET\OPMLCore.NET.csproj" />
</ItemGroup>
```
And then `dotnet restore`.
# Usage
How to use is below.
```
using OPMLCore.NET; //Add
Opml opml = new Opml("opmlFilePath");
foreach (Outline outline in opml.Body.Outlines)
{
//Output outline node
Console.WriteLine(outline.Text);
Console.WriteLine(outline.XMLUrl);
//output child's output node
foreach (Outline childOutline in outline.Outlines)
{
Console.WriteLine(childOutline.Text);
Console.WriteLine(childOutline.XMLUrl);
}
}
```
For more detail, show test code or source code.
# License
Lisense is MIT License.

@ -1,52 +0,0 @@
using System;
using System.Text;
using System.Xml;
using System.Collections.Generic;
namespace OPMLCore.NET {
public class Body
{
///<summary>
/// Outline list
///</summary>
public List<Outline> Outlines { get; set; } = new List<Outline>();
///<summary>
/// Constructor
///</summary>
public Body()
{
}
///<summary>
/// Constructor
///</summary>
/// <param name="element">element of Body</param>
public Body(XmlElement element)
{
if (element.Name.Equals("body", StringComparison.CurrentCultureIgnoreCase))
{
foreach (XmlNode node in element.ChildNodes)
{
if (node.Name.Equals("outline", StringComparison.CurrentCultureIgnoreCase))
{
Outlines.Add(new Outline((XmlElement)node));
}
}
}
}
public override string ToString() {
StringBuilder buf = new StringBuilder();
buf.Append("<body>\r\n");
foreach (Outline outline in Outlines)
{
buf.Append(outline.ToString());
}
buf.Append("</body>\r\n");
return buf.ToString();
}
}
}

@ -1,213 +0,0 @@
using System;
using System.Text;
using System.Xml;
using System.Collections.Generic;
namespace OPMLCore.NET {
public class Head
{
///<summary>
/// title
///</summary>
public string Title { get; set; }
///<summary>
/// Created date
///</summary>
public DateTime? DateCreated { get; set; } = null;
///<summary>
/// Modified date
///</summary>
public DateTime? DateModified { get; set; } = null;
///<summary>
/// ownerName
///</summary>
public string OwnerName { get; set; }
///<summary>
/// ownerEmail
///</summary>
public string OwnerEmail { get; set; }
///<summary>
/// ownerId
///</summary>
public string OwnerId { get; set;}
///<summary>
/// docs
///</summary>
public string Docs { get; set;}
///<summary>
/// expansionState
///</summary>
public List<string> ExpansionState { get; set; } = new List<string>();
///<summary>
/// vertScrollState
///</summary>
public string VertScrollState { get; set; }
///<summary>
/// windowTop
///</summary>
public string WindowTop { get; set; }
///<summary>
/// windowLeft
///</summary>
public string WindowLeft { get; set; }
///<summary>
/// windowBottom
///</summary>
public string WindowBottom { get; set; }
///<summary>
/// windowRight
///</summary>
public string WindowRight { get; set; }
///<summary>
/// Constructor
///</summary>
public Head()
{
}
///<summary>
/// Constructor
///</summary>
/// <param name="element">element of Head</param>
public Head(XmlElement element)
{
if (element.Name.Equals("head", StringComparison.CurrentCultureIgnoreCase))
{
foreach (XmlNode node in element.ChildNodes)
{
Title = GetStringValue(node, "title", Title);
DateCreated = GetDateTimeValue(node, "dateCreated", DateCreated);
DateModified = GetDateTimeValue(node, "dateModified", DateModified);
OwnerName = GetStringValue(node, "ownerName", OwnerName);
OwnerEmail = GetStringValue(node, "ownerEmail", OwnerEmail);
OwnerId = GetStringValue(node, "ownerId", OwnerId);
Docs = GetStringValue(node, "docs", Docs);
ExpansionState = GetExpansionState(node, "expansionState", ExpansionState);
VertScrollState = GetStringValue(node, "vertScrollState", VertScrollState);
WindowTop = GetStringValue(node, "windowTop", WindowTop);
WindowLeft = GetStringValue(node, "windowLeft", WindowLeft);
WindowBottom = GetStringValue(node, "windowBottom", WindowBottom);
WindowRight = GetStringValue(node, "windowRight", WindowRight);
}
}
}
private string GetStringValue(XmlNode node, string name, string value)
{
if (node.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
{
return node.InnerText;
} else if (!node.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
return value;
} else {
return string.Empty;
}
}
private DateTime? GetDateTimeValue(XmlNode node, string name, DateTime? value)
{
if (node.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
{
try {
return DateTime.Parse(node.InnerText);
} catch {
return null;
}
} else if (!node.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)){
return value;
} else {
return null;
}
}
private List<string> GetExpansionState(XmlNode node, string name, List<string> value)
{
if (node.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
{
List<string> list = new List<string>();
var items = node.InnerText.Split(',');
foreach(var item in items)
{
list.Add(item.Trim());
}
return list;
} else if (!node.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
{
return value;
} else {
return new List<string>();
}
}
public override string ToString()
{
StringBuilder buf = new StringBuilder();
buf.Append("<head>\r\n");
buf.Append(GetNodeString("title", Title));
buf.Append(GetNodeString("dateCreated", DateCreated));
buf.Append(GetNodeString("dateModified", DateModified));
buf.Append(GetNodeString("ownerName", OwnerName));
buf.Append(GetNodeString("ownerEmail", OwnerEmail));
buf.Append(GetNodeString("ownerId", OwnerId));
buf.Append(GetNodeString("docs", Docs));
buf.Append(GetNodeString("expansionState", ExpansionState));
buf.Append(GetNodeString("vertScrollState", VertScrollState));
buf.Append(GetNodeString("windowTop", WindowTop));
buf.Append(GetNodeString("windowLeft", WindowLeft));
buf.Append(GetNodeString("windowBottom", WindowBottom));
buf.Append(GetNodeString("windowRight", WindowRight));
buf.Append("</head>\r\n");
return buf.ToString();
}
private string GetNodeString(string name, string value)
{
if (string.IsNullOrEmpty(value))
{
return string.Empty;
} else {
return $"<{name}>{value}</{name}>\r\n";
}
}
private string GetNodeString(string name, DateTime? value)
{
if (value == null)
{
return string.Empty;
} else {
return $"<{name}>{value?.ToString("R")}</{name}>\r\n";
}
}
private string GetNodeString(string name, List<string> value)
{
if (value.Count == 0) {
return string.Empty;
}
StringBuilder buf = new StringBuilder();
foreach (var item in value)
{
buf.Append(item);
buf.Append(",");
}
return $"<{name}>{buf.Remove(buf.Length - 1, 1).ToString()}</{name}>\r\n";
}
}
}

@ -1,7 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

@ -1,93 +0,0 @@
using System;
using System.Text;
using System.Xml;
namespace OPMLCore.NET {
public class Opml {
///<summary>
/// Version of OPML
///</summary>
public string Version { get; set;}
///<summary>
/// Encoding of OPML
///</summary>
public string Encoding { get; set;}
///<summary>
/// Head of OPML
///</summary>
public Head Head { get; set;} = new Head();
///<summary>
/// Body of OPML
///</summary>
public Body Body { get; set;} = new Body();
///<summary>
/// Constructor
///</summary>
public Opml()
{
}
///<summary>
/// Constructor
///</summary>
/// <param name="location">Location of the OPML file</param>
public Opml(string location)
{
XmlDocument doc = new XmlDocument();
doc.Load(location);
readOpmlNodes(doc);
}
///<summary>
/// Constructor
///</summary>
/// <param name="doc">XMLDocument of the OPML</param>
public Opml(XmlDocument doc)
{
readOpmlNodes(doc);
}
private void readOpmlNodes(XmlDocument doc) {
foreach (XmlNode nodes in doc)
{
if (nodes.Name.Equals("opml", StringComparison.CurrentCultureIgnoreCase))
{
foreach (XmlNode childNode in nodes)
{
if (childNode.Name.Equals("head", StringComparison.CurrentCultureIgnoreCase))
{
Head = new Head((XmlElement) childNode);
}
if (childNode.Name.Equals("body", StringComparison.CurrentCultureIgnoreCase))
{
Body = new Body((XmlElement) childNode);
}
}
}
}
}
public override string ToString()
{
StringBuilder buf = new StringBuilder();
String ecoding = string.IsNullOrEmpty(Encoding)?"UTF-8":Encoding;
buf.Append($"<?xml version=\"1.0\" encoding=\"{ecoding}\" ?>\r\n");
String version = string.IsNullOrEmpty(Version)?"2.0":Version;
buf.Append($"<opml version=\"{version}\">\r\n");
buf.Append(Head.ToString());
buf.Append(Body.ToString());
buf.Append("</opml>");
return buf.ToString();
}
}
}

@ -1,203 +0,0 @@
using System;
using System.Text;
using System.Xml;
using System.Collections.Generic;
namespace OPMLCore.NET {
public class Outline
{
///<summary>
/// Text of the XML file (required)
///</summary>
public string Text { get; set; }
///<summary>
/// true / false
///</summary>
public string IsComment { get; set; }
///<summary>
/// true / false
///</summary>
public string IsBreakpoint { get; set; }
///<summary>
/// outline node was created
///</summary>
public DateTime? Created { get; set; } = null;
///<summary>
/// Categories
///</summary>
public List<string> Category { get; set; } = new List<string>();
///<summary>
/// Description
///</summary>
public string Description { get; set; }
///<summary>
/// HTML URL
///</summary>
public string HTMLUrl { get; set; }
///<summary>
/// Language
///</summary>
public string Language { get; set; }
///<summary>
/// Title
///</summary>
public string Title { get; set; }
///<summary>
/// Type (rss/atom)
///</summary>
public string Type { get; set; }
///<summary>
/// Version of RSS.
/// RSS1 for RSS1.0. RSS for 0.91, 0.92 or 2.0.
///</summary>
public string Version { get; set; }
///<summary>
/// URL of the XML file
///</summary>
public string XMLUrl { get; set; }
///<summary>
/// Outline list
///</summary>
public List<Outline> Outlines { get; set; } = new List<Outline>();
///<summary>
/// Constructor
///</summary>
public Outline()
{
}
///<summary>
/// Constructor
///</summary>
/// <param name="element">element of Head</param>
public Outline(XmlElement element)
{
Text = element.GetAttribute("text");
IsComment = element.GetAttribute("isComment");
IsBreakpoint = element.GetAttribute("isBreakpoint");
Created = GetDateTimeAttribute(element, "created");
Category = GetCategoriesAtrribute(element, "category");
Description = element.GetAttribute("description");
HTMLUrl = element.GetAttribute("htmlUrl");
Language = element.GetAttribute("language");
Title = element.GetAttribute("title");
Type = element.GetAttribute("type");
Version = element.GetAttribute("version");
XMLUrl = element.GetAttribute("xmlUrl");
if (element.HasChildNodes) {
foreach (XmlNode child in element.ChildNodes)
{
if (child.Name.Equals("outline", StringComparison.CurrentCultureIgnoreCase))
{
Outlines.Add(new Outline((XmlElement) child));
}
}
}
}
private DateTime? GetDateTimeAttribute(XmlElement element, string name)
{
string dt = element.GetAttribute(name);
try {
return DateTime.Parse(dt);
} catch {
return null;
}
}
private List<string> GetCategoriesAtrribute(XmlElement element, string name)
{
List<string> list = new List<string>();
var items = element.GetAttribute(name).Split(',');
foreach(var item in items)
{
list.Add(item.Trim());
}
return list;
}
public override string ToString()
{
StringBuilder buf = new StringBuilder();
buf.Append("<outline");
buf.Append(GetAtrributeString("text", Text));
buf.Append(GetAtrributeString("isComment", IsComment));
buf.Append(GetAtrributeString("isBreakpoint", IsBreakpoint));
buf.Append(GetAtrributeString("created", Created));
buf.Append(GetAtrributeString("category", Category));
buf.Append(GetAtrributeString("description", Description));
buf.Append(GetAtrributeString("htmlUrl", HTMLUrl));
buf.Append(GetAtrributeString("language", Language));
buf.Append(GetAtrributeString("title", Title));
buf.Append(GetAtrributeString("type", Type));
buf.Append(GetAtrributeString("version", Version));
buf.Append(GetAtrributeString("xmlUrl", XMLUrl));
if (Outlines.Count > 0)
{
buf.Append(">\r\n");
foreach (Outline outline in Outlines)
{
buf.Append(outline.ToString());
}
buf.Append("</outline>\r\n");
} else {
buf.Append(" />\r\n");
}
return buf.ToString();
}
private string GetAtrributeString(string name, string value)
{
if (string.IsNullOrEmpty(value))
{
return string.Empty;
} else {
return $" {name}=\"{value}\"";
}
}
private string GetAtrributeString(string name, DateTime? value)
{
if (value == null)
{
return string.Empty;
} else {
return $" {name}=\"{value?.ToString("R")}\"";
}
}
private string GetAtrributeString(string name, List<string> value)
{
if (value.Count == 0) {
return string.Empty;
}
StringBuilder buf = new StringBuilder();
foreach (var item in value)
{
buf.Append(item);
buf.Append(",");
}
return $" {name}=\"{buf.Remove(buf.Length - 1, 1).ToString()}\"";
}
}
}

@ -1,251 +0,0 @@
using System;
using System.Linq;
using System.Text;
using System.Xml;
using Xunit;
using OPMLCore.NET;
namespace test
{
public class UnitTest1
{
[Fact]
public void NormalTest()
{
StringBuilder xml = new StringBuilder();
xml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
xml.Append("<opml version=\"2.0\">");
xml.Append("<head>");
xml.Append("<title>mySubscriptions.opml</title>");
xml.Append("<dateCreated>Sat, 18 Jun 2005 12:11:52 GMT</dateCreated>");
xml.Append("<dateModified>Tue, 02 Aug 2005 21:42:48 GMT</dateModified>");
xml.Append("<ownerName>fnya</ownerName>");
xml.Append("<ownerEmail>fnya@example.com</ownerEmail>");
xml.Append("<ownerId>http://news.com.com/</ownerId>");
xml.Append("<docs>http://news.com.com/</docs>");
xml.Append("<expansionState>1, 6, 13, 16, 18, 20</expansionState>");
xml.Append("<vertScrollState>1</vertScrollState>");
xml.Append("<windowTop>106</windowTop>");
xml.Append("<windowLeft>106</windowLeft>");
xml.Append("<windowBottom>558</windowBottom>");
xml.Append("<windowRight>479</windowRight>");
xml.Append("</head>");
xml.Append("<body>");
xml.Append("<outline ");
xml.Append("text=\"CNET News.com\" ");
xml.Append("isComment=\"true\" ");
xml.Append("isBreakpoint=\"true\" ");
xml.Append("created=\"Tue, 02 Aug 2005 21:42:48 GMT\" ");
xml.Append("category=\"/Harvard/Berkman,/Politics\" ");
xml.Append("description=\"Tech news and business reports by CNET News.com.\" ");
xml.Append("htmlUrl=\"http://news.com.com/\" ");
xml.Append("language=\"unknown\" ");
xml.Append("title=\"CNET News.com\" ");
xml.Append("type=\"rss\" ");
xml.Append("version=\"RSS2\" ");
xml.Append("xmlUrl=\"http://news.com.com/2547-1_3-0-5.xml\" ");
xml.Append("/>");
xml.Append("</body>");
xml.Append("</opml>");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml.ToString());
Opml opml = new Opml(doc);
Assert.True(opml.Head.Title == "mySubscriptions.opml");
Assert.True(opml.Head.DateCreated == DateTime.Parse("Sat, 18 Jun 2005 12:11:52 GMT"));
Assert.True(opml.Head.DateModified == DateTime.Parse("Tue, 02 Aug 2005 21:42:48 GMT"));
Assert.True(opml.Head.OwnerName == "fnya");
Assert.True(opml.Head.OwnerEmail == "fnya@example.com");
Assert.True(opml.Head.OwnerId == "http://news.com.com/");
Assert.True(opml.Head.Docs == "http://news.com.com/");
Assert.True(opml.Head.ExpansionState.ToArray().SequenceEqual("1,6,13,16,18,20".Split(',')));
Assert.True(opml.Head.VertScrollState == "1");
Assert.True(opml.Head.WindowTop == "106");
Assert.True(opml.Head.WindowLeft == "106");
Assert.True(opml.Head.WindowBottom == "558");
Assert.True(opml.Head.WindowRight == "479");
foreach (var outline in opml.Body.Outlines)
{
Assert.True(outline.Text == "CNET News.com");
Assert.True(outline.IsComment == "true");
Assert.True(outline.IsBreakpoint == "true");
Assert.True(outline.Created == DateTime.Parse("Tue, 02 Aug 2005 21:42:48 GMT"));
Assert.True(outline.Category.ToArray().SequenceEqual("/Harvard/Berkman,/Politics".Split(',')));
Assert.True(outline.Description == "Tech news and business reports by CNET News.com.");
Assert.True(outline.HTMLUrl == "http://news.com.com/");
Assert.True(outline.Language == "unknown");
Assert.True(outline.Title == "CNET News.com");
Assert.True(outline.Type == "rss");
Assert.True(outline.Version == "RSS2");
Assert.True(outline.XMLUrl == "http://news.com.com/2547-1_3-0-5.xml");
}
}
[Fact]
public void ChildNodeTest()
{
StringBuilder xml = new StringBuilder();
xml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
xml.Append("<opml version=\"2.0\">");
xml.Append("<head>");
xml.Append("<title>mySubscriptions.opml</title>");
xml.Append("</head>");
xml.Append("<body>");
xml.Append("<outline ");
xml.Append("text=\"IT\" >");
xml.Append("<outline ");
xml.Append("text=\"washingtonpost.com\" ");
xml.Append("htmlUrl=\"http://www.washingtonpost.com\" ");
xml.Append("xmlUrl=\"http://www.washingtonpost.com/rss.xml\" ");
xml.Append("/>");
xml.Append("</outline>");
xml.Append("</body>");
xml.Append("</opml>");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml.ToString());
Opml opml = new Opml(doc);
foreach (var outline in opml.Body.Outlines)
{
foreach(var childOutline in outline.Outlines) {
Assert.True(childOutline.Text == "washingtonpost.com");
Assert.True(childOutline.HTMLUrl == "http://www.washingtonpost.com");
Assert.True(childOutline.XMLUrl == "http://www.washingtonpost.com/rss.xml");
}
}
}
[Fact]
public void CreateNormalOpmlTest()
{
Opml opml = new Opml();
opml.Encoding = "UTF-8";
opml.Version = "2.0";
Head head = new Head();
head.Title = "mySubscriptions.opml";
head.DateCreated = DateTime.Parse("Sat, 18 Jun 2005 12:11:52 GMT").ToUniversalTime();
head.DateModified = DateTime.Parse("Tue, 02 Aug 2005 21:42:48 GMT").ToUniversalTime();
head.OwnerName = "fnya";
head.OwnerEmail = "fnya@example.com";
head.OwnerId = "http://news.com.com/";
head.Docs = "http://news.com.com/";
head.ExpansionState.Add("1");
head.ExpansionState.Add("6");
head.ExpansionState.Add("13");
head.ExpansionState.Add("16");
head.ExpansionState.Add("18");
head.ExpansionState.Add("20");
head.VertScrollState = "1";
head.WindowTop = "106";
head.WindowLeft = "106";
head.WindowBottom = "558";
head.WindowRight = "479";
opml.Head = head;
Outline outline = new Outline();
outline.Text = "CNET News.com";
outline.IsComment = "true";
outline.IsBreakpoint = "true";
outline.Created = DateTime.Parse("Tue, 02 Aug 2005 21:42:48 GMT").ToUniversalTime();
outline.Category.Add("/Harvard/Berkman");
outline.Category.Add("/Politics");
outline.Description = "Tech news and business reports by CNET News.com.";
outline.HTMLUrl = "http://news.com.com/";
outline.Language = "unknown";
outline.Title = "CNET News.com";
outline.Type = "rss";
outline.Version = "RSS2";
outline.XMLUrl = "http://news.com.com/2547-1_3-0-5.xml";
Body body = new Body();
body.Outlines.Add(outline);
opml.Body = body;
StringBuilder xml = new StringBuilder();
xml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
xml.Append("<opml version=\"2.0\">\r\n");
xml.Append("<head>\r\n");
xml.Append("<title>mySubscriptions.opml</title>\r\n");
xml.Append("<dateCreated>Sat, 18 Jun 2005 12:11:52 GMT</dateCreated>\r\n");
xml.Append("<dateModified>Tue, 02 Aug 2005 21:42:48 GMT</dateModified>\r\n");
xml.Append("<ownerName>fnya</ownerName>\r\n");
xml.Append("<ownerEmail>fnya@example.com</ownerEmail>\r\n");
xml.Append("<ownerId>http://news.com.com/</ownerId>\r\n");
xml.Append("<docs>http://news.com.com/</docs>\r\n");
xml.Append("<expansionState>1,6,13,16,18,20</expansionState>\r\n");
xml.Append("<vertScrollState>1</vertScrollState>\r\n");
xml.Append("<windowTop>106</windowTop>\r\n");
xml.Append("<windowLeft>106</windowLeft>\r\n");
xml.Append("<windowBottom>558</windowBottom>\r\n");
xml.Append("<windowRight>479</windowRight>\r\n");
xml.Append("</head>\r\n");
xml.Append("<body>\r\n");
xml.Append("<outline ");
xml.Append("text=\"CNET News.com\" ");
xml.Append("isComment=\"true\" ");
xml.Append("isBreakpoint=\"true\" ");
xml.Append("created=\"Tue, 02 Aug 2005 21:42:48 GMT\" ");
xml.Append("category=\"/Harvard/Berkman,/Politics\" ");
xml.Append("description=\"Tech news and business reports by CNET News.com.\" ");
xml.Append("htmlUrl=\"http://news.com.com/\" ");
xml.Append("language=\"unknown\" ");
xml.Append("title=\"CNET News.com\" ");
xml.Append("type=\"rss\" ");
xml.Append("version=\"RSS2\" ");
xml.Append("xmlUrl=\"http://news.com.com/2547-1_3-0-5.xml\" ");
xml.Append("/>\r\n");
xml.Append("</body>\r\n");
xml.Append("</opml>");
Assert.True(opml.ToString() == xml.ToString());
}
[Fact]
public void CreateChildOpmlTest()
{
Opml opml = new Opml();
opml.Encoding = "UTF-8";
opml.Version = "2.0";
Head head = new Head();
head.Title = "mySubscriptions.opml";
opml.Head = head;
Outline outline = new Outline();
outline.Text = "IT";
Outline childOutline = new Outline();
childOutline.Text = "CNET News.com";
childOutline.HTMLUrl = "http://news.com.com/";
childOutline.XMLUrl = "http://news.com.com/2547-1_3-0-5.xml";
outline.Outlines.Add(childOutline);
Body body = new Body();
body.Outlines.Add(outline);
opml.Body = body;
StringBuilder xml = new StringBuilder();
xml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
xml.Append("<opml version=\"2.0\">\r\n");
xml.Append("<head>\r\n");
xml.Append("<title>mySubscriptions.opml</title>\r\n");
xml.Append("</head>\r\n");
xml.Append("<body>\r\n");
xml.Append("<outline text=\"IT\">\r\n");
xml.Append("<outline text=\"CNET News.com\" ");
xml.Append("htmlUrl=\"http://news.com.com/\" ");
xml.Append("xmlUrl=\"http://news.com.com/2547-1_3-0-5.xml\" />\r\n");
xml.Append("</outline>\r\n");
xml.Append("</body>\r\n");
xml.Append("</opml>");
Assert.True(opml.ToString() == xml.ToString());
}
}
}

@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\OPMLCore.NET\OPMLCore.NET.csproj" />
</ItemGroup>
</Project>
Loading…
Cancel
Save