protected override bool AcceptTagElement(DefineBitsJPEG3Tag tag, XElement element)
        {
            switch (element.Name.LocalName)
            {
            case "alpha":
                tag.BitmapAlphaData = XBinary.FromXml(element.Element("data"));
                break;

            default:
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Accepts xml element during parsing.
        /// </summary>
        /// <param name="tag">Tag to accept element</param>
        /// <param name="element">Element to be accepted.</param>
        protected void AcceptElement(T tag, XElement element)
        {
            switch (element.Name.LocalName)
            {
            case REST_ELEM:
                tag.RestData = Convert.FromBase64String(element.Value);
                break;

            case DATA_TAG:
                var data = XBinary.FromXml(element.Element("data"));
                SetData(tag, data);
                break;

            default:
                var handled = AcceptTagElement(tag, element);
                if (!handled)
                {
                    throw new FormatException("Invalid element " + element.Name.LocalName);
                }
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Formats tag into xml
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public XElement FormatTag(T tag)
        {
            var xTag     = new XElement(TagName);
            var objectID = GetObjectID(tag);

            if (objectID.HasValue)
            {
                xTag.Add(new XAttribute(OBJECT_ID_ATTRIB, objectID.Value));
            }
            var data = GetData(tag);

            if (data != null)
            {
                xTag.Add(new XElement("data", XBinary.ToXml(data)));
            }

            FormatTagElement(tag, xTag);
            if (tag.RestData != null && tag.RestData.Length > 0)
            {
                xTag.Add(new XElement(REST_ELEM, FormatBase64(tag.RestData)));
            }
            return(xTag);
        }
 protected override void FormatTagElement(DefineBitsJPEG3Tag tag, XElement xTag)
 {
     xTag.Add(new XElement("alpha", XBinary.ToXml(tag.BitmapAlphaData)));
 }
Esempio n. 5
0
        public virtual void Output(byte[] outData)
        {
            try
            {
                IOmonitor.IdleForLock(_IOprocessing);
                //
                byte[] outdevData;

                switch (_OutputConverting)
                {
                case OutputConvertings.String:
                    outdevData = Encoding.Convert(ParentIDE.Machine.CharSet, _OutputDevice.CharSet
                                                  , outData);
                    break;

                case OutputConvertings.ParsingNumber:
                    outdevData = XBinary.ConvertBinaryNumberBytesToTextNumberBytes(outData
                                                                                   , ParentIDE.Machine.ByteOrder, _OutputDevice.CharSet);
                    Array.Resize <byte>(ref outdevData, outdevData.Length + _bOutSeparator.Length);
                    Array.Copy(_bOutSeparator, 0, outdevData, outdevData.Length
                               - _bOutSeparator.Length, _bOutSeparator.Length);
                    break;

                case OutputConvertings.None:
                    outdevData = outData;
                    break;

                default:
                    throw new Exception();
                }

                bool outDone, locked;

                if (!OutputAsyncAllowed)
                {
                    locked = false;
                    if ((OutputDeviceThreadSafe.Initialize & _OutputDeviceIsThreadSafeFor) == 0)
                    {
                        IOmonitor.IdleForLock(_OutputDevice, out locked);
                        if (!_OutputDevice.IsInitialized)
                        {
                            _OutputDevice.Initialize(this);
                        }
                    }
                    else
                    if (!_OutputDevice.IsInitialized)
                    {
                        _OutputDevice.Initialize(this);
                    }

                    if (!locked && (OutputDeviceThreadSafe.Output & _OutputDeviceIsThreadSafeFor) == 0)
                    {
                        IOmonitor.IdleForLock(_OutputDevice, out locked);
                    }
                    if (_bOutputForeword != null)
                    {
                        _OutputDevice.Output(this, _bOutputForeword);
                    }
                    _OutputDevice.Output(this, outdevData);
                    if (_bOutputAfterword != null)
                    {
                        _OutputDevice.Output(this, _bOutputAfterword);
                    }
                    if (locked)
                    {
                        IOmonitor.Unlock(_OutputDevice);
                    }
                }
                else
                // using output buffer:
                {
                    if (_BackgroundOutputTask == null)
                    // I. if buffer is empty
                    {
                        locked = false;
                        if ((OutputDeviceThreadSafe.Initialize & _OutputDeviceIsThreadSafeFor) == 0)
                        {
                            IOmonitor.TryLock(_OutputDevice, out locked);
                            if (locked && !_OutputDevice.IsInitialized)
                            {
                                _OutputDevice.Initialize(this);
                            }
                        }
                        else
                        if (!_OutputDevice.IsInitialized)
                        {
                            _OutputDevice.Initialize(this);
                        }

                        // try instant output synchronously
                        outDone = false;
                        if ((OutputDeviceThreadSafe.Output & _OutputDeviceIsThreadSafeFor) == 0)
                        {
                            if (locked || IOmonitor.TryLock(_OutputDevice))
                            {
                                if (_OutputDevice.IsReadyToOutput)
                                {
                                    if (_bOutputForeword != null)
                                    {
                                        _OutputDevice.Output(this, _bOutputForeword);
                                    }
                                    _OutputDevice.Output(this, outdevData);
                                    if (_bOutputAfterword != null)
                                    {
                                        _OutputDevice.Output(this, _bOutputAfterword);
                                    }
                                    outDone = true;
                                }
                                IOmonitor.Unlock(_OutputDevice);
                            }
                        }
                        else
                        if (_OutputDevice.IsReadyToOutput)
                        {
                            if (_bOutputForeword != null)
                            {
                                _OutputDevice.Output(this, _bOutputForeword);
                            }
                            _OutputDevice.Output(this, outdevData);
                            if (_bOutputAfterword != null)
                            {
                                _OutputDevice.Output(this, _bOutputAfterword);
                            }
                            outDone = true;
                        }

                        // if sync output didn't occure, starting async task for outputting buffer
                        if (!outDone)
                        {
                            lock (_OutputBuffer)
                            {
                                _OutputBuffer.AddRange(outdevData);
                                _BackgroundOutputTask = Task.Run(_BackgroundOutputAction);
                            }
                        }
                    }
                    else
                    // II. if buffer is not empty
                    {
                        // initializing output device if it needs to
                        if ((OutputDeviceThreadSafe.Initialize & _OutputDeviceIsThreadSafeFor) == 0)
                        {
                            if (IOmonitor.TryLock(_OutputDevice))
                            {
                                if (!_OutputDevice.IsInitialized)
                                {
                                    _OutputDevice.Initialize(this);
                                }
                                IOmonitor.Unlock(_OutputDevice);
                            }
                        }
                        else
                        if (!_OutputDevice.IsInitialized)
                        {
                            _OutputDevice.Initialize(this);
                        }

                        // populating buffer
                        lock (_OutputBuffer)
                            _OutputBuffer.AddRange(outdevData);
                    }
                }
            }
            finally
            {
                IOmonitor.Unlock(_OutputDevice);
                //
                IOmonitor.Unlock(_IOprocessing);
            }
        }
Esempio n. 6
0
 ActionBase IActionVisitor <XElement, ActionBase> .Visit(ActionUnknown action, XElement xAction)
 {
     action.Data = XBinary.FromXml(xAction.Element("data"));
     return(action);
 }
 protected override void FormatTagElement(DefineBitsJPEG4Tag tag, XElement xTag)
 {
     xTag.Add(new XAttribute("deblock", tag.DeblockParam));
     xTag.Add(new XElement("alpha", XBinary.ToXml(tag.BitmapAlphaData)));
 }
Esempio n. 8
0
        public virtual int Input(out byte[] inData, int length)
        {
            try
            {
                IOmonitor.IdleForLock(_IOprocessing);
                //
                int    resultLength = -1;
                byte[] inBuff;

                int   parentMachineRequestCharCount, inputDeviceRequestByteCount;
                Int64 number;

                InputConvertings inputConverting = _InputConverting;

                inData = new byte[length];

                if (!InputFromBufferAllowed)
                {
                    switch (inputConverting)
                    {
                    case InputConvertings.None:
                        DirectInput(out inBuff, length);
                        resultLength = inBuff.Length <= length ? inBuff.Length : length;
                        Array.Copy(inBuff, inData, resultLength);
                        break;

                    case InputConvertings.String:
                        parentMachineRequestCharCount = ParentIDE.Machine.CharSet.GetMaxCharCount(length);
                        inputDeviceRequestByteCount   = _InputDevice.CharSet.GetMaxByteCount(parentMachineRequestCharCount);
                        DirectInput(out inBuff, inputDeviceRequestByteCount);
                        inBuff = Encoding.Convert(_InputDevice.CharSet, ParentIDE.Machine.CharSet
                                                  , inBuff);
                        resultLength = inBuff.Length <= length ? inBuff.Length : length;
                        Array.Copy(inBuff, inData, resultLength);
                        break;

                    case InputConvertings.ParsingNumber:
                        byte[] inBuff2;
                        parentMachineRequestCharCount = XBinary.MaxDigitCount(256, 10, length) + 1;
                        inputDeviceRequestByteCount   = _InputDevice.CharSet.GetMaxByteCount(parentMachineRequestCharCount);
                        DirectInput(out inBuff, inputDeviceRequestByteCount);
                        if (XBinary.TryParseTextNumberBytesToBinaryNumberBytes(inBuff
                                                                               , _InputDevice.CharSet, out inBuff2, length, ParentIDE.Machine.ByteOrder))
                        {
                            inData       = inBuff2;
                            resultLength = length;
                        }
                        else
                        {
                            resultLength = 0;
                        }
                        break;

                    default:
                        throw new Exception();
                    }
                }
                else
                {
                    // using input buffer:
                    switch (inputConverting)
                    {
                    case InputConvertings.None:
                        if (_InputBuffer.Length == 0)
                        {
                            DirectInput(out _InputBuffer, length);
                        }
                        //
                        if (_InputBuffer.Length == 0)
                        {
                            resultLength = 0;
                        }
                        else if (_InputBuffer.Length - _InBuffPtr <= length)
                        {
                            resultLength = _InputBuffer.Length - _InBuffPtr;
                            Array.Copy(_InputBuffer, _InBuffPtr, inData, 0, resultLength);
                            _InputBuffer = new byte[0];
                            _InBuffPtr   = 0;
                        }
                        else if (_InputBuffer.Length - _InBuffPtr > length)
                        {
                            resultLength = length;
                            Array.Copy(_InputBuffer, _InBuffPtr, inData, 0, resultLength);
                            _InBuffPtr += resultLength;
                        }
                        break;

                    case InputConvertings.String:
                        if (_InputBuffer.Length == 0)
                        {
                            parentMachineRequestCharCount = ParentIDE.Machine.CharSet.GetMaxCharCount(length);
                            inputDeviceRequestByteCount   = _InputDevice.CharSet.GetMaxByteCount(parentMachineRequestCharCount);
                            DirectInput(out inBuff, inputDeviceRequestByteCount);
                            _InputBuffer = Encoding.Convert(_InputDevice.CharSet, ParentIDE.Machine.CharSet
                                                            , inBuff);
                        }
                        //
                        if (_InputBuffer.Length == 0)
                        {
                            resultLength = 0;
                        }
                        else if (_InputBuffer.Length - _InBuffPtr <= length)
                        {
                            resultLength = _InputBuffer.Length - _InBuffPtr;
                            Array.Copy(_InputBuffer, _InBuffPtr, inData, 0, resultLength);
                            _InputBuffer = new byte[0];
                            _InBuffPtr   = 0;
                        }
                        else if (_InputBuffer.Length - _InBuffPtr > length)
                        {
                            resultLength = length;
                            Array.Copy(_InputBuffer, _InBuffPtr, inData, 0, resultLength);
                            _InBuffPtr += resultLength;
                        }
                        break;

                    case InputConvertings.ParsingNumber:
                        if (_InputWordBuffer.Length == 0)
                        {
                            parentMachineRequestCharCount = XBinary.MaxDigitCount(256, 10, length) + 1;
                            inputDeviceRequestByteCount   = _InputDevice.CharSet.GetMaxByteCount(parentMachineRequestCharCount);
                            DirectInput(out inBuff, inputDeviceRequestByteCount);
                            byte[] unicodeLineBytes = Encoding.Convert(_InputDevice.CharSet, Encoding.Unicode, inBuff);
                            char[] unicodeLineChars = new char[Encoding.Unicode.GetCharCount(unicodeLineBytes, 0, unicodeLineBytes.Length)];
                            Encoding.Unicode.GetChars(unicodeLineBytes, 0, unicodeLineBytes.Length, unicodeLineChars, 0);
                            string newLine = new string(unicodeLineChars);
                            _InputWordBuffer = newLine.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
                        }
                        //
                        if (_InputWordBuffer.Length == 0)
                        {
                            resultLength = 0;
                        }
                        else if (_InputWordBuffer.Length - _WdBuffPtr > 0)
                        {
                            if (Int64.TryParse(_InputWordBuffer[_WdBuffPtr], out number))
                            {
                                inData = XBinary.FormatSignedNumberBytes(BitConverter.GetBytes(number), length
                                                                         , XBinary.HostMachineByteOrder, ParentIDE.Machine.ByteOrder);
                                resultLength = length;
                            }
                            else
                            {
                                resultLength = 0;
                            }
                            //
                            _WdBuffPtr++;
                            if (_InputWordBuffer.Length == _WdBuffPtr)
                            {
                                _InputWordBuffer = new string[0];
                                _WdBuffPtr       = 0;
                            }
                        }
                        break;

                    default:
                        throw new Exception();
                    }
                }

                return(resultLength);
            }
            finally
            {
                //
                IOmonitor.Unlock(_IOprocessing);
            }
        }
Esempio n. 9
0
 XElement IActionVisitor <XElement, XElement> .Visit(ActionUnknown action, XElement arg)
 {
     return(new XElement("Unknown",
                         new XAttribute("type", (byte)action.ActionCode),
                         XBinary.ToXml(action.Data)));
 }