static Canary15DataSegment()
 {
     Canary15Trace.TraceDateTime(Canary15DataSegment.UtcNow, 0, "Canary15DataSegment().UtcNow.");
     Canary15Trace.TraceTimeSpan(Canary15DataSegment.defaultRefreshPeriod, 1, "Canary15DataSegment().defaultRefreshPeriod.");
     Canary15Trace.TraceTimeSpan(Canary15DataSegment.ReplicationDuration, 2, "Canary15DataSegment().ReplicationDuration.");
     Canary15DataSegment.topoConfigSession      = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 119, ".cctor", "f:\\15.00.1497\\sources\\dev\\clients\\src\\common\\Canary15DataSegment.cs");
     Canary15DataSegment.adClientAccessObjectId = Canary15DataSegment.topoConfigSession.GetClientAccessContainerId();
     Canary15DataSegment.LoadClientAccessADObject();
     byte[] array  = ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest().ObjectGuid.ToByteArray();
     byte[] array2 = Canary15DataSegment.topoConfigSession.GetDatabasesContainerId().ObjectGuid.ToByteArray();
     Canary15DataSegment.adObjectIdsBinary = new byte[array.Length + array2.Length];
     array.CopyTo(Canary15DataSegment.adObjectIdsBinary, 0);
     array2.CopyTo(Canary15DataSegment.adObjectIdsBinary, array.Length);
     if (Canary15Trace.IsTraceEnabled(TraceType.DebugTrace))
     {
         using (SHA256Cng sha256Cng = new SHA256Cng())
         {
             byte[] bytes = sha256Cng.ComputeHash(Canary15DataSegment.adObjectIdsBinary);
             Canary15Trace.TraceDebug(2L, "adObjectIdsBinaryHash:{0}", new object[]
             {
                 Canary15DataSegment.GetHexString(bytes)
             });
             sha256Cng.Clear();
         }
     }
 }
示例#2
0
 internal static void TraceByteArray(int id, string message, byte[] bytes)
 {
     if (Canary15Trace.SkipTrace)
     {
         return;
     }
     Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
     {
         message ?? string.Empty,
         Canary15Trace.GetHexString(bytes)
     });
 }
示例#3
0
        internal static void TraceTimeSpan(TimeSpan dateTime, int id, string message)
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string text = string.Format("Duration={0},", dateTime.ToDuration());

            Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
            {
                message ?? string.Empty,
                text
            });
        }
示例#4
0
        internal static void TraceDateTime(DateTime dateTime, int id, string message)
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string text = string.Format("UTC={0}", dateTime.ToUniversalSortable());

            Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
            {
                message ?? string.Empty,
                text
            });
        }
示例#5
0
        internal static void TraceState(this Canary15DataSegment.DataSegmentHeader header, int id, string message)
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string text = string.Format("H.H={0},", header.GetHashCode());

            text += string.Format("State={0},Bits={1:X}", header.State.ToString(), (int)header.Bits);
            Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
            {
                message ?? string.Empty,
                text
            });
        }
        public static bool GetEntry(long ticks, out byte[] key, out long keyIndex, out int segment)
        {
            bool result;

            lock (Canary15DataManager.segments)
            {
                Canary15DataManager.CheckAndUpdateSegment();
                if (Canary15DataManager.activeSegment != null && Canary15DataManager.activeSegment.FindEntry(ticks, out key, out keyIndex))
                {
                    segment = Canary15DataManager.activeSegment.SegmentIndex;
                    result  = true;
                }
                else if (Canary15DataManager.historySegment != null && Canary15DataManager.historySegment.FindEntry(ticks, out key, out keyIndex))
                {
                    segment = Canary15DataManager.historySegment.SegmentIndex;
                    result  = true;
                }
                else
                {
                    key      = Canary15DataSegment.BackupKey;
                    keyIndex = -2L;
                    segment  = -2;
                    if (Canary15DataManager.traceEnableCounter > 0)
                    {
                        Canary15DataManager.traceEnableCounter--;
                        new DateTime(ticks, DateTimeKind.Utc);
                        Canary15Trace.LogToIIS("Canary.T" + Canary15DataManager.traceEnableCounter, ticks.ToString());
                        if (Canary15DataManager.activeSegment != null)
                        {
                            Canary15DataManager.activeSegment.LogToIIS(9);
                            Canary15DataManager.activeSegment.Trace(9, "GetEntry()");
                        }
                        if (Canary15DataManager.historySegment != null)
                        {
                            Canary15DataManager.historySegment.LogToIIS(9);
                            Canary15DataManager.historySegment.Trace(9, "GetEntry()");
                        }
                        if (Canary15DataManager.pendingSegment != null)
                        {
                            Canary15DataManager.pendingSegment.LogToIIS(9);
                            Canary15DataManager.pendingSegment.Trace(9, "GetEntry()");
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }
示例#7
0
        internal static void TraceVersion()
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string formatString = string.Format("TraceVersion[{0}:{1}:{2}:{3}]", new object[]
            {
                Canary15Trace.MachineName,
                Canary15Trace.AppDomain,
                Canary15Trace.ThreadId,
                Canary15Trace.buildType
            });

            Canary15Trace.TraceDebug(0L, formatString, new object[0]);
        }
示例#8
0
        internal static void TraceData(this Canary15DataSegment.DataSegmentHeader header, int id, string message)
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string text = string.Format("H.H={0},", header.GetHashCode());

            text += string.Format("N={0}, L={1},", header.NumberOfEntries, header.EntrySize);
            text += string.Format("V={0}, H={1}", header.Version, header.HeaderSize);
            Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
            {
                message ?? string.Empty,
                text
            });
        }
示例#9
0
        internal static void LogToIIS(this Canary15DataSegment segment, int id)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("0{0:x}.", segment.SegmentIndex);
            stringBuilder.AppendFormat("{0:x}.", (int)segment.State);
            stringBuilder.AppendFormat("{0:x}.", (int)segment.Header.Bits);
            stringBuilder.AppendFormat("{0:x}.", (int)segment.Header.State);
            stringBuilder.AppendFormat("{0:x}.", segment.Header.Period.Ticks);
            stringBuilder.AppendFormat("{0:x}.", segment.Header.StartTime.Ticks);
            stringBuilder.AppendFormat("{0:x}.", segment.Header.EndTime.Ticks);
            stringBuilder.AppendFormat("{0:x}.", segment.Header.ReadyTime.Ticks);
            stringBuilder.AppendFormat("{0:x}.", segment.Header.ReplicationDuration.Ticks);
            stringBuilder.AppendFormat("{0:x}.", segment.Header.ReadTime.Ticks);
            stringBuilder.AppendFormat("{0:x}.", segment.NextRefreshTime.Ticks);
            stringBuilder.AppendFormat("{0:x}", Canary15DataSegment.UtcNowTicks);
            Canary15Trace.LogToIIS(string.Format("Canary.S{0}=", id), stringBuilder.ToString());
        }
示例#10
0
        internal static void Trace(this Canary15DataSegment segment, int id, string message)
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string text = string.Format("S.H={0},", segment.GetHashCode());

            text += string.Format("S.I={0},", segment.SegmentIndex);
            text += string.Format("S.R={0},", segment.NextRefreshTime.ToUniversalSortable());
            text += string.Format("S.S={0}", segment.State.ToString());
            Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
            {
                message ?? string.Empty,
                text
            });
            segment.Header.Trace(id, message);
        }
示例#11
0
        internal static void TraceSchedule(this Canary15DataSegment.DataSegmentHeader header, int id, string message)
        {
            if (Canary15Trace.SkipTrace)
            {
                return;
            }
            string text = string.Format("H.H={0},", header.GetHashCode());

            text += string.Format("S={0},E={1},R={2},", header.StartTime.ToUniversalSortable(), header.EndTime.ToUniversalSortable(), header.ReadyTime.ToUniversalSortable());
            text += string.Format("W={0},", (header.ReadyTime - header.ReplicationDuration).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"));
            text += string.Format("D={0},P={1},", header.ReplicationDuration.ToDuration(), header.Period.ToDuration());
            text += string.Format("N={0},L={1}", header.NumberOfEntries, header.EntrySize);
            Canary15Trace.TraceDebug((long)id, "{0}{1}", new object[]
            {
                message ?? string.Empty,
                text
            });
        }
        private static string GetHexString(byte[] bytes)
        {
            if (!Canary15Trace.IsTraceEnabled(TraceType.DebugTrace))
            {
                return(null);
            }
            if (bytes == null)
            {
                return("NULL_BYTE_ARRAY");
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (byte b in bytes)
            {
                stringBuilder.AppendFormat("{0:x2}", b);
            }
            return(stringBuilder.ToString());
        }
 internal void ReadSegmentFromAD()
 {
     byte[] array = (byte[])Canary15DataSegment.adClientAccessContainer[this.adPropertyDefinition];
     Canary15Trace.TraceByteArray(0, "ReadSegmentFromAD", array);
     this.header = new Canary15DataSegment.DataSegmentHeader(array, Canary15DataSegment.UtcNowTicks);
     if ((this.header.Bits & Canary15DataSegment.SegmentFlags.InvalidHeader) != Canary15DataSegment.SegmentFlags.InvalidHeader && this.header.Bits != Canary15DataSegment.SegmentFlags.None)
     {
         int num             = this.header.HeaderSize;
         int entrySize       = this.header.EntrySize;
         int numberOfEntries = this.header.NumberOfEntries;
         this.data = new byte[numberOfEntries][];
         for (int i = 0; i < numberOfEntries; i++)
         {
             this.data[i] = new byte[entrySize];
             Array.Copy(array, num, this.data[i], 0, entrySize);
             num += entrySize;
         }
         this.header.Bits |= Canary15DataSegment.SegmentFlags.Data;
     }
     this.header.ComputeState(this.data);
 }
        static Canary15DataManager()
        {
            Canary15Trace.TraceVersion();
            Canary15Trace.TraceTimeSpan(Canary15DataManager.defaultPeriod, 0, "Canary15DataManager().DefaultPeriod.");
            Canary15DataSegment.SampleUtcNow();
            Canary15DataManager.NextRefreshTime = Canary15DataSegment.UtcNow;
            Canary15DataManager.segments        = new Canary15DataSegment[3];
            for (int i = 0; i < 3; i++)
            {
                Canary15DataManager.segments[i] = Canary15DataSegment.CreateFromADData(i);
            }
            bool flag = Canary15DataManager.segments[0].IsNull || Canary15DataManager.segments[1].IsNull || Canary15DataManager.segments[2].IsNull;

            if (Canary15DataManager.segments[0].IsNull || (Canary15DataManager.segments[1].IsNull && !Canary15DataManager.segments[2].IsNull))
            {
                Canary15DataManager.segments[1].MarkADSegmentForDeletion();
                Canary15DataManager.segments[2].MarkADSegmentForDeletion();
                Canary15DataManager.Create(0);
            }
            if (flag)
            {
                long num   = 36000000000L;
                long ticks = Canary15DataManager.segments[0].Header.ReplicationDuration.Ticks;
                if (ticks == 0L)
                {
                    ticks = Canary15DataSegment.ReplicationDuration.Ticks;
                }
                long num2 = Canary15DataManager.segments[0].Header.StartTime.Ticks - ticks;
                if (num2 > Canary15DataSegment.UtcNow.Ticks)
                {
                    num2 = Canary15DataSegment.UtcNow.Ticks;
                }
                Canary15DataManager.CreateFromLegacyData(2, num2 - num, ticks + num, ticks);
                Canary15DataManager.segments[2].LogToIIS(0);
            }
        }
 internal static void SampleUtcNow()
 {
     Canary15DataSegment.utcNowTicks = DateTime.UtcNow.Ticks;
     Canary15Trace.TraceDateTime(Canary15DataSegment.UtcNow, 0, "SampleUtcNow()");
 }