Event handler for Tridion workflow automatic decision - tridion

Having trouble with automatic decisions in Tridion 2011 SP1.
I have an auto-decision item that go down one of two paths (one to a manual decision and the other to a manual activity). Screenshot attached.
What I need to do is analyse the permissions of the user that submits the first step in the workflow and automatically move the workflow down the correct path.
I am using an event handler for the AutomaticAssignActivity (tested successfully with event log writes) and have found in the API how to finish the activity but there's not overload for assigning the next activity.
I found this post an interesting read and tried to implement the CoreServiceSession and SessionAwareCoreServiceClient but each time the code tries to load the core service I receive the following error: Could not load file or assembly 'Tridion.ContentManager.CoreService.Client, Version=6.1.0.996, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b' or one of its dependencies. The system cannot find the file specified.
I am using the core service in my web layer for some minor content generation but it doesn't want to work from within the events system. What am I doing wrong? My events system DLL is in the Tridion bin folder where Tridion.ContentManager.CoreService.Client.dll sits.
Any help appreciated :)

Note that if you are developing an Event handler, you should better use the TOM.NET API (it is the preferred API for Event System and templating developments)
For all the rest, use Core Service
If you want to use core service, you can create a .NET DLL and then call it from your automated activity. This thread has some good information about it:
Which API can I use for writing SDL Tridion workflow activities?

Related

Error when calling method in custom assembly from Azure functions

see screenshot for the express version:
I have an Azure function (in Visual Studio), that triggers correctly an Service Bus event. In its run-method I want to call a method in a custom assembly. This works ok, until I use any method that uses Dynamics CRM assemblies. (I have tried both the assemblies from the downloadable sdk and the nuget package. I get the exact dll it asks for in the error message.
As soon as I call the my method I get the error below. I can run this exact method from a console app. (my custom assembly is a standard (not core) class library...
Additional information: Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
This is not an answer, but rather an advice to anyone getting this problem (and its also a rant).
Avoid Azure functions at all cost and use "web jobs" instead when you can. After doing this with webjobs it was as simple as it should be, I have spent a week with different Azure-function-related problems
Cons with Azure functions:
Dynamic crappy scripting language (.csx), which gives you mysterious runtime error messages refering wrong places
Lock-in to azure platform
The usage on the browser editor is a joke unless its a really simple method and the error messages there comes up over and over again in least most annoying way (second to popups) and make you spread out your code
Pros:
Maybe you get a pad on the head from your MS-indoctinated architect for using the latest technologies so he might be able to squeeze in the word "Microservices" on some powerpoint presentation.

Impersonate in Tridion 2011 without using core service

I'm trying to impersonate a user in a C# TBB. is it possible to know who initiated the publish action of a component in the TBB which is a part of the component template rendering with the component?
As mentioned in below article
http://yatb.mitza.net/2012/05/publishing-from-template-code-using.html
Once you will get the Current Publish transaction you can use the properties .Creator to get the user.
To get the Current Publish Transaction you can refer
http://yatb.mitza.net/2012/05/publishing-from-template-code-using.html
In your TBB you have access to the engine.GetSession(), which returns a Session object, containing the User information, I'm sure via that you can do in your code, what you are trying to achieve.
It would be interesting to know a little more about what you are trying to archive.

Get .NET assembly version for aspx file

I want to make a "properties style web form" that shows the application version for various .NET applications.
If I know the URL e.g. /someapp/default.aspx is it possible via reflection to execute that page and figure out the assembly version?
It's quite easy to find the executing assembly version, but without modifying the other application, is it possible?
Both the property page and the other application is running on the same server and in the same application pool.
Update: I've had some luck with
var url = "~/SomeApp/default.aspx";
var appType = System.Web.Compilation.BuildManager.GetCompiledType(url);
But navigating appType to find the assembly file version is not the same everytime.
Without modifying the web application to expose the version number through some URL-based retrieval (a simple page GET being the easy, obvious one), you're going to need to find a way to figure out where the DLL for the web application is from the URL.
If you can know the DLL's location, either by some convention (e.g. /appX/ is always at D:\Sites\appX\bin\appX.dll) or some configuration (you manually enter where each URL base's DLL is in a database), then you can retrieve that DLL's assembly version using the following code:
Assembly assembly = Assembly.LoadFrom("MyAssembly.dll");
Version ver = assembly.GetName().Version;
Code taken from this question.
Edit:
I've had a little look around, and there are some APIs to inspect the IIS configuration, so this is certainly a route to explore if you're trying to get from the URL to the assembly location. This question has an example of getting the physical path from the application/site name, for example. Microsoft.Web.Administration is the assembly to explore.
The ASP.NET engine streams nothing but HTML, javascript, etc.. to the client. There is nothing left of the assembly that gets passed in the response that can show what version of .net/asp.net that the application is running unless the developer on the server side adds it.
That said, you can gather some information from a utility at http://uptime.netcraft.com/up/graph that will give you some server information. Not down to the assembly version, but this is as close as I believe you are going to get.
You may implement custom HttpModule, put it to the bin folder of each application that you wish to monitor and append register this module in web.config files. In this module for example you should handle request, retrieve all required information and put it to response cookie.

Updating DotNetNuke module from another app

I have several DNN modules that I wish to update silently, using the portal's built-in module upgrade facilities called from a separate application, in this case a Windows service. I was able to make it all work with version 4.3 of the portal by modifying the DNN source in key areas to allow DotNetNuke.dll to function outside of a web application. I'm now trying to do the same thing with the 4.9.0 source code and I'm having problems.
Everything works fine until DNN tries to read from the database. I have my Windows service project, the DNN library project, and several other related projects loaded in one VS solution (the additional projects are the same ones that are in the main solution file provided with the DNN source). I call PaInstaller.Install in my service to update each module. Execution gets to reflection.vb and then it tries to create a DotNetNuke.Data.SqlDataProvider object based on the type name. It raises an exception when calling System.Web.Compilation.BuildManager.GetType. The exception says:
Could not load type 'DotNetNuke.Data.SqlDataProvider' from assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I read this to mean it simply couldn't locate the DotNetNuke.SqlDataProvider.dll assembly. What's strange is that assembly is in the Bin folder for the DNN library project, and I also have it in the folder where my Windows service is running. The actual SqlDataProvider project is also loaded in the solution. I can't for the life of me understand why the runtime environment can't locate the assembly.
Has anyone tried something like this before, or know what could cause an assembly not to be found while stepping through the DNN source? Am I better off using something other than BuildManager.GetType to get an instance of the SQL provider type?
Chris,
Honestly depending on your needs, I would look at doing this a different way, as this is going to be very fragile with each DNN upgrade that happens in the future.
I'd look more towards using the "bulk install" option that DNN already has. Have your service upload the module zips to the /install/modules folder, then from there, call /install/install.aspx?mode=installresources and you are done!
If you need a third party solution to parse the results, have your windows service go through and pull the HTML response and parse it to validate success.

Can Microsoft Code Contracts be used with an ASP.NET Website?

I'm currently using Microsoft Code Contracts in an ASP.NET MVC application without any issues but I can not seem to get it quite running in a basic ASP.NET Web site. I'm not entirely sure it was made to work with this type of project (although it shouldn't matter) so I wanted to bring it up to everyone.
I can compile the contracts just fine but the code skips over them since I'm assuming it hasn't been enabled through the Properties Page like you would do in other project types (ie ASP.NET MVC). I've gone to the property page of the project (which displays a dialog instead of the typical properties page) in my ASP.NET web site but it does not yield the same menu options and as such, doesn't have a section devoted to Code Contracts.
Also, I have Microsoft Code Contracts properly enabled within a class library project that I use to separate my business logic from the web site. The contracts compile fine but when a contract is violated, it throws a rather uninformative "Exception of type 'System.ExecutionEngineException' was thrown" error with no inner exception. My contract specifies a message to display upon violation but it is nowhere within the exception. It simply halts the execution of the process (which I believe is the default functionality for Microsoft Code Contracts).
I can't find anywhere that explicitly states that a particular project type can or can't (or shouldn't) be used with Contracts so I just wanted to see if anyone has had this issue.
Thanks for any help!
I had the same problem and this is how I solved it:
In the Referenced Class Libraries, right click -> properties -> code contracts.
Make sure "perform contract checking" is checked. I had mine set to "Full"
Contract Reference Assembly: make sure it is set to "Build"
Save your changes.
In the Referenced Class Libraries that have no contracts in their code, set the Contract Reference Assembly to "Do Not Build".
Then in the MVC project, have the Code Contracts "perform contract checking" checked. I had mine set to "Full".
Hope that helps somebody.
This sounds less like a Contracts and more like a build/config issue. Have you tried to deploy a prebuilt website? Are you sure that your website code sees the contracts code? Is the ASP.NET runtime using the CLR 4.0, or does it see the earlier Microsoft.Contracts.dll? Etc.

Resources