Skip to content

OpenDDRdotORG/OpenDDR-CSharp

Repository files navigation

OpenDDR-CSharp

Dear OpenDDR user,

this is the ALPHA version of the C# porting of OpenDDR!

We implemented all the features of OpenDDR Java version (except Group Aspect Identification), but we still need to improve performance.

All contributions are welcome. Thanks for your helping OpenDDR growing!

Below a description of the directory tree:

  • DDR-Simple-API: contains the porting of the W3C's Device Description Repository Simple API
  • OpenDDR-CSharp: contains the porting of the Java version of OpenDDR
  • OpenDDRTest: contains a simple test project of the C# version of OpenDDR

A basic explanation of the properties in oddr.properties:

  • oddr.ua.device.builder.path: Path of the file that explains how to identify the devices. In this, for each builder, are specified the device IDs that the builder handles and the identification rules
  • oddr.ua.device.datasource.path: Path of the device datasource
  • oddr.ua.device.builder.patch.paths: Path of the patch file for the builder file
  • oddr.ua.device.datasource.patch.paths: Path of the patch file for the device data source
  • oddr.ua.browser.datasource.path: Path of the browser data source
  • oddr.ua.operatingSystem.datasource.path: Path of the operating system data source
  • ddr.vocabulary.core.path: Path of the W3C vocabulary file
  • oddr.vocabulary.path: Path of the OpenDDR vocabulary
  • oddr.limited.vocabulary.path: Path of the reduced vocabulary. This vocabulary is usefull to limitate the memory load. It can be safely left unspecified.
  • oddr.vocabulary.device: IRI of the default vocabulary. It is the target namespace specified in a vocabulary
  • oddr.threshold: Identification threshold. It is used to balance the request evaluation time and identification matching.

The sample class below shows how to use OpenDDR:


public class SimpleTest
{
	public static void Main(string[] args)
	{
		string oddrPropertiesPath = args[0];
		string userAgent = args[1];

		Properties props = new Properties(oddrPropertiesPath);

		Type stype = Type.GetType("Oddr.ODDRService, OpenDdr");

		IService openDDRService = ServiceFactory.newService(stype, props.GetProperty("oddr.vocabulary.device"), props);

		IPropertyName vendorDevicePropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
		IPropertyRef vendorDeviceRef = openDDRService.NewPropertyRef(vendorDevicePropertyName, "device");

		IPropertyName modelDevicePropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
		IPropertyRef modelDeviceRef = openDDRService.NewPropertyRef(modelDevicePropertyName, "device");

		IPropertyName vendorBrowserPropertyName = openDDRService.NewPropertyName("vendor", @"http://www.openddr.org/oddr-vocabulary");
		IPropertyRef vendorBrowserRef = openDDRService.NewPropertyRef(vendorBrowserPropertyName, "webBrowser");

		IPropertyName modelBrowserPropertyName = openDDRService.NewPropertyName("model", @"http://www.openddr.org/oddr-vocabulary");
		IPropertyRef modelBrowserRef = openDDRService.NewPropertyRef(modelBrowserPropertyName, "webBrowser");

		IPropertyRef[] propertyRefs = new IPropertyRef[] { vendorDeviceRef, modelDeviceRef, vendorBrowserRef, modelBrowserRef };

		IEvidence e = new BufferedODDRHTTPEvidence();
		e.Put("User-Agent", userAgent);

		IPropertyValues propertyValues = openDDRService.GetPropertyValues(e, propertyRefs);
		if (propertyValues.GetValue(vendorDeviceRef).Exists())
		{
			Console.WriteLine(propertyValues.GetValue(vendorDeviceRef).GetString());
		}

		if (propertyValues.GetValue(modelDeviceRef).Exists())
		{
			Console.WriteLine(propertyValues.GetValue(modelDeviceRef).GetString());
		}

		if (propertyValues.GetValue(vendorBrowserRef).Exists())
		{
			Console.WriteLine(propertyValues.GetValue(vendorBrowserRef).GetString());
		}

		if (propertyValues.GetValue(modelBrowserRef).Exists())
		{
			Console.WriteLine(propertyValues.GetValue(modelBrowserRef).GetString());
		}

		Console.WriteLine(((BufferedODDRHTTPEvidence) e).deviceFound.Get("is_wireless_device"));

		Console.ReadKey();
	}
}

Releases

No releases published

Packages

No packages published

Languages