How to Deserialize and Serialize Build Process Parameters in TFS - c#

I am trying to create a new build definition using TFS 2013 API. The process template that I have to refer contains several custom activities and parameters. While creating the Build Definition, some of the Property value needs to be updated dynamically. So I tried to Deserialize the process parameters using below code:
IDictionary<string, object> processParams = WorkflowHelpers.DeserializeProcessParameters(defaultTemplate.Parameters);
This code always throwing below exception:
An unhandled exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll
Additional information: No matching constructor found on type 'System.Activities.Activity'. You can use the Arguments or FactoryMethod directives to construct this type.
This is really frustrating and I can't get rid of this error yet.
I have also tried to deserialize the process parameters using below code:
using (StringReader stringReader = new StringReader(parameterValues))
{
object obj = XamlServices.Load(
ActivityXamlServices.CreateReader(
new XamlXmlReader((TextReader)stringReader, new XamlXmlReaderSettings { LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly() }
)));
}
This works but when I serialize it again using XamlServices.Save(XamlWriter writer, object instance) method, the parameters got changed which is not compatible with build workflow.
So, how can I update the build process parameters here ? Can the WorkflowHelpers class can be used in other ways ? Or is there any other way to update the process parameters so that it gets reflected in the build definition. Any help is highly appreciated.

This is working fine now.
Below is new code:
IDictionary<string, object> processParams = WorkflowHelpers.DeserializeProcessParameters(defaultTemplate.ProcessParameters);
Instead of defaultTemplate.Parameters, I need to pass defaultTemplate.ProcessParameters

Related

C# Problems with XML Serialization

i have a problem with a webservice but i don´t see the error. I have used a wsdl to generate the Web Reference in VS2017. This is the class which was generated:
https://gist.github.com/meteora1986/b43c9750ddeb50187420edd6741301f5
When using this class the xml used for the webservice is not generated with the XMLAttributes-options. While debugging i discoverd following errors by the XMLImporter:
errors
So i tried to serialize it to get a more detailed error message with code like
try
{
var serializer = new XmlSerializer(typeof(ari_webserviceService));
}
catch (Exception ex)
{
// codes
}
And got from from the exeption these messages:
1. inner Message: There was an error reflecting field 'Site'.
2. inner MessageThere was an error reflecting type 'System.ComponentModel.ISite'.
But these fields or types aren´t used in the webservice class? Can anybody help?
I have absolutly no idea of web-services in general.
But your webservice is derived from SoapHttpClientProtocol. If you go up the base-classes by HttpWebClientProtocol and WebClientProtocol to finally end with Component you'll see the property Component.Site.
You might be able to solve your problem if you implement the IXmlSerializable interface to have full control what (and how) you want to serialize the data...

Auto Generated Schema only works when done in Memory

I generated a Json Schema off of a currently existing class.
JSchemaGenerator generator = new JSchemaGenerator();
JSchema schema = generator.Generate(typeof(Client));
This will validate fine, however, I need to put on dependencies (which you can't do from the class), so I copied the Schema results to a file. Now, the file will validate as fine on http://www.jsonschemavalidator.net/. However, when I try to load it using the following:
using (StreamReader file = File.OpenText("c:\\myJson.json"))
{
file.BaseStream.Position = 0;
using (JsonTextReader reader = new JsonTextReader(file))
{
JSchema schema2 = JSchema.Load(reader);
}
}
I will always get errors on any internal references in the file:
"Contact": {"$ref": "#/definitions/Contact"},
An exception of type 'Newtonsoft.Json.Schema.JSchemaReaderException'
occurred in Newtonsoft.Json.Schema.dll but was not handled in user code
Additional information: Could not resolve schema reference
'#/definitions/Contact/ Path 'definitions.Contact' Line 120, position 20
Why would this be fine if done in memory, but if loaded from a file will fail?
So I found the problem. While you can generate your schema from your existing models, it may not always do it correctly.
We found that some of the classes referenced were added with an extra Item layer in them (not sure why) Once we removed the reference of "Item" at the end, it worked fine. It also generated a second Item layer in the object, which I had to remove to get validation to work on that object.

Serializing/Deserializing a roundtrip with NetTopologySuite's IO Library for GeoJson reveals a potential bug

I'm having trouble using NetTopologySuite's GeoJsonReader to deserialize Feature objects. In particular, I'm receiving the following exception (which at first glance seems straightforward, so please read on):
An unhandled exception of type 'System.ArgumentException' occurred in Newtonsoft.Json.dll. Additional information: Expected token '{' not found.
Just doing a simple round-trip results in this exception:
public static string DoIt( Feature feature )
{
GeoJsonWriter writer = new GeoJsonWriter();
var geoJson = writer.Write(feature);
GeoJsonReader reader = new GeoJsonReader();
var deserializedFeature = reader.Read<Feature>(geoJson );
}
in this case, geoJson is pretty straightforward:
"{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-104.50348159865847,40.891762392617345],[-104.50348672999991,40.891415817000279],[-104.50355999200002,40.887782408000135],[-104.5036332529998,40.884149000000093],[-104.50845260799991,40.884357883000121],[-104.51307160051412,40.884558081989375],[-104.51307160051412,40.891762392617345],[-104.50348159865847,40.891762392617345]]]},\"properties\":null}"
Please let me know what I'm doing wrong. By the way, I'm using NetTopologySuite 1.14, NetTopologySuite.IO.GeoJSON 1.14, & Json.Net 9.0.1.
this is actually a bug.
code fixed, see #120

Need to process a dataset via dynamic runtime code in C#

I have been working with C# dynamic code for run time processes. My problem is I cannot seem to pass a dataset object to the dynamic code with out getting:
"Could not load file or assembly 'file:///C:\Users\mgallanx\AppData\Local\Temp\npbylo5z.dll' or one of its dependencies. The system cannot find the file specified."
Here is the simplest dataset processing string I am using:
mycodestring = "using System;
using System.Data;
namespace DaCodeNS
{
public static class DaCode
{
public static DataSet DaMethod( Dataset dsIn)
{
return dsIn;
}
}
}"
the calling method sets the parameters to add the System.dll and System.Data.dll, creates an Object[] mp to one element of sIn.
The call then is:
CompilerResults results = provider.CompileAssemblyFromSource (parameters, mycodestring);
var cls = results.CompiledAssembly.GetType ("DaCodeNS.DaCode");
var method = cls.GetMethod ("DaMethod", BindingFlags.Static | BindingFlags.Public);
return (DataSet) method.Invoke (null, mp);
It breaks at the GetMethod line.
I can get similar code passing integers around to play, but changing the return and passed to DataSet blows up. Any help is appreciated.
You're most likely not including all of the references needed to make your dynamic code compile/run. A simple way to find all the needed references would be to create a standa-alone project that just includes the code you're going to compile. Then look at the references you needed to add to the project to get it to compile/run.

How to add a property to a document type in Umbraco from code?

Could anyone give me an example of how to programatically add a property to an existing document type in Umbraco CMS? This is what I tried:
var dt = DocumentType.GetByAlias("TestDocType");
dt.AddPropertyType(new DataTypeDefinition(-49),"testprop", "test prop");
But it throws an exception:
Method not found: 'Void umbraco.cms.businesslogic.ContentType.AddPropertyType(umbraco.cms.businesslogic.datatype.DataTypeDefinition, System.String, System.String)'.
Any ideas?
I managed to fix it. The website was recently upgraded from Umbraco 4.5 to Umbraco 4.7.1, so the dll's had to be replaced with the more recent ones. In the older version of Umbraco the method's return type was public void AddPropertyType whereas the new one public PropertyType AddPropertyType. Apparently during the upgrade the new cms.dll wasn't copied over, so I copied it from a clean Umbraco 4.7.1 solution, changed the code to receive the return type and it helped.
Required namespaces:
using umbraco.cms.businesslogic.datatype;
using umbraco.cms.businesslogic.web;
So the final code(assuming correct assemblies are referenced):
var dt = DocumentType.GetByAlias("TestDocType");
var pType = dt.AddPropertyType(new DataTypeDefinition(-49),"testprop", "test prop");
That code looks fine to me, it should work.
Make sure your first line is actually returning a documentype, not null.
Also, do you have the proper 'usings' in place, you'll need at least some of these?
using umbraco.cms.businesslogic.web;
using umbraco.NodeFactory;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.datatype;

Categories