예제 #1
0
        private IDataStreamParser CreateConverter()
        {
            if (_convert == null)
            {
                ScriptContainer container = new ScriptContainer(_engine, Guid.Empty, _script, _enableDebug, _referencedAssemblies.Select(a => a.GetName()));
                _convert = (IDataStreamParser)ScriptUtils.GetInstance(container, _classname);
                if (_state != null)
                {
                    IPersistDynamicNode persist = _convert as IPersistDynamicNode;
                    if (persist != null)
                    {
                        persist.SetState(_state, GetLogger());
                    }
                }
            }

            return(_convert);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <summary>
        /// Write the key to a DataWriter
        /// </summary>
        /// <remarks>This method could throw almost any exception</remarks>
        /// <param name="stm">The DataWriter object</param>
        public override void ToWriter(DataWriter stm)
        {
            IDataStreamParser convert = CreateConverter();

            convert.ToWriter(stm, this, GetLogger());
        }
예제 #4
0
        /// <summary>
        /// Create a key from a DataReader
        /// </summary>
        /// <param name="stm">The data reader</param>
        /// <remarks>This method could throw almost any exception</remarks>
        /// <exception cref="System.IO.EndOfStreamException">Throw when end of stream reached</exception>
        public override void FromReader(DataReader stm)
        {
            IDataStreamParser convert = CreateConverter();

            convert.FromReader(stm, this, GetLogger());
        }