Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion FreeFrame.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeFrame", "FreeFrame\FreeFrame.csproj", "{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7624DAC1-357B-4264-8501-F60942B4AD85}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeFrameTests", "FreeFrameTests\FreeFrameTests.csproj", "{C9665752-3F93-4FA8-8F2C-BF701D932E8A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -17,6 +17,10 @@ Global
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Release|Any CPU.Build.0 = Release|Any CPU
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
73 changes: 73 additions & 0 deletions FreeFrame/Components/Importer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using FreeFrame.Components.Shapes;

namespace FreeFrame.Components
{
public static class Importer
{
static public void Import()
{
//TODO: find a solution for opening a crossplatform file dialog. Do I need a crossplatform dialog?
//using (OpenFileDialog openFileDialog = new OpenFileDialog())
//{
//}
}
static public List<Shape> ImportFromStream(Stream pStream)
{
List<Shape> shapes = new List<Shape>();

using (XmlReader reader = XmlReader.Create(pStream))
{
while (reader.Read())
{
if (reader.HasAttributes)
{
//Console.WriteLine("Attributes of <" + reader.Name + ">");
switch (reader.Name)
{
case "xml":
case "svg":
break; // Skip knowned elements
case "polygon":
shapes.Add(new SVGPolygon(reader));
break;
case "path":
shapes.Add(new SVGPath(reader));
break;
case "rect":
shapes.Add(new SVGRectangle(reader));
break;
case "circle":
shapes.Add(new SVGCircle(reader));
break;
default:
// TODO: show all the elemnt are not valid, be careful
break;
}
}
}
}
return (shapes);
}
static public List<Shape> ImportFromFile(string pFilename)
{
if (!File.Exists(pFilename))
throw new ArgumentException($"'{pFilename}' file cannot be found.", nameof(pFilename)); // TODO: replace by a simple alert window

byte[] byteArray = Encoding.UTF8.GetBytes(File.ReadAllText(pFilename));

return ImportFromStream(new MemoryStream(byteArray));
}
static public List<Shape> ImportFromString(string pString)
{
byte[] byteArray = Encoding.UTF8.GetBytes(pString);

return ImportFromStream(new MemoryStream(byteArray));
}
}
}
Loading