Пример #1
0
        public MyRecord ConvertToMyRecord(IList <TempSpan> tempSpans)
        {
            var myRecord = new MyRecord();

            foreach (var tempSpan in tempSpans)
            {
                myRecord.Spans.Add(tempSpan.Span);
                var theProcess = myRecord.Processes.SingleOrDefault(x => x.CreateKey() == tempSpan.Process.CreateKey());
                if (theProcess == null)
                {
                    myRecord.Processes.Add(tempSpan.Process);
                }
            }

            return(myRecord);
        }
Пример #2
0
        public IList <TempSpan> ConvertBackToTempSpans(MyRecord myRecord)
        {
            var tempSpans = new List <TempSpan>();

            if (myRecord == null)
            {
                return(tempSpans);
            }

            var processes = myRecord.Processes;
            var mySpans   = myRecord.Spans;

            foreach (var mySpan in mySpans)
            {
                var process  = processes.Single(x => x.CreateKey() == mySpan.ProcessKey);
                var tempSpan = new TempSpan(process, mySpan);
                tempSpans.Add(tempSpan);
            }

            return(tempSpans);
        }
Пример #3
0
        public void AddOrUpdate(string filePath, MyRecord addRecord)
        {
            if (addRecord == null)
            {
                return;
            }
            var oldRecord = Get(filePath) ?? new MyRecord();

            var processDic = oldRecord.Processes.ToDictionary(x => x.CreateKey(), StringComparer.OrdinalIgnoreCase);

            foreach (var process in addRecord.Processes)
            {
                var key = process.CreateKey();
                if (!processDic.ContainsKey(key))
                {
                    processDic.Add(key, process);
                }
            }

            var spanDic = oldRecord.Spans.ToDictionary(x => x.SpanId, StringComparer.OrdinalIgnoreCase);

            foreach (var span in addRecord.Spans)
            {
                if (!spanDic.ContainsKey(span.SpanId))
                {
                    spanDic.Add(span.SpanId, span);
                }
            }

            var saveRecord = new MyRecord();

            saveRecord.Processes = processDic.Values.ToList();
            saveRecord.Spans     = spanDic.Values.ToList();
            JsonFile.Save(saveRecord, filePath);
            RecordRefresh(saveRecord.Spans.Count, GetClock());
        }