Skip to content

Commit

Permalink
v3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
David Egli committed Mar 21, 2013
1 parent 94df957 commit 86224cd
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 31 deletions.
4 changes: 2 additions & 2 deletions XamlImageConverter.ItemWizard/ItemWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ public class ItemWizard: IWizard {
try {
var litem = folder.ProjectItems.AddFromFileCopy(file);
litem.Properties.Item("CustomTool").Value = "";
if (file.EndsWith(".xic.xaml")) litem.Properties.Item("ItemType").Value = "XamlImageConverterPostCompile";
else if (file.EndsWith(".xaml")) litem.Properties.Item("ItemType").Value = "Content";
if (file.EndsWith(".xaml")) litem.Properties.Item("ItemType").Value = "XamlImageConverterPostCompile";
//else if (file.EndsWith(".xaml")) litem.Properties.Item("ItemType").Value = "Content";
} catch (Exception ex) {
}
}
Expand Down
2 changes: 1 addition & 1 deletion XamlImageConverter.VSIX/Demo/Kaxaml.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Grid xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="200" Background="White">
Width="200" Height="200" Background="White">

<Grid.Resources>
<Storyboard x:Key="rotate">
Expand Down
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.ItemWizard.dll
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.ItemWizard.pdb
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.Web.dll
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.Web.pdb
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.dll
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/XamlImageConverter.pdb
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/xiconvert.exe
Binary file not shown.
Binary file modified XamlImageConverter.VSIX/xiconvert.pdb
Binary file not shown.
18 changes: 13 additions & 5 deletions XamlImageConverter.Web/HttpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public class Group : IDisposable {

public XElement Dynamic = new XElement(xic+"Dynamic");
public bool DynamicResult;
public static string[] validAttributes = new string[] { "Element", "Storyboard", "Frames", "Filmstrip", "Dpi", "RenderDpi", "Quality", "Filename", "Left", "Top", "Right", "Bottom", "Width", "Height", "Cultures", "RenderTimeout", "Page", "FitToPage", "File", "Loop", "Pause", "Skin", "Theme", "Type", "Image" };

public void ApplyParameters(string filename, XElement e, Dictionary<string, string> parameters) {
var validAttributes = new string[] { "Element", "Storyboard", "Frames", "Filmstrip", "Dpi", "RenderDpi", "Quality", "Filename", "Left", "Top", "Right", "Bottom", "Width", "Height", "Cultures", "RenderTimeout", "Page", "FitToPage", "File", "Loop", "Pause", "Skin", "Theme", "Type", "Image" };

var type = "png";
int? h = 0;
Expand Down Expand Up @@ -225,8 +225,9 @@ public class Group : IDisposable {
.Where(e => e.Attributes().Any(a => a.Name.Namespace == xic));
foreach (var isn in isnapshots) {
var name = isn.Attribute(xxamlns+"Name") ?? isn.Attribute("Name");
if (name == null) continue;
var sn = new XElement(xic+"Snapshot", new XAttribute("Element", name.Value));
if (name == null && isn != xaml) continue;
var sn = new XElement(xic+"Snapshot");
if (name != null) sn.Add(new XAttribute("Element", name.Value));
foreach (var ia in isn.Attributes().Where(a => a.Name.Namespace == xic)) {
sn.Add(new XAttribute(ia.Name.LocalName, ia.Value));
}
Expand All @@ -235,11 +236,19 @@ public class Group : IDisposable {
}

public XElement CreateDirect(string filename, Dictionary<string, string> parameters) {
if (filename.EndsWith(".xic.xaml")) return XElement.Load(InFilename(filename), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
XElement source;
var file = InFilename(filename);
source = XElement.Load(file, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
if (source.Name == xic+"XamlImageConverter" || source.Name == sb+"SkinBuilder") {
foreach (var key in validAttributes) parameters.Remove(key);
return source;
}

XElement snapshot, scene;
var res = new XElement(xic + "XamlImageConverter",
new XAttribute(XNamespace.Xmlns + "xic", xic.NamespaceName),
scene = new XElement(xic + "Scene",
new XAttribute("OutputPath", Path.GetDirectoryName(filename.Replace("/","\\")).Replace("\\","/")),
new XAttribute("Source", filename)
)
);
Expand All @@ -249,7 +258,6 @@ public class Group : IDisposable {
ApplyParameters(null, snapshot, parameters);
} else parameters.Remove("xic");
}
var source = XElement.Load(InFilename(filename));
ParseXaml(source, scene);
DynamicResult = true;
if (parameters.Count > 0) return Dynamic;
Expand Down
Binary file modified XamlImageConverter.v11.suo
Binary file not shown.
5 changes: 2 additions & 3 deletions XamlImageConverter/CompilerTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ public class XamlImageConverter: Task {
compiler = new Compiler();
}

#if DEBUG
//System.Diagnostics.Debugger.Launch();
//System.Diagnostics.Debugger.Break();
#endif
compiler.SourceFiles = SourceFiles.ToList();
compiler.ProjectPath = ProjectPath;
compiler.LibraryPath = LibraryPath;
compiler.Loggers.Add(new Logger(Log));
//#if DEBUG
compiler.Loggers.Add(new FileLogger());
//#endif
compiler.SeparateAppDomain = true;
compiler.Parallel = true;
compiler.Compile();
Expand Down
4 changes: 2 additions & 2 deletions XamlImageConverter/XamlCapture/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,11 @@ public class StepQueue {
CoreCompile();
CheckBuilding = false;
if (NeedsBuilding) {
var current = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var current = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
var setup = new AppDomainSetup();
setup.ApplicationBase = ProjectPath;
setup.PrivateBinPath = MapPath("~/bin") + ";" + MapPath("~/bin/Lazy") + ";" + MapPath("~/bin/Debug") + ";" + MapPath("~/bin/Release");
setup.ShadowCopyDirectories = MapPath("~/bin") + ";" + MapPath("~/bin/Lazy") + ";" + MapPath("~/bin/Debug") + ";" + MapPath("~/bin/Release");
setup.ShadowCopyDirectories = setup.PrivateBinPath + ";" + current;
setup.ShadowCopyFiles = "true";
var domain = AppDomain.CreateDomain("XamlImageConverter Compiler", null, setup);
var aname = Assembly.GetExecutingAssembly().GetName();
Expand Down
25 changes: 18 additions & 7 deletions XamlImageConverter/XamlCapture/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ public class Group: Canvas {
} else {
if (directXaml != null) {// file is direct xaml
try {
using (var sr = new StringReader(directXaml))
using (var r = System.Xml.XmlReader.Create(sr, new System.Xml.XmlReaderSettings() { CloseInput = true })) {
var x = XElement.Parse(directXaml, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri);
foreach (var a in x.DescendantsAndSelf()
.SelectMany(y => y.Attributes().Where(at => at.Name.Namespace == Compiler.xic))) {
a.Remove();
}
using (var r = x.CreateReader()) {
element = XamlReader.Load(r) as FrameworkElement;
}
} catch (Exception ex) {
Expand All @@ -251,14 +255,21 @@ public class Group: Canvas {
Scene.XamlFile = file;

try {
using (FileLock(file))
using (var stream = File.OpenRead(file)) {
XElement xe;
using (FileLock(file)) {
xe = XElement.Load(file, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri);
}
foreach (var a in xe.DescendantsAndSelf()
.SelectMany(y => y.Attributes().Where(at => at.Name.Namespace == Compiler.xic))) {
a.Remove();
}
using (var r = xe.CreateReader()) {
if (Source.ToLower().EndsWith(".xaml") || Source.ToLower().EndsWith(".psd") || Source.ToLower().EndsWith(".svg")) {
ParserContext context;
//ParserContext context;
//if (string.IsNullOrEmpty(XamlElement.BaseUri))
context = new ParserContext { BaseUri = new Uri("file:https:///" + file) };
//context = new ParserContext { BaseUri = new Uri("file:https:///" + file) };
//else context = new ParserContext { BaseUri = new Uri(XamlElement.BaseUri) };
element = XamlReader.Load(stream, context) as FrameworkElement;
element = XamlReader.Load(r) as FrameworkElement;
} else {
throw new CompilerException("Input format not supported.", 20, XElement);
}
Expand Down
28 changes: 17 additions & 11 deletions XamlImageConverter/XamlCapture/XamlScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ public static class XamlScene {
}
}

public static void ParseXaml(XElement xaml, XElement scene) {
public static void ParseXaml(Compiler compiler, XElement xaml, XElement scene) {
var isnapshots = xaml.DescendantsAndSelf()
.Where(e => e.Attributes().Any(a => a.Name.Namespace == xic));
foreach (var isn in isnapshots) {
var name = isn.Attribute(Compiler.xxamlns + "Name") ?? isn.Attribute("Name");
if (name == null) continue;
var sn = new XElement(xic + "Snapshot", new XAttribute("Element", name.Value));
if (name == null && isn != xaml) {
compiler.Errors.Error("Xaml element for snapshot must be named or root element.", "35", isn);
continue;
}
var sn = new XElement(xic + "Snapshot");
if (name != null) sn.Add(new XAttribute("Element", name.Value));
foreach (var ia in isn.Attributes().Where(a => a.Name.Namespace == xic)) {
sn.Add(new XAttribute(ia.Name.LocalName, ia.Value));
}
Expand All @@ -57,17 +61,20 @@ public static class XamlScene {
}

public static XElement CreateDirect(Compiler compiler, string filename, Dictionary<string, string> parameters) {
if (filename.EndsWith(".xic.xaml")) {
XElement source;
var file = compiler.MapPath(filename);
using (compiler.FileLock(file)) {
source = XElement.Load(file, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
}
if (source.Name == xic+"XamlImageConverter" || source.Name == sb+"SkinBuilder") {
foreach (var key in validAttributes) parameters.Remove(key);
filename = compiler.MapPath(filename);
using (compiler.FileLock(filename)) {
return XElement.Load(filename, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
}
return source;
}
XElement snapshot, scene;
var res = new XElement(xic + "XamlImageConverter",
new XAttribute(XNamespace.Xmlns+"xic", xic.NamespaceName),
scene = new XElement(xic+"Scene",
new XAttribute("OutputPath", Path.GetDirectoryName(filename.Replace("/", "\\")).Replace("\\", "/")),
new XAttribute("Source", filename)
)
);
Expand All @@ -77,8 +84,7 @@ public static class XamlScene {
ApplyParameters(compiler, snapshot, null, parameters);
} else parameters.Remove("xic");
}
var source = XElement.Load(compiler.MapPath(filename));
ParseXaml(source, scene);
ParseXaml(compiler, source, scene);
return res;
}

Expand Down Expand Up @@ -106,7 +112,7 @@ public static class XamlScene {
ApplyParameters(compiler, snapshot, filename, parameters);
scene.Add(snapshot);
}
ParseXaml(e, scene);
ParseXaml(compiler, e, scene);
return res;
} else {
return e;
Expand Down

0 comments on commit 86224cd

Please sign in to comment.