Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="plugin"></param>
        /// <returns></returns>
        internal static bool PluginHandler(IUlibPlugin plugin)
        {
            var iPlugin = (ISerializePlugin)plugin;
            var tp      = iPlugin.GetType();
            var ioface  = tp.GetInterface("IObjectSerializer");

            if (ioface != null)
            {
                var externalPlugin = (IObjectSerializer)iPlugin;

                var encodeInfo     = tp.GetMethod("ObjectEncode");
                var encodeDelegate =
                    (ObjectEncoder)
                    Delegate.CreateDelegate(typeof(ObjectEncoder), iPlugin, encodeInfo);

                TypeEncoders.Add(externalPlugin.ObjectType, encodeDelegate);

                var decodeInfo     = tp.GetMethod("ObjectDecode");
                var decodeDelegate =
                    (ObjectDecoder)
                    Delegate.CreateDelegate(typeof(ObjectDecoder), iPlugin, decodeInfo);

                TypeDecoders.Add(externalPlugin.ObjectCode, decodeDelegate);
            }
            var icface = tp.GetInterface("IComponentSerializer");

            if (icface != null)
            {
                var externalPlugin = (IComponentSerializer)iPlugin;


                var encodeInfo     = tp.GetMethod("ComponentEncode");
                var encodeDelegate =
                    (ComponentEncoder)
                    Delegate.CreateDelegate(typeof(ComponentEncoder), iPlugin, encodeInfo);

                ComponentEncoders.Add(externalPlugin.ClassName, encodeDelegate);

                var decodeInfo     = tp.GetMethod("ComponentDecode");
                var decodeDelegate =
                    (ComponentDecoder)
                    Delegate.CreateDelegate(typeof(ComponentDecoder), iPlugin, decodeInfo);

                ComponentDecoders.Add(externalPlugin.ClassName, decodeDelegate);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="plugin"></param>
        /// <returns></returns>
        internal static bool PluginRemove(IUlibPlugin plugin)
        {
            var tp     = plugin.GetType();
            var ioface = tp.GetInterface("IObjectSerializer");

            if (ioface != null)
            {
                var externalPlugin = (IObjectSerializer)plugin;

                if (TypeEncoders.ContainsKey(externalPlugin.ObjectType))
                {
                    lock (TypeEncoders)
                        TypeEncoders.Remove(externalPlugin.ObjectType);
                }

                if (TypeDecoders.ContainsKey(externalPlugin.ObjectCode))
                {
                    lock (TypeDecoders)
                        TypeDecoders.Remove(externalPlugin.ObjectCode);
                }
            }
            var icface = tp.GetInterface("IComponentSerializer");

            if (icface != null)
            {
                var externalPlugin = (IComponentSerializer)plugin;

                if (ComponentEncoders.ContainsKey(externalPlugin.ClassName))
                {
                    lock (ComponentEncoders)
                        ComponentEncoders.Remove(externalPlugin.ClassName);
                }

                if (ComponentDecoders.ContainsKey(externalPlugin.ClassName))
                {
                    lock (ComponentDecoders)
                        ComponentDecoders.Remove(externalPlugin.ClassName);
                }
            }
            return(true);
        }