Ejemplo n.º 1
0
        protected override void UnpackResponse()
        {
            base.UnpackResponse();

            MemoryStream responseStream = new MemoryStream(m_responsePayload);
            BinaryReader responseReader = new BinaryReader(responseStream, Encoding.Unicode);

            // Try to unpack the data.
            try
            {
                // Seek past return code.
                responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin);

                int count = responseReader.ReadInt32();

                m_promoData.Clear();

                for (int i = 0; i < count; i++)
                {
                    PromoInfo pi = new PromoInfo();

                    pi.promoGroupID         = responseReader.ReadInt32();
                    pi.promoGroupLineNumber = responseReader.ReadUInt16();

                    ushort stringLen = responseReader.ReadUInt16();
                    if (stringLen > 0)
                    {
                        pi.promoText = new string(responseReader.ReadChars(stringLen));
                    }
                    else
                    {
                        pi.promoText = " ";
                    }

                    m_promoData.Add(pi);
                }
            }
            catch (EndOfStreamException e)
            {
                throw new MessageWrongSizeException("Get Promo Text Message", e);
            }
            catch (Exception e)
            {
                throw new ServerException("Get Promo Text Message", e);
            }

            // Close the streams.
            responseReader.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepares the request to be sent to the server
        /// </summary>
        protected override void PackRequest()
        {
            // Create the streams that will be written to
            MemoryStream requestStream = new MemoryStream();
            BinaryWriter requestWriter = new BinaryWriter(requestStream, Encoding.Unicode);

            requestWriter.Write(m_operatorID);

            Dictionary <string, object> orig  = new Dictionary <string, object>();
            Dictionary <string, object> promo = new Dictionary <string, object>();

            if (m_originalPromoData != null)
            {
                foreach (PromoInfo pi in m_originalPromoData)
                {
                    orig.Add(pi.promoGroupID.ToString() + "," + pi.promoGroupLineNumber.ToString(), pi);
                }
            }

            foreach (PromoInfo pi in m_promoData)
            {
                promo.Add(pi.promoGroupID.ToString() + "," + pi.promoGroupLineNumber.ToString(), pi);
            }

            //lines to remove
            if (m_originalPromoData == null)
            {
                requestWriter.Write((int)0);
            }
            else
            {
                List <PromoInfo> remove = new List <PromoInfo>();

                foreach (KeyValuePair <string, object> o in orig)
                {
                    PromoInfo pi = (PromoInfo)o.Value;

                    if (!promo.ContainsKey(pi.promoGroupID.ToString() + "," + pi.promoGroupLineNumber.ToString()))
                    {
                        remove.Add(pi);
                    }
                }

                requestWriter.Write((int)remove.Count);

                foreach (PromoInfo pi in remove)
                {
                    requestWriter.Write(pi.promoGroupID);
                    requestWriter.Write((ushort)pi.promoGroupLineNumber);
                }
            }

            //lines to add or update
            List <PromoInfo> addOrUpdate = new List <PromoInfo>();

            foreach (KeyValuePair <string, object> o in promo)
            {
                PromoInfo pi = (PromoInfo)o.Value;

                if (!orig.ContainsKey(pi.promoGroupID.ToString() + "," + pi.promoGroupLineNumber.ToString()) ||
                    ((PromoInfo)orig[pi.promoGroupID.ToString() + "," + pi.promoGroupLineNumber.ToString()]).promoText != pi.promoText)
                {
                    addOrUpdate.Add(pi);
                }
            }

            requestWriter.Write((int)addOrUpdate.Count);

            foreach (PromoInfo pi in addOrUpdate)
            {
                requestWriter.Write(pi.promoGroupID);
                requestWriter.Write((ushort)pi.promoGroupLineNumber);
                requestWriter.Write((ushort)pi.promoText.Length);
                requestWriter.Write(pi.promoText.ToCharArray());
            }

            // Set the bytes to be sent.
            m_requestPayload = requestStream.ToArray();

            // Close the streams.
            requestWriter.Close();
        }