Exemple #1
0
        public static List <CFXEnvelope> EnvelopesFromMessage(Message msg)
        {
            if (msg.Body is byte[])
            {
                byte[]   msgData = msg.Body as byte[];
                CFXCodec codec   = CFXCodec.raw;
                if (string.Compare(msg.Properties.ContentEncoding, "gzip", true) == 0)
                {
                    codec = CFXCodec.gzip;
                }
                msgData = Decode(msgData, codec);

                List <CFXEnvelope> results;

                string jsonData = Encoding.UTF8.GetString(msgData);
                if (IsMessageList(jsonData))
                {
                    results = CFXEnvelope.FromJsonList(jsonData);
                }
                else
                {
                    results = new List <CFXEnvelope>(new CFXEnvelope [] { CFXEnvelope.FromJson(jsonData) });
                }

                return(results);
            }

            throw new ArgumentException("AMQP Message Body does not contain a valid CFX Envelope");
        }
Exemple #2
0
        public static List <CFXEnvelope> EnvelopesFromMessage(Message msg)
        {
            if (msg.Body is byte[])
            {
                byte[] msgData = msg.Body as byte[];
                if (msg.Properties?.ContentEncoding == "CFX-COMPRESSED")
                {
                    msgData = Decompress(msgData);
                }

                List <CFXEnvelope> results;

                string jsonData = Encoding.UTF8.GetString(msgData);
                if (IsMessageList(jsonData))
                {
                    results = CFXEnvelope.FromJsonList(jsonData);
                }
                else
                {
                    results = new List <CFXEnvelope>(new CFXEnvelope [] { CFXEnvelope.FromJson(jsonData) });
                }

                return(results);
            }

            throw new ArgumentException("AMQP Message Body does not contain a valid CFX Envelope");
        }
Exemple #3
0
        public void ReplayEvents()
        {
            CFX.Utilities.AppLog.LoggingEnabled = true;
            CFX.Utilities.AppLog.LoggingLevel   = LogMessageType.All;
            //CFX.Utilities.AppLog.AmqpTraceEnabled = true;
            CFX.Utilities.AppLog.OnTraceMessage += AppLog_OnTraceMessage;


            string          handle = "Heller.Reflow.1809-Booth";
            AmqpCFXEndpoint ep     = new AmqpCFXEndpoint();

            ep.HeartbeatFrequency = TimeSpan.FromSeconds(4);
            ep.Open(handle);
            ep.AddPublishChannel(new Uri("amqp://cfxbroker.connectedfactoryexchange.com"), "/exchange/AegisCloud");

            string fileName = @"d:\stuff\TestData.json";
            string file;

            using (StreamReader reader = new StreamReader(fileName))
            {
                file = reader.ReadToEnd();
            }

            string        message     = null;
            int           startPos    = 0;
            DateTime?     startTime   = null;
            DateTime      actualStart = DateTime.Now;
            List <string> messages    = new List <string>();

            while ((message = GetNextMessage(file, ref startPos)) != null)
            {
                messages.Add(message);
            }

            messages.Reverse();

            foreach (string msg in messages)
            {
                CFXEnvelope env = CFXEnvelope.FromJson(msg);
                if (!startTime.HasValue)
                {
                    startTime = env.TimeStamp;
                }
                env.TimeStamp = actualStart + (env.TimeStamp - startTime.Value);

                if (env.MessageBody is WorkStarted || env.MessageBody is WorkCompleted)
                {
                    env.Source = handle;
                    if (env.MessageBody is WorkStarted)
                    {
                        //WorkStarted ws = env.MessageBody as WorkStarted;
                        //ws.Units = new List<CFX.Structures.UnitPosition>();
                        //ws.Units.Add(new CFX.Structures.UnitPosition() { PositionNumber = 1 });
                    }
                    ep.Publish(env);
                    //break;
                }
            }


            DateTime start = DateTime.Now;

            while ((DateTime.Now - start) < TimeSpan.FromSeconds(30))
            {
                System.Threading.Thread.Sleep(1);
            }
        }