Example #1
0
 public bool InitializeIfNeeded(HostId identity)
 {
     if (this.HostId == HostId.NotInitialized)
     {
         lock (this.initLock)
         {
             if (this.HostId == HostId.NotInitialized)
             {
                 CommonDiagnosticsLog.Initialize(identity);
                 ADSessionSettings             sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), OrganizationId.ForestWideOrgId, null, false);
                 ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 500, "InitializeIfNeeded", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\MessageTracking\\ServerCache.cs");
                 Server server = topologyConfigurationSession.FindLocalServer();
                 if (server == null || string.IsNullOrEmpty(server.Fqdn) || string.IsNullOrEmpty(server.Domain))
                 {
                     TraceWrapper.SearchLibraryTracer.TraceError <string, string>(this.GetHashCode(), "Failed to get local server, or it is invalid Fqdn={0}, Domain={1}", (server == null) ? "<null>" : server.Fqdn, (server == null) ? "<null>" : server.Domain);
                     return(false);
                 }
                 this.localServer = server;
                 ADSite localSite = topologyConfigurationSession.GetLocalSite();
                 if (localSite == null)
                 {
                     TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Failed to get local site.", new object[0]);
                     return(false);
                 }
                 this.localServerSiteId = localSite.Id;
                 this.HostId            = identity;
             }
         }
         return(true);
     }
     return(true);
 }
    /*public PreviewRequest(string s1, string s2, List<string> strings) : this()
     * {
     *  HostId = new HostId(s1, s2);                                                    // implement
     *  SelectorsDictionary = new SelectorsDictionary(strings);                         // implement
     * }*/

    public PreviewRequest()
    {
        HostId = new HostId
        {
            Type  = ConfigDat.HostType,
            Value = ConfigDat.HostId
        };
    }
Example #3
0
 public void TestDelayOperation(string operation)
 {
     if (ServerCache.Instance.IsTimeoutOverrideConfigured)
     {
         lock (TrackingEventBudget.TestOperationCount)
         {
             string text = ServerCache.TryReadRegistryKey <string>(operation, string.Empty);
             if (!string.IsNullOrEmpty(text))
             {
                 string[] array = text.Split(new char[]
                 {
                     ':'
                 });
                 int    num    = -1;
                 HostId hostId = ServerCache.Instance.HostId;
                 string y      = Names <HostId> .Map[(int)hostId];
                 if (array.Length != 2 || !StringComparer.OrdinalIgnoreCase.Equals(array[0], y) || !int.TryParse(array[1], out num))
                 {
                     TraceWrapper.SearchLibraryTracer.TraceError <string>(this.GetHashCode(), "TEST CODE: Invalid registry key: {0}", text);
                 }
                 else
                 {
                     int num2 = 0;
                     if (!TrackingEventBudget.TestOperationCount.TryGetValue(operation, out num2))
                     {
                         num2 = 0;
                     }
                     num2++;
                     TrackingEventBudget.TestOperationCount[operation] = num2;
                     if (num2 > num)
                     {
                         TraceWrapper.SearchLibraryTracer.TraceDebug <string, int>(this.GetHashCode(), "TEST CODE: Delaying {0} operation, count={1}", operation, num2);
                         TimeSpan elapsed = this.timer.Elapsed;
                         if (elapsed < this.timeBudgetAllowed)
                         {
                             int num3 = (int)(this.timeBudgetAllowed - elapsed).TotalMilliseconds;
                             TraceWrapper.SearchLibraryTracer.TraceDebug <int>(this.GetHashCode(), "TEST CODE: Pause injected, sleeping away remaining budget: {0} milliseconds", num3);
                             Thread.Sleep(num3);
                             TrackingEventBudget.TestOperationCount.Clear();
                         }
                         else
                         {
                             TraceWrapper.SearchLibraryTracer.TraceDebug <double>(this.GetHashCode(), "TEST CODE: Already over budget, sleep skipped. Elapsed time for this request: {0}", elapsed.TotalMilliseconds);
                         }
                     }
                     else
                     {
                         TraceWrapper.SearchLibraryTracer.TraceDebug <int, string, int>(this.GetHashCode(), "TEST CODE: {0} {1} operations completed (will delay after {2})", num2, operation, num);
                     }
                 }
             }
         }
     }
 }
Example #4
0
        public void A()
        {
            var request = new Request(
                id: Guid.NewGuid(),
                environmentId: 1,
                domainId: 2,
                path: "/",
                method: HttpMethod.Post,
                serverId: HostId.Create(1, 1),
                programId: 3,
                originId: 10,
                referrer: "https://google.com/",
                sessionId: 456234,
                securityTokenId: 500,
                responseTime: TimeSpan.FromSeconds(1.3)
                );

            Assert.Null(request.ClientId);

            var ms = new MemoryStream();

            var log = new RequestLog(ms);

            var count = 1_000_000;

            for (var i = 0; i < count; i++)
            {
                request.ComputeUnits = i;

                log.Append(request);
            }

            ms.Position = 0;

            var readCount = 0;

            // ~ 93MB per million requests

            // 0.02 cents per month per 10,000,000 requests

            // $0.0125 per GB

            // throw new Exception((ms.Length / (1000 * 1000)).ToString());

            while (log.TryRead(out var b))
            {
                Assert.Equal(readCount, b.ComputeUnits);

                readCount++;
            }

            Assert.Equal(count, readCount);
        }
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (HostId.Length != 0)
                    {
                        hash ^= HostId.GetHashCode();
                    }
                    if (NewHostId.Length != 0)
                    {
                        hash ^= NewHostId.GetHashCode();
                    }
                    if (_unknownFields != null)
                    {
                        hash ^= _unknownFields.GetHashCode();
                    }
                    return(hash);
                }
Example #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            hash ^= players_.GetHashCode();
            if (HasHostId)
            {
                hash ^= HostId.GetHashCode();
            }
            if (Token.Length != 0)
            {
                hash ^= Token.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Example #7
0
        private Host GetHost(LogEventInfo logEventInfo)
        {
            var hostId   = HostId?.Render(logEventInfo);
            var hostName = HostName?.Render(logEventInfo);
            var hostIp   = HostIp?.Render(logEventInfo);

            if (string.IsNullOrEmpty(hostId) &&
                string.IsNullOrEmpty(hostName) &&
                string.IsNullOrEmpty(hostIp))
            {
                return(null);
            }

            var host = new Host
            {
                Id   = hostId,
                Name = hostName,
                Ip   = string.IsNullOrEmpty(hostIp) ? null : new[] { hostIp }
            };

            return(host);
        }
Example #8
0
        public void SerializeTest()
        {
            Uid id = Uid.Parse("5dTcGYChmFCf1zMMuAp72C");

            var request = new Request(
                id: id,
                environmentId: 1,
                domainId: 2,
                path: "/",
                method: HttpMethod.Post,
                edgeLocation: "ch1",
                edgeCacheStatus: EdgeCacheStatus.Hit,
                serverId: HostId.Create(1, 1),
                clientId: default(Uid),
                clientLocation: "US/NY/New`York",
                programId: 3,
                programVersion: "1.0.0",
                originId: 10,
                referrer: "https://google.com/",
                sessionId: 456234,
                securityTokenId: 500,
                status: 301,
                responseTime: TimeSpan.FromSeconds(1.93),
                receivedBytes: 100,
                sentBytes: 54052
                );

            request.Timings = new[] {
                new Timing("decode", TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(0.445)),
                new Timing("encode", TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1.3))
            };

            var ms = new MemoryStream();

            Serializer.Serialize(ms, request);

            ms.Position = 0;

            var b = Serializer.Deserialize <Request>(ms);

            Assert.Equal(id, b.Id);
            Assert.Equal(1, b.EnvironmentId);
            Assert.Equal(2, b.DomainId);
            Assert.Equal(HttpMethod.Post, b.Method);
            Assert.Equal("/", b.Path);
            Assert.Equal(4294967297, b.ServerId);
            Assert.Equal(3, b.ProgramId);
            Assert.Equal("1.0.0", b.ProgramVersion);
            Assert.Equal(10, b.OriginId);
            Assert.Equal("https://google.com/", b.Referrer);
            Assert.Equal(1.93, b.ResponseTime.TotalSeconds);
            Assert.Equal(100, b.ReceivedBytes);
            Assert.Equal(54052, b.SentBytes);
            Assert.Equal("US/NY/New`York", b.ClientLocation);
            Assert.Equal(EdgeCacheStatus.Hit, b.EdgeCacheStatus);
            Assert.Equal("ch1", b.EdgeLocation);
            Assert.Equal(456234, b.SessionId);
            Assert.Equal(500, b.SecurityTokenId);
            Assert.Equal("decode", b.Timings[0].Name);
            Assert.Equal(0.445, b.Timings[0].Duration.TotalSeconds);
            Assert.Equal("encode", b.Timings[1].Name);
            Assert.Equal(1, b.Timings[1].Start.TotalSeconds);
            Assert.Equal(1.3, b.Timings[1].Duration.TotalSeconds);
        }
Example #9
0
 public string GetIdentity()
 {
     return(HostId.ToString());
 }
Example #10
0
 public void Ids()
 {
     Assert.Equal(1L, HostId.Create(0, 1));
 }
Example #11
0
 public override int GetHashCode() =>
 Id.GetHashCode() ^ HostId.GetHashCode() ^ Data.GetHashCode() ^ TimeStamp.GetHashCode();