Skip to content

Commit

Permalink
XmlExporterCLI finished
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinkmrMask committed Sep 1, 2021
1 parent 7bf7b19 commit 604985c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 153 deletions.
127 changes: 17 additions & 110 deletions csharp/Platform.Data.Doublets.Xml/DefaultXmlStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Platform.Data.Doublets;
using Platform.Data.Doublets.Sequences.Converters;
using Platform.Data.Doublets.Sequences.Frequencies.Cache;
using Platform.Data.Doublets.Sequences.Frequencies.Counters;
using Platform.Data.Doublets.Sequences.Indexes;
using Platform.Data.Doublets.Unicode;

Expand All @@ -20,78 +21,16 @@ namespace Platform.Data.Doublets.Xml
/// <seealso cref="IXmlStorage{TLink}"/>
public class DefaultXmlStorage<TLink> : IXmlStorage<TLink>
{
/// <summary>
/// <para>
/// The zero.
/// </para>
/// <para></para>
/// </summary>
private static readonly TLink _zero = default;
/// <summary>
/// <para>
/// The zero.
/// </para>
/// <para></para>
/// </summary>
private static readonly TLink _one = Arithmetic.Increment(_zero);

/// <summary>
/// <para>
/// The string to unicode sequence converter.
/// </para>
/// <para></para>
/// </summary>
private readonly StringToUnicodeSequenceConverter<TLink> _stringToUnicodeSequenceConverter;
/// <summary>
/// <para>
/// The links.
/// </para>
/// <para></para>
/// </summary>
private readonly ILinks<TLink> _links;
/// <summary>
/// <para>
/// The unicode symbol marker.
/// </para>
/// <para></para>
/// </summary>
private TLink _unicodeSymbolMarker;
/// <summary>
/// <para>
/// The unicode sequence marker.
/// </para>
/// <para></para>
/// </summary>
private TLink _unicodeSequenceMarker;
/// <summary>
/// <para>
/// The element marker.
/// </para>
/// <para></para>
/// </summary>
private TLink _elementMarker;
/// <summary>
/// <para>
/// The text element marker.
/// </para>
/// <para></para>
/// </summary>
private TLink _textElementMarker;
/// <summary>
/// <para>
/// The document marker.
/// </para>
/// <para></para>
/// </summary>
private TLink _documentMarker;

/// <summary>
/// <para>
/// Represents the unindex.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="ISequenceIndex{TLink}"/>

private class Unindex : ISequenceIndex<TLink>
{
/// <summary>
Expand All @@ -109,6 +48,7 @@ private class Unindex : ISequenceIndex<TLink>
/// <para></para>
/// </returns>
public bool Add(IList<TLink> sequence) => true;

/// <summary>
/// <para>
/// Determines whether this instance might contain.
Expand Down Expand Up @@ -156,16 +96,11 @@ public DefaultXmlStorage(ILinks<TLink> links, bool indexSequenceBeforeCreation,
_links = links;
}

/// <summary>
/// <para>
/// Inits the constants using the specified links.
/// </para>
/// <para></para>
/// </summary>
/// <param name="links">
/// <para>The links.</para>
/// <para></para>
/// </param>
public DefaultXmlStorage(ILinks<TLink> links, bool indexSequenceBeforeCreation = false) :
this(links, indexSequenceBeforeCreation,
new LinkFrequenciesCache<TLink>(links,
new TotalSequenceSymbolFrequencyCounter<TLink>(links))) { }

private void InitConstants(ILinks<TLink> links)
{
var markerIndex = _one;
Expand All @@ -176,6 +111,7 @@ private void InitConstants(ILinks<TLink> links)
_textElementMarker = links.GetOrCreate(meaningRoot, Arithmetic.Increment(ref markerIndex));
_documentMarker = links.GetOrCreate(meaningRoot, Arithmetic.Increment(ref markerIndex));
}

/// <summary>
/// <para>
/// Creates the document using the specified name.
Expand All @@ -191,6 +127,7 @@ private void InitConstants(ILinks<TLink> links)
/// <para></para>
/// </returns>
public TLink CreateDocument(string name) => Create(_documentMarker, name);

/// <summary>
/// <para>
/// Creates the element using the specified name.
Expand All @@ -206,6 +143,7 @@ private void InitConstants(ILinks<TLink> links)
/// <para></para>
/// </returns>
public TLink CreateElement(string name) => Create(_elementMarker, name);

/// <summary>
/// <para>
/// Creates the text element using the specified content.
Expand All @@ -221,25 +159,9 @@ private void InitConstants(ILinks<TLink> links)
/// <para></para>
/// </returns>
public TLink CreateTextElement(string content) => Create(_textElementMarker, content);
/// <summary>
/// <para>
/// Creates the marker.
/// </para>
/// <para></para>
/// </summary>
/// <param name="marker">
/// <para>The marker.</para>
/// <para></para>
/// </param>
/// <param name="content">
/// <para>The content.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>The link</para>
/// <para></para>
/// </returns>

private TLink Create(TLink marker, string content) => _links.GetOrCreate(marker, _stringToUnicodeSequenceConverter.Convert(content));

/// <summary>
/// <para>
/// Attaches the element to parent using the specified element to attach.
Expand Down Expand Up @@ -271,6 +193,7 @@ private void InitConstants(ILinks<TLink> links)
/// <para></para>
/// </returns>
public TLink GetDocument(string name) => Get(_documentMarker, name);

/// <summary>
/// <para>
/// Gets the text element using the specified content.
Expand Down Expand Up @@ -301,25 +224,9 @@ private void InitConstants(ILinks<TLink> links)
/// <para></para>
/// </returns>
public TLink GetElement(string name) => Get(_elementMarker, name);
/// <summary>
/// <para>
/// Gets the marker.
/// </para>
/// <para></para>
/// </summary>
/// <param name="marker">
/// <para>The marker.</para>
/// <para></para>
/// </param>
/// <param name="content">
/// <para>The content.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>The link</para>
/// <para></para>
/// </returns>

private TLink Get(TLink marker, string content) => _links.SearchOrDefault(marker, _stringToUnicodeSequenceConverter.Convert(content));

/// <summary>
/// <para>
/// Gets the children using the specified parent.
Expand All @@ -335,7 +242,7 @@ private void InitConstants(ILinks<TLink> links)
/// <para></para>
/// </returns>
public IList<TLink> GetChildren(TLink parent) {
var childrens = new List<TLink>();
List<TLink> childrens = new List<TLink>();
_links.Each((link) => {
childrens.Add(_links.GetTarget(link));
return this._links.Constants.Continue;
Expand Down
44 changes: 1 addition & 43 deletions csharp/Platform.Data.Doublets.Xml/XmlExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,7 @@ public Task Export(string documentName, string fileName, CancellationToken token
}
}, token);
}

/// <summary>
/// <para>
/// Writes the writer.
/// </para>
/// <para></para>
/// </summary>
/// <param name="writer">
/// <para>The writer.</para>
/// <para></para>
/// </param>
/// <param name="token">
/// <para>The token.</para>
/// <para></para>
/// </param>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>

private void Write(XmlWriter writer, CancellationToken token, ElementContext context)
{
var parentContexts = new Stack<ElementContext>();
Expand All @@ -104,33 +86,9 @@ private void Write(XmlWriter writer, CancellationToken token, ElementContext con
}
}

/// <summary>
/// <para>
/// Represents the element context.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="XmlElementContext"/>
private class ElementContext : XmlElementContext
{
/// <summary>
/// <para>
/// The parent.
/// </para>
/// <para></para>
/// </summary>
public readonly TLink Parent;

/// <summary>
/// <para>
/// Initializes a new <see cref="ElementContext"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="parent">
/// <para>A parent.</para>
/// <para></para>
/// </param>
public ElementContext(TLink parent) => Parent = parent;
}

Expand Down
42 changes: 42 additions & 0 deletions csharp/Platform.Data.Doublets.Xml/XmlExporterCLI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;
using Platform.IO;
using Platform.Data.Doublets.Memory.United.Generic;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

namespace Platform.Data.Doublets.Xml
{
public class XmlExporterCLI : ICommandLineInterface
{
public void Run(params string[] args)
{
var linksFile = ConsoleHelpers.GetOrReadArgument(0, "Links file", args);
var exportFile = ConsoleHelpers.GetOrReadArgument(1, "Xml file", args);

if (File.Exists(exportFile))
{
Console.WriteLine("Entered xml file does already exists.");
}
else
{
using (var cancellation = new ConsoleCancellation())
{
using (var memoryAdapter = new UnitedMemoryLinks<uint>(linksFile))
{
{
Console.WriteLine("Press CTRL+C to stop.");
var links = memoryAdapter.DecorateWithAutomaticUniquenessAndUsagesResolution();
if (cancellation.NotRequested)
{
var storage = new DefaultXmlStorage<uint>(links);
var exporter = new XmlExporter<uint>(storage);
exporter.Export(linksFile, exportFile, cancellation.Token).Wait();
}
}
}
}
}
}
}
}

0 comments on commit 604985c

Please sign in to comment.