Ejemplo n.º 1
0
        /// <summary>
        /// Declares a type.
        /// </summary>
        /// <param name="instanceId">The instance id.</param>
        /// <param name="typeDefinition">The event type definition.</param>
        public void RegisterType(string instanceId, NativeTypeDefinition typeDefinition)
        {
            Log.Info("RegisterType: instanceId = {0}, schemaTypeName = {1}",
                     instanceId,
                     typeDefinition.SchemaTypeName);

            try
            {
                var instance           = GetInstanceOrFault(instanceId);
                var fabricator         = instance.SchemaFabricator;
                var eventTypeSchemaSet = new XmlSchemaSet();

                foreach (var schemaText in typeDefinition.Schemas)
                {
                    var reader = XmlReader.Create(new StringReader(schemaText));
                    var schema = XmlSchema.Read(reader, HandleSchemaValidation);
                    eventTypeSchemaSet.Add(schema);
                }

                eventTypeSchemaSet.Compile();

                fabricator.GetNativeElement(
                    eventTypeSchemaSet,
                    typeDefinition.SchemaTypeName);
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (Exception e)
            {
                Log.Error("RegisterType: failure due to exception", e);
                throw;
            }
        }
Ejemplo n.º 2
0
 internal override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     if (arrayKind != ArrayKind.Invalid)
     {
         // if this is an array of, say, structures, we want to print the definition of the structure type
         elementType.GetDefinitionsRecursive(set, parentDef);
     }
 }
Ejemplo n.º 3
0
        public static NativeTypeDefinition Get(NativeTypeDesc desc)
        {
            // delegates are marshaled as _Delegate COM interface
            // UUID = FB6AB00F-5096-3AF8-A33D-D7885A5FA829

            return(NativeTypeDefinition.Get <DelegateInterfaceDefinition>(
                       new TypeDefKey(typeof(Delegate), (desc.Flags & MarshalFlags.TypeDefKeyFlags) | MarshalFlags.ComInterop)));
        }
Ejemplo n.º 4
0
        public static NativeTypeDefinition Get(NativeTypeDesc desc)
        {
            // when a delegate is marshaled as an unmanaged function pointer, its
            // parameters and return type have P/Invoke's default marshaling behavior
            // regardless of whether the function pointer is passed to a static entry
            // point or to a COM member

            return(NativeTypeDefinition.Get <FunctionPtrDefinition>(
                       new TypeDefKey(desc.Type, (desc.Flags & MarshalFlags.TypeDefKeyFlags) & ~MarshalFlags.ComInterop)));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Declares a native type.  Not required, but encouraged.
        /// </summary>
        /// <param name="nativeType">Type of the native.</param>
        public void RegisterType(Type nativeType)
        {
            if ((nativeType == null) ||
                (nativeType.IsBuiltinDataType()))
            {
                return;
            }

            lock (_registeredTypes)
            {
                if (_registeredTypes.Contains(nativeType))
                {
                    return;
                }

                var dataContractExporter = new XsdDataContractExporter();
                dataContractExporter.Export(nativeType);

                var rootElementName      = dataContractExporter.GetRootElementName(nativeType);
                var rootElementSchemaSet = dataContractExporter.Schemas;

                using (var wrapper = CreateControlManager())
                {
                    WithExceptionHandling(
                        delegate
                    {
                        var controlManager      = wrapper.Channel;
                        var eventTypeDefinition = new NativeTypeDefinition(
                            rootElementName,
                            rootElementSchemaSet);

                        controlManager.RegisterType(_instanceId, eventTypeDefinition);
                    });
                }

                _registeredTypes.Add(nativeType);

                Log.Info("RegisterType: Type '{0}' registered", nativeType.FullName);

                if (TypeRegistered != null)
                {
                    TypeRegistered(this, new TypeEventArgs(nativeType));
                }
            }
        }
Ejemplo n.º 6
0
        public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
        {
            foreach (NativeField nf in fields)
            {
                DefinedNativeType def_type = nf.Type as DefinedNativeType;
                if (def_type != null)
                {
                    if (!set.Contains(def_type.Definition))
                    {
                        set.Add(def_type.Definition);

                        def_type.Definition.GetDefinitionsRecursive(set, def_type.Definition);
                    }
                    if (parentDef != null)
                    {
                        set.AddDependency(parentDef, def_type.Definition);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 internal override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     if (arrayKind != ArrayKind.Invalid)
     {
         // if this is an array of, say, structures, we want to print the definition of the structure type
         elementType.GetDefinitionsRecursive(set, parentDef);
     }
 }
Ejemplo n.º 8
0
 public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     // empty
 }
Ejemplo n.º 9
0
 public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     signature.GetDefinitionsRecursive(set, parentDef);
 }
Ejemplo n.º 10
0
 public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     // no defined types here
 }
Ejemplo n.º 11
0
 public static StructureDefinition Get(NativeTypeDesc desc)
 {
     return(NativeTypeDefinition.Get <StructureDefinition>(
                new TypeDefKey(desc.Type, (desc.Flags & MarshalFlags.TypeDefKeyFlags))));
 }
Ejemplo n.º 12
0
 public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     // empty
 }
Ejemplo n.º 13
0
 public static EnumDefinition Get(NativeTypeDesc desc, UnmanagedType underlyingType)
 {
     return(NativeTypeDefinition.Get <EnumDefinition>(
                new TypeDefKeyWithUnmanagedType(desc.Type, (desc.Flags & MarshalFlags.TypeDefKeyFlags), underlyingType)));
 }
Ejemplo n.º 14
0
 public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     // no defined types here
 }
Ejemplo n.º 15
0
 public override void GetDefinitionsRecursive(NativeTypeDefinitionSet set, NativeTypeDefinition parentDef)
 {
     signature.GetDefinitionsRecursive(set, parentDef);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Declares a type.
        /// </summary>
        /// <param name="instanceId">The instance id.</param>
        /// <param name="typeDefinition">The event type definition.</param>
        public void RegisterType(string instanceId, NativeTypeDefinition typeDefinition)
        {
            Log.Info("RegisterType: instanceId = {0}, schemaTypeName = {1}",
                     instanceId,
                     typeDefinition.SchemaTypeName);

            try
            {
                var instance = GetInstanceOrFault(instanceId);
                var fabricator = instance.SchemaFabricator;
                var eventTypeSchemaSet = new XmlSchemaSet();

                foreach (var schemaText in typeDefinition.Schemas)
                {
                    var reader = XmlReader.Create(new StringReader(schemaText));
                    var schema = XmlSchema.Read(reader, HandleSchemaValidation);
                    eventTypeSchemaSet.Add(schema);
                }

                eventTypeSchemaSet.Compile();

                fabricator.GetNativeElement(
                    eventTypeSchemaSet,
                    typeDefinition.SchemaTypeName);
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (Exception e)
            {
                Log.Error("RegisterType: failure due to exception", e);
                throw;
            }
        }