I would like to import a new reference into my Workflow Designer, however I encounter a weird problem.
Here's my code to import a reference.
var root = GetRootElement();
VisualBasicSettings vbs = VisualBasic.GetSettings(root);
vbs.ImportReferences.Add(new VisualBasicImportReference { Assembly = Assembly.Load("Castle.Core").FullName, Import = "Castle.Core.Configuration.Xml" });
private object GetRootElement()
{
var modelservice = workflowDesigner.Context.Services.GetService<ModelService>();
if (modelservice == null)
return null;
var rootmodel = modelservice.Root.GetCurrentValue();
return rootmodel;
}
It works when I load my designer for the first time, the assembly is well added into the hashset ImportReferences then I also see the namespace in the "Imports" panel. But when I call the above method when user picks a dll through a picker dialog, I call the code above, the assembly is also well added to ImportReferences, but the "Imports" panel is not refreshed...
Any ideas ?
Thanks for your help.
Have you tried DesignerView.OnReferenceUpdated? It seems what you're looking for:
If the referenced assembly is added, the namespaces of the types found
in the assembly are added to the list of imported namespaces. If the
referenced assembly is removed, the namespaces of the types found in
the assembly are removed from the list of imported namespaces.
Usage example:
var designerView = workflowDesigner.Context.Services.GetService<DesignerView>();
designerView.OnReferenceUpdated(assemblyName, true/false);
Actually, the namespace is well imported, it was hided in the dropdownlist above.
Here's the most simple code to import a namespace.
http://blogs.msdn.com/b/tilovell/archive/2011/11/02/wf4-adding-vb-namespace-imports-to-your-workflow-programmatically.aspx
Related
And I am not talking about Newtonsoft.Json - I want the actual object model that is tailored to project.assets.json
Is there a library for that?
After poking around the dotnet/sdk repository, I eventually found a reference to the NuGet/NuGet.Client repository, which defines a LockFile class that contains many of the same properties as a project.assets.json file.
Turns out this class is published in the NuGet.ProjectModel package. Also turns out this package also includes classes to turn this file into an object model.
Sample code that "serializes" the file contents into an object model:
using NuGet.ProjectModel;
class Program
{
static void Main()
{
string content = System.IO.File.ReadAllText("my-folder/project.assets.json");
var lockFileFormat = new LockFileFormat();
var lockFile = lockFileFormat.Parse(content, "In Memory");
}
}
Scenario: I want to load a assembly at run time which is present in Solution.
The belo code will not work as it is not present in Cuurent App Domain.
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Also if i will search in referenced assemblies, then also it can not be found as it is not referenced. So the below code will also not work:
public static IEnumerable<Assembly> GetAssemblies()
{
var list = new List<string>();
var stack = new Stack<Assembly>();
stack.Push(Assembly.GetEntryAssembly());
do
{
var asm = stack.Pop();
yield return asm;
foreach (var reference in asm.GetReferencedAssemblies())
if (!list.Contains(reference.FullName))
{
stack.Push(Assembly.Load(reference));
list.Add(reference.FullName);
}
}
while (stack.Count > 0);
}
Do you guyz have some suggestion ?
Sign your assembly, then in your app.config, specify the fully qualified assembly name. Call Assembly.Load(string), passing the assembly name from your app.config.
NOTE: The assembly you are attempting to load must be in a location where the runtime can find it. Your best bet is either to put it into the Global Assembly Cache, or make sure it is in the same folder as your executing assembly.
I have a regular class I've added to a Razor WebPages to handle some extra database work. To use the data classes, I added Imports WebMatrix.Data to the class and all works fine.
I need to access Request.QueryString and the Session and AppState dictionaries in another class. I don't fancy passing in these objects. I've looked around but can't find what classes to import.
Any ideas?
You can always grab it from session, which should still be available even in Razor by doing
var ctx = System.Web.HttpContext.Current;
var qvar = ctx.Request.QueryString.Get("ABC");
var svar = ctx.Session["XYZ"];
I created a tile map editor for my game and it will generate a file when the user is done with the design. The file will store the assets used and other information.
this is the code on how i generate the file
var ba:ByteArray = new ByteArray();
var masterData:Object = { map:Data.instance.mapLayerArr,
asset:assetCollection,
gridrow:Data.instance.gridRow,
gridColumn: Data.instance.gridColumn,
cellWidth: Data.instance.cellWidth,
cellHeight: Data.instance.cellHeight,
assetCount: Data.instance.assetCount,
layerCount: Data.instance.layerCount,
version: Data.instance.version};
ba.writeObject(masterData);
ba.compress();
file = new FileReference();
file.save(ba, Data.instance.fileName);
problem starts when i want to embed the generated file inside my game.
this is the code in my program.
[Embed(source='../../../../res/tilemapdata/File Name', mimeType='application/octet-stream')]
public static const TileMapFile:Class;
public function TileMapLoader()
{
var byteArray:ByteArray;
byteArray = new TileMapFile();
byteArray.uncompress();
var obj:Object;
obj = byteArray.readObject();
trace(fileReference);
}
whenever i run it ends in "obj = byteArray.readObject();" and will display this error.
[Fault] exception, information=ArgumentError: Error #2173: Unable to read object in stream. The class flex.messaging.io.ArrayCollection does not implement flash.utils.IExternalizable but is aliased to an externalizable class.
You are using a strange class flex.messaging.io.ArrayCollection - try replacing all such imports with mx.collections.ArrayCollection.
Also make sure that all classes that are stored in file has [RemoteClass] metatag or they would be restored as Object instances.
A good read about the situation (adobe's official documentation): (Explicitly mapping ActionScript and Java objects)
I have experianced the same problem. General rules which help me to solve:
better to have explicitly declared metatag [RemoteClass] on your client-side actionscript classes.
collections of server-side classes (lists,arrays,etc.) easier to handle when represented client-side flash by mx.collections.ArrayCollection.
at some point you may need to explicitly declare client-side Flash class with the server-side class relationship by coding before any deserialization occures flash.net.registerClassAlias("net.acme.serverside.Foo", clientside.Foo ); otherwise your objects goes untyped as generic flash.Object after deserialization.
Check, that your ArrayCollection alias registered by this way:
import mx.collections.ArrayCollection;
...
registerClassAlias("flex.messaging.io.ArrayCollection", ArrayCollection);
instead of:
import mx.collections.ArrayCollection;
...
registerClassAlias("mx.collections.ArrayCollection", ArrayCollection);
There explanation:
http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/io/ArrayCollection.html
I need to be able to load external configuration files into my flex app. I've read that this is possible using embeds, so long as the mimeType is set to application/octet-stream.
package learning {
import org.flixel.*;
public class PlayState extends FlxState {
[Embed(source = "../../data/tiles.png")] private var _tiles:Class;
[Embed(source = '../../data/map.txt', mimeType = "application/octet-stream")] private var ExternalMapData:Class;
public var txt:FlxText;
public var player:FlxSprite;
override public function create():void {
bgColor = 0xffaaaaaa;
super.create();
}
override public function update():void {
super.update();
}
}
}
When I compile this using mxmlc, it compiles successfully with no errors. When I run the SWF, it loads all the Flixel menus then hangs.
If I comment out the [Embed(source = '../../data/map.txt' line, it compiles and doesn't hang.
Why is this embed causing a freeze?
Version info for mxmlc:
Adobe Flex Compiler (mxmlc)
Version 4.0.0 build 14159
EDIT
It turns out errors weren't being displayed properly, but this is what I'm getting from attempting the embed:
VerifyError: Error #1014: Class mx.core::ByteArrayAsset could not be found.
Google turns up a bunch of people with the same problem, but no apparent solution.
import mx.core.ByteArrayAsset; ByteArrayAsset
doesn't help either.
Aha! It turns out the solution was very simple - runtime shared libraries weren't being statically linked into the swf, and the path wasn't being set properly for access during runtime. The solution is simple:
Either modify flex-config to say
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
or manually pass in the parameter to mxmlc
mxmlc -static-link-runtime-shared-libraries=true -debug=true Main.swf -- Main.as
I'll answer this one with my answer to another question:
[Embed(source = "ExampleText.txt", mimeType = "application/octet-stream")]
protected var AAAAAA:Class;
var tmp:ByteArray = new AAAAAA();
var result:String = tmp.readMultiByte(tmp.bytesAvailable, tmp.endian);