ActivityBuilder.Implementation doesn't include NamespacesForImplementation when serialized - workflow-foundation-4

I'm having a problem serializing to xaml a WorkflowService that includes an ActivityBuilder for its Body parameter. The ActivityBuilder contains C# expressions and the serialized WorkflowService doesn't activate because some C# expressions refer to custom types. The actual error is "Type 'SomeTypeIPassToAnArgument' is not defined".
My ActivityBuilder is created from a xaml file which includes a TextExpression.NamespacesForImplementation element. This is missing when the WorkflowService is serialized and it seems this is the cause of the problem.
I found that if I serialize the ActivityBuilder itself, the namespaces are included, but using ActivityBuilder.Implementation fails. Unfortunately, when I build the WorkflowService to serialize I have to use ActivityBuilder.Implementation as its Body parameter. I tried using the TextExpression.SetNamespacesForImplementation method to ensure these were attached to the implementation but that didn't help.
The following snippet shows what I'm trying to do and where it's failing.
var loadedXaml = File.ReadAllText(#"C:\workflow.xaml");
Assert.IsTrue(loadedXaml.Contains("NamespacesForImplementation"));
var xamlReader = new XamlXmlReader(new StringReader(loadedXaml));
var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader);
var builder = XamlServices.Load(builderReader) as ActivityBuilder;
// namespaces are available in the builder itself
Assert.AreNotEqual(0, TextExpression.GetNamespacesForImplementation(builder).Count);
// when saving, the assert fails because the namespaces aren't serialized
var savedXaml = XamlServices.Save(builder.Implementation);
Assert.IsTrue(savedXaml.Contains("NamespacesForImplementation"));
Any idea why this isn't working, or if there's an alternative approach I could use that would work? Ultimately my aim is to be able to load workflows from xaml and incorporate them in a serialized WorkflowService that I can host in an MVC app using a VirtualPathProvider.
Thanks!

You can't use ActivityBuilder as the body of a WorkflowService, ActivityBuilder is just intended to manipulate an Activity at design time. To convert your ActivityBuilder to an Activity, use ActivityXamlServices.CreateBuilderWriter.
You can leverage XamlServices.Transform to pipe a XamlReader over your ActivityBuilder to the writer you create in ActivityXamlServices.CreateBuilderWriter.

Related

Fetch a component by its tcm id using the core services

I need to fetch a component based on its tcm id using the core services. Please help me which function of core service I can use along with some sample code if possible as well.
Thanks in advance!!
Check the section in the documentation, which you can find here
A basic sample (out of my head, untested ;) ):
ComponentData component = (ComponentData)client.Read(yourComponentId, new ReadOptions());
string title = component.Title;
XElement content = XElement.Parse(component.Content);
The Read method will get you an IdentifiableObjectData object, which you can cast to the needed type if you're sure about what you're supposed to be getting back.
The ReadOptions object will instruct the CoreService how to load the item, for instance, with all Keyword URI's loaded as well using LoadFlags.KeywordXlinks

Actionscript Webservice set result format as e4x

I'm trying to use Webservice component in my Flex 4 application.
I need to use this in Actioncript and not using MXML tags.
I'm able to invoke the WSDL operations successfully, but the resultFormat is Object by default.
How do I set it to e4x?
var lookupService:WebService = new WebService();
lookupService.wsdl =url;
lookupService.loadWSDL();
lookupService.doLookup.addEventListener(ResultEvent.RESULT, lookupResultHandler);
lookupService.doLookup.addEventListener(FaultEvent.FAULT, faultHandler);
lookupService.doLookup(lookupString);
I tried to set the format by
lookupService.resultFormat = "e4x";
But this is not working. The calls are not even going through when I do this.
Can you please provide your suggestions for implementing this using AS3?
If you take a look at the two web service classes, you'll realize that resultFormat is not a property on either of them. Resultset is a property on the operations array.
If that doesn't help, you'll have to quantify "not working." What isn't working? Are you getting compile errors? Are you getting runtime errors? IS the data not being returned? Is the data not be returned as XML?
You'll probably have to set this up in MXML and dissect the generated ActionScript to figure out the appropriate AS3 syntax.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/soap/WebService.html

Coldfusion returning typed objects / AMF remoting

Is the same possible in ColdFusion?
Currently I am using .Net/Fluorine to return objects to the client.
Whilst in testing I like to pass strings representing the select statement and the custom object I wish to have returned from my service.
Fluorine has a class ASObject to which you can set the var 'typeName'; which works great.
I am hoping that this is possible in Coldfusion. Does anyone know whether you can set the type of the returned object in a similar way.
This is especially helpful with large collections as the flash player will convert them to a local object of the same name thus saving interating over the collection to convert the objects to a particular custom object.
foreach (DataRow row in ds.Tables[0].Rows)
{
ASObject obj = new ASObject();
foreach (DataColumn col in ds.Tables[0].Columns)
{
obj.Add(col.ColumnName, row[col.ColumnName]);
}
obj.TypeName = pObjType;
al.Add(obj);
}
Many thanks,
Yes, it works and is built right in so you don't have to use an external server side piece.
ColdFusion Components (CFCs) are the ColdFusion version of an Class.
ColdFusion's Flash/Flex Remoting Gateway will do the automatic conversion of CFCs into ActionScript objects.
Remember that CF is Java based; so the paths and class names are case sensitive. I assume .NET is not like that.
The CFC and ActionScript object should list all properties in the same order. In AS3, you can define them as public variables; in the CFC you should define them using the cfproperty tag. The ActionScript Object should use the RemoteClass metadata tag to specify the absolute location of the CFC. The CFC's cfcomponent tag should specify the alias attribute which is the absolute path location of the CFC Object.
If the CFC method in your service returns an object; the return type on your cffunction tag should be the absolute path to the CFC Object.
I would expect a lot of this is similar to what you've been doing with .NET; just with different syntax. I'm pretty sure you have to enable Flex / Flash Remoting in the CFADmin before any of this will work.
There should be a CF to Flex data type conversion chart somewhere in the CF Docs.
You can also return a struct with a special key called 'type' with the value of the AS class that the properties represent, and Flex will populate those objects.
For example
{
id=2,
name=kevin,
__type__=com.company.user
}
(note that is 'underscore underscore type underscore underscore', the formatting is bein stripped)

how can i use structure map asp.net 3.5

I am new to the structure map but i want to use it in my asp.net site for dependency injection
can any one suggest me simple example to use structure map for the dependency injection
you will need to do something like this:-
StructureMapConfiguration
.ForRequestedType<IResourceA>()
.TheDefaultIsConcreteType<ResourceB>()
.CacheBy(InstanceScope.Singleton);
This tells StructureMap to inject ResourceB when there is a request for ResourceA.
Structure Map
You can configure programatically or via configuration file.
Programatical example (there are other ways):
StructureMap.StructureMapConfiguration.ForRequestedType<ISomething>().TheDefaultIsConcreteType<ConcreteSomething>();
then you can get an instance of the configured type using this sort of code:
//The concrete type will be ConcreteSomething
ISomething instance = ObjectFactory.GetInstance<ISomething>();
You can do it in a config file:
<StructureMap MementoStyle="Attribute">
<DefaultInstance PluginType="Blah.ISomething, Blah.SomethingDLL" PluggedType="Blah.Concrete.ConcreteSomething,Blah.ConcreteDLL"/>
</StructureMap>
and in the main method or Global.asax you can set this config by saying:
StructureMap.ObjectFactory.Initialize(x => { x.PullConfigurationFromAppConfig = true; });
and use it the same way as above:
ISomething instance = ObjectFactory.GetInstance<ISomething>();
If the concrete class has a constructor that needs instances injected in it, and you have those configured, the concrete types will get injected by the framework.
There are ways of passing parameters to constructors, dealing with Gereric types, creating named instances that are configured with specific constructor/property values. I use this framework and like it very much.

JSON string to list or other usable format in asp.net 2.0

I have one JSON that is coming in a string format. I need to store it in a key-pair value or something like that. I am using asp.net 2.0 and can not use 3rd party DLL like Newtonsoft.Json.dll. I guess last option will be to use regular expression.
Can anybody please help me in this?
If you go to http://www.json.org/ and look towards the bottom of the page there are dozens of json libraries most of them open source, I believe they list 8 for C#. If you can not reference one of these libraries, I think your best bet would be to find one with a permissive license and simply add the code to your project.
Another idea is to look at the diagrams, grammer, and syntax at http://www.json.org/ and just write your own parser, but regex is NOT the way to do it. If you dont know how to write a parser you could look at one of the open source json libraries or start with something less complicated like a good CSV parser, here is a paper that looks pretty good: http://www.boyet.com/Articles/CsvParser.html
It is possible to serialize JSON using JScript in C# into key/value pairs. You need to add a few references to your project. They're part of the .NET framework, you just need to add the references to your project. You'll need:
Microsoft.JSript
Microsoft.Vsa
First, the usings at the top of your class:
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
Then the Engine that will execute the script needs to be initialized somewhere in your 'Page' code-behind:
VsaEngine Engine = VsaEngine.CreateEngine();
Then you just create this method and call it by passing in your JSON object:
object EvalJScript(string JScript)
{
object result = null;
try
{
result = Microsoft.JScript.Eval.JScriptEvaluate(JScript, Engine);
}
catch (Exception ex)
{
return ex.Message;
}
return result;
}
The type of object returned (if JSON is passed in) is a 'JSObject'. You can access its values as key/value pairs. Read the MSDN documentation for more details on this object.
Here's an example of using the code:
string json = "({Name:\"Dan\",Occupation:\"Developer\"})";
JSObject o = EvalJScript(json) as JSObject;
string name = o["Name"] as string; // Value of 'name' will be 'Dan'
Could you use JScript.NET?
If so, should be easy enough with eval() - then just loop through the objects returned and translate into KeyValuePair's or whatever
You will need to use jscript.net as the code behind language, but other pages of your site should be fine to stay as c# if thats what you prefer.
As mentioned in previous comment, you will need to be aware of the security aspects and risks - only use eval if you trust the JSON you're parsing!

Resources