Пример #1
0
        public void OpenXesSerializationTest()
        {
            var storage = new RedisStorage(Host);
            var key = Guid.NewGuid().ToString();
            var list = new DistributedList<EventType>(storage, key);

            list.Add(new EventType("Start", "Start", DateTime.Now, EventType.Transition.Start));
            list.Add(new EventType("Start", "Start", DateTime.Now.AddSeconds(1), EventType.Transition.Complete));
            list.Add(new EventType("Phone Call", "Helen", DateTime.Now.AddSeconds(2), EventType.Transition.Start));
            list.Add(new EventType("Phone Call", "Helen", DateTime.Now.AddSeconds(3), EventType.Transition.Complete));
            list.Add(new EventType("End", "End", DateTime.Now.AddSeconds(4), EventType.Transition.Start));
            list.Add(new EventType("End", "End", DateTime.Now.AddSeconds(5), EventType.Transition.Complete));

            storage = new RedisStorage(Host);
            list = new DistributedList<EventType>(storage, key);

            var localList = list.ToList();
            localList.Count.ShouldBe(6);
            localList.Where(e => e != null).Count().ShouldBe(6);

            var @case = new TraceType(Guid.NewGuid().ToString(), list);
            var log = LogType.Create(new[] { @case });
            var xml = log.Serialize();

            Assert.IsTrue(xml.Contains("Phone Call"));
        }
Пример #2
0
        public static void SaveXes(string fileName, string caseName = null, bool clearListAfterSave = false)
        {
            var storage = new RedisStorage(DistributedMemoryHost);
            var list = new DistributedList<EventType>(storage, XesLogKey);

            var @case = new TraceType(caseName ?? Guid.NewGuid().ToString(), list);
            LogType log = null;
            if (!File.Exists(fileName))
            {
                log = LogType.Create(new[] { @case });
            }
            else
            {
                using (StreamReader reader = new StreamReader(fileName))
                {
                    log = LogType.Deserialize(reader.BaseStream);
                }

                var tracesList = log.trace.ToList();
                tracesList.Add(@case);
                log.trace = tracesList.ToArray();
            }

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
            {
                log.Serialize(file.BaseStream);
            }

            if (clearListAfterSave)
            {
                list.Clear();
            }
        }