ToolPack1
Changes
.gitignore 4(+4 -0)
Build/ConfigurationTool.dll 0(+0 -0)
Build/ConfigurationTool.pdb 0(+0 -0)
Build/Console.exe.config 6(+6 -0)
Build/Console.pdb 0(+0 -0)
Build/RW_Tool.dll 0(+0 -0)
Build/RW_Tool.pdb 0(+0 -0)
ToolPack1/ConfigurationTool/Serializer/XMLSerializer.cs 118(+17 -101)
ToolPack1/RW_Tool/DataSource/DS_Base.cs 12(+12 -0)
ToolPack1/RW_Tool/Interface/IImporter.cs 12(+12 -0)
ToolPack1/RW_Tool/Interface/IReader.cs 12(+12 -0)
ToolPack1/RW_Tool/Interface/IWriter.cs 12(+12 -0)
ToolPack1/RW_Tool/Properties/AssemblyInfo.cs 36(+36 -0)
ToolPack1/RW_Tool/RW_Tool.csproj 56(+56 -0)
ToolPack1/RW_Tool/RWI.cs 29(+29 -0)
ToolPack1/ToolPack1.sln 7(+7 -0)
Details
.gitignore 4(+4 -0)
diff --git a/.gitignore b/.gitignore
index da53351..a94c31b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
ToolPack1/.vs/
+ToolPack1/packages/
ToolPack1/Console/bin/
@@ -13,3 +14,6 @@ ToolPack1/SingletonTool/obj/
ToolPack1/SimpleBenchmark/bin/
ToolPack1/SimpleBenchmark/obj/
+
+ToolPack1/RW_Tool/bin/
+ToolPack1/RW_Tool/obj/
Build/ConfigurationTool.dll 0(+0 -0)
diff --git a/Build/ConfigurationTool.dll b/Build/ConfigurationTool.dll
index 4e2ab37..bb9cb84 100644
Binary files a/Build/ConfigurationTool.dll and b/Build/ConfigurationTool.dll differ
Build/ConfigurationTool.pdb 0(+0 -0)
diff --git a/Build/ConfigurationTool.pdb b/Build/ConfigurationTool.pdb
index 90a158c..f34c55a 100644
Binary files a/Build/ConfigurationTool.pdb and b/Build/ConfigurationTool.pdb differ
Build/Console.exe.config 6(+6 -0)
diff --git a/Build/Console.exe.config b/Build/Console.exe.config
new file mode 100644
index 0000000..016d28f
--- /dev/null
+++ b/Build/Console.exe.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
+ </startup>
+</configuration>
\ No newline at end of file
Build/Console.pdb 0(+0 -0)
diff --git a/Build/Console.pdb b/Build/Console.pdb
new file mode 100644
index 0000000..0ec2057
Binary files /dev/null and b/Build/Console.pdb differ
Build/RW_Tool.dll 0(+0 -0)
diff --git a/Build/RW_Tool.dll b/Build/RW_Tool.dll
new file mode 100644
index 0000000..dfcfb8a
Binary files /dev/null and b/Build/RW_Tool.dll differ
Build/RW_Tool.pdb 0(+0 -0)
diff --git a/Build/RW_Tool.pdb b/Build/RW_Tool.pdb
new file mode 100644
index 0000000..fac0d9b
Binary files /dev/null and b/Build/RW_Tool.pdb differ
diff --git a/ToolPack1/ConfigurationTool/ConfigEntity.cs b/ToolPack1/ConfigurationTool/ConfigEntity.cs
index 74a2224..258ef94 100644
--- a/ToolPack1/ConfigurationTool/ConfigEntity.cs
+++ b/ToolPack1/ConfigurationTool/ConfigEntity.cs
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
using System.IO;
+using RW_Tool;
+using RW_Tool.DataSource.FileOrStream;
+
using ConfigurationTool.Serializer;
using SingletonTool;
@@ -31,8 +34,8 @@ namespace ConfigurationTool
switch (param.Format)
{
- case EnumFormat.XML: Serializer = new XMLSerializer<T>(); break;
- case EnumFormat.Binary: Serializer = new BinarySerializer<T>(); break;
+ case EnumFormat.XML: Serializer = new XMLSerializer<T>(Params.ConfigPath); break;
+ case EnumFormat.Binary: Serializer = new BinarySerializer<T>(Params.ConfigPath); break;
}
if (File.Exists(Params.ConfigPath))
@@ -43,12 +46,12 @@ namespace ConfigurationTool
//Прочитать файл
public void Import()
{
- Data = Serializer.Import(Params.ConfigPath);
+ Data = Serializer.Read();
}
//Сохранить в файл
public void Export()
{
- Serializer.Export(Data, Params.ConfigPath);
+ Serializer.Write(Data);
}
}
}
diff --git a/ToolPack1/ConfigurationTool/ConfigurationTool.csproj b/ToolPack1/ConfigurationTool/ConfigurationTool.csproj
index 809f7b2..27ab877 100644
--- a/ToolPack1/ConfigurationTool/ConfigurationTool.csproj
+++ b/ToolPack1/ConfigurationTool/ConfigurationTool.csproj
@@ -49,15 +49,24 @@
<Compile Include="ConfigurationManager.cs" />
<Compile Include="CustomSerializer\ICustomSerialazible.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RW\Bin\Bin_Reader.cs" />
+ <Compile Include="RW\Bin\Bin_Writer.cs" />
+ <Compile Include="RW\XML\XML_Reader.cs" />
+ <Compile Include="RW\XML\XML_Writer.cs" />
<Compile Include="Serializer\BinarySerializer.cs" />
<Compile Include="Serializer\ISerializer.cs" />
<Compile Include="Serializer\XMLSerializer.cs" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\RW_Tool\RW_Tool.csproj">
+ <Project>{78207c90-5cfa-4ded-a047-cf711cba3f86}</Project>
+ <Name>RW_Tool</Name>
+ </ProjectReference>
<ProjectReference Include="..\SingletonTool\SingletonTool.csproj">
<Project>{e69e7d23-3595-4742-ad69-9b245ce9c7b8}</Project>
<Name>SingletonTool</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
diff --git a/ToolPack1/ConfigurationTool/RW/Bin/Bin_Reader.cs b/ToolPack1/ConfigurationTool/RW/Bin/Bin_Reader.cs
new file mode 100644
index 0000000..cdd9d45
--- /dev/null
+++ b/ToolPack1/ConfigurationTool/RW/Bin/Bin_Reader.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+
+using ConfigurationTool.CustomSerializer;
+
+using RW_Tool.Interface;
+using RW_Tool.DataSource.FileOrStream;
+
+namespace ConfigurationTool.RW.Bin
+{
+ public class Bin_Reader<T> : IReader<T, DS_FileOrStream>
+ where T : class, new()
+ {
+ public T Read(DS_FileOrStream ds)
+ {
+ switch (ds.Type)
+ {
+ case "File": return ReadFile(ds.AsFile.FilePath);
+ case "Stream": return ReadStream(ds.AsStream.Stream);
+
+ default: throw new Exception();
+ }
+ }
+
+ public T ReadFile(string file)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ // десериализация
+ using (FileStream fs = new FileStream(file, FileMode.Open))
+ {
+ return (T)formatter.Deserialize(fs);
+ }
+ }
+ else
+ {
+ ICustomSerialazible res = (ICustomSerialazible)new T();
+
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ // десериализация
+ using (FileStream fs = new FileStream(file, FileMode.Open))
+ {
+ res.Import(formatter.Deserialize(fs));
+ }
+
+ return (T)res;
+ }
+ }
+ public T ReadStream(Stream stream)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ // десериализация
+ return (T)formatter.Deserialize(stream);
+ }
+ else
+ {
+ ICustomSerialazible res = (ICustomSerialazible)new T();
+
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ // десериализация
+ res.Import(formatter.Deserialize(stream));
+
+ return (T)res;
+ }
+ }
+ }
+}
diff --git a/ToolPack1/ConfigurationTool/RW/Bin/Bin_Writer.cs b/ToolPack1/ConfigurationTool/RW/Bin/Bin_Writer.cs
new file mode 100644
index 0000000..1c121ab
--- /dev/null
+++ b/ToolPack1/ConfigurationTool/RW/Bin/Bin_Writer.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+
+using ConfigurationTool.CustomSerializer;
+
+using RW_Tool.Interface;
+using RW_Tool.DataSource.FileOrStream;
+
+namespace ConfigurationTool.RW.Bin
+{
+
+
+ public class Bin_Writer<T> : IWriter<T, DS_FileOrStream>
+ {
+ public void Write(T entity, DS_FileOrStream ds)
+ {
+ switch (ds.Type)
+ {
+ case "File": WriteFile(entity, ds.AsFile.FilePath); return;
+ case "Stream": WriteStream(entity, ds.AsStream.Stream); return;
+
+ default: throw new Exception();
+ }
+ }
+
+ public void WriteFile(T entity, string file)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ // получаем поток, куда будем записывать сериализованный объект
+ using (FileStream fs = new FileStream(file, FileMode.Create))
+ {
+ formatter.Serialize(fs, entity);
+ }
+ }
+ else
+ {
+ ICustomSerialazible ser = (ICustomSerialazible)entity;
+
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ // получаем поток, куда будем записывать сериализованный объект
+ using (FileStream fs = new FileStream(file, FileMode.Create))
+ {
+ formatter.Serialize(fs, ser.Export());
+ }
+ }
+ }
+ public void WriteStream(T entity, Stream stream)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ formatter.Serialize(stream, entity);
+ }
+ else
+ {
+ ICustomSerialazible ser = (ICustomSerialazible)entity;
+
+ // передаем в конструктор тип класса
+ BinaryFormatter formatter = new BinaryFormatter();
+
+ formatter.Serialize(stream, ser.Export());
+ }
+ }
+ }
+}
+
diff --git a/ToolPack1/ConfigurationTool/RW/XML/XML_Reader.cs b/ToolPack1/ConfigurationTool/RW/XML/XML_Reader.cs
new file mode 100644
index 0000000..fcd964b
--- /dev/null
+++ b/ToolPack1/ConfigurationTool/RW/XML/XML_Reader.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.IO;
+using System.Xml.Serialization;
+
+using RW_Tool.Interface;
+using RW_Tool.DataSource.FileOrStream;
+
+using ConfigurationTool.CustomSerializer;
+
+namespace ConfigurationTool.RW.XML
+{
+ public class XML_Reader<T> : IReader<T, DS_FileOrStream>
+ where T : class, new()
+ {
+ public T Read(DS_FileOrStream ds)
+ {
+ switch (ds.Type)
+ {
+ case "File": return ReadFile(ds.AsFile.FilePath);
+ case "Stream": return ReadStream(ds.AsStream.Stream);
+
+ default: throw new Exception();
+ }
+ }
+
+ public T ReadFile(string file)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(typeof(T));
+
+ // десериализация
+ using (FileStream fs = new FileStream(file, FileMode.Open))
+ {
+ return (T)formatter.Deserialize(fs);
+ }
+ }
+ else
+ {
+ ICustomSerialazible res = (ICustomSerialazible)new T();
+
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(res.SerialazibleType);
+
+ // десериализация
+ using (FileStream fs = new FileStream(file, FileMode.Open))
+ {
+ res.Import(formatter.Deserialize(fs));
+ }
+
+ return (T)res;
+ }
+ }
+ public T ReadStream(Stream stream)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(typeof(T));
+
+ // десериализация
+ return (T)formatter.Deserialize(stream);
+ }
+ else
+ {
+ ICustomSerialazible res = (ICustomSerialazible)new T();
+
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(res.SerialazibleType);
+
+ // десериализация
+ res.Import(formatter.Deserialize(stream));
+
+ return (T)res;
+ }
+ }
+ }
+
+
+
+}
diff --git a/ToolPack1/ConfigurationTool/RW/XML/XML_Writer.cs b/ToolPack1/ConfigurationTool/RW/XML/XML_Writer.cs
new file mode 100644
index 0000000..c84a146
--- /dev/null
+++ b/ToolPack1/ConfigurationTool/RW/XML/XML_Writer.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.IO;
+using System.Xml.Serialization;
+
+using RW_Tool.Interface;
+using RW_Tool.DataSource.FileOrStream;
+
+using ConfigurationTool.CustomSerializer;
+
+namespace ConfigurationTool.RW.XML
+{
+ public class XML_Writer<T> : IWriter<T, DS_FileOrStream>
+ {
+ public void Write(T entity, DS_FileOrStream ds)
+ {
+ switch (ds.Type)
+ {
+ case "File": WriteFile(entity, ds.AsFile.FilePath); return;
+ case "Stream": WriteStream(entity, ds.AsStream.Stream); return;
+
+ default: throw new Exception();
+ }
+ }
+
+ public void WriteFile(T entity, string file)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(typeof(T));
+
+ // получаем поток, куда будем записывать сериализованный объект
+ using (FileStream fs = new FileStream(file, FileMode.Create))
+ {
+ formatter.Serialize(fs, entity);
+ }
+ }
+ else
+ {
+ ICustomSerialazible ser = (ICustomSerialazible)entity;
+
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(ser.SerialazibleType);
+
+ // получаем поток, куда будем записывать сериализованный объект
+ using (FileStream fs = new FileStream(file, FileMode.Create))
+ {
+ formatter.Serialize(fs, ser.Export());
+ }
+ }
+ }
+ public void WriteStream(T entity, Stream stream)
+ {
+ if (typeof(T).GetInterface("ICustomSerialazible") == null)
+ {
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(typeof(T));
+
+ formatter.Serialize(stream, entity);
+ }
+ else
+ {
+ ICustomSerialazible set = (ICustomSerialazible)entity;
+
+ // передаем в конструктор тип класса
+ XmlSerializer formatter = new XmlSerializer(set.SerialazibleType);
+
+ formatter.Serialize(stream, set.Export());
+ }
+ }
+ }
+}
diff --git a/ToolPack1/ConfigurationTool/Serializer/BinarySerializer.cs b/ToolPack1/ConfigurationTool/Serializer/BinarySerializer.cs
index ab74b24..061b547 100644
--- a/ToolPack1/ConfigurationTool/Serializer/BinarySerializer.cs
+++ b/ToolPack1/ConfigurationTool/Serializer/BinarySerializer.cs
@@ -9,114 +9,35 @@ using System.Runtime.Serialization.Formatters.Binary;
using ConfigurationTool.CustomSerializer;
+using RW_Tool;
+using RW_Tool.DataSource.FileOrStream;
+
+using RW_Tool.Interface;
+using ConfigurationTool.RW.Bin;
+
namespace ConfigurationTool.Serializer
{
class BinarySerializer<T>
- : ISerializer<T>
+ :
+ RWI<T, DS_FileOrStream>,
+ ISerializer<T>
where T : class, new()
{
-
- public T Import(string file)
+ public BinarySerializer(string file) : base(new DS_File() { FilePath = file })
{
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- // десериализация
- using (FileStream fs = new FileStream(file, FileMode.Open))
- {
- return (T)formatter.Deserialize(fs);
- }
- }
- else
- {
- ICustomSerialazible res = (ICustomSerialazible)new T();
-
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- // десериализация
- using (FileStream fs = new FileStream(file, FileMode.Open))
- {
- res.Import(formatter.Deserialize(fs));
- }
-
- return (T)res;
- }
+ Reader = new Bin_Reader<T>();
+ Writer = new Bin_Writer<T>();
}
-
- public void Export(T data, string file)
+ public BinarySerializer(Stream stream) : base(new DS_Stream() { Stream = stream })
{
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- // получаем поток, куда будем записывать сериализованный объект
- using (FileStream fs = new FileStream(file, FileMode.Create))
- {
- formatter.Serialize(fs, data);
- }
- }
- else
- {
- ICustomSerialazible entity = (ICustomSerialazible)data;
-
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- // получаем поток, куда будем записывать сериализованный объект
- using (FileStream fs = new FileStream(file, FileMode.Create))
- {
- formatter.Serialize(fs, entity.Export());
- }
- }
+ Reader = new Bin_Reader<T>();
+ Writer = new Bin_Writer<T>();
}
+ public T Read()
+ => Reader.Read(DataStorage);
- public T Import(Stream stream)
- {
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- // десериализация
- return (T)formatter.Deserialize(stream);
- }
- else
- {
- ICustomSerialazible res = (ICustomSerialazible)new T();
-
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- // десериализация
- res.Import(formatter.Deserialize(stream));
-
- return (T)res;
- }
- }
-
- public void Export(T data, Stream stream)
- {
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- formatter.Serialize(stream, data);
- }
- else
- {
- ICustomSerialazible entity = (ICustomSerialazible)data;
-
- // передаем в конструктор тип класса
- BinaryFormatter formatter = new BinaryFormatter();
-
- formatter.Serialize(stream, entity.Export());
- }
- }
+ public void Write(T entity)
+ => Writer.Write(entity, DataStorage);
}
}
diff --git a/ToolPack1/ConfigurationTool/Serializer/ISerializer.cs b/ToolPack1/ConfigurationTool/Serializer/ISerializer.cs
index fd0c5cb..b483a4b 100644
--- a/ToolPack1/ConfigurationTool/Serializer/ISerializer.cs
+++ b/ToolPack1/ConfigurationTool/Serializer/ISerializer.cs
@@ -2,18 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
-
-using System.IO;
namespace ConfigurationTool.Serializer
{
- interface ISerializer<T>
+ public interface ISerializer<T>
{
- T Import(string file);
- void Export(T data, string file);
-
- T Import(Stream stream);
- void Export(T data, Stream stream);
+ T Read();
+ void Write(T entity);
}
}
ToolPack1/ConfigurationTool/Serializer/XMLSerializer.cs 118(+17 -101)
diff --git a/ToolPack1/ConfigurationTool/Serializer/XMLSerializer.cs b/ToolPack1/ConfigurationTool/Serializer/XMLSerializer.cs
index 59e43f5..8db7eab 100644
--- a/ToolPack1/ConfigurationTool/Serializer/XMLSerializer.cs
+++ b/ToolPack1/ConfigurationTool/Serializer/XMLSerializer.cs
@@ -7,118 +7,34 @@ using System.Threading.Tasks;
using System.IO;
using System.Xml.Serialization;
-using ConfigurationTool.CustomSerializer;
+using RW_Tool;
+using RW_Tool.DataSource.FileOrStream;
+using ConfigurationTool.RW.XML;
namespace ConfigurationTool.Serializer
{
class XMLSerializer<T>
- : ISerializer<T>
+ :
+ RWI<T, DS_FileOrStream>,
+ ISerializer<T>
where T : class, new()
{
- public T Import(string file)
+
+ public XMLSerializer(string file) : base(new DS_File() { FilePath = file })
{
- var a = typeof(T).GetInterfaces();
- var b = typeof(T).GetInterface("ICustomSerialazible");
-
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(typeof(T));
-
- // десериализация
- using (FileStream fs = new FileStream(file, FileMode.Open))
- {
- return (T)formatter.Deserialize(fs);
- }
- }
- else
- {
- ICustomSerialazible res = (ICustomSerialazible)new T();
-
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(res.SerialazibleType);
-
- // десериализация
- using (FileStream fs = new FileStream(file, FileMode.Open))
- {
- res.Import(formatter.Deserialize(fs));
- }
-
- return (T)res;
- }
+ Reader = new XML_Reader<T>();
+ Writer = new XML_Writer<T>();
}
-
- public void Export(T data, string file)
+ public XMLSerializer(Stream stream) : base(new DS_Stream() { Stream = stream })
{
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(typeof(T));
-
- // получаем поток, куда будем записывать сериализованный объект
- using (FileStream fs = new FileStream(file, FileMode.Create))
- {
- formatter.Serialize(fs, data);
- }
- }
- else
- {
- ICustomSerialazible entity = (ICustomSerialazible)data;
-
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(entity.SerialazibleType);
-
- // получаем поток, куда будем записывать сериализованный объект
- using (FileStream fs = new FileStream(file, FileMode.Create))
- {
- formatter.Serialize(fs, entity.Export());
- }
- }
+ Reader = new XML_Reader<T>();
+ Writer = new XML_Writer<T>();
}
+ public T Read()
+ => Reader.Read(DataStorage);
- public T Import(Stream stream)
- {
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(typeof(T));
-
- // десериализация
- return (T)formatter.Deserialize(stream);
- }
- else
- {
- ICustomSerialazible res = (ICustomSerialazible)new T();
-
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(res.SerialazibleType);
-
- // десериализация
- res.Import(formatter.Deserialize(stream));
-
- return (T)res;
- }
- }
-
- public void Export(T data, Stream stream)
- {
- if (typeof(T).GetInterface("ICustomSerialazible") == null)
- {
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(typeof(T));
-
- formatter.Serialize(stream, data);
- }
- else
- {
- ICustomSerialazible entity = (ICustomSerialazible)data;
-
- // передаем в конструктор тип класса
- XmlSerializer formatter = new XmlSerializer(entity.SerialazibleType);
-
- formatter.Serialize(stream, entity.Export());
- }
- }
+ public void Write(T entity)
+ => Writer.Write(entity, DataStorage);
}
}
ToolPack1/RW_Tool/DataSource/DS_Base.cs 12(+12 -0)
diff --git a/ToolPack1/RW_Tool/DataSource/DS_Base.cs b/ToolPack1/RW_Tool/DataSource/DS_Base.cs
new file mode 100644
index 0000000..690012d
--- /dev/null
+++ b/ToolPack1/RW_Tool/DataSource/DS_Base.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace RW_Tool.DataSource
+{
+ public abstract class DS_Base
+ {
+ public abstract string Type {get;}
+ }
+}
diff --git a/ToolPack1/RW_Tool/DataSource/FileOrStream/FileOrStream.cs b/ToolPack1/RW_Tool/DataSource/FileOrStream/FileOrStream.cs
new file mode 100644
index 0000000..3845366
--- /dev/null
+++ b/ToolPack1/RW_Tool/DataSource/FileOrStream/FileOrStream.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.IO;
+
+using RW_Tool.DataSource;
+
+namespace RW_Tool.DataSource.FileOrStream
+{
+ public abstract class DS_FileOrStream : DS_Base
+ {
+ public DS_File AsFile => (DS_File)this;
+ public bool IsFile => this is DS_File;
+
+ public DS_Stream AsStream => (DS_Stream)this;
+ public bool IsStream => this is DS_Stream;
+ }
+
+ public class DS_File: DS_FileOrStream
+ {
+ public override string Type => "File";
+
+ public string FilePath { set; get; }
+ public FileInfo FileInfo => new FileInfo(FilePath);
+ }
+ public class DS_Stream: DS_FileOrStream
+ {
+ public override string Type => "Stream";
+
+ public Stream Stream { set; get; }
+ }
+}
ToolPack1/RW_Tool/Interface/IImporter.cs 12(+12 -0)
diff --git a/ToolPack1/RW_Tool/Interface/IImporter.cs b/ToolPack1/RW_Tool/Interface/IImporter.cs
new file mode 100644
index 0000000..4e16d9f
--- /dev/null
+++ b/ToolPack1/RW_Tool/Interface/IImporter.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace RW_Tool.Interface
+{
+ public interface IImporter<T1,T2>
+ {
+ void Import(T1 entity, T2 param);
+ }
+}
ToolPack1/RW_Tool/Interface/IReader.cs 12(+12 -0)
diff --git a/ToolPack1/RW_Tool/Interface/IReader.cs b/ToolPack1/RW_Tool/Interface/IReader.cs
new file mode 100644
index 0000000..73a8e0f
--- /dev/null
+++ b/ToolPack1/RW_Tool/Interface/IReader.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace RW_Tool.Interface
+{
+ public interface IReader<T1,T2>
+ {
+ T1 Read(T2 param);
+ }
+}
ToolPack1/RW_Tool/Interface/IWriter.cs 12(+12 -0)
diff --git a/ToolPack1/RW_Tool/Interface/IWriter.cs b/ToolPack1/RW_Tool/Interface/IWriter.cs
new file mode 100644
index 0000000..826f9f3
--- /dev/null
+++ b/ToolPack1/RW_Tool/Interface/IWriter.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace RW_Tool.Interface
+{
+ public interface IWriter<T1, T2>
+ {
+ void Write(T1 entity, T2 param);
+ }
+}
ToolPack1/RW_Tool/Properties/AssemblyInfo.cs 36(+36 -0)
diff --git a/ToolPack1/RW_Tool/Properties/AssemblyInfo.cs b/ToolPack1/RW_Tool/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..1090c7a
--- /dev/null
+++ b/ToolPack1/RW_Tool/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Общие сведения об этой сборке предоставляются следующим набором
+// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
+// связанные со сборкой.
+[assembly: AssemblyTitle("RW_Tool")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("RW_Tool")]
+[assembly: AssemblyCopyright("Copyright © 2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
+// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
+// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
+[assembly: ComVisible(false)]
+
+// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
+[assembly: Guid("78207c90-5cfa-4ded-a047-cf711cba3f86")]
+
+// Сведения о версии сборки состоят из следующих четырех значений:
+//
+// Основной номер версии
+// Дополнительный номер версии
+// Номер сборки
+// Редакция
+//
+// Можно задать все значения или принять номер сборки и номер редакции по умолчанию.
+// используя "*", как показано ниже:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
ToolPack1/RW_Tool/RW_Tool.csproj 56(+56 -0)
diff --git a/ToolPack1/RW_Tool/RW_Tool.csproj b/ToolPack1/RW_Tool/RW_Tool.csproj
new file mode 100644
index 0000000..f6b1d46
--- /dev/null
+++ b/ToolPack1/RW_Tool/RW_Tool.csproj
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{78207C90-5CFA-4DED-A047-CF711CBA3F86}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>RW_Tool</RootNamespace>
+ <AssemblyName>RW_Tool</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <Deterministic>true</Deterministic>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="RWI.cs" />
+ <Compile Include="DataSource\DS_Base.cs" />
+ <Compile Include="DataSource\FileOrStream\FileOrStream.cs" />
+ <Compile Include="Interface\IImporter.cs" />
+ <Compile Include="Interface\IReader.cs" />
+ <Compile Include="Interface\IWriter.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
ToolPack1/RW_Tool/RWI.cs 29(+29 -0)
diff --git a/ToolPack1/RW_Tool/RWI.cs b/ToolPack1/RW_Tool/RWI.cs
new file mode 100644
index 0000000..e1baef1
--- /dev/null
+++ b/ToolPack1/RW_Tool/RWI.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using RW_Tool.Interface;
+
+namespace RW_Tool
+{
+ public class RWI<T1,T2>
+ {
+ public T2 DataStorage { protected set; get; }
+
+ public IReader<T1, T2> Reader { protected set; get; }
+ public bool HaveReader => Reader != null;
+
+ public IWriter<T1, T2> Writer { protected set; get; }
+ public bool HaveWriter => Writer != null;
+
+ public IImporter<T1, T2> Importer { protected set; get; }
+ public bool HaveImporter => Importer != null;
+
+
+ public RWI(T2 ds)
+ {
+ this.DataStorage = ds;
+ }
+ }
+}
ToolPack1/ToolPack1.sln 7(+7 -0)
diff --git a/ToolPack1/ToolPack1.sln b/ToolPack1/ToolPack1.sln
index 3c14c96..e6682f6 100644
--- a/ToolPack1/ToolPack1.sln
+++ b/ToolPack1/ToolPack1.sln
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigurationTool", "Config
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleBenchmark", "SimpleBenchmark\SimpleBenchmark.csproj", "{F862BC1F-ABC5-4C80-9210-1722DA94A04C}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RW_Tool", "RW_Tool\RW_Tool.csproj", "{78207C90-5CFA-4DED-A047-CF711CBA3F86}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -37,6 +39,10 @@ Global
{F862BC1F-ABC5-4C80-9210-1722DA94A04C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F862BC1F-ABC5-4C80-9210-1722DA94A04C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F862BC1F-ABC5-4C80-9210-1722DA94A04C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {78207C90-5CFA-4DED-A047-CF711CBA3F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {78207C90-5CFA-4DED-A047-CF711CBA3F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {78207C90-5CFA-4DED-A047-CF711CBA3F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {78207C90-5CFA-4DED-A047-CF711CBA3F86}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -46,6 +52,7 @@ Global
{E69E7D23-3595-4742-AD69-9B245CE9C7B8} = {9FC03DF2-3AFE-4A62-B380-B9CBFF6486D1}
{E8A983A0-FF7D-4E9A-9234-3F19CCB93700} = {9FC03DF2-3AFE-4A62-B380-B9CBFF6486D1}
{F862BC1F-ABC5-4C80-9210-1722DA94A04C} = {9FC03DF2-3AFE-4A62-B380-B9CBFF6486D1}
+ {78207C90-5CFA-4DED-A047-CF711CBA3F86} = {9FC03DF2-3AFE-4A62-B380-B9CBFF6486D1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {408C4B5A-5AF0-418D-A722-B2B253B5F831}