Has anyone found a way to save a FlowDocument as BAML or other compressed format? I can import XML with images to create a new FlowDocument:
<TextRange class instance>.Load(fs, DataFormats.Rtf)
However, I haven't found a good way to save it in a 'native' compressed format. Uncompressed XAML is easy to generate using:
<TextRange class instance>.Save(fs, DataFormats.Xaml);
But is there any programmatic method to save it to a compressed format?
If there isn't an existing method, does anyone know where to find a programmatic XAML compiler? Or even just the BAML specifications? I could programmatically generate an entire XAML window with the FlowDocument embedded, but I'd still want to convert the XAML to BAML for faster load times. I'm using relatively large rtf documents and conversion time using DataFormats.Rtf is significant.
I do not think it is possible... The BamlWriter is marked as internal, this will hopefully open up soon!
I unfortunatly do not know of any XAML compilers
Well, it turns out you can run Visual C# 2008 Express w/o the GUI. And you can modify the final program name via code before you compile as well. I'm sure you can do it via APIs, but here's the hack I found:
The program's is name determined in .csproj, in the xml tag.
Run via code or batch file: "\Common7\IDE\vcsexpress" ".sln" /rebuild Release /projectconfig Release /out errors.txt
I like to examine and then delete the errors.txt after each run to make it easier to see if I got a clean build. This isn't ideal because you have to have a full bought version of Visual C# 2008 on each machine you use this way, but it is a way to create a new executable to display each flow document in a programatic way. Also if you have an error in your XAML, you may generate a program that won't run.
Note that the BAML format does NOT compress the text, only the tags and other 'plumbing'. Even the Margin and Padding information is saved in clear ASCII. This is inherited by the end .exe leaving the text clearly visible in sections to notepad or similar.
The XamlPackage format is compressed:
<TextRange class instance>.Save(fs, DataFormats.Xaml);
Related
I'm working with a scriptable CAD/CAM system that runs on Windows 10 whose built-in code pane is not very useful. The user-defined scripting code for this CAD/CAM system is not saved in text files, but rather, in a field in an SQL Server. I'm thinking there might be some way of setting up Visual Studio/VSCode (or maybe Notepad++) to work with the code in the database the same way it would do if were in a text file. I could probably set up some sort of .Net FileSystemWatcher utility that keeps a bunch of code files it sees in a directory synched with code in the SQL Server data field. But I have deadlines, and I'm supposed to be scripting this CAD/CAM system--not building tools to script the CAD/CAM system. Any ideas for a "quick fix"?
I’m working with an application for both Windows desktop and Windows store, potentially I will add Windows Phone in the future. I’m having most of my logic in a library and create different GUI for the different platforms.
I want to localize my application and want to share string resources between the platforms. But how do I do that?
For Windows desktop the most common approach seems to be using resx files. Here is a short example:
http://compositeextensions.codeplex.com/discussions/52910
For Windows store app resw files are used instead, here is an example of that:
http://msdn.microsoft.com/en-us/library/windows/apps/hh965326.aspx
Both these solutions are platform specific which I don’t like :-(. I really want to have all my string in one file/language and being able to use that in all platforms. Is there any solution for this?
Update 17 Feb 2014: As I understand it resx and resw files are in the same format. What is missing in Windows store app is that no class file is generated for the resw file. If I just could get a file like that my problems would be solved. Then I could put an instance of that class in my view model and access all text via properties.
The class file generated in WPF application almost works. The problem is this line that looks something like this:
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ResxTest.Properties.StringTest", typeof(StringTest).Assembly);
To get this to compile I need to change it to this:
global::System.Resources.ResourceManager temp = new System.Resources.ResourceManager("ResxTest.Properties.StringTest", typeof(StringTest).GetTypeInfo().Assembly);
But the resource ResxTest.Properties.StringTest can’t be loaded in my Windows Store application. For some reason I need to rename my resource to Resource.resw and load it with the name “Resource”. I have tried all kind of names but this is the only one that works. Using name MyApplication.MyResource never works.
I’m not sure if I’m on the right track. I’m almost so desperate that I will make my own solution were I convert an XML-file with all strings I needed to a huge class with properties that I could use to get all string without any resource files. But I think that is ugly and cheating so I hope someone could give me a better idea :-).
Update 24 Feb 2014: I was wrong! Things are working quite nicely with Portable class library. If I use that I could put an instance of auto generated C# class in my view model and access all strings from that object.
But if I use an ordinary library things doesn’t work as properly in Windows Store app (WPF is fine). I have tried to copy all files to a Windows store class library from a working Portable class library. When I try to create an instance of the auto generated file I always get:
An exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll but was not handled in user code
Additional information: Unable to load resources for resource file "MetroLib.StringResources" in package…
Quite annoying since I’m using the express editions of Visual Studio where portable class library isn’t available. So probably I will develop my own solution to generate classes from a resource file (which also gives me some other benefits). But I’m still curious what I’m doing wrong.
I finally solved the problem. I simply developed a simple tool (ResToCode) to convert resource files to pure C# classes. Quite similar to what Visual Studios resgen.exe is doing, but with some extra features. It works really well so I’m quite happy about it :-).
The tool is available for anyone at CodeProject:
http://www.codeproject.com/Articles/744528/ResToCode-Localization-tool-for-Windows-Desktop-St
You can put all your resources in a Portable class library and use these libraries on all platform. You might have to check what version of .NET framework you are using. Portable libraries are not available on all the versions of all the platforms.
http://msdn.microsoft.com/en-us/library/vstudio/hh871422(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/vstudio/gg597391(v=vs.110).aspx#members
Have you looked at the Multilingual App Toolkit? It keeps the translations in an industry standard XLIFF format and can generate resources files for Windows and Windows Phone.
I had the same issue with the MissingManifestResourceException for Portable Class Libraries too. Today I created a new Portable Class Library with another name (without the string 'Resources' in it): and it works like a charm. No idea why this hasn't worked before (perhaps the name of the resource).
Does anybody know way to batch trace (vectorize) many bitmaps into flash .swf format on the fly?
I could do it with Flash Pro, but i am looking for tracing big numbers of them so need automated way to do it.
there are some batch tracing progs for svg, but i need to trace into .swf
(p.s. I now there are tools to embed bitmap into swf , I actually need to trace them)
thanks
You could trace the images directly from AS3 using the
as3potrace library & save it. A minimal code for tracing can be
found here. Another project is the vectorizationpackage.
Use a console script to modify the image path in the as3 code &
recompile for multiple images. To recompile from command line, you
would need to use JSFL as suggested by mitim.
I'm a newbie in MS Search so please forgive the dumb question :-)
I'm storing a large amount of specialized text files for a card game (bridge).
These files are plain textfiles with a specific format to describe a bridge game played in a championship.
The only difference with a regular .txt file is the file extension that is NOT ".txt" but ".lin"
What I need is implement a new iFilter that is an exact copy of the standard MS Search text iFilter, but with another file extension.
Is this possible by copy/pasting an existing filter and tweaking (tampering) its content?
Or do I have to use c# to edit the iFilter and recompile?
The Windows 7 SDK has a sample IFilter implementation that would be a good blue print for what you are trying to do. It contains a project called "SmpFilt" The code shows parsing of a text file with a custom file extension. You will need to modify the code to parse your text instead and pull out any custom attributes from your .lin files.
Unfortunately, you can no longer build custom IFilters with managed code (C#/VB, etc). The sample project is in c++. Windows 7 and Server 2008 won't load IFilters written in managed code.
Good luck.
I'd like to run a custom EXE against my XAML Resource Dictionaries. Let's say this exe that I've got is going to strip out comments, whitespace and unused resources. The original XAML files need to be untouched, but the XAML (silverlight) and BAML (wpf) that ends up in the XAPs and DLLs needs to be transformed. It needs to work on my computer and the build server.
My question is: what's the simplest and most reliable way to run this exe?
My first thought was to have a pre-build event. But this would have to work on the original XAML file. Development would become quite painful.
By the time the post build event has been run, my resources are already compiled into the dlls.
What are my options?
You should implement the "exe" as an MSbuild Task.
Essentially you build a C# class that inherits from the Microsoft.Build.Utilities.Task class, and overide the Execute() method.
Something like
public class CleanXAML : Task
{
}
Then you spefify (either in your build file, or an external .tasks file that you import, the task name and the path to the DLL you just built)
<UsingTask AssemblyFile="C:\customtasks\XamlTasks.dll"
TaskName="Rob.CustomTasks.Xaml.CleanXaml"/>
That enables you to invoke this like any other MsBuild task
<CleanXaml Source="$(PathtoOriginalXaml)"
Destination="$(SourceCodePath)\$(cleanXaml.xaml)" />
From there you need to figure out the best way to "inject" this into your build process. Depending on how you are building (msbuild, vs2010, teambuild, or teambuild workflow) there are different ways to do this. Essentially you need this to happen BEFORE the CoreCompile target is invoked and make sure your "output xaml" properly replaces what CSC.exe is going to expect.
Do some searches on MsBuild tasks for more info, or ask any question you've got here.
I would highly recommend this approach vs. using a CallEXE task in MSBuild, b/c this way the MSBuild properties and items stay in context so you are just moving from build step to build step, vs sidetracking the whole thing to do the transform, then hoping it keeps working.