Using OutArgument in Definition of another Activity - workflow-foundation-4

I'm creating a Workflow that can call a custom activity called post that will do a webrequest and return the response as an xmldoc. I tried to return dynamic but that didn't work. I then want to take a specific value in the xml doc and add it into the post dada of the next post call to chain calls together. What I can't figure out is how to get the response data from the first post into the post data of the second post. Any help would be greatly appreciated.
Variable<XmlDocument> output1 = new Variable<XmlDocument>();
ActivityBuilder ab1 = new ActivityBuilder();
ab1.Name = "CustomWorkflow";
ab1.Implementation = new Sequence
{
Activities =
{
new Post()
{
PostData =
"<xml></xml>",
EndPoint =
"www.test.com",
ContentType = "text/xml;charset=\"utf-8\"",
Accept = "text/xml",
Headers = "SOAPAction,Test",
Response = new OutArgument<XmlDocument>(output1)
},
new Post()
{
PostData =
"<xml>"+ output1.GetSingleNode("stuff here") "</xml>",
EndPoint =
"www.test.com",
ContentType = "text/xml;charset=\"utf-8\"",
Accept = "text/xml",
Headers = "SOAPAction,Test"
}
},
Variables =
{
output1
}
};

think you are asking: How do I transfer a value from 1 Activity to another.
If so, there are a couple of ways to do this.
1)
Have a variable at the workflow level that takes the output from your first activity and then pass this variable as an input parameter to the next activity.
2)
Have a variable that is a data structure and pass the structure into all your activities in sequence. In each activity you can add/edit/delete data in the structure and because a workflow variable is a reference variable then this data is available to the next activity is the sequence once you pass in the data object.
Instead of a variable you can use an Argument if you want to pass initial data into the workflow. From then on Arguments behaves like Variables

Related

Validate Smart Format object against the token available in the string

I am trying to validate the smart format object against the token present in the string.
Sample:-
object obj = {"Id": "1", "RegNo": "REG123"}
Smart.Format("Your Id - {Id} for registration - {RegNo}", obj);
If I do not pass RegNo property/value in the object then smart format throws an error. Instead do we have any proper validation method to validate the tokens required against the object provided.
Any help would be appreciated.
SmartFormat provides various extensions which allow to format a string depending on the provided arguments. Here is the example code for a missing "RegNo". Still, this is not "validation", but rather "conditional formatting".
// Create a formatter with necessary extensions, including NewtonsoftJsonSource
var smart = new SmartFormatter(settings ?? new SmartSettings())
.AddExtensions(new NewtonsoftJsonSource(), new DefaultSource())
.AddExtensions(new NullFormatter(), new DefaultFormatter());
// Parse the JSON input
var jObject = JObject.Parse(#"{""Id"": ""1"", ""RegNo"": null}");
var result = smart.Format("Id: {Id:isnull:Value is Null|{}} - RegNo: {RegNo:isnull:Value is Null|{}}", jObject);
// Result: "Id: 1 - RegNo: Value is Null"

Using kendo.saveAs to download an excel or csv file from an action method

I have a Kendo Grid. I'm using a jquery AJAX call to send data from the Grid to an Action method for processing. Ok fine, no problem there. So after the processing of the data i now want to down either an excel file or csv file (which are basically the same thing). But Jquerys AJAX method doesn't allow Action method to return files like (an excel file). I had figured out another way to do this using
window.location.href = "Controller/Actionmethod/MethodName?" + parameters
But this was a no go as my boss wants it all in one Action Method, not two..
So now introduce this into the success call back of my AJAX call:
kendo.saveAs({
dataURI: data.file,
fileName: "PayrollExport.csv"
});
And here is my code for building the csv file which works fine.
var export = Fundraisers.ProcessPledgeCardUltiproExport().Where(t => FundraiserIDs.Contains(t.FundraiserID)).ToList();
var csv = new StringBuilder();
csv.AppendLine(String.Format("Employee Number, Deduction code, Benefit Status, Coverage Start, Deduction Start Date, Employee Amount"));
foreach (var e in export)
{
var newLine = String.Format("{0},{1},{2},{3},{4:d},{5}", e.EmployeeID, "UW", "A", "", new DateTime(DateTime.Now.Year + 1, 1, 1), e.PledgeAmount);
csv.AppendLine(newLine);
}
var byteArray = Encoding.ASCII.GetBytes(csv.ToString());
var stream = new MemoryStream(byteArray);
Now my question is: How do i return this from the action method.?
All i have as of right now is return Json(new { success = true, file = stream });
An example of what i would need that works for a PDF file is something along the line of:
return Json(new { success = true, message = "Verified!", file = "data:text/html;base64," + Convert.ToBase64String(fileContent) });
Any idea on the what i should put in the return for the posted above code after creating the csv file?
Any help would be much appreciated.

F# - Http request response body to string to use with json type provider

I get a response from a web api which simply returns an F# record of the data corresponding to the id in the request url.
The question I have is how do I get the text representation of the response.Body so I can plug it into the commented out line below and use it with json type provider. Or is there a different way of doing this that I am missing,
let response = Http.Request("http://localhost:50442/api/getrates/" + input)
let sample = Json.Sample.Parse(""" {"CurrencyId":1,"CurrencyCode":"AUD","Value":0.98542} """)
//let sample = Json.Sample.Parse("\"\"\" " + response.Body.ToString() + " \"\"\"")
let data = sample.Value
return "Rate for: " + input + " = " + data.ToString()
You need some sample JSON for the type provider to inspect at compile-time (from a local file, a literal string, or from a remote URL), which is used to detect the schema and generate the types.
Then at runtime you dynamically load some new data set which matches the same schema, and you have typed access.
// provide some URL, file path, or raw JSON sample
// that can be used at compile time to generate types
type Json = JsonProvider<"sample.json">
// at runtime, load up new sample matching that schema
let response = Http.Request("<some url that serves JSON at runtime>")
let samples = Json.Parse(response.Body.ToString())
// or do it this way
let samples = Json.Load("<some url that serves JSON at runtime>")
// magic!
sample.[0].EyeColor

Send parameters in order in HTTPService

I am trying to work with a simple HTTPService. The problem is that my webservice is conscious of the order of arguments it gets. I will tell the problem with an example:
var service:HTTPService = new HTTPService();
var params:Object = new Object();
params.rows = 0;
params.facet = "true";
service.send(params);
Note that in the above code I have mentioned the parameter rows before facet, but the url I recieve is facet=true&rows=0. So I recieve the argument rows before facet and hence my webservice does not work. I figured out that the contents of array is always sent in alphabetical order, which I dont want.
Is there any way I can achieve explict ordering of parameters sent?
Note that I am not in power of changing the logic of webservice(its basically a RPC service supporting both desktop and web client).
Thanks.
I am assuming you are using a get method. Instead of passing params to the HTTPService, build a url string. You can pass get params just by changing that string then calling the service.
service.url = "originalURL" + "?" + "rows=0" + "&" + "facet=true";
service.send();

Specifying multiple parameters of the same name using HTTPService

Ruby on Rails controllers will automatically convert parameters to an array if they have a specific format, like so:
http://foo.com?x[]=1&x[]=5&x[]=bar
This would get converted into the following array:
['1','5','bar']
Is there any way I can do this with an ActionScript 3 HTTPService object, by using the request parameter? For example, It would be nice to do something like the following:
var s:HTTPService = new HTTPService();
s.request['x[]'] = 1;
s.request['x[]'] = 5;
s.request['x[]'] = 'bar';
However, that will simply overwrite each value, resulting in only the last value being sent. Anyone have a better idea? I know I could just append stuff to the query string, but I'd like to do it in the POST body.
I was working on this same problem as well. Fortunatly, Flex supports this out of the box.
Just use an Array for the field value:
var service:HTTPService = new HTTPService();
service.useProxy = true;
service.destination = "myservicet";
service.resultFormat = HTTPService.RESULT_FORMAT_XML;
var fields:Array = ["categories", "organisation"];
var params:Object = new Object();
params.q = "stackoverflow";
params.rows = 0;
params.facet = "true";
params["facet.field"] = fields;
service.send(params);
The HTTPService will convert this t0 the url parameters:
facet=true&q=stackoverflow&facet%2Efield=categories&facet%2Efield=organisation&rows=0
Hope this helps!
Added for more clarity. When there is only 1 argument in the array, do not pass the fields as an array. For some reason, flex will not send this to the http service
I usually do something like this...
var s:HTTPService = new HTTPService();
s.url = "http://foo.com";
s.method = "post";
// add listeners...
s.addEventListenser(ResultEvent.RESULT,function(event:ResultEvent){
mx.controls.Alert.show(event.result.toString());
});
// send the data...
s.send({
a: 1,
b: 5,
c: "bar"
});
which would result in the HTTP Get / POST of:
http://foo.com?a=1&b=5&c=bar
You could also just create an associative array and pass it to the HTTPService send method, that would be something like:
var postdata:Object = {};
postdata["a"] = 1;
postdata["b"] = 5;
postdata["c"] = "bar";
// s is the HTTPService from above...
s.send(postdata);
You mentioned that All POST parameters must have the same name.
Elements that have the same name will overwrite each other in an associative array.
However, I have dealt with calendar cells before, and all 31 cells belong to the Date category.
What I did was:
var params:Object = new Object;
for (var i:uint=0; i<31; i++){
params["Date"+(jj.toString())] = date[i];
}
HTTPService....etc.
HTTPService.send(params);
So, on the POST receiving side, it would be interpreted as Date0...Date31.
Don't know if this was what you wanted, and the post was so long ago.
Come to think about it.
Why don't you do an array push of all of the elements under the same index name?
However, this means you are sending an array to the receiving side.
If you are POST-ing this, how will this be URL-referenced?

Resources