Пример #1
0
        private void SerializeCustom()
        {
            var s       = new CustomBinaryFormatter();
            var message = new CustomTypicalMessage()
            {
                StringProp = "hello",
                GuidProp   = Guid.NewGuid(),
                IntProp    = 123,
                DateProp   = DateTime.UtcNow,
            };

            s.Register <CustomTypicalMessage>(0);

            var stream = new MemoryStream();

            s.Serialize(stream, message);
            var bytes = stream.ToArray();

            RunTest("Greg Young Custom Serializer", () =>
            {
                var stream2 = new MemoryStream();
                s.Serialize(stream2, message);
            },
                    () =>
            {
                stream.Position = 0;
                s.Deserialize(stream);
            }, bytes.Length);
        }
 public static void RegisterMessagesWithSerializer(CustomBinaryFormatter formatter)
 {
     formatter.Register<VMSpawnMeessage>(1000);
     formatter.Register<TerminateMessage>(1001);
     formatter.Register<VMTerminating>(1002);
     formatter.Register<VMInitializedMessage>(1003);
     formatter.Register<VMSpawnedMessage>(1004);
     formatter.Register<DiagnosticInstanceMessage>(1008);
     formatter.Register<PauseVMMessage>(1009);
     formatter.Register<ResumeVMMessage>(1010);
     formatter.Register<ForceFullRunMessage>(1011);
     formatter.Register<RunRecursiveRunDetectorMessage>(1012);
     formatter.Register<RecursiveRunResultMessage>(1013);
     formatter.Register<InvalidLicenseMessage>(1014);
     formatter.Register<RegisterLicenseMessage>(1015);
     formatter.Register<ValidLicenseMessage>(1016);
     formatter.Register<ConfigurationUpdateMessage>(1017);
     formatter.Register<RunRelatedTestsMessage>(1019);
     formatter.Register<ManualMinimizationRequestMessage>(1020);
     formatter.Register<AssembliesMinimizedMessage>(1021);
     formatter.Register<UpdateCustomOutputpathMessage>(1022);
     formatter.Register<GoToFileAndLineMessage>(1023);
     formatter.Register<RequestVisualGraphMessage>(1024);
     formatter.Register<VisualGraphGeneratedMessage>(1025);
     formatter.Register<RequestRiskMetricsMessage>(1026);
     formatter.Register<RiskMetricGeneratedMessage>(1027);
     formatter.Register<RequestMessage<AssemblyPathRequest, AssemblyPathResponse>>(1028);
     formatter.Register<AssemblyPathResponse>(1029);
     formatter.Register<RequestMessage<IsSolutionInitializedRequest, IsSolutionInitializedResponse>>(1030);
     formatter.Register<IsSolutionInitializedResponse>(1031);
     formatter.Register<PartialRunMessage>(1032);
     formatter.Register<RealtimeChangeMessage>(1033);
     formatter.Register<ProfilerCompletedMessage>(1034);
     formatter.Register<ProfilerInitializedMessage>(1035);
     formatter.Register<RequestRuntimeTestInformationMessage>(1036);
     formatter.Register<TestInformationGeneratedMessage>(1037);
     formatter.Register<RealtimeChangeList>(1038);
     formatter.Register<OrderedBuildList>(1039);
     formatter.Register<RequestMessage<OrderedBuildList, OrderedBuildList>>(1040);
     formatter.Register<MinimizerInitializedMessage>(1041);
     formatter.Register<ProfiledTestRunStarted>(1042);
     formatter.Register<ProfilerLoadErrorOccurredMessage>(1043);
     formatter.Register<GetLastAffectedGraphMessage>(1044);
     formatter.Register<TestProfilerCorruptedMessage>(1045);
     formatter.Register<RequestProfiledGraphMessage>(1046);
 }
 public static void RegisterMessagesWithSerializer(CustomBinaryFormatter formatter)
 {
     formatter.Register <VMSpawnMeessage>(1000);
     formatter.Register <TerminateMessage>(1001);
     formatter.Register <VMTerminating>(1002);
     formatter.Register <VMInitializedMessage>(1003);
     formatter.Register <VMSpawnedMessage>(1004);
     formatter.Register <DiagnosticInstanceMessage>(1008);
     formatter.Register <PauseVMMessage>(1009);
     formatter.Register <ResumeVMMessage>(1010);
     formatter.Register <ForceFullRunMessage>(1011);
     formatter.Register <RunRecursiveRunDetectorMessage>(1012);
     formatter.Register <RecursiveRunResultMessage>(1013);
     formatter.Register <InvalidLicenseMessage>(1014);
     formatter.Register <RegisterLicenseMessage>(1015);
     formatter.Register <ValidLicenseMessage>(1016);
     formatter.Register <ConfigurationUpdateMessage>(1017);
     formatter.Register <RunRelatedTestsMessage>(1019);
     formatter.Register <ManualMinimizationRequestMessage>(1020);
     formatter.Register <AssembliesMinimizedMessage>(1021);
     formatter.Register <UpdateCustomOutputpathMessage>(1022);
     formatter.Register <GoToFileAndLineMessage>(1023);
     formatter.Register <RequestVisualGraphMessage>(1024);
     formatter.Register <VisualGraphGeneratedMessage>(1025);
     formatter.Register <RequestRiskMetricsMessage>(1026);
     formatter.Register <RiskMetricGeneratedMessage>(1027);
     formatter.Register <RequestMessage <AssemblyPathRequest, AssemblyPathResponse> >(1028);
     formatter.Register <AssemblyPathResponse>(1029);
     formatter.Register <RequestMessage <IsSolutionInitializedRequest, IsSolutionInitializedResponse> >(1030);
     formatter.Register <IsSolutionInitializedResponse>(1031);
     formatter.Register <PartialRunMessage>(1032);
     formatter.Register <RealtimeChangeMessage>(1033);
     formatter.Register <ProfilerCompletedMessage>(1034);
     formatter.Register <ProfilerInitializedMessage>(1035);
     formatter.Register <RequestRuntimeTestInformationMessage>(1036);
     formatter.Register <TestInformationGeneratedMessage>(1037);
     formatter.Register <RealtimeChangeList>(1038);
     formatter.Register <OrderedBuildList>(1039);
     formatter.Register <RequestMessage <OrderedBuildList, OrderedBuildList> >(1040);
     formatter.Register <MinimizerInitializedMessage>(1041);
     formatter.Register <ProfiledTestRunStarted>(1042);
     formatter.Register <ProfilerLoadErrorOccurredMessage>(1043);
     formatter.Register <GetLastAffectedGraphMessage>(1044);
     formatter.Register <TestProfilerCorruptedMessage>(1045);
     formatter.Register <RequestProfiledGraphMessage>(1046);
 }
Пример #4
0
        internal static List<HistoryRecord> GetRecords(ServerInfo server, bool isServer, DateTypes dateType, DateTime startDate)
        {
            var records = new List<HistoryRecord>();
            var key = GetKey(server, isServer);
            using (var dateIndexStream = new FileStream(GetFile(false, true), FileMode.OpenOrCreate))
            {
                using (var dateContentStream = new FileStream(GetFile(false, false), FileMode.OpenOrCreate))
                {
                    var dateFormatter = new CustomBinaryFormatter(dateIndexStream, dateContentStream);
                    dateFormatter.Register<HistoryDate>(1);

                    var endDate = DateTime.Now.Date;
                    var samplingSpan = 1;
                    switch (dateType)
                    {
                        case DateTypes.Hour:
                            endDate = startDate.AddDays(1);
                            samplingSpan = 1;
                            break;
                        case DateTypes.Day:
                            endDate = startDate.AddDays(1);
                            samplingSpan = 24;
                            break;
                        case DateTypes.Week:
                            endDate = startDate.AddDays(7);
                            samplingSpan = 7 * 24;
                            break;
                        case DateTypes.Month:
                            endDate = startDate.AddMonths(1);
                            samplingSpan = 31 * 24;
                            break;
                        case DateTypes.Year:
                            endDate = startDate.AddYears(1);
                            samplingSpan = 365 * 24;
                            break;
                        default:
                            break;
                    }
                    var count = dateFormatter.Count;
                    Debug.WriteLine("all date count:" + count);
                    Debug.WriteLine("start date:" + startDate);
                    var dates = new List<HistoryDate>();
                    for (long i = 0; i < count; i++)
                    {
                        var date = dateFormatter.Deserialize<HistoryDate>(false);
                        var dateTime = DateTime.Parse(date.Date);
                        Debug.WriteLine("current date:" + dateTime);
                        if (startDate.Date <= dateTime && dateTime <= endDate)
                            dates.Add(date);
                    }
                    Debug.WriteLine("valid date count:" + dates.Count);
                    if (dates.Count > 0)
                    {
                        var start = dates.Aggregate((d1, d2) => DateTime.Parse(d1.Date) < DateTime.Parse(d2.Date) ? d1 : d2);
                        var end = dates.Aggregate((d1, d2) => DateTime.Parse(d1.Date) > DateTime.Parse(d2.Date) ? d1 : d2);

                        using (var dataIndexStream = new FileStream(GetFile(true, true), FileMode.OpenOrCreate))
                        {
                            using (var dataContentStream = new FileStream(GetFile(true, false), FileMode.OpenOrCreate))
                            {
                                var historyFormatter = new CustomBinaryFormatter(dataIndexStream, dataContentStream);
                                historyFormatter.Register<HistoryRecord>(1);

                                for (var i = start.Index; i < end.Index; i += samplingSpan)
                                {
                                    historyFormatter.MoveTo(i);
                                    var record = historyFormatter.Deserialize<HistoryRecord>(false);
                                    if (record.Key == key)
                                        records.Add(record);
                                }
                                historyFormatter.Close();
                                dataContentStream.Close();
                            }
                            dataIndexStream.Close();
                        }
                    }
                    dateFormatter.Close();
                    dateContentStream.Close();
                }
                dateIndexStream.Close();
            }
            return records;
        }
Пример #5
0
        internal static void AddRecords(List<HistoryRecord> records)
        {
            lock (SyncRoot)
            {
                using (var dataIndexStream = new FileStream(GetFile(true, true), FileMode.OpenOrCreate))
                {
                    using (var dataContentStream = new FileStream(GetFile(true, false), FileMode.OpenOrCreate))
                    {
                        var historyFormatter = new CustomBinaryFormatter(dataIndexStream, dataContentStream);
                        historyFormatter.Register<HistoryRecord>(1);

                        historyFormatter.MoveToEnd();
                        var historyCount = historyFormatter.Count;
                        records.ForEach(r =>
                        {
                            historyFormatter.Serialize<HistoryRecord>(r);
                        });

                        historyFormatter.Flush();

                        using (var dateIndexStream = new FileStream(GetFile(false, true), FileMode.OpenOrCreate))
                        {
                            using (var dateContentStream = new FileStream(GetFile(false, false), FileMode.OpenOrCreate))
                            {
                                var dateFormatter = new CustomBinaryFormatter(dateIndexStream, dateContentStream);
                                dateFormatter.Register<HistoryDate>(1);

                                var dateCount = dateFormatter.Count;
                                var today = DateTime.Now.Date.AddDays(1);
                                var yesterday = DateTime.Now.Date;
                                long todayIndex = -1;
                                var foundYesterday = false;
                                for (long i = 0; i < dateCount; i++)
                                {
                                    var date = dateFormatter.Deserialize<HistoryDate>(false);
                                    if (DateTime.Parse(date.Date) == today)
                                        todayIndex = i;
                                    if (DateTime.Parse(date.Date) == yesterday)
                                        foundYesterday = true;
                                }
                                if (!foundYesterday)
                                {
                                    dateFormatter.MoveToEnd();
                                    dateFormatter.Serialize<HistoryDate>(new HistoryDate { Date = yesterday.ToString(), Index = historyCount });
                                }

                                if (todayIndex != -1)
                                {
                                    dateFormatter.MoveTo(todayIndex);
                                    dateFormatter.Serialize<HistoryDate>(new HistoryDate { Date = today.ToString(), Index = historyFormatter.Count }, true);
                                }
                                else
                                {
                                    dateFormatter.MoveToEnd();
                                    dateFormatter.Serialize<HistoryDate>(new HistoryDate { Date = today.ToString(), Index = historyFormatter.Count });
                                }

                                dateFormatter.Flush();
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        internal static List <HistoryRecord> GetRecords(ServerInfo Server, bool IsServer, DateTypes DateType, DateTime StartDate)
        {
            var records = new List <HistoryRecord>();
            var key     = GetKey(Server, IsServer);

            using (FileStream dateIndexStream = new FileStream(GetFile(false, true), FileMode.OpenOrCreate))
            {
                using (FileStream dateContentStream = new FileStream(GetFile(false, false), FileMode.OpenOrCreate))
                {
                    var dateFormatter = new CustomBinaryFormatter(dateIndexStream, dateContentStream);
                    dateFormatter.Register <HistoryDate>(1);

                    var endDate      = DateTime.Now.Date;
                    var samplingSpan = 1;
                    switch (DateType)
                    {
                    case DateTypes.Hour:
                        endDate      = StartDate.AddDays(1);
                        samplingSpan = 1;
                        break;

                    case DateTypes.Day:
                        endDate      = StartDate.AddDays(1);
                        samplingSpan = 24;
                        break;

                    case DateTypes.Week:
                        endDate      = StartDate.AddDays(7);
                        samplingSpan = 7 * 24;
                        break;

                    case DateTypes.Month:
                        endDate      = StartDate.AddMonths(1);
                        samplingSpan = 31 * 24;
                        break;

                    case DateTypes.Year:
                        endDate      = StartDate.AddYears(1);
                        samplingSpan = 365 * 24;
                        break;

                    default:
                        break;
                    }
                    var count = dateFormatter.Count;
                    System.Diagnostics.Debug.WriteLine("all date count:" + count);
                    System.Diagnostics.Debug.WriteLine("start date:" + StartDate);
                    var dates = new List <HistoryDate>();
                    for (long i = 0; i < count; i++)
                    {
                        var date     = dateFormatter.Deserialize <HistoryDate>(false);
                        var dateTime = DateTime.Parse(date.Date);
                        System.Diagnostics.Debug.WriteLine("current date:" + dateTime);
                        if (StartDate.Date <= dateTime && dateTime <= endDate)
                        {
                            dates.Add(date);
                        }
                    }
                    System.Diagnostics.Debug.WriteLine("valid date count:" + dates.Count);
                    if (dates.Count > 0)
                    {
                        var start = dates.Aggregate((d1, d2) => DateTime.Parse(d1.Date) < DateTime.Parse(d2.Date) ? d1 : d2);
                        var end   = dates.Aggregate((d1, d2) => DateTime.Parse(d1.Date) > DateTime.Parse(d2.Date) ? d1 : d2);

                        using (FileStream dataIndexStream = new FileStream(GetFile(true, true), FileMode.OpenOrCreate))
                        {
                            using (FileStream dataContentStream = new FileStream(GetFile(true, false), FileMode.OpenOrCreate))
                            {
                                var historyFormatter = new CustomBinaryFormatter(dataIndexStream, dataContentStream);
                                historyFormatter.Register <HistoryRecord>(1);

                                for (long i = start.Index; i < end.Index; i += samplingSpan)
                                {
                                    historyFormatter.MoveTo(i);
                                    var record = historyFormatter.Deserialize <HistoryRecord>(false);
                                    if (record.Key == key)
                                    {
                                        records.Add(record);
                                    }
                                }
                                historyFormatter.Close();
                                dataContentStream.Close();
                            }
                            dataIndexStream.Close();
                        }
                    }
                    dateFormatter.Close();
                    dateContentStream.Close();
                }
                dateIndexStream.Close();
            }
            return(records);
        }
Пример #7
0
        internal static void AddRecords(List <HistoryRecord> Records)
        {
            lock (_syncRoot)
            {
                using (FileStream dataIndexStream = new FileStream(GetFile(true, true), FileMode.OpenOrCreate))
                {
                    using (FileStream dataContentStream = new FileStream(GetFile(true, false), FileMode.OpenOrCreate))
                    {
                        var historyFormatter = new CustomBinaryFormatter(dataIndexStream, dataContentStream);
                        historyFormatter.Register <HistoryRecord>(1);

                        historyFormatter.MoveToEnd();
                        var historyCount = historyFormatter.Count;
                        Records.ForEach(r =>
                        {
                            historyFormatter.Serialize <HistoryRecord>(r);
                        });

                        historyFormatter.Flush();

                        using (FileStream dateIndexStream = new FileStream(GetFile(false, true), FileMode.OpenOrCreate))
                        {
                            using (FileStream dateContentStream = new FileStream(GetFile(false, false), FileMode.OpenOrCreate))
                            {
                                var dateFormatter = new CustomBinaryFormatter(dateIndexStream, dateContentStream);
                                dateFormatter.Register <HistoryDate>(1);

                                var  dateCount      = dateFormatter.Count;
                                var  today          = DateTime.Now.Date.AddDays(1);
                                var  yesterday      = DateTime.Now.Date;
                                long todayIndex     = -1;
                                var  foundYesterday = false;
                                for (long i = 0; i < dateCount; i++)
                                {
                                    var date = dateFormatter.Deserialize <HistoryDate>(false);
                                    if (DateTime.Parse(date.Date) == today)
                                    {
                                        todayIndex = i;
                                    }
                                    if (DateTime.Parse(date.Date) == yesterday)
                                    {
                                        foundYesterday = true;
                                    }
                                }
                                if (!foundYesterday)
                                {
                                    dateFormatter.MoveToEnd();
                                    dateFormatter.Serialize <HistoryDate>(new HistoryDate {
                                        Date = yesterday.ToString(), Index = historyCount
                                    });
                                }

                                if (todayIndex != -1)
                                {
                                    dateFormatter.MoveTo(todayIndex);
                                    dateFormatter.Serialize <HistoryDate>(new HistoryDate {
                                        Date = today.ToString(), Index = historyFormatter.Count
                                    }, true);
                                }
                                else
                                {
                                    dateFormatter.MoveToEnd();
                                    dateFormatter.Serialize <HistoryDate>(new HistoryDate {
                                        Date = today.ToString(), Index = historyFormatter.Count
                                    });
                                }

                                dateFormatter.Flush();
                            }
                        }
                    }
                }
            }
        }