Rafal
Posts: 1
Joined: Mon Dec 17, 2012 11:55 am

Manual creation of user application (C#)

Mon Dec 17, 2012 4:47 pm

I'm trying to manually create user application using template application. When I try to use TemplateManager method "Copy" or "Merge" there is NullReferenceException. What's wrong?
Here is my code and exception:

GpsGate.VehicleTracker.VehicleTrackerApplication template = new GpsGate.VehicleTracker.VehicleTrackerApplication();
template.LoadByID(8); //template app_id is 8.
Franson.Directory.Application a = tm.Copy(template) as Franson.Directory.Application;
GpsGate.VehicleTracker.VehicleTrackerApplication app = a as GpsGate.VehicleTracker.VehicleTrackerApplication;


System.NullReferenceException was unhandled by user code
Source=Franson
StackTrace:
in Franson.Directory.Security.RoleTagWriter.ExportObjectDataXML(TemplateXmlWriter writer, TemplateExportContext context)
in Franson.Templating.TemplateExporter.WriteObject(XmlWriter writer, TemplateBag template, BOItem item)
in Franson.Templating.TemplateExporter.ExportObject(XmlWriter writer, TemplateBag template)
in Franson.Templating.TemplateExporter.Export(Stream stream)
in Franson.Templating.TemplateManager.Copy(BOItem template)
in SMSManager.Registration.AppCreation(RegistrationEntry entry, Int32 expireMonths)


My second question is about TemplateImporter. Can someone show a sample code for application creation from imported xml file?

User avatar
Mattias
GpsGate
Posts: 135
Joined: Wed Dec 16, 2009 3:59 pm
Location: Sweden

RE: Manual creation of user application (C#)

Wed Dec 19, 2012 5:32 pm

TemplateImporter example, create an application from an XML file.

Code: Select all

string path = "AppTemplate.xml";

using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read))
{
	TemplateImporter importer = new TemplateImporter(TemplateMode.Copy);
	List<BOItem> items = importer.Import(stream);
	VehicleTrackerApplication app = items[0] as VehicleTrackerApplication;
}
Regarding your NullReferenceException. It depends on how your application is configured. I can only guess that a privilege object is missing from the "template" table in the database. This table keeps references/GUIDs for all objects. Try disabling privileges, one at a time, in your template app until you can successfully copy it. I do not have a better solution at the moment.
I guess you cannot just export your template app either?

Regards,
Mattias

Return to “GpsGate for Developers”