Example #1
0
                public async sealed override Task WriteAsync(cMethodControl pMC, cBytes pBytes, int pOffset, cBatchSizer pWriteSizer, cTrace.cContext pContext)
                {
                    while (pOffset < pBytes.Count)
                    {
                        byte lByte = pBytes[pOffset++];

                        if (mBufferedCR)
                        {
                            mBufferedCR = false;

                            if (lByte == cASCII.LF)
                            {
                                await YWriteLineAsync(pMC, mLine, pWriteSizer, pContext).ConfigureAwait(false);

                                mLine.Clear();
                                continue;
                            }

                            mLine.Add(cASCII.CR);
                        }

                        if (lByte == cASCII.CR)
                        {
                            mBufferedCR = true;
                        }
                        else
                        {
                            mLine.Add(lByte);
                        }
                    }
                }
Example #2
0
        public cTextCommandPart(ulong pNumber) : base(false, false)
        {
            var lBytes = cTools.ULongToBytesReverse(pNumber);

            lBytes.Reverse();
            Bytes = new cBytes(lBytes);
        }
Example #3
0
 public cLiteralCommandPart(IList <byte> pBytes, bool pBinary = false, bool pSecret = false, bool pEncoded = false) : base(pBinary, pSecret, pEncoded)
 {
     if (pBytes == null)
     {
         throw new ArgumentNullException(nameof(pBytes));
     }
     Bytes = new cBytes(pBytes);
 }
        internal cNetworkSendEventArgs(cBytes pBuffer)
        {
            Bytes = pBuffer.Count;
            List <cBytes> lBuffers = new List <cBytes>(1);

            lBuffers.Add(pBuffer);
            Buffers = lBuffers.AsReadOnly();
        }
        internal cNetworkSendEventArgs(IEnumerable <byte> pBuffer)
        {
            cBytes lBuffer = new cBytes(new List <byte>(pBuffer));

            Bytes = lBuffer.Count;
            List <cBytes> lBuffers = new List <cBytes>(1);

            lBuffers.Add(lBuffer);
            Buffers = lBuffers.AsReadOnly();
        }
Example #6
0
            public readonly cBytes Bytes; // may be null

            public cBody(bool pBinary, cSection pSection, uint?pOrigin, IList <byte> pBytes)
            {
                Binary  = pBinary;
                Section = pSection ?? throw new ArgumentNullException(nameof(pSection));
                Origin  = pOrigin;

                if (pBytes == null)
                {
                    Bytes = null;
                }
                else
                {
                    Bytes = new cBytes(pBytes);
                }
            }
            public void InvokeNetworkSend(cBytes pBuffer, cTrace.cContext pParentContext)
            {
                if (NetworkSend == null)
                {
                    return;                      // pre-check for efficiency only
                }
                var lContext = pParentContext.NewMethod(nameof(cCallbackSynchroniser), nameof(InvokeNetworkSend));

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cCallbackSynchroniser));
                }
                ZInvokeAndForget(new cNetworkSendEventArgs(pBuffer), lContext);
                // NOTE the event is fired by parallel code in the ZInvokeEvents routine: when adding an event you must put code there also
            }
Example #8
0
 internal cBodyStructureParameter(IList <byte> pName, IList <byte> pValue, string pStringValue, string pLanguageTag)
 {
     if (pName == null)
     {
         throw new ArgumentNullException(nameof(pName));
     }
     if (pValue == null)
     {
         throw new ArgumentNullException(nameof(pValue));
     }
     Name        = cTools.UTF8BytesToString(pName);
     RawValue    = new cBytes(pValue);
     StringValue = pStringValue;
     LanguageTag = pLanguageTag;
 }
Example #9
0
 public cResponseDataFetch(uint pMSN, fMessageCacheAttributes pAttributes, cFetchableFlags pFlags, cEnvelope pEnvelope, DateTime?pReceived, IList <byte> pRFC822, IList <byte> pRFC822Header, IList <byte> pRFC822Text, uint?pSize, cBodyPart pBody, cBodyPart pBodyStructure, IList <cBody> pBodies, uint?pUID, cHeaderFields pHeaderFields, IDictionary <string, uint> pBinarySizes, ulong?pModSeq)
 {
     MSN           = pMSN;
     Attributes    = pAttributes;
     Flags         = pFlags;
     Envelope      = pEnvelope;
     Received      = pReceived;
     RFC822        = pRFC822 == null ? null : new cBytes(pRFC822);
     RFC822Header  = pRFC822Header == null ? null : new cBytes(pRFC822Header);
     RFC822Text    = pRFC822Text == null ? null : new cBytes(pRFC822Text);
     Size          = pSize;
     Body          = pBody;
     BodyStructure = pBodyStructure;
     Bodies        = new ReadOnlyCollection <cBody>(pBodies);
     UID           = pUID;
     HeaderFields  = pHeaderFields;
     BinarySizes   = new cBinarySizes(pBinarySizes);
     ModSeq        = pModSeq;
 }
Example #10
0
        internal static void _Tests(cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cBase64), nameof(_Tests));

            LCheck(
                "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.",
                "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",
                lContext);

            LCheck("pleasure.", "cGxlYXN1cmUu", lContext);
            LCheck("leasure.", "bGVhc3VyZS4=", lContext);
            LCheck("easure.", "ZWFzdXJlLg==", lContext);
            LCheck("asure.", "YXN1cmUu", lContext);
            LCheck("sure.", "c3VyZS4=", lContext);

            lContext.TraceVerbose(new cBytes(Encode(new cBytes("\0fred\0angus"))).ToString());

            void LCheck(string pFrom, string pExpected, cTrace.cContext pContext)
            {
                cBytes lFrom     = new cBytes(pFrom);
                cBytes lExpected = new cBytes(pExpected);
                cBytes lTo       = new cBytes(Encode(lFrom));

                if (!TryDecode(lTo, out var lReturn, out _))
                {
                    throw new cTestsException();
                }

                var lResult = $"'{lFrom}'\t'{lTo}'\t'{lReturn}'";

                pContext.TraceVerbose(lResult);

                if (!cASCII.Compare(lFrom, lReturn, true))
                {
                    throw new cTestsException($"base64 round trip failure {lResult}", pContext);
                }
                if (!cASCII.Compare(lTo, lExpected, true))
                {
                    throw new cTestsException($"base64 unexpected intermediate {lTo} vs {lExpected}", pContext);
                }
            }
        }
Example #11
0
                private async Task ZIdlePollCommandAsync(cBytes pCommand, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZIdlePollCommandAsync), pCommand);

                    cCommandTag lTag = new cCommandTag();

                    mIdleBuffer.Clear();

                    mIdleBuffer.AddRange(lTag);
                    mIdleBuffer.Add(cASCII.SPACE);
                    mIdleBuffer.AddRange(pCommand);
                    mIdleBuffer.Add(cASCII.CR);
                    mIdleBuffer.Add(cASCII.LF);

                    lContext.TraceVerbose("sending {0}", mIdleBuffer);
                    mSynchroniser.InvokeNetworkSend(mIdleBuffer, lContext);
                    await mConnection.WriteAsync(mIdleBuffer.ToArray(), mBackgroundCancellationTokenSource.Token, lContext).ConfigureAwait(false);

                    await ZIdleProcessResponsesAsync(false, null, lTag, false, lContext).ConfigureAwait(false);
                }
Example #12
0
        public cTextCommandPart(string pString, bool pSecret = false) : base(pSecret, false)
        {
            if (string.IsNullOrEmpty(pString))
            {
                throw new ArgumentOutOfRangeException(nameof(pString));
            }

            var lBytes = new cByteList(pString.Length);

            foreach (char lChar in pString)
            {
                if (lChar < ' ' || lChar > '~')
                {
                    throw new ArgumentOutOfRangeException(nameof(pString));
                }
                lBytes.Add((byte)lChar);
            }

            Bytes = new cBytes(lBytes);
        }
Example #13
0
                private static eProcessStatusAttributeResult ZProcessDataStatusAttribute(cBytesCursor pCursor, cBytes pAttributeSpace, ref ulong?rNumber, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cMailboxCache), nameof(ZProcessDataStatusAttribute));

                    if (!pCursor.SkipBytes(pAttributeSpace))
                    {
                        return(eProcessStatusAttributeResult.notprocessed);
                    }

                    if (pCursor.GetNumber(out var lNumber))
                    {
                        lContext.TraceVerbose("got {0}", lNumber);
                        rNumber = lNumber;
                        return(eProcessStatusAttributeResult.processed);
                    }

                    lContext.TraceWarning("likely malformed status-att-list-item: no number?");
                    return(eProcessStatusAttributeResult.error);
                }
Example #14
0
 private cHeaderFieldMsgId(string pName, cBytes pValue, string pMsgId) : base(pName, pValue)
 {
     MsgId = pMsgId;
 }
Example #15
0
        internal static void _Tests(cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cHeaderFields), nameof(_Tests));

            cStrings          lStrings;
            cHeaderFieldNames lABCDE = new cHeaderFieldNames("a", "B", "c", "D", "e");
            cHeaderFieldNames lDEFGH = new cHeaderFieldNames("f", "g", "h", "D", "e");
            cHeaderFieldNames lGHIJK = new cHeaderFieldNames("i", "g", "h", "j", "K");

            var lBytes =
                new cBytes(
                    "angus:  value of angus\r\n" +
                    "fred      :     value of fred      \r\n" +
                    "charlie  \t  :   value    \r\n    \t    of    \r\n   charlie  \t\t   \r\n" +
                    "message-id   :  <*****@*****.**>  \r\n" +
                    "MESSAGE-id  : <1234   @   local(blah)  .machine .example> \r\n" +
                    "IN-reply-TO:    <*****@*****.**><*****@*****.**>\r\n\t<*****@*****.**>\r\n" +
                    "REfEReNCeS:\r\n\t<*****@*****.**>\r\n\t<   \"12345\"   @   local(blah)   .machine .example>   \r\n" +
                    "Importance: low\r\n" +
                    "anotherone: just in case\r\n" +
                    "\r\n" +
                    "check: stop\r\n");

            if (!TryConstruct(lBytes, out var lFields))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.1");
            }

            if (lFields.Count != 9)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.1.1");
            }

            if (!lFields.Contains("a"))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.2");
            }
            if (!lFields.Contains(lABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.3");
            }
            if (!lFields.Contains(lDEFGH))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.4");
            }
            if (!lFields.Contains(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.5");
            }
            if (lFields.ContainsNone(lABCDE) || lFields.ContainsNone(lDEFGH) || lFields.ContainsNone(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.6");
            }

            if (lFields.Missing(lABCDE).Count != 0 || lFields.Missing(lDEFGH).Count != 0)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.7");
            }

            if (cTools.ASCIIBytesToString(lFields.FirstNamed("fred").Value) != "     value of fred      ")
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.8");
            }
            if (lFields.FirstNamed("a") != null)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.9");
            }

            if (lFields.AllNamed("fred").Count() != 1)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.10");
            }
            if (lFields.AllNamed("a").Count() != 0)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.11");
            }
            if (lFields.AllNamed("mEsSaGe-ID").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.12");
            }

            //if (!lFields.All("mEsSaGe-ID").All(h => h is cHeaderFieldMsgId lMsgId && lMsgId.MsgId == "*****@*****.**")) throw new cTestsException($"{nameof(cHeaderFields)}.1.13");


            //lStrings = (lFields.First(cHeaderFieldNames.InReplyTo) as cHeaderFieldMsgIds)?.MsgIds;
            //if (lStrings.Count != 3 || !lStrings.Contains("*****@*****.**") || !lStrings.Contains("*****@*****.**") || !lStrings.Contains("*****@*****.**")) throw new cTestsException($"{nameof(cHeaderFields)}.1.15");

            lStrings = lFields.References;
            if (lStrings.Count != 2 || !lStrings.Contains("*****@*****.**") || !lStrings.Contains("*****@*****.**"))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.16");
            }

            if (lFields.Importance != eImportance.low)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.17");
            }


            if (!lFields.Contains("check") || lFields.AllNamed("check").Count() != 0)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.1.18");
            }



            lBytes = new cBytes("a: 1\r\nc: 2\r\nc: two\r\ne: 3\r\n\r\n");
            if (!TryConstruct(lABCDE, false, lBytes, out var lFieldsABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.1");
            }
            if (!TryConstruct(lABCDE, false, lBytes, out var lFieldsABCDE2))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.1.1");
            }

            lBytes = new cBytes("e: 3\r\ng: 4\r\ng: four\r\n\r\n");
            if (!TryConstruct(lDEFGH, false, lBytes, out var lFieldsDEFGH))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.2");
            }

            lBytes = new cBytes("g: 4\r\ni: 5\r\nk: 6\r\nk: six\r\n");
            if (!TryConstruct(lGHIJK, false, lBytes, out var lFieldsGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.3");
            }

            lBytes =
                new cBytes(
                    "Importance: normal\r\n" +
                    "message-id   :  <[email protected]  \r\n" +
                    "IN-reply-TO:    <*****@*****.**><[email protected]\r\n\t<*****@*****.**>\r\n" +
                    "g: 4\r\ng: four\r\ni: 5\r\nk: 6\r\nk: six\r\n");

            if (!TryConstruct(lABCDE, true, lBytes, out var lNotABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.4");
            }

            lBytes =
                new cBytes(
                    "Importance: high\r\n" +
                    "a: 1\r\nc: 2\r\nc: two\r\ni: 5\r\nk: 6\r\nk: six\r\n");

            if (!TryConstruct(lDEFGH, true, lBytes, out var lNotDEFGH))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.4");
            }

            lBytes =
                new cBytes(
                    "Importance: error\r\n" +
                    "a: 1\r\nc: 2\r\nc: two\r\ne: 3\r\n");

            if (!TryConstruct(lGHIJK, true, lBytes, out var lNotGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.5");
            }


            if (lNotABCDE.Contains("a") || lNotABCDE.Contains("e") || !lNotABCDE.Contains("f") || !lNotABCDE.Contains("g"))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.6");
            }
            if (lNotABCDE.Contains(lABCDE) || lNotABCDE.Contains(lDEFGH) || !lNotABCDE.Contains(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.7");
            }
            if (!lNotABCDE.ContainsNone(lABCDE) || lNotABCDE.ContainsNone(lDEFGH) || lNotABCDE.ContainsNone(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.8");
            }
            if (lNotABCDE.Missing(lABCDE) != lABCDE || lNotABCDE.Missing(lDEFGH) != new cHeaderFieldNames("d", "E") || lNotABCDE.Missing(lGHIJK).Count != 0)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.9");
            }

            bool lFailed;

            lFailed = false;
            try { lNotABCDE.FirstNamed("A"); }
            catch { lFailed = true; }
            if (!lFailed)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.10");
            }

            if (lNotABCDE.FirstNamed(kHeaderFieldName.MessageId) == null || lNotABCDE.FirstNamed(kHeaderFieldName.InReplyTo) == null || lNotABCDE.Importance != eImportance.normal)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.11");
            }
            if (lNotDEFGH.Importance != eImportance.high)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.12");
            }
            if (lNotGHIJK.Importance != null)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.13");
            }

            if (!ReferenceEquals((lFieldsABCDE + null), lFieldsABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.14.1");
            }
            if (!ReferenceEquals((null + lFieldsABCDE), lFieldsABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.14.2");
            }
            if (!ReferenceEquals((lFieldsABCDE + lFields), lFields))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.14.3");
            }
            if (!ReferenceEquals(lFields, (lFieldsABCDE + lFields)))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.14.4");
            }
            if (!ReferenceEquals(lFieldsABCDE, (lFieldsABCDE + lFieldsABCDE2)))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.14.5");
            }

            var lNotDE = lNotABCDE + lNotDEFGH;

            if (!lNotDE.ContainsNone(new cHeaderFieldNames("d", "E")))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.15.1");
            }
            if (!lNotDE.Contains(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.15.2");
            }
            if (!lNotDE.Contains(new cHeaderFieldNames("a", "c", "f", "h")))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.15.3");
            }
            if (lNotDE.AllNamed("a").Count() != 1 || lNotDE.AllNamed("b").Count() != 0 || lNotDE.AllNamed("c").Count() != 2 || lNotDE.AllNamed("f").Count() != 0 || lNotDE.AllNamed("g").Count() != 2 || lNotDE.AllNamed("h").Count() != 0 || lNotDE.AllNamed("i").Count() != 1 || lNotDE.AllNamed("j").Count() != 0 || lNotDE.AllNamed("k").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.15.4");
            }

            var lAll = lNotABCDE + lNotGHIJK;

            if (!lAll.Contains(lABCDE) || !lAll.Contains(lDEFGH) || !lAll.Contains(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.16.1");
            }
            if (lAll.AllNamed("a").Count() != 1 || lAll.AllNamed("b").Count() != 0 || lAll.AllNamed("c").Count() != 2 || lAll.AllNamed("d").Count() != 0 || lAll.AllNamed("e").Count() != 1 || lAll.AllNamed("f").Count() != 0 || lAll.AllNamed("g").Count() != 2 || lAll.AllNamed("h").Count() != 0 || lAll.AllNamed("i").Count() != 1 || lAll.AllNamed("j").Count() != 0 || lAll.AllNamed("k").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.16.2");
            }

            var lNotABC = lNotABCDE + lFieldsDEFGH;

            if (!lNotABC.ContainsNone(new cHeaderFieldNames("a", "B", "C")))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.17.1");
            }
            if (!lNotABC.Contains(new cHeaderFieldNames("d", "e", "f", "g", "h")))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.17.2");
            }
            if (lNotABC.AllNamed("d").Count() != 0 || lNotABC.AllNamed("e").Count() != 1 || lNotABC.AllNamed("f").Count() != 0 || lNotABC.AllNamed("g").Count() != 2 || lNotABC.AllNamed("h").Count() != 0 || lNotABC.AllNamed("i").Count() != 1 || lNotABC.AllNamed("j").Count() != 0 || lNotABC.AllNamed("k").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.16.2");
            }

            var lNotABCDE2 = lNotABCDE + lFieldsGHIJK;

            if (!lNotABCDE2.ContainsNone(lABCDE) || !lNotABCDE2.Contains(lGHIJK))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.18.1");
            }
            if (lNotABCDE2.AllNamed("f").Count() != 0 || lNotABCDE2.AllNamed("g").Count() != 2 || lNotABCDE2.AllNamed("h").Count() != 0 || lNotABCDE2.AllNamed("i").Count() != 1 || lNotABCDE2.AllNamed("j").Count() != 0 || lNotABCDE2.AllNamed("k").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.18.2");
            }

            var lNotFGH = lFieldsABCDE + lNotDEFGH;

            if (!lNotFGH.ContainsNone(new cHeaderFieldNames("F", "G", "H")) || !lNotFGH.Contains(lABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.19.1");
            }
            if (lNotFGH.AllNamed("a").Count() != 1 || lNotFGH.AllNamed("b").Count() != 0 || lNotFGH.AllNamed("c").Count() != 2 || lNotFGH.AllNamed("d").Count() != 0 || lNotFGH.AllNamed("e").Count() != 1 || lNotFGH.AllNamed("i").Count() != 1 || lNotFGH.AllNamed("j").Count() != 0 || lNotFGH.AllNamed("k").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.19.2");
            }

            var lNotGHIJK2 = lFieldsABCDE + lNotGHIJK;

            if (!lNotGHIJK2.ContainsNone(lGHIJK) || !lNotGHIJK2.Contains(lABCDE))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.20.1");
            }
            if (lNotGHIJK2.AllNamed("a").Count() != 1 || lNotGHIJK2.AllNamed("b").Count() != 0 || lNotGHIJK2.AllNamed("c").Count() != 2 || lNotGHIJK2.AllNamed("d").Count() != 0 || lNotGHIJK2.AllNamed("e").Count() != 1 || lNotGHIJK2.AllNamed("f").Count() != 0)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.20.2");
            }

            var lAtoH = lFieldsABCDE + lFieldsDEFGH;

            if (!lAtoH.Contains(lABCDE) || !lAtoH.Contains(lDEFGH) || !lAtoH.ContainsNone(new cHeaderFieldNames("I", "J", "K")))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.21.1");
            }
            if (lAtoH.AllNamed("a").Count() != 1 || lAtoH.AllNamed("b").Count() != 0 || lAtoH.AllNamed("c").Count() != 2 || lAtoH.AllNamed("d").Count() != 0 || lAtoH.AllNamed("e").Count() != 1 || lAtoH.AllNamed("f").Count() != 0 || lAtoH.AllNamed("g").Count() != 2 || lAtoH.AllNamed("h").Count() != 0)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.21.2");
            }

            lFailed = false;
            try { lAtoH.AllNamed("i"); }
            catch { lFailed = true; }
            if (!lFailed)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.21.3");
            }

            var lNotF = lFieldsABCDE + lFieldsGHIJK;

            if (lNotF.Contains("F") || !lNotF.Contains(lABCDE) || !lNotF.Contains(lGHIJK) || lNotF.Contains(lDEFGH))
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.22.1");
            }
            if (lNotF.AllNamed("a").Count() != 1 || lNotF.AllNamed("b").Count() != 0 || lNotF.AllNamed("c").Count() != 2 || lNotF.AllNamed("d").Count() != 0 || lNotF.AllNamed("e").Count() != 1 || lNotF.AllNamed("g").Count() != 1 || lNotF.AllNamed("h").Count() != 0 || lNotF.AllNamed("i").Count() != 1 || lNotF.AllNamed("j").Count() != 0 || lNotF.AllNamed("k").Count() != 2)
            {
                throw new cTestsException($"{nameof(cHeaderFields)}.2.22.2");
            }
        }
Example #16
0
 private cHeaderFieldMsgIds(string pName, cBytes pValue, cStrings pMsgIds) : base(pName, pValue)
 {
     MsgIds = pMsgIds;
 }
Example #17
0
 internal cHeaderField(string pName, cBytes pValue)
 {
     Name  = pName ?? throw new ArgumentNullException(nameof(pName));
     Value = pValue ?? throw new ArgumentNullException(nameof(pValue));
 }
Example #18
0
 public abstract Task WriteAsync(cMethodControl pMC, cBytes pBytes, int pOffset, cBatchSizer pWriteSizer, cTrace.cContext pContext);
Example #19
0
 public override Task WriteAsync(cMethodControl pMC, cBytes pBytes, int pOffset, cBatchSizer pWriteSizer, cTrace.cContext pContext) => YWriteAsync(pMC, pBytes, pOffset, pWriteSizer, pContext);
Example #20
0
        public cTextCommandPart(cSequenceSet pSequenceSet) : base(false, false)
        {
            cByteList lBytes = new cByteList();
            cByteList lTemp  = new cByteList();

            bool lFirst = true;

            foreach (var lItem in pSequenceSet)
            {
                if (lFirst)
                {
                    lFirst = false;
                }
                else
                {
                    lBytes.Add(cASCII.COMMA);
                }

                if (lItem == cSequenceSetItem.Asterisk)
                {
                    lBytes.Add(cASCII.ASTERISK);
                    continue;
                }

                if (lItem is cSequenceSetNumber lNumber)
                {
                    lTemp = cTools.UIntToBytesReverse(lNumber.Number);
                    lTemp.Reverse();
                    lBytes.AddRange(lTemp);
                    continue;
                }

                if (!(lItem is cSequenceSetRange lRange))
                {
                    throw new ArgumentException("invalid form 1", nameof(pSequenceSet));
                }

                if (lRange.From == cSequenceSetItem.Asterisk)
                {
                    lBytes.Add(cASCII.ASTERISK);
                    continue;
                }

                if (!(lRange.From is cSequenceSetNumber lFrom))
                {
                    throw new ArgumentException("invalid form 2", nameof(pSequenceSet));
                }

                lTemp = cTools.UIntToBytesReverse(lFrom.Number);
                lTemp.Reverse();
                lBytes.AddRange(lTemp);

                lBytes.Add(cASCII.COLON);

                if (lRange.To == cSequenceSetItem.Asterisk)
                {
                    lBytes.Add(cASCII.ASTERISK);
                    continue;
                }

                if (!(lRange.To is cSequenceSetNumber lTo))
                {
                    throw new ArgumentException("invalid form 3", nameof(pSequenceSet));
                }

                lTemp = cTools.UIntToBytesReverse(lTo.Number);
                lTemp.Reverse();
                lBytes.AddRange(lTemp);
            }

            Bytes = new cBytes(lBytes);
        }
Example #21
0
 private cHeaderFieldImportance(cBytes pValue, eImportance pImportance) : base(kHeaderFieldName.Importance, pValue)
 {
     Importance = pImportance;
 }