Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Occasional Contributor
Posts: 11
Registered: ‎05-06-2016
Accepted Solution

Custom Trigger Creation - NullReferenceException at creating

[ Edited ]

Hi, 

 

I am absolutly new developer and i'm trying to create custom trigger. I was trying to recreate scenario descripted here: http://community.hexagongeospatial.com/t5/Developer-Discussions/Custom-Trigger-Creation/m-p/1920#M11...

in hope to make it work or at least to get into Execute metod body and get exceptions from there. Unfortunately it seems like program is never firing it and i don't know why. Here is code:

 

WorkflowSettings:

<WorkflowTrigger name="CustomReportNameTrigger" type="GeospaceCustomTrigger" method="action">
						<Param name="ReportsToGenerate" value="asd"/> <!--just for tests-->
						<Param name="Directory" value="C:\Program Files\Intergraph\GeoMedia SmartClient\Program\Workflows\TestReports\"/>
					</WorkflowTrigger>

FormSettings:

<FormAction name="CustomReportAction" label="Some label" action="SCRIPT[IG.trigger({triggerNames:['CustomReportNameTrigger'],urlParams:{FileName:{FORM.ID}}}).done(function(result){ })]" />

C# code:

 

using Intergraph.Emea.Data;
using Intergraph.Emea.Ioc;
using Intergraph.Emea.Workflows;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeospaceCustomTrigger
{
    [ExtensibleType("GeospaceCustomTrigger")]
    public class GeospaceCustomTrigger : WorkflowTriggerBase
    {
        private IDescriptionProvider descriptionProvider;
        private IReportProvider reportProvider;
        private string _fullReportName;
        private string _source;
        private string _log;

        public string Directory { get; set; }
        public string[] ReportsToGenerate { get; set; }

        public GeospaceCustomTrigger(IDescriptionProvider descriptionProvider, IReportProvider reportProvider)
            : base()
        {
            this.descriptionProvider = descriptionProvider;
            this.reportProvider = reportProvider;

            if (!EventLog.SourceExists(_source))
            {
                EventLog.CreateEventSource(_source, _log);
            }
            EventLog.WriteEntry(_source, descriptionProvider == null ? "jest nulem" : descriptionProvider.ToString());
            EventLog.WriteEntry(_source, reportProvider == null ? "jest nulem" : reportProvider.ToString());
        }



        public override void Execute()
        {
            EventLog.WriteEntry(_source, "FullReportNameDone");

            var querystring = WorkflowControllerContext.RequestProvider.GetQueryString();
            var workflow = querystring["workflow"];
            var nodeId = "FieldWorkEditDS";
            var reportName = "Structure";
            var reportFormat = "pdf";
            DomainObject domainObject = null;

            var currentNode = descriptionProvider.GetWorkflowNodeDescription(nodeId, workflow);
            var formDescription = descriptionProvider.GetFormDescription(currentNode.Form, workflow);


            if (ReportsToGenerate != null)
            {
                foreach (string reportId in ReportsToGenerate)
                {
                    Form form = Form.CreateForm(formDescription, WorkflowControllerContext, WorkflowData, domainObject, ModelScopes.Report);

                    ReportResult reportResult = WorkflowControllerContext.ReportProvider.RenderReport(reportName, reportFormat, formDescription, new List<Form>() { form }, new List<WorkflowData>() { WorkflowData });

                    string Id = reportId;
                    string reportNameNew = System.IO.Path.GetFileNameWithoutExtension(reportResult.FileName);
                    reportNameNew = reportNameNew + "_" + Id + System.IO.Path.GetExtension(reportResult.FileName);

                    using (FileStream fs = new FileStream(Path.Combine(Directory, reportNameNew + "." + reportFormat), FileMode.Create))
                    {
                        fs.Write(reportResult.Data, 0, reportResult.Data.Length);
                    }
                }
            }
        }
    }
}

The error in workflow logs is:

 

11.05.2016 09:22:42 ERROR - Controller Trigger has raised an exception in Action FireData.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Intergraph.Emea.Workflows.TriggerController.ExecuteTriggers(TriggerExecution triggerExecution, IEnumerable`1 workflowTriggerDescriptions, IWorkflowControllerContext workflowControllerContext, WorkflowData workflowData)
   at Intergraph.Emea.Workflows.TriggerController.FireData(List`1 triggerNames, DomainObject domainObject)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)

 

Do i need to register this C# handler in some kind of special place or compiling .DLL file and putting it in C:\Program Files\Intergraph\GeoMedia SmartClient\Program\Workflows\bin directory is fine enough?

Or maybe i neet to register this

type="GeospaceCustomTrigger"

in some place? What am i doing wrong, that trigger is never making it to the constructor or Execute method body?

Thanks in advance,

Bartek

Highlighted
Contributor
Posts: 63
Registered: ‎02-22-2016

Re: Custom Trigger Creation - NullReferenceException at creating

As far as I knew, if a Custom Trigger dll is not loaded/present it reports following ERROR

 

11.05.2016 11:56:49 ERROR - Controller Trigger has raised an exception in Action FireData.
Intergraph.Emea.Ioc.ObjectLoadException: Cannot load type SomeCustomTrigger.
   at Intergraph.Emea.Ioc.ObjectFactory.GetExtensibleType(String typeAlias, IEnumerable`1 assemblies)
   at Intergraph.Emea.Workflows.TriggerController.ExecuteTriggers(TriggerExecution triggerExecution, IEnumerable`1 workflowTriggerDescriptions, IWorkflowControllerContext workflowControllerContext, WorkflowData workflowData)

.......

 

I'm also kind of newbie. But here is some code that worked for me. May be it helps you to reference.

 

ReportCustomTrigger.cs

 

using Intergraph.Emea.Data;
using Intergraph.Emea.Diagnostics.Log;
using Intergraph.Emea.Ioc;
using Intergraph.Emea.Placeholders;
using Intergraph.Emea.Workflows;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Intergraph.Emea.Dubai.Workflows
{
    [ExtensibleType("ReportCustomTrigger")]
    public class ReportCustomTrigger : WorkflowTriggerBase
    {
        public string FormName { get; set; }
        public string ReportName { get; set; }
        public string TargetReportName { get; set; }
        public string ReportFormat { get; set; }
        public string ReportDirectory { get; set; }

        public override void Execute()
        {
            FormDescription currentFormDescription = null;
            if (string.IsNullOrEmpty(FormName))
            {
                WorkflowNodeDescription currentNode = WorkflowControllerContext.DescriptionProvider.GetWorkflowNodeDescription(WorkflowControllerContext.RequestProvider.GetQueryString()[QueryStringNames.NodeId], WorkflowControllerContext.Workflow);
                currentFormDescription = WorkflowControllerContext.DescriptionProvider.GetFormDescription(currentNode.Form, WorkflowControllerContext.Workflow);
            }
            else
                currentFormDescription = WorkflowControllerContext.DescriptionProvider.GetFormDescription(FormName, WorkflowControllerContext.Workflow);

            DomainObject domainObject = null;
            if (!string.IsNullOrEmpty(currentFormDescription.IdField) && WorkflowData.Contains(PlaceholderType.Form, currentFormDescription.IdField))
                domainObject = WorkflowControllerContext.GetDatabase().SelectById(GetDomainObjectMetadata(currentFormDescription), WorkflowData.GetValue(PlaceholderType.Form, currentFormDescription.IdField));
            Form currentForm = Form.CreateForm(currentFormDescription, WorkflowControllerContext, WorkflowData, domainObject, ModelScopes.Report);
            ReportResult renderedReport = WorkflowControllerContext.ReportProvider.RenderReport(ReportName, string.IsNullOrEmpty(ReportFormat) ? "pdf" : ReportFormat, currentFormDescription, new List<Form>() { currentForm }, new List<WorkflowData>() { WorkflowData });
            using (FileStream fs = new FileStream(Path.Combine(ReportDirectory, TargetReportName + "." + ReportFormat), FileMode.Create))
            {
                fs.Write(renderedReport.Data, 0, renderedReport.Data.Length);
                Log.DefaultLog.Debug("Create single file");
            }

            Log.DefaultLog.Debug("Files completed");
        }

        private DbDomainObjectMetadata GetDomainObjectMetadata(FormDescription formDescription)
        {
            DbDomainObjectMetadata metadata = new DbDomainObjectMetadata(formDescription.Table, formDescription.IdField);
            FormFieldDescriptionCollection formFields = formDescription.GetAllFormFields(true);
            foreach (var formField in formFields)
            {
                if (formField is FormFileDescription)
                {
                    FormFileDescription formFile = formField as FormFileDescription;

                    if (!string.IsNullOrEmpty(formFile.FileNameField))
                        metadata.Fields.Add(new DbFieldInfo(formFile.FileNameField, typeof(string)));
                    if (!string.IsNullOrEmpty(formFile.ContentTypeField))
                        metadata.Fields.Add(new DbFieldInfo(formFile.ContentTypeField, typeof(string)));
                }

                metadata.Fields.Add(new DbFieldInfo(formField.Name, formField.GetClrType(), isKeyField: formField.Name.Equals(formDescription.IdField, StringComparison.OrdinalIgnoreCase)));
            }

            return metadata;
        }
    }
}

Workflow

 

			    <WorkflowTrigger name="trgLDGen" type="ReportCustomTrigger" method="action">
		             <Param name="FormName" value="prodDrawing"/>
		             <Param name="ReportName" value="TELERIK_REPORT"/>
		             <Param name="TargetReportName" value="{FORM.F_DRAWING_NUMBER}"/>
		             <Param name="ReportFormat" value="pdf"/>
		             <Param name="ReportDirectory" value="{FORM.PDF_LOC}"/>
		        </WorkflowTrigger>

And trigger it

Highlighted
Occasional Contributor
Posts: 11
Registered: ‎05-06-2016

Re: Custom Trigger Creation - NullReferenceException at creating

Thank you Vipanth, the code you pasted works as expected, tho i dont know yet why your code is working and mine is not Smiley Happy

Highlighted
Contributor
Posts: 63
Registered: ‎02-22-2016

Re: Custom Trigger Creation - NullReferenceException at creating

That we shall leave it for experts Smiley Tongue

 

Or you can try replacing my code lines with your's, one by one and do trail-n-error. (My newbie style!)