private void ShowStatsTopList(string[] args, PublicMessageEventArgs e, string what, Func <UserStatisticsBucket, int> countMember) { TimeSpan ago = TimeSpan.Zero; string agoParam = "2w"; string numParam = "42"; if (args.Length >= 1) { agoParam = args[0]; } if (args.Length >= 2) { numParam = args[1]; } try { ago = TimeUtils.ParseTimeSpan(agoParam); } catch (FormatException) { Client.SendMessageToChat(e.Message.Chat.ID, $"Ik snap er niks van. Wat bedoel je met '{MessageUtils.HtmlEscape(agoParam)}'? Probeer eens '5d', '8u', '4w' of doe gek met '3w2d7u'.", "HTML", true); return; } if (!Int32.TryParse(numParam, out int number)) { Client.SendMessageToChat(e.Message.Chat.ID, $"Ik snap er niks van. Wat bedoel je met '{MessageUtils.HtmlEscape(agoParam)}'? Hoe moet ik daar een getal van maken?", "HTML", true); return; } if (number == 0 || ago == TimeSpan.Zero) { Client.SendMessageToChat(e.Message.Chat.ID, $"Haha, erg grappig 👏 Hier zijn je nul resultaten, malloot.", "HTML", true); return; } var collection = GetStatisticsCollection(); int numberOfDays = (int)Math.Ceiling(ago.TotalDays); int grandTotal = 0; var sinds = DateTime.UtcNow - TimeSpan.FromDays(numberOfDays); var yearDay = (sinds.Year * 1000) + sinds.DayOfYear; var allStats = new List <(UserStatistics stats, int total)>(); foreach (var stats in collection.FindAll()) { int total = 0; var buckets = stats.Buckets.Where(x => x.YearDay >= yearDay).ToList(); buckets.ForEach(x => total += countMember(x)); if (total > 0) { allStats.Add((stats, total)); grandTotal += total; } } var sortedAggregatedCollection = allStats.OrderByDescending(x => x.total).Take(number); if (sortedAggregatedCollection.Count() < number) { number = sortedAggregatedCollection.Count(); } StringBuilder result = new StringBuilder(); result.AppendLine($"Top <b>{number}</b> {what} vanaf <b>{TimeService.AsDutchString(DateTime.Now - ago)}</b>:"); int place = 1; foreach (var record in sortedAggregatedCollection) { result.AppendLine($"{place}: {MessageUtils.HtmlEscape(record.stats.UserName.TrimStart().TrimStart('@'))} ({record.total})"); place++; } result.AppendLine($"<i>Totaal aantal {what}: {grandTotal} voor {allStats.Count()} personen</i>"); Client.SendMessageToChat(e.Message.Chat.ID, $"{result}", "HTML", disableWebPagePreview: true, disableNotification: true); }
private void SendAgentStatInfo() { var agentConfig = TinyIoCContainer.Current.Resolve <AgentConfig>(); var pinpointConfig = TinyIoCContainer.Current.Resolve <PinpointConfig>(); while (true) { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(pinpointConfig.CollectorIp), pinpointConfig.UdpStatListenPort); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); #region assemble agent stat batch entity var agentStatBatch = new TAgentStatBatch(); agentStatBatch.AgentId = agentConfig.AgentId; agentStatBatch.StartTimestamp = agentConfig.AgentStartTime; agentStatBatch.AgentStats = new List <TAgentStat>(); #endregion #region assemble agent stat entity var agentStat = new TAgentStat(); agentStat.AgentId = agentConfig.AgentId; agentStat.StartTimestamp = agentConfig.AgentStartTime; agentStat.Timestamp = TimeUtils.GetCurrentTimestamp(); agentStat.CollectInterval = 5000; agentStat.Gc = new TJvmGc() { Type = TJvmGcType.PARALLEL, JvmMemoryHeapUsed = 73842768, JvmMemoryHeapMax = 436207616, JvmMemoryNonHeapUsed = 196555576, JvmMemoryNonHeapMax = -1, JvmGcOldCount = 5, JvmGcOldTime = 945, JvmGcDetailed = new TJvmGcDetailed() { JvmGcNewCount = 110, JvmGcNewTime = 1666, JvmPoolCodeCacheUsed = 0.22167689005533855, JvmPoolNewGenUsed = 0.025880894190828566, JvmPoolOldGenUsed = 0.20353155869704026, JvmPoolSurvivorSpaceUsed = 0.4635740007672991, JvmPoolMetaspaceUsed = 0.9706939329583961 } }; agentStat.CpuLoad = new TCpuLoad() { JvmCpuLoad = 0.002008032128514056, SystemCpuLoad = AgentStat.GetCpuLoad() }; agentStat.Transaction = new TTransaction() { SampledNewCount = 0, SampledContinuationCount = 0, UnsampledContinuationCount = 0, UnsampledNewCount = 0 }; agentStat.ActiveTrace = new TActiveTrace() { Histogram = new TActiveTraceHistogram() { Version = 0, HistogramSchemaType = 2, ActiveTraceCount = new List <int>() { 0, 0, 0, 0 } } }; agentStat.DataSourceList = new TDataSourceList() { DataSourceList = new List <TDataSource>() { new TDataSource() { Id = 1, DatabaseName = "test", ServiceTypeCode = 6050, Url = "jdbc:mysql://192.168.1.1:3306/test", MaxConnectionSize = 8 } } }; #endregion for (var i = 0; i < 6; i++) { agentStat.Timestamp -= 5000; agentStatBatch.AgentStats.Add(agentStat); } try { using (var serializer = new HeaderTBaseSerializer()) { var data = serializer.serialize(agentStatBatch); server.SendTo(data, ip); } } catch (Exception ex) { Logger.Current.Error(ex.ToString()); } Thread.Sleep(5 * 60 * 1000); } }
internal Transaction( IApmLogger logger, string name, string type, Sampler sampler, DistributedTracingData distributedTracingData, IPayloadSender sender, IConfigSnapshot configSnapshot, ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer ) { ConfigSnapshot = configSnapshot; Timestamp = TimeUtils.TimestampNow(); var idBytes = new byte[8]; Id = RandomGenerator.GenerateRandomBytesAsString(idBytes); _logger = logger?.Scoped($"{nameof(Transaction)}.{Id}"); _sender = sender; _currentExecutionSegmentsContainer = currentExecutionSegmentsContainer; Name = name; HasCustomName = false; Type = type; StartActivity(); var isSamplingFromDistributedTracingData = false; if (distributedTracingData == null) { // Here we ignore Activity.Current.ActivityTraceFlags because it starts out without setting the IsSampled flag, so relying on that would mean a transaction is never sampled. IsSampled = sampler.DecideIfToSample(idBytes); if (Activity.Current != null && Activity.Current.IdFormat == ActivityIdFormat.W3C) { TraceId = Activity.Current.TraceId.ToString(); ParentId = Activity.Current.ParentId; // Also mark the sampling decision on the Activity if (IsSampled) { Activity.Current.ActivityTraceFlags |= ActivityTraceFlags.Recorded; } } else { TraceId = _activity.TraceId.ToString(); } } else { TraceId = distributedTracingData.TraceId; ParentId = distributedTracingData.ParentId; IsSampled = distributedTracingData.FlagRecorded; isSamplingFromDistributedTracingData = true; _traceState = distributedTracingData.TraceState; } SpanCount = new SpanCount(); _currentExecutionSegmentsContainer.CurrentTransaction = this; if (isSamplingFromDistributedTracingData) { _logger.Trace() ?.Log("New Transaction instance created: {Transaction}. " + "IsSampled ({IsSampled}) is based on incoming distributed tracing data ({DistributedTracingData})." + " Start time: {Time} (as timestamp: {Timestamp})", this, IsSampled, distributedTracingData, TimeUtils.FormatTimestampForLog(Timestamp), Timestamp); } else { _logger.Trace() ?.Log("New Transaction instance created: {Transaction}. " + "IsSampled ({IsSampled}) is based on the given sampler ({Sampler})." + " Start time: {Time} (as timestamp: {Timestamp})", this, IsSampled, sampler, TimeUtils.FormatTimestampForLog(Timestamp), Timestamp); } void StartActivity() { _activity = new Activity("ElasticApm.Transaction"); _activity.SetIdFormat(ActivityIdFormat.W3C); _activity.Start(); } }
private void BlockSyncWorker() { var rnd = new Random(); Logger.LogDebug("Starting block synchronization worker"); while (_running) { try { var myHeight = _blockManager.GetHeight(); if (myHeight > _networkManager.LocalNode.BlockHeight) { _networkManager.LocalNode.BlockHeight = myHeight; } if (_peerHeights.Count == 0) { Logger.LogWarning("Peer height map is empty, nobody responds to pings?"); Thread.Sleep(TimeSpan.FromMilliseconds(1_000)); continue; } var maxHeight = _peerHeights.Values.Max(); if (myHeight >= maxHeight) { Logger.LogTrace($"Nothing to do: my height is {myHeight} and peers are at {maxHeight}"); Thread.Sleep(TimeSpan.FromMilliseconds(1_000)); continue; } const int maxPeersToAsk = 1; const int maxBlocksToRequest = 10; var peers = _peerHeights .Where(entry => entry.Value >= maxHeight) .Select(entry => entry.Key) .OrderBy(_ => rnd.Next()) .Take(maxPeersToAsk) .ToArray(); var leftBound = myHeight + 1; var rightBound = Math.Min(maxHeight, myHeight + maxBlocksToRequest); Logger.LogTrace($"Sending query for blocks [{leftBound}; {rightBound}] to {peers.Length} peers"); foreach (var peer in peers) { _networkManager.SendTo( peer, _networkManager.MessageFactory.SyncBlocksRequest(leftBound, rightBound) ); } var waitStart = TimeUtils.CurrentTimeMillis(); while (true) { lock (_peerHasBlocks) { Monitor.Wait(_peerHasBlocks, TimeSpan.FromMilliseconds(1_000)); } if (TimeUtils.CurrentTimeMillis() - waitStart > 5_000) { break; } } } catch (Exception e) { Logger.LogError($"Error in block synchronizer: {e}"); Thread.Sleep(1_000); } } }
public void TimeSpanFromFractionalMillisecondsRoundedTests(double fractionalMilliseconds, double expectedRounded) => ShouldBeWithTolerance(TimeUtils.TimeSpanFromFractionalMilliseconds(fractionalMilliseconds).TotalMilliseconds, expectedRounded);
protected static bool OccursBetween(ITimedDto containedDto, ITimedDto containingDto) => containingDto.Timestamp <= containedDto.Timestamp && TimeUtils.ToEndDateTime(containedDto.Timestamp, containedDto.Duration) <= TimeUtils.ToEndDateTime(containingDto.Timestamp, containingDto.Duration);
private string GetElapsedTimeString(int minSeconds, int maxSeconds) { TimeUtils.ElapsedTimeType type; int num; TimeUtils.ElapsedTimeType type2; int num2; TimeUtils.GetElapsedTime(minSeconds, out type, out num); if (minSeconds == maxSeconds) { object[] objArray1 = new object[] { TimeUtils.GetElapsedTimeString(minSeconds, this.m_timeStringSet) }; return(GameStrings.Format("GLOBAL_APPROXIMATE_DATETIME", objArray1)); } TimeUtils.GetElapsedTime(maxSeconds, out type2, out num2); if (type == type2) { switch (type) { case TimeUtils.ElapsedTimeType.SECONDS: { object[] objArray2 = new object[2]; objArray2[0] = num; object[] objArray3 = new object[] { num2 }; objArray2[1] = GameStrings.Format(this.m_timeStringSet.m_seconds, objArray3); return(GameStrings.Format("GLOBAL_APPROXIMATE_DATETIME_RANGE", objArray2)); } case TimeUtils.ElapsedTimeType.MINUTES: { object[] objArray4 = new object[2]; objArray4[0] = num; object[] objArray5 = new object[] { num2 }; objArray4[1] = GameStrings.Format(this.m_timeStringSet.m_minutes, objArray5); return(GameStrings.Format("GLOBAL_APPROXIMATE_DATETIME_RANGE", objArray4)); } case TimeUtils.ElapsedTimeType.HOURS: { object[] objArray6 = new object[2]; objArray6[0] = num; object[] objArray7 = new object[] { num2 }; objArray6[1] = GameStrings.Format(this.m_timeStringSet.m_hours, objArray7); return(GameStrings.Format("GLOBAL_APPROXIMATE_DATETIME_RANGE", objArray6)); } case TimeUtils.ElapsedTimeType.YESTERDAY: return(GameStrings.Get(this.m_timeStringSet.m_yesterday)); case TimeUtils.ElapsedTimeType.DAYS: { object[] objArray8 = new object[2]; objArray8[0] = num; object[] objArray9 = new object[] { num2 }; objArray8[1] = GameStrings.Format(this.m_timeStringSet.m_days, objArray9); return(GameStrings.Format("GLOBAL_APPROXIMATE_DATETIME_RANGE", objArray8)); } case TimeUtils.ElapsedTimeType.WEEKS: { object[] objArray10 = new object[] { num, num2 }; return(GameStrings.Format(this.m_timeStringSet.m_weeks, objArray10)); } } return(GameStrings.Get(this.m_timeStringSet.m_monthAgo)); } string str = TimeUtils.GetElapsedTimeString(type, num, this.m_timeStringSet); string str2 = TimeUtils.GetElapsedTimeString(type2, num2, this.m_timeStringSet); object[] args = new object[] { str, str2 }; return(GameStrings.Format("GLOBAL_APPROXIMATE_DATETIME_RANGE", args)); }
internal void CollectAllMetrics() { var sync = Interlocked.CompareExchange(ref _syncPoint, 1, 0); if (sync != 0) { return; } try { var samplesFromAllProviders = new List <MetricSample>(); foreach (var metricsProvider in MetricsProviders) { if (metricsProvider.ConsecutiveNumberOfFailedReads == MaxTryWithoutSuccess) { continue; } try { var samplesFromCurrentProvider = metricsProvider.GetSamples(); if (samplesFromCurrentProvider != null) { var sampleArray = samplesFromCurrentProvider as MetricSample[] ?? samplesFromCurrentProvider.ToArray(); if (sampleArray.Any()) { samplesFromAllProviders.AddRange(sampleArray); } metricsProvider.ConsecutiveNumberOfFailedReads = 0; } else { metricsProvider.ConsecutiveNumberOfFailedReads++; } } catch (Exception e) { metricsProvider.ConsecutiveNumberOfFailedReads++; _logger.Error() ?.LogException(e, "Failed reading {ProviderName} {NumberOfFail} times", metricsProvider.DbgName, metricsProvider.ConsecutiveNumberOfFailedReads); } if (metricsProvider.ConsecutiveNumberOfFailedReads != MaxTryWithoutSuccess) { continue; } _logger.Info() ?.Log("Failed reading {operationName} {numberOfTimes} consecutively - the agent won't try reading {operationName} anymore", metricsProvider.DbgName, metricsProvider.ConsecutiveNumberOfFailedReads, metricsProvider.DbgName); } var metricSet = new MetricSet(TimeUtils.TimestampNow(), samplesFromAllProviders); try { _payloadSender.QueueMetrics(metricSet); _logger.Debug() ?.Log("Metrics collected: {data}", samplesFromAllProviders.Any() ? samplesFromAllProviders.Select(n => n.ToString()).Aggregate((i, j) => i + ", " + j) : "no metrics collected"); } catch (Exception e) { _logger.Error() ?.LogException(e, "Failed sending metrics through PayloadSender - metrics collection stops"); _timer.Stop(); _timer.Dispose(); } } catch (Exception e) { _logger.Error() ?.LogExceptionWithCaller(e); } finally { _syncPoint = 0; } }
static void Main(string[] args) { // These two settings files are excluded for the GIT solution #if DEBUG var settings = JsonSettings.FromFile("settings.debug.json"); #else var settings = JsonSettings.FromFile("settings.release.json"); #endif TimeUtils.Initialize(settings.Timezones?.ToArray()); var kernel = new StandardKernel(); kernel.Bind <ILoggerFactory>().To <ConsoleLoggerFactory>(); kernel.Bind <ISettingsService>().ToConstant(settings); kernel.Bind <ITimeService>().To <TimeService>().InSingletonScope(); // Core services var database = kernel.Get <Database>(); database.Setup("Data"); kernel.Bind <IDatabase>().ToConstant(database); kernel.Bind <IPrivateConversationManager>().To <PrivateConversationManager>().InSingletonScope(); // Set up the messaging client CancellationTokenSource source = new CancellationTokenSource(); TelegramClient client = kernel.Get <JeHoofdTelegramClient>(); client.Setup(settings.BotKey, source.Token); kernel.Bind <IMessagingClient>().ToConstant(client); // Set up the console commands var helpCommand = new HelpCommand(); kernel.Bind <IConsoleCommand>().ToConstant(new ExitCommand { TokenSource = source }).InSingletonScope(); kernel.Bind <IConsoleCommand>().To <PingCommand>().InSingletonScope(); kernel.Bind <IConsoleCommand>().To <HelpCommand>().InSingletonScope(); kernel.Bind <IConsoleCommand>().To <LogLevelCommand>().InSingletonScope(); kernel.Bind <IConsoleCommand>().To <MeCommand>().InSingletonScope(); kernel.Bind <IConsoleCommand>().To <VerbodenWoord.VwCommand>().InSingletonScope(); kernel.Bind <IConsoleCommand>().To <FailedCommand>().InSingletonScope(); kernel.Bind <IConsoleCommand>().To <RetryCommand>().InSingletonScope(); // Simple set-up kernel.Bind <IBotModule>().To <TgCommands.WhereAmI>().InSingletonScope(); kernel.Bind <IBotModule>().To <VerbodenWoord.PrivateChatModule>().InSingletonScope(); kernel.Bind <IBotModule>().To <VerbodenWoord.ProcessVerbodenWoord>().InSingletonScope(); kernel.Bind <IBotModule>().To <VerbodenWoord.GeradenWoordCommands>().InSingletonScope(); kernel.Bind <IBotModule>().To <VerbodenWoord.HuntCommand>().InSingletonScope(); kernel.Bind <IBotModule>().To <ChatStats.GatherStatistics>().InSingletonScope(); kernel.Bind <IBotModule>().To <ChatStats.ChatStatsCommands>().InSingletonScope(); kernel.Bind <IBotModule>().To <ChatMgmt.Admin>().InSingletonScope(); kernel.Bind <IBotModule>().To <ChatMgmt.Ban>().InSingletonScope(); kernel.Bind <IBotModule>().To <ChatMgmt.WhoAmI>().InSingletonScope(); kernel.Bind <IBotModule>().To <ChatMgmt.WhereAmI>().InSingletonScope(); var modules = kernel.GetAll <IBotModule>().ToList(); // Start the system modules.ForEach(m => m.Startup()); client.Start(); // Runt the console loop in the background var consoleLoop = kernel.Get <ConsoleLoop>(); consoleLoop.Run(source.Token); // Shut down the modules modules.ForEach(m => m.Shutdown()); Console.WriteLine("Program terminated. Have a nice day."); }
public static void ClearAllCachesSince(long sinceTimestamp) { long endTimestamp = TimeUtils.BinaryStamp(); AssetCache.ClearAllCachesBetween(sinceTimestamp, endTimestamp); }
internal void StartTimer(DateTime time, int durationSeconds) { this.StartTime = time; this.EndTime = (int)TimeUtils.ToUnixTimestamp(time) + durationSeconds; this.Seconds = durationSeconds; }
static AssetCache() { AssetCache.cacheTable = new Dictionary <string, AssetCache>(); AssetCache.m_assetLoading = new Dictionary <string, int>(); AssetCache.s_cacheClearTime = TimeUtils.BinaryStamp(); }
/// <summary> /// Low level SendMessage method. Requires that Connect() be called first to open /// a connection. You can call this method multiple times without reconnecting to /// send multiple messages. /// </summary> /// <returns>True or False</returns> public bool SendMessage() { if (!string.IsNullOrEmpty(LogFile)) { LogString("\r\n*** Starting SMTP Send Operation - " + DateTime.Now.ToString()); } string lcResponse = string.Empty; // if (SenderEmail.IndexOf("<") > 0) // { // int lnIndex=SenderEmail.IndexOf("<"); // int lnIndex2 = SenderEmail.IndexOf(">"); // string lcEmail = SenderEmail.Substring(lnIndex+1,lnIndex2-lnIndex -1); // // lcResponse = SendReceive("MAIL FROM: <" + lcEmail + ">\r\n"); // } // else // lcResponse = SendReceive("MAIL FROM: <" + SenderEmail + ">\r\n"); // lcResponse = SendReceive("MAIL FROM: <" + GetEmailFromFullAddress(SenderEmail) + ">\r\n"); if (!CheckResponseCode(lcResponse, "250")) { return(false); } // lcResponse = SendReceive("rcpt to: <" + Recipient + ">\r\n"); // if (!CheckResponseCode(lcResponse,"250") ) // { // return false; // } if (!SendRecipients(Recipient)) { return(false); } if (!SendRecipients(CC)) { return(false); } if (!SendRecipients(BCC)) { return(false); } lcResponse = SendReceive("DATA\r\n"); if (!CheckResponseCode(lcResponse, "354")) { lcResponse = Read(); if (!CheckResponseCode(lcResponse, "354")) { return(false); } } Send("to: " + Recipient + "\r\n"); Send("cc: " + CC + "\r\n"); string Email = SenderEmail; if (SenderName != null && SenderName.Length > 0) { Email = "\"" + SenderName + "\" <" + Email + ">"; } Send("from: " + Email + "\r\n"); Send("subject: " + Subject + "\r\n"); Send("x-mailer: wwSmtp .Net\r\n"); Send("Importance: normal\r\n"); Send("Mime-Version: 1.0\r\n"); Send("Content-Type: " + ContentType + "\r\n"); Send("Content-Transfer-Encoding:" + CharacterEncoding + "\r\n"); Send("Date: " + TimeUtils.MimeDateTime(DateTime.Now) + "\r\n"); Send("\r\n" + Message + "\r\n"); lcResponse = SendReceive(".\r\n"); if (!CheckResponseCode(lcResponse, "250")) { return(false); } return(true); }
/// <inheritdoc /> public async Task FileStatusCheckAsync(PartitionFileStatusCheckType partitionFileStatusCheckType = PartitionFileStatusCheckType.Full, CdmIncrementalPartitionType incrementalType = CdmIncrementalPartitionType.None) { using ((this.Ctx.Corpus.Storage.FetchAdapter(this.InDocument.Namespace) as StorageAdapterBase)?.CreateFileQueryCacheContext()) { string fullPath = this.Ctx.Corpus.Storage.CreateAbsoluteCorpusPath(this.EntityPath, this.InDocument); DateTimeOffset?modifiedTime = await this.Ctx.Corpus.ComputeLastModifiedTimeAsync(fullPath, this); // check patterns first as this is a more performant way of querying file modification times // from ADLS and we can cache the times for reuse in the individual partition checks below if (partitionFileStatusCheckType == PartitionFileStatusCheckType.Full || partitionFileStatusCheckType == PartitionFileStatusCheckType.FullAndIncremental) { foreach (var pattern in this.DataPartitionPatterns) { if (pattern.IsIncremental) { Logger.Error(pattern.Ctx, Tag, nameof(FileStatusCheckAsync), pattern.AtCorpusPath, CdmLogCode.ErrUnexpectedIncrementalPartitionTrait, nameof(CdmDataPartitionPatternDefinition), pattern.FetchObjectDefinitionName(), Constants.IncrementalTraitName, nameof(DataPartitionPatterns)); } else { await pattern.FileStatusCheckAsync(); } } foreach (var partition in this.DataPartitions) { if (partition.IsIncremental) { Logger.Error(partition.Ctx, Tag, nameof(FileStatusCheckAsync), partition.AtCorpusPath, CdmLogCode.ErrUnexpectedIncrementalPartitionTrait, nameof(CdmDataPartitionDefinition), partition.FetchObjectDefinitionName(), Constants.IncrementalTraitName, nameof(DataPartitions)); } else { await partition.FileStatusCheckAsync(); } } } if (partitionFileStatusCheckType == PartitionFileStatusCheckType.Incremental || partitionFileStatusCheckType == PartitionFileStatusCheckType.FullAndIncremental) { foreach (var pattern in this.IncrementalPartitionPatterns) { if (this.ShouldCallFileStatusCheck(incrementalType, true, pattern)) { await pattern.FileStatusCheckAsync(); } } foreach (var partition in this.IncrementalPartitions) { if (this.ShouldCallFileStatusCheck(incrementalType, false, partition)) { await partition.FileStatusCheckAsync(); } } } // update modified times this.LastFileStatusCheckTime = DateTimeOffset.UtcNow; this.LastFileModifiedTime = TimeUtils.MaxTime(modifiedTime, this.LastFileModifiedTime); await this.ReportMostRecentTimeAsync(this.LastFileModifiedTime); } }
/// <summary> /// Awake /// </summary> void Awake() { time = this; timers = new List<Timer>(); removalPending = new List<int>(); }
public static bool IsDateTime(this IParameter parameter) { return(TimeUtils.IsDateTime(parameter.Value)); }
protected async Task <SampleAppResponse> SendGetRequestToSampleAppAndVerifyResponse(Uri uri, int expectedStatusCode, bool timeHttpCall = true, bool addTraceContextHeaders = false ) { var startTime = DateTime.UtcNow; if (timeHttpCall) { _logger.Debug() ?.Log("HTTP call to sample application started at {Time} (as timestamp: {Timestamp})", startTime, TimeUtils.ToTimestamp(startTime)); } try { var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri); if (addTraceContextHeaders) { httpRequestMessage.Headers.Add("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"); httpRequestMessage.Headers.Add("tracestate", "rojo=00f067aa0ba902b7,congo=t61rcWkgMzE"); } var response = await SendGetRequestToSampleAppAndVerifyResponseImpl(httpRequestMessage, expectedStatusCode); return(new SampleAppResponse(response.Headers, await response.Content.ReadAsStringAsync())); } finally { if (timeHttpCall) { _sampleAppClientCallTiming.Should().BeNull(); var endTime = DateTime.UtcNow; _logger.Debug() ?.Log("HTTP call to sample application ended at {Time} (as timestamp: {Timestamp}), Duration: {Duration}ms", endTime, TimeUtils.ToTimestamp(endTime), TimeUtils.DurationBetweenTimestamps(TimeUtils.ToTimestamp(startTime), TimeUtils.ToTimestamp(endTime))); _sampleAppClientCallTiming = new TimedEvent(startTime, endTime); } } }
public static bool IsTimeSpan(this IParameter parameter) { return(TimeUtils.IsTimeSpan(parameter.Value)); }
private void Update() { this.InitTimeStringSet(); this.m_timeInQueue += UnityEngine.Time.deltaTime; this.m_waitTime.Text = TimeUtils.GetElapsedTimeString(Mathf.RoundToInt(this.m_timeInQueue), this.m_timeStringSet); }
public async Task TestLoadsAndSetsTimesCorrectly() { var inputPath = TestHelper.GetInputFolderPath(testsSubpath, "TestLoadsAndSetsTimesCorrectly"); var timeBeforeLoad = DateTime.Now; var cdmCorpus = new CdmCorpusDefinition(); cdmCorpus.SetEventCallback(new EventCallback { Invoke = CommonDataModelLoader.ConsoleStatusReport }, CdmStatusLevel.Warning); cdmCorpus.Storage.Mount("someNamespace", new LocalAdapter(inputPath)); cdmCorpus.Storage.Mount("local", new LocalAdapter(inputPath)); cdmCorpus.Storage.Unmount("cdm"); cdmCorpus.Storage.DefaultNamespace = "local"; var cdmManifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("someNamespace:/default.manifest.cdm.json"); var statusTimeAtLoad = cdmManifest.LastFileStatusCheckTime; // hard coded because the time comes from inside the file Assert.AreEqual(TimeUtils.GetFormattedDateString(statusTimeAtLoad), "2019-02-01T15:36:19.410Z"); System.Threading.Thread.Sleep(100); await cdmManifest.FileStatusCheckAsync(); Assert.IsTrue(cdmManifest.LastFileStatusCheckTime > timeBeforeLoad); Assert.IsTrue(cdmManifest.LastFileStatusCheckTime > statusTimeAtLoad); Assert.AreEqual(cdmManifest.SubManifests.Count, 1); Assert.IsTrue(cdmManifest.SubManifests.AllItems[0].LastFileStatusCheckTime > timeBeforeLoad); Assert.AreEqual(cdmManifest.Entities.Count, 1); Assert.AreEqual(cdmManifest.Entities.AllItems[0].DataPartitions.Count, 1); var entity = cdmManifest.Entities.AllItems[0]; var subManifest = cdmManifest.SubManifests.AllItems[0] as CdmManifestDeclarationDefinition; var maxTime = TimeUtils.MaxTime(entity.LastFileModifiedTime, subManifest.LastFileModifiedTime); Assert.AreEqual(TimeUtils.GetFormattedDateString(cdmManifest.LastChildFileModifiedTime), TimeUtils.GetFormattedDateString(maxTime)); }
/// <summary> /// This is the main Session processing routine. This routine creates the /// new threads to run each session on. It monitors for shutdown/cancel operation /// and then shuts down the worker threads and summarizes the results. /// /// The worker method call for each Session request processing is /// SessionThreadRunner(). /// </summary> /// <param name="requests"></param> /// <param name="threadCount"></param> /// <param name="seconds"></param> /// <returns></returns> public List <HttpRequestData> CheckAllSites(IEnumerable <HttpRequestData> requests, int threadCount = 2, int seconds = 60, bool runOnce = false) { ThreadsUsed = threadCount; //if (UnlockKey.RegType == RegTypes.Free && // (threadCount > UnlockKey.FreeThreadLimit || // requests.Count() > UnlockKey.FreeSitesLimit)) //{ // Running = false; // SetError("The free version is limited to " + UnlockKey.FreeSitesLimit + " urls to check and " + UnlockKey.FreeThreadLimit + " simultaneous threads.\r\n\r\n" + // "Please reduce the URL or thread counts, or consider purchasing the Professional version that includes unlimited sites and threads."); // return null; //} if (!runOnce) { var validator = new SiteValidator(this); if (!validator.CheckAllServers(requests)) { SetError(validator.ErrorMessage); Running = false; return(null); } } Results = new List <HttpRequestData>(); requests = requests.Where(req => req.IsActive).ToList(); foreach (var plugin in App.Plugins) { try { if (!plugin.OnLoadTestStarted(requests as List <HttpRequestData>)) { return(null); } } catch (Exception ex) { App.Log(plugin.GetType().Name + " failed in OnLoadTestStarted(): " + ex.Message); } } Running = true; var threads = new List <Thread>(); CancelThreads = false; RequestsProcessed = 0; RequestsFailed = 0; // add warmup seconds to the request seconds += Options.WarmupSeconds; StartTime = DateTime.UtcNow; for (int i = 0; i < threadCount; i++) { var thread = new Thread(RunSessions); thread.Start(requests); threads.Add(thread); } var lastProgress = DateTime.UtcNow.AddSeconds(-10); while (!CancelThreads) { if (DateTime.UtcNow.Subtract(StartTime).TotalSeconds > seconds + 1) { TimeTakenForLastRunMs = (int)DateTime.UtcNow.Subtract(StartTime).TotalMilliseconds; CancelThreads = true; Thread.Sleep(3000); foreach (var thread in threads) { thread.Abort(); } Thread.Sleep(1000); break; } Thread.Sleep(100); if (DateTime.UtcNow.Subtract(lastProgress).TotalMilliseconds > 950) { lastProgress = DateTime.UtcNow; OnProgress(new ProgressInfo() { SecondsProcessed = (int)DateTime.UtcNow.Subtract(StartTime).TotalSeconds, TotalSecondsToProcessed = seconds, RequestsProcessed = RequestsProcessed, RequestsFailed = RequestsFailed, }); } } Running = false; seconds = seconds - Options.WarmupSeconds; // strip off WarmupSeconds var results = Results.Where(res => !res.IsWarmupRequest); var result = results.FirstOrDefault(); var min = StartTime; if (result != null) { min = result.Timestamp; min = TimeUtils.Truncate(min, DateTimeResolution.Second); } var max = min.AddSeconds(seconds + 1).AddMilliseconds(-1); Results = results.Where(res => res.Timestamp > min && res.Timestamp < max).ToList(); if (Results.Count > 0) { max = Results.Max(res => res.Timestamp); TimeTakenForLastRunMs = (int)TimeUtils.Truncate(max).Subtract(min).TotalMilliseconds; } else { TimeTakenForLastRunMs = (int)TimeUtils.Truncate(DateTime.UtcNow).Subtract(min).TotalMilliseconds; } foreach (var plugin in App.Plugins) { try { plugin.OnLoadTestCompleted(Results, TimeTakenForLastRunMs); } catch (Exception ex) { App.Log(plugin.GetType().Name + " failed in OnLoadTestCompleted(): " + ex.Message); } } return(Results); }
public void End() { if (Duration.HasValue) { _logger.Trace() ?.Log("Ended {Span} (with Duration already set)." + " Start time: {Time} (as timestamp: {Timestamp}), Duration: {Duration}ms", this, TimeUtils.FormatTimestampForLog(Timestamp), Timestamp, Duration); } else { Assertion.IfEnabled?.That(!_isEnded, $"Span's Duration doesn't have value even though {nameof(End)} method was already called." + $" It contradicts the invariant enforced by {nameof(End)} method - Duration should have value when {nameof(End)} method exits" + $" and {nameof(_isEnded)} field is set to true only when {nameof(End)} method exits." + $" Context: this: {this}; {nameof(_isEnded)}: {_isEnded}"); var endTimestamp = TimeUtils.TimestampNow(); Duration = TimeUtils.DurationBetweenTimestamps(Timestamp, endTimestamp); _logger.Trace() ?.Log("Ended {Span}. Start time: {Time} (as timestamp: {Timestamp})," + " End time: {Time} (as timestamp: {Timestamp}), Duration: {Duration}ms", this, TimeUtils.FormatTimestampForLog(Timestamp), Timestamp, TimeUtils.FormatTimestampForLog(endTimestamp), endTimestamp, Duration); } var isFirstEndCall = !_isEnded; _isEnded = true; if (ShouldBeSentToApmServer && isFirstEndCall) { try { DeduceDestination(); } catch (Exception e) { _logger.Warning()?.LogException(e, "Failed deducing destination fields for span."); } // Spans are sent only for sampled transactions so it's only worth capturing stack trace for sampled spans // ReSharper disable once CompareOfFloatsByEqualityOperator if (ConfigSnapshot.StackTraceLimit != 0 && ConfigSnapshot.SpanFramesMinDurationInMilliseconds != 0) { if (Duration >= ConfigSnapshot.SpanFramesMinDurationInMilliseconds || ConfigSnapshot.SpanFramesMinDurationInMilliseconds < 0) { StackTrace = StacktraceHelper.GenerateApmStackTrace(_stackFrames ?? new EnhancedStackTrace(new StackTrace(true)).GetFrames(), _logger, ConfigSnapshot, $"Span `{Name}'"); } } _payloadSender.QueueSpan(this); } if (isFirstEndCall) { _currentExecutionSegmentsContainer.CurrentSpan = _parentSpan; } }
public void TimeSpanFromFractionalMillisecondsExactTests(double fractionalMilliseconds) => ShouldBeWithTolerance(TimeUtils.TimeSpanFromFractionalMilliseconds(fractionalMilliseconds).TotalMilliseconds, fractionalMilliseconds);
public ActionResult Edit(ProductModel request) { if (ModelState.IsValid) { try { var model = db.Products.Find(request.Id); var dummy = (DummyModel)Session["Dummy"]; if (dummy.NailDesigns.Any(i => i != null)) { if (model.Dummye == null) { var newDummy = new Dummye(); db.Dummyes.Add(newDummy); model.Dummye = newDummy; model.DummyId = newDummy.Id; } model.Dummye.ServiceId = request.ServiceId; model.Dummye.h1Id = dummy.NailDesigns[0]?.Id; model.Dummye.h2Id = dummy.NailDesigns[1]?.Id; model.Dummye.h3Id = dummy.NailDesigns[2]?.Id; model.Dummye.h4Id = dummy.NailDesigns[3]?.Id; model.Dummye.h5Id = dummy.NailDesigns[4]?.Id; model.Dummye.h6Id = dummy.NailDesigns[5]?.Id; model.Dummye.h7Id = dummy.NailDesigns[6]?.Id; model.Dummye.h8Id = dummy.NailDesigns[7]?.Id; model.Dummye.h9Id = dummy.NailDesigns[8]?.Id; model.Dummye.h10Id = dummy.NailDesigns[9]?.Id; } else { if (model.Dummye != null) { db.Dummyes.Remove(model.Dummye); model.DummyId = null; } } model.ServiceId = request.ServiceId; model.ProductTypeId = request.ProductTypeId; model.Name = request.Name; model.Description = request.Description; model.TimeCost = TimeUtils.TimeToUt(request.TimeCost); db.SaveChanges(); return(RedirectToAction("List")); } catch (Exception exc) { Console.WriteLine(exc); } } InitFilds(); return(PartialView(request)); }
private bool CheckNewBest(List <double> solution, double value, bool onlyImprovements = true) { if (Result == null || value > Result.BestValue || value == Result.BestValue && !onlyImprovements) { Result = new OptimizationResult <double>(value, solution, iterationNumber, evaluation.iFFE, TimeUtils.DurationInSeconds(startTime)); return(true); } return(false); }
IEnumerator M_LoadConfig(Action onComplete, Action onError) { string url = GameConfig.HOST_RES() + "ab/" + GameConfig.LOCAL_CONFIG_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond(); WWW loader = new WWW(url); yield return(loader); if (string.IsNullOrEmpty(loader.error)) { VersionBundleConfig config = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(loader.text); m_loadedConfig = config; M_CacheBundles(); if (onComplete != null) { onComplete(); } } else { JZLog.LogError(loader.error); if (onError != null) { onError(); } } }
public GitHubContributorsResult GetOverallContributors(int maxAttempts = 3) { // Initialize a new StringBuilder for logging/testing purposes var stringBuilder = new StringBuilder(); // Map the path to the file containg HQ members that should be excluded in the list var configPath = HostingEnvironment.MapPath("~/config/githubhq.txt"); if (!File.Exists(configPath)) { var message = $"Config file was not found: {configPath}"; LogHelper.Debug <GitHubService>(message); throw new Exception(message); } // Parse the logins (usernames) var login = File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray(); // A dictionary for the response of each repository var responses = new Dictionary <string, IRestResponse <List <GitHubContributorModel> > >(); // Hashset for keeping track of missing responses var missing = new HashSet <string>(); Log(stringBuilder, "Attempt 1"); // Iterate over the repositories foreach (var repo in GetRepositories()) { Log(stringBuilder, $"-> Making request to {GitHubApiClient}/repos/{RepositoryOwner}/{repo}/stats/contributors"); // Make the request to the GitHub API var response = GetRepositoryContributors(repo); Log(stringBuilder, $" -> {(int)response.StatusCode} -> {response.StatusCode}"); switch (response.StatusCode) { case HttpStatusCode.OK: responses[repo] = response; break; case HttpStatusCode.Accepted: missing.Add(repo); break; default: var message = $"Failed getting contributors for repository {repo}: {response.StatusCode}\r\n\r\n{response.Content}"; Log(stringBuilder, message); throw new Exception(message); } } for (var i = 2; i <= maxAttempts; i++) { // Break the loop if there are no missing repositories if (missing.Count == 0) { break; } // Wait for a few seconds so the GitHub cache hopefully has been populated Thread.Sleep(5000); Log(stringBuilder, $"Attempt {i}"); foreach (var repo in GetRepositories()) { // Make the request to the GitHub API var response = GetRepositoryContributors(repo); // Error checking switch (response.StatusCode) { case HttpStatusCode.OK: // Set the response in the dictionary responses[repo] = response; // Remove the repository from queue missing.Remove(repo); break; case HttpStatusCode.Accepted: break; default: var message = $"Failed getting contributors for repository {repo}: {response.StatusCode}\r\n\r\n{response.Content}"; Log(stringBuilder, message); throw new Exception(message); } } } if (missing.Count > 0) { var message = $"Unable to get contributors for one or more repositories:\r\n{string.Join("\r\n", missing)}"; Log(stringBuilder, message); throw new Exception(message); } // filter to only include items from the last year (if we ran 4.6.1 we could have used ToUnixTimeSeconds()) var filteredRange = TimeUtils.GetUnixTimeFromDateTime(DateTime.UtcNow.AddYears(-1)); var contributors = new List <GitHubContributorModel>(); // Iterate over the responses (we don't care about the keys at this point) foreach (var response in responses.Values) { // Iterate over the contributors of the individual response foreach (var contrib in response.Data) { // Make sure we only get weeks from the past year var contribWeeks = contrib.Weeks.Where(x => x.W >= filteredRange).ToList(); // Populate the properties contrib.TotalAdditions = contribWeeks.Sum(x => x.A); contrib.TotalDeletions = contribWeeks.Sum(x => x.D); contrib.Total = contribWeeks.Sum(x => x.C); // Append the contributor to the aggregated list contributors.Add(contrib); } } // Group and sort the contributors from each repository var globalContributors = contributors .Where(g => g.Total > 0 && login.Contains(g.Author.Login) == false) .GroupBy(g => g.Author.Id) .Select(g => new GitHubGlobalContributorModel(g)) .OrderByDescending(c => c.TotalCommits) .ThenByDescending(c => c.TotalAdditions) .ThenByDescending(c => c.TotalDeletions) .ToList(); return(new GitHubContributorsResult(globalContributors, $"{stringBuilder}{string.Empty}")); }
/// <summary> /// 加载版本文件 /// </summary> /// <param name="onComplete"></param> /// <param name="onError"></param> public void LoadVersion(Action onComplete, Action onError) { string url = GameConfig.HOST_RES() + GameConfig.LOCAL_HTTP_CONFIG_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond(); BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(url), (req, resp) => { if (resp != null) { Loom.RunAsync(() => { m_httpConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(resp.DataAsText); M_CacheHttpBundles(); string infoFilePath = PathUtils.MakeFilePath(GameConfig.LOCAL_DOWNLOAD_INFO_FILE, PathUtils.PathType.MobileDiskWrite); if (File.Exists(infoFilePath)) { using (FileStream infoStream = File.OpenRead(infoFilePath)) { if (infoStream != null) { byte[] index = new byte[infoStream.Length]; infoStream.Read(index, 0, index.Length); string content = System.Text.Encoding.Default.GetString(index); DownloadFileInfo downloadFileInfo = JsonFx.Json.JsonReader.Deserialize <DownloadFileInfo>(content); ResHelper.Instance().lastZipIndex = downloadFileInfo.totalSize; for (int i = 0; i < downloadFileInfo.ids.Length; i++) { ResHelper.Instance().downloadedFiles.Add(downloadFileInfo.ids[i], 1); } } } } if (GameConfig.useLocalRes) { m_version = new VersionConfig(); m_version.version = "0.0.0"; Loom.QueueOnMainThread(() => { if (onComplete != null) { onComplete(); } }); } else { url = GameConfig.HOST_RES_ZIP() + "zip/" + GameConfig.LOCAL_VERSION_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond(); BestHTTP.HTTPRequest zipRequest = new BestHTTP.HTTPRequest(new Uri(url), (zipReq, zipResp) => { if (zipResp != null) { m_version = JsonFx.Json.JsonReader.Deserialize <VersionConfig>(zipResp.DataAsText); if (null != onComplete) { onComplete(); } } else { if (null != onError) { onError(); } } }); zipRequest.Send(); } }); } else { if (null != onError) { onError(); } } }); request.DisableCache = true; request.Send(); }
private TwitterRateLimiting(int limit, int remaining, int reset) { Limit = limit; Remaining = remaining; Reset = TimeUtils.GetDateTimeFromUnixTime(reset); }
public bool Stop(long iterationNumber, long FFE, DateTime startTime) { return(TimeUtils.DurationInSeconds(startTime) >= maxRunningTime); }
// GET: Order public ActionResult Index() { string timestamps = TimeUtils.GetTimeStamp(DateTime.UtcNow, 10);//时间戳 10 位 return(Content(timestamps)); }
// Use this for initialization void Start () { REF = this; this.StartCoroutine(everySecond()); Application.runInBackground = true; }