Exemple #1
0
        /// <summary>
        /// Create the data endpoint
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <param name="globalMeta">Global meta dictionary</param>
        /// <param name="meta">Meta dictionary</param>
        /// <returns></returns>
        public override IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta)
        {
            IDataEndpoint ret = Script.Container.GetInstance(ClassName) as IDataEndpoint;

            if (ret == null)
            {
                throw new NetServiceException(CANAPE.Documents.Properties.Resources.ScriptDataEndpointFactory_InvalidType);
            }

            ServerConfig config = (ServerConfig)Config;

            foreach (KeyValuePair <string, string> pair in config.Properties)
            {
                meta[pair.Key] = pair.Value;
            }

            ret.Meta = meta;

            ret.GlobalMeta = globalMeta;

            if (ret is IPersistNode)
            {
                IPersistNode persist = ret as IPersistNode;

                persist.SetState(config.GetConfig(), logger);
            }

            return(ret);
        }
Exemple #2
0
        void OnSerializing(StreamingContext context)
        {
            IPersistNode persist = _convert as IPersistNode;

            if (persist != null)
            {
                _state = persist.GetState(GetLogger());
            }

            _container = DynamicScriptContainer.GetCachedContainer(_container);
        }
        /// <summary>
        /// Create the layer
        /// </summary>
        /// <param name="logger">The logger to use when creating</param>
        /// <returns>The network layer</returns>
        public override INetworkLayer CreateLayer(Logger logger)
        {
            if (Script == null)
            {
                throw new InvalidOperationException(String.Format(Properties.Resources.ScriptNetworkLayerFactory_SpecifyScript, Description));
            }

            if (ClassName == null)
            {
                throw new InvalidOperationException(String.Format(Properties.Resources.ScriptNetworkLayerFactory_SpecifyClassName, Description));
            }

            object obj = Script.Container.GetInstance(ClassName);

            INetworkLayer layer = obj as INetworkLayer;

            if (layer == null)
            {
                IDataStreamParser parser = obj as IDataStreamParser;
                if (parser != null)
                {
                    layer = new ParserNetworkLayer(DynamicScriptContainer.Create(Script.Container, ClassName), logger);
                }
            }

            if (layer == null)
            {
                throw new InvalidOperationException(String.Format(Properties.Resources.ScriptNetworkLayerFactory_InvalidType, Script.Name));
            }

            IPersistNode persist = layer as IPersistNode;

            if (persist != null)
            {
                persist.SetState(new DynamicConfigObject(_config), logger);
            }

            return(layer);
        }
Exemple #4
0
        /// <summary>
        /// Create the converter
        /// </summary>
        /// <returns></returns>
        protected T CreateConverter()
        {
            if ((_convert == null) && !_errorInConvert)
            {
                _convert = (T)_container.GetInstance();
                if (_convert == null)
                {
                    _errorInConvert = true;
                }
                else
                {
                    if (_state != null)
                    {
                        IPersistNode persist = _convert as IPersistNode;
                        if (persist != null)
                        {
                            persist.SetState(_state, GetLogger());
                        }
                    }
                }
            }

            return(_convert);
        }
Exemple #5
0
        /// <summary>
        /// Method to create the data endpoint
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <param name="globalMeta">Global meta dictionary</param>
        /// <param name="meta">Meta dictionary</param>
        /// <returns>The data endpoint</returns>
        public override IDataEndpoint Create(Logger logger, MetaDictionary meta, MetaDictionary globalMeta)
        {
            IDataEndpoint server = null;

            ConstructorInfo ci = _type.GetConstructor(new [] { typeof(Logger) });

            if (ci != null)
            {
                server = (IDataEndpoint)ci.Invoke(new [] { logger });
            }
            else
            {
                ci = _type.GetConstructor(new Type[0]);
                if (ci == null)
                {
                    throw new NetServiceException("Can not find an appropriate constructor for endpoint");
                }

                server = (IDataEndpoint)ci.Invoke(new object[0]);
            }

            server.Meta       = meta;
            server.GlobalMeta = globalMeta;

            if (Config != null)
            {
                IPersistNode persist = server as IPersistNode;

                if (persist != null)
                {
                    persist.SetState(Config, logger);
                }
            }

            return(server);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override BasePipelineNode OnCreate(Logger logger, NetGraph graph, Dictionary <string, object> stateDictionary)
        {
            BasePipelineNode node = null;

            if (Container != null)
            {
                try
                {
                    if (String.IsNullOrWhiteSpace(ClassName))
                    {
                        throw new ArgumentException(String.Format(CANAPE.Scripting.Properties.Resources.DynamicNodeFactory_MustSpecifyClassName, Label));
                    }

                    // Determine what type of object we create, if it is an BasePipelineNode then return as is,
                    // if it is a parser then create the parsing pipeline node to contain it
                    object o = ScriptUtils.GetInstance(Container, ClassName);
                    if (o is BasePipelineNode)
                    {
                        node = o as BasePipelineNode;
                        if (State != null)
                        {
                            IPersistNode persist = node as IPersistNode;
                            if (persist != null)
                            {
                                persist.SetState(State, logger);
                            }
                        }
                    }
                    else if (o is IDataStreamParser)
                    {
                        // If we are selecting the whole packet, then we convert a binary stream
                        if (SelectionPath == "/")
                        {
                            DynamicBinaryStreamPipelineNode stmNode = new DynamicBinaryStreamPipelineNode();
                            stmNode.Container = DynamicScriptContainer.Create(Container, ClassName);
                            stmNode.State     = State;

                            node = stmNode;
                        }
                        else
                        {
                            DynamicStreamPipelineNode dynNode = new DynamicStreamPipelineNode();

                            dynNode.Container = DynamicScriptContainer.Create(Container, ClassName);
                            dynNode.State     = State;

                            node = dynNode;
                        }
                    }
                    else if (o is IDataArrayParser)
                    {
                        DynamicArrayPipelineNode dynNode = new DynamicArrayPipelineNode();

                        dynNode.Container = DynamicScriptContainer.Create(Container, ClassName);
                        dynNode.State     = State;

                        node = dynNode;
                    }
                    else if (o is IDataStringParser)
                    {
                        DynamicStringPipelineNode dynNode = new DynamicStringPipelineNode();

                        dynNode.Container = DynamicScriptContainer.Create(Container, ClassName);
                        dynNode.State     = State;

                        node = dynNode;
                    }
                    else if (o == null)
                    {
                        throw new InvalidOperationException(String.Format(CANAPE.Scripting.Properties.Resources.DynamicNodeFactory_CannotCreateType, ClassName, Label));
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format(CANAPE.Scripting.Properties.Resources.DynamicNodeFactory_InvalidNodeType, o.GetType().Name, Label));
                    }

                    node.Enabled = Enabled;
                }
                catch (EndOfStreamException)
                {
                    // End of stream
                }
                catch (ThreadAbortException)
                {
                }
            }
            else
            {
                throw new ArgumentException(String.Format(CANAPE.Scripting.Properties.Resources.DynamicNodeFactory_NoScriptSpecified, Label));
            }

            return(node);
        }