public void AddFormatterFilter(IFormatterFilter<byte[]> filter)
 {
     _filters.Add(filter);
 }
Ejemplo n.º 2
0
        private object GetFormatterFilter(XElement element)
        {
            string filterType = GetAttribute(element, "Type");
            string filterName = GetAttribute(element, "Name");

            if (filterType == "ByteArrayTypedFormatterFilter")
            {
                int formatterTypeIndex = int.Parse(GetAttribute(element, "FormatterTypeIndex"));

                ByteArrayTypedFormatterFilter filter = new ByteArrayTypedFormatterFilter(filterName, formatterTypeIndex);

                if (element.Element("FormatterFilter") != null)
                {
                    foreach (var subFilterElement in element.Elements("FormatterFilter"))
                    {
                        IFormatterFilter <byte[]> subFilter = (IFormatterFilter <byte[]>)GetFormatterFilter(subFilterElement);
                    }
                }

                return(filter);
            }
            else if (filterType == "ByteArrayLengthGreatThanFormatterFilter")
            {
                int length = int.Parse(GetAttribute(element, "Length"));

                ByteArrayLengthGreatThanFormatterFilter filter = new ByteArrayLengthGreatThanFormatterFilter(filterName, length);

                if (element.Element("FormatterFilter") != null)
                {
                    foreach (var subFilterElement in element.Elements("FormatterFilter"))
                    {
                        IFormatterFilter <byte[]> subFilter = (IFormatterFilter <byte[]>)GetFormatterFilter(subFilterElement);
                    }
                }

                return(filter);
            }
            else if (filterType == "ByteArrayLengthEqualFormatterFilter")
            {
                int length = int.Parse(GetAttribute(element, "Length"));

                ByteArrayLengthEqualFormatterFilter filter = new ByteArrayLengthEqualFormatterFilter(filterName, length);

                if (element.Element("FormatterFilter") != null)
                {
                    foreach (var subFilterElement in element.Elements("FormatterFilter"))
                    {
                        IFormatterFilter <byte[]> subFilter = (IFormatterFilter <byte[]>)GetFormatterFilter(subFilterElement);
                    }
                }

                return(filter);
            }
            else if (filterType == "Custom")
            {
                string customTypeName = GetAttribute(element, "CustomTypeName");
                Type   type           = Type.GetType(customTypeName);

                object[] args = null;

                if (element.Elements("Parameter") != null)
                {
                    args = new object[element.Elements("Parameter").Count()];
                    int i = 0;
                    foreach (var paraElement in element.Elements("Parameter"))
                    {
                        string pType  = GetAttribute(paraElement, "Type");
                        string pValue = GetAttribute(paraElement, "Value");
                        object p      = Convert.ChangeType(pValue, Type.GetType(pType));
                        args[i] = p;
                        i++;
                    }
                }

                object custom = System.Activator.CreateInstance(type, args);

                return(custom);
            }
            else
            {
                throw new UnknownElementException("Unknown FormatterFilter type:" + filterType);
            }
        }
Ejemplo n.º 3
0
 public void AddFormatterFilter(IFormatterFilter <byte[]> filter)
 {
     _filters.Add(filter);
 }
Ejemplo n.º 4
0
        private object GetInterpreter(XElement element)
        {
            string interpreterType = GetAttribute(element, "Type");
            string interpreterName = GetAttribute(element, "Name");

            var headerElement  = element.Element("Header");
            var trailerElement = element.Element("Tailer");

            IObjectWithName returnInterpreter = null;

            if (interpreterType == "MultipleFormatterByteArrayInterpreter")
            {
                MultipleFormatterByteArrayInterpreter interpreter = new MultipleFormatterByteArrayInterpreter(interpreterName);

                if (headerElement != null && !string.IsNullOrEmpty(headerElement.Value.Trim()))
                {
                    string headerString = headerElement.Value;
                    interpreter.SetHeaders(HexStringToByteArray(headerString));
                }

                if (trailerElement != null && !string.IsNullOrEmpty(trailerElement.Value.Trim()))
                {
                    string tailerString = trailerElement.Value;
                    interpreter.SetTailers(HexStringToByteArray(tailerString));
                }

                foreach (var formatterElement in element.Elements("Formatter"))
                {
                    interpreter.AddFormatter((IFormatter <byte[]>)GetFormatter(formatterElement));
                }

                if (element.Element("FormatterFilter") != null)
                {
                    foreach (var filterElement in element.Elements("FormatterFilter"))
                    {
                        IFormatterFilter <byte[]> filter = (IFormatterFilter <byte[]>)GetFormatterFilter(filterElement);
                        interpreter.AddFormatterFilter(filter);
                    }
                }

                returnInterpreter = interpreter;
            }
            else if (interpreterType == "SingleFormatterByteArrayInterpreter")
            {
                SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter(interpreterName);

                if (headerElement != null && !string.IsNullOrEmpty(headerElement.Value.Trim()))
                {
                    string headerString = headerElement.Value;
                    interpreter.SetHeaders(HexStringToByteArray(headerString));
                }

                if (trailerElement != null && !string.IsNullOrEmpty(trailerElement.Value.Trim()))
                {
                    string tailerString = trailerElement.Value;
                    interpreter.SetTailers(HexStringToByteArray(tailerString));
                }

                var formatterElement = element.Element("Formatter");

                interpreter.AddFormatter((IFormatter <byte[]>)GetFormatter(formatterElement));

                returnInterpreter = interpreter;
            }
            else if (interpreterType == "StringInterpreter")
            {
                StringInterpreter interpreter = new StringInterpreter(interpreterName);

                var formatterElement = element.Element("Formatter");

                interpreter.AddFormatter((IFormatter <string>)GetFormatter(formatterElement));

                returnInterpreter = interpreter;
            }
            else
            {
                throw new UnknownElementException("Unknown interpreter type:" + interpreterType);
            }

            _adapterObjects[_currentAdapterName].Add(returnInterpreter.Name, returnInterpreter);

            return(returnInterpreter);
        }
Ejemplo n.º 5
0
 public void AddNextFormatterFilter(IFormatterFilter <T> filter)
 {
     _filters.Add(filter);
 }