/// <summary> /// 执行指定任务 /// </summary> /// <param name="context"></param> /// <param name="action"></param> public void ExecuteJob(IJobExecutionContext context, Action action) { try { // 1. 获取Task 基本信息及 Task 配置的其他参数,任务启动时会读取配置文件节点的值传递过来 TaskModel task = QuartzHelper.GetTaskDetail(context); // 2. 记录Task 运行状态数据库 DbLogHelper.WriteRunInfo(task.TaskName + " 开始", task.TaskID.ToString(), ""); // 3. 开始执行相关任务 PerformanceTracer.Invoke(action, task.TaskName);//监控并执行任务 // 4. 记录Task 运行状态数据库 DbLogHelper.WriteRunInfo(task.TaskName + " 结束", task.TaskID.ToString(), "成功执行"); } catch (Exception ex) { JobExecutionException e2 = new JobExecutionException(ex); //true 是立即重新执行任务 e2.RefireImmediately = true; // 记录异常到数据库和 log 文件中。 DbLogHelper.WriteErrorInfo(ex); } }
public ResourceViewModel([NotNull] ResourceManager resourceManager, [NotNull] Configuration configuration, [NotNull] ISourceFilesProvider sourceFilesProvider, [NotNull] CodeReferenceTracker codeReferenceTracker, [NotNull] ITracer tracer, [NotNull] PerformanceTracer performanceTracer) { Contract.Requires(resourceManager != null); Contract.Requires(configuration != null); Contract.Requires(sourceFilesProvider != null); Contract.Requires(codeReferenceTracker != null); Contract.Requires(tracer != null); Contract.Requires(performanceTracer != null); _resourceManager = resourceManager; _configuration = configuration; _sourceFilesProvider = sourceFilesProvider; _codeReferenceTracker = codeReferenceTracker; _tracer = tracer; _performanceTracer = performanceTracer; _resourceTableEntiyCountUpdateThrottle = new DispatcherThrottle(() => OnPropertyChanged(nameof(ResourceTableEntryCount))); _resourceTableEntries = _selectedEntities.ObservableSelectMany(entity => entity.Entries); _resourceTableEntries.CollectionChanged += (_, __) => _resourceTableEntiyCountUpdateThrottle.Tick(); _restartFindCodeReferencesThrottle = new DispatcherThrottle(DispatcherPriority.ContextIdle, () => BeginFindCodeReferences(sourceFilesProvider.SourceFiles)); resourceManager.TableEntries.CollectionChanged += (_, __) => _restartFindCodeReferencesThrottle.Tick(); resourceManager.LanguageChanged += ResourceManager_LanguageChanged; }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); ConnectEvents(); _compositionHost = ToolWindow?.CompositionHost; if (_compositionHost == null) { return; } _tracer = _compositionHost.GetExportedValue <ITracer>(); _refactorings = _compositionHost.GetExportedValue <IRefactorings>(); _performanceTracer = _compositionHost.GetExportedValue <PerformanceTracer>(); // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService; if (null == mcs) { return; } // Create the command for the menu item. CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyCommand, ShowToolWindow); // Create the command for the tool window CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTool, ShowToolWindow); // Create the command for the solution explorer context menu CreateMenuCommand(mcs, PkgCmdIdList.cmdidMySolutionExplorerContextMenu, ShowSelectedResourceFiles).BeforeQueryStatus += SolutionExplorerContextMenuCommand_BeforeQueryStatus; // Create the command for the text editor context menu CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTextEditorContextMenu, MoveToResource).BeforeQueryStatus += TextEditorContextMenuCommand_BeforeQueryStatus; }
private void Solution_AfterClosing() { using (PerformanceTracer.Start("DTE event: Solution closed")) { ReloadSolution(); } }
/// <summary> /// 执行指定任务 /// </summary> /// <param name="context"></param> /// <param name="action"></param> public void ExecuteJob(IJobExecutionContext context, Action action) { try { //记录文件日志- 开始执行相关任务 LogHelper.ServerInfo(context.Trigger.Key.Name + "开始执行"); //记录数据库日志 DBLogHelper.WriteRunLog(context.Trigger.JobKey.Name, context.Trigger.JobKey.Group, "开始执行"); //开始执行 PerformanceTracer.Invoke(action, context.Trigger.JobKey.Name); //记录文件日志- 开始执行相关任务 LogHelper.ServerInfo(context.Trigger.Key.Name + "成功执行"); //记录数据库日志 DBLogHelper.WriteRunLog(context.Trigger.JobKey.Name, context.Trigger.JobKey.Group, "成功执行"); } catch (Exception ex) { JobExecutionException e2 = new JobExecutionException(ex); //true 是立即重新执行任务 e2.RefireImmediately = true; //记录文件日志- 开始执行相关任务 //logger.Warn(ex.Message); LogHelper.ServerError(e2.Message, ex); // 记录异常到数据库和 log 文件中。 DBLogHelper.WriteErrorLog(context.Trigger.JobKey.Name, context.Trigger.JobKey.Group, ex.Message); } }
static void Main(string[] args) { // Protokolldatei löschen, falls diese vorhanden ist string logfileName = "c:\\trace.log"; if (File.Exists(logfileName)) { File.Delete(logfileName); } // Trace-Listener zum Schreiben in eine Datei erzeugen und // an die Listeners-Auflistung der Trace-Klasse anfügen Trace.Listeners.Clear(); Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener( logfileName)); // PerformanceTracer-Instanz erzeugen performanceTracer = new PerformanceTracer(); // CPU-Auslastungs-Thread mit einem 100ms-Intervall starten performanceTracer.StartCPUUsageTraceThread(100); // Speicher- und prozessorintensive Methode aufrufen Stress(); // CPU-Auslastungs-Thread stoppen performanceTracer.StopCPUUsageTraceThread(); // Trace-Listener schließen Trace.Listeners[0].Close(); }
public DteSourceFilesProvider([NotNull] ICompositionHost compositionHost) { Contract.Requires(compositionHost != null); _compositionHost = compositionHost; _performanceTracer = compositionHost.GetExportedValue <PerformanceTracer>(); _configuration = compositionHost.GetExportedValue <Configuration>(); }
public SourceFilesProvider([NotNull] Configuration configuration, [NotNull] PerformanceTracer performanceTracer) { Contract.Requires(configuration != null); Contract.Requires(performanceTracer != null); _configuration = configuration; _performanceTracer = performanceTracer; }
public VisualDrawingContextView() { InitializeComponent(); using (PerformanceTracer.StartNew("VisualDrawing")) { VisualLineHost.PerformanceTest(); } }
public LineDrawView() { InitializeComponent(); using (PerformanceTracer.StartNew("Line Drawing")) { PerformanceTest(); } }
public ShellViewModel([NotNull] ResourceViewModel resourceViewModel, [NotNull] PerformanceTracer performanceTracer) { Contract.Requires(resourceViewModel != null); Contract.Requires(performanceTracer != null); _performanceTracer = performanceTracer; resourceViewModel.SelectedEntities.CollectionChanged += SelectedEntities_CollectionChanged; }
private void Solution_ContentChanged([CanBeNull] object item) { using (PerformanceTracer.Start("DTE event: Solution content changed")) { CompositionHost.GetExportedValue <ISourceFilesProvider>().Invalidate(); ReloadSolution(); } }
public ShellViewModel([NotNull] ResourceViewModel resourceViewModel, [NotNull] PerformanceTracer performanceTracer) { Contract.Requires(resourceViewModel != null); Contract.Requires(performanceTracer != null); _performanceTracer = performanceTracer; _updateThrottle = new DispatcherThrottle(DispatcherPriority.Background, () => IsLoading = false); resourceViewModel.SelectedEntities.CollectionChanged += SelectedEntities_CollectionChanged; }
private void DocumentEvents_DocumentOpened([CanBeNull] EnvDTE.Document document) { using (PerformanceTracer.Start("DTE event: Document opened")) { if (!AffectsResourceFile(document)) { return; } ReloadSolution(); } }
private void Solution_Opened() { using (PerformanceTracer.Start("DTE event: Solution opened")) { ReloadSolution(); var resourceManager = CompositionHost.GetExportedValue <ResourceManager>(); resourceManager.ProjectFileSaved -= ResourceManager_ProjectFileSaved; resourceManager.ProjectFileSaved += ResourceManager_ProjectFileSaved; } }
public ResourceViewModel(ResourceManager resourceManager, IConfiguration configuration, ISourceFilesProvider sourceFilesProvider, CodeReferenceTracker codeReferenceTracker, ITracer tracer, PerformanceTracer performanceTracer) { ResourceManager = resourceManager; _configuration = configuration; _sourceFilesProvider = sourceFilesProvider; _codeReferenceTracker = codeReferenceTracker; _tracer = tracer; _performanceTracer = performanceTracer; ResourceTableEntries = SelectedEntities.ObservableSelectMany(entity => entity.Entries); ResourceTableEntries.CollectionChanged += (_, __) => ResourceTableEntries_CollectionChanged(); resourceManager.LanguageChanged += ResourceManager_LanguageChanged; }
public void Slice() { using (PerformanceTracer.BeginPerformanceTrace("NetworkClient.Slice")) { _queue.Slice(); while (_queue.Count > 0) { var packet = _queue.Dequeue(); TracePacket(packet.PacketBuffer, packet.Name, packet.RealLength); InvokeHandlers(packet.PacketHandlers, packet.PacketBuffer, packet.RealLength); } } }
protected override void OnAttached() { base.OnAttached(); var listBox = AssociatedObject; if (listBox == null) { return; } listBox.SelectAll(); listBox.SelectionChanged += ListBox_SelectionChanged; ((INotifyCollectionChanged)listBox.Items).CollectionChanged += (_, __) => _collectionChangedThrottle.Tick(); _performanceTracer = listBox.GetExportProvider().GetExportedValue <PerformanceTracer>(); }
public ActionResult Get() { List <SupplierEntity> list = new List <SupplierEntity>(); for (int i = 1; i < 8; i++) { list.Add(new SupplierEntity { AgentId = 1, AgentType = 2, ApplyAuthentication = 3, BaiduID = 4 }); } //return this.HandleSuccess("OK", list); try { throw new SFO2OException("错误测试"); } catch (Exception ex) { return(this.HandleError(ex)); } return(PerformanceTracer.Invoke(() => { //TODO:调用并且跟踪指定代码块的执行时间 return this.HandleError("错误测试"); }, "跟踪模块名称")); PerformanceTracer.Invoke(() => { //TODO:调用并且跟踪指定代码块的执行时间 }, "跟踪模块名称"); PerformanceTracer.InvokeAsync(() => { //TODO:通过异步方式调用的方式处理一些不太重要的工作 }, "跟踪模块名称"); //return this.HandleError("参数错误!"); }
private void DocumentEvents_DocumentSaved([NotNull] EnvDTE.Document document) { Contract.Requires(document != null); using (PerformanceTracer.Start("DTE event: Document saved")) { if (!AffectsResourceFile(document)) { return; } var resourceManager = CompositionHost.GetExportedValue <ResourceManager>(); if (resourceManager.IsSaving) { return; } // Run custom tool (usually attached to neutral language) even if a localized language changes, // e.g. if custom tool is a text template, we might want not only to generate the designer file but also // extract some localization information. // => find the resource entity that contains the document and run the custom tool on the neutral project file. // ReSharper disable once PossibleNullReferenceException bool Predicate(ResourceEntity e) => e.Languages.Select(lang => lang.ProjectFile) .OfType <DteProjectFile>() .Any(projectFile => projectFile.ProjectItems.Any(p => p.Document == document)); var entity = resourceManager.ResourceEntities.FirstOrDefault(Predicate); var neutralProjectFile = (DteProjectFile)entity?.NeutralProjectFile; // VS will run the custom tool on the project item only. Run the custom tool on any of the descendants, too. var projectItems = neutralProjectFile?.ProjectItems.SelectMany(projectItem => projectItem.Descendants()); _customToolRunner.Enqueue(projectItems); ReloadSolution(); } }
public ResourceViewModel([NotNull] ResourceManager resourceManager, [NotNull] Configuration configuration, [NotNull] ISourceFilesProvider sourceFilesProvider, [NotNull] CodeReferenceTracker codeReferenceTracker, [NotNull] ITracer tracer, [NotNull] PerformanceTracer performanceTracer) { Contract.Requires(resourceManager != null); Contract.Requires(configuration != null); Contract.Requires(sourceFilesProvider != null); Contract.Requires(codeReferenceTracker != null); Contract.Requires(tracer != null); Contract.Requires(performanceTracer != null); ResourceManager = resourceManager; _configuration = configuration; _sourceFilesProvider = sourceFilesProvider; _codeReferenceTracker = codeReferenceTracker; _tracer = tracer; _performanceTracer = performanceTracer; ResourceTableEntries = SelectedEntities.ObservableSelectMany(entity => entity.Entries); ResourceTableEntries.CollectionChanged += (_, __) => ResourceTableEntries_CollectionChanged(); resourceManager.TableEntries.CollectionChanged += (_, __) => BeginFindCodeReferences(); resourceManager.LanguageChanged += ResourceManager_LanguageChanged; }
/// <summary> /// Standard constructor for the tool window. /// </summary> public MyToolWindow() : base(null) { try { // Set the window title reading it from the resources. Caption = Resources.ToolWindowTitle; // Set the image that will appear on the tab of the window frame when docked with an other window. // The resource ID correspond to the one defined in the resx file while the Index is the offset in the bitmap strip. // Each image in the strip being 16x16. BitmapResourceID = 301; BitmapIndex = 1; var path = Path.GetDirectoryName(GetType().Assembly.Location); Contract.Assume(path != null); _compositionHost.AddCatalog(new DirectoryCatalog(path, @"*.dll")); _compositionHost.ComposeExportedValue((IVsServiceProvider)this); _compositionHost.ComposeExportedValue((ISourceFilesProvider)this); _trace = _compositionHost.GetExportedValue <ITracer>(); _performanceTracer = _compositionHost.GetExportedValue <PerformanceTracer>(); _configuration = _compositionHost.GetExportedValue <Configuration>(); _resourceManager = _compositionHost.GetExportedValue <ResourceManager>(); _resourceManager.BeginEditing += ResourceManager_BeginEditing; VisualComposition.Error += VisualComposition_Error; } catch (Exception ex) { _trace.TraceError("MyToolWindow .ctor failed: " + ex); MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Resources.ExtensionLoadingError, ex.Message)); } }
public SourceFilesProvider([NotNull] Configuration configuration, [NotNull] PerformanceTracer performanceTracer) { _configuration = configuration; _performanceTracer = performanceTracer; }
public DteSourceFilesProvider(IExportProvider exportProvider) { _performanceTracer = exportProvider.GetExportedValue <PerformanceTracer>(); _configuration = exportProvider.GetExportedValue <IConfiguration>(); _solution = exportProvider.GetExportedValue <DteSolution>(); }
private void Update() { double time = GizmoSDK.GizmoBase.Time.SystemSeconds; if (_frameTime > 0) { _frameDurationTime = 0.999 * _frameDurationTime + 0.001 * (time - _frameTime); } _frameTime = time; try { Performance.Enter("Initializer.Update"); // Example of getting performance graphical output #if SHOW_TRACERS if (_counter == 10) { tracer = new PerformanceTracer(); tracer.AddAll(); tracer.Run(); } #endif // SHOW_TRACERS _counter++; // Exemple of getting allocate dmemory in native parts #if SHOW_MEMORY if (_counter % 30 == 0) { //System.GC.Collect(); //System.GC.WaitForPendingFinalizers(); GizmoSDK.GizmoBase.Monitor.AddValue("mem", MemoryControl.GetAllocMem()); GizmoSDK.GizmoBase.Monitor.AddValue("internal", MemoryControl.GetAllocMem(0, 0, false, true)); GizmoSDK.GizmoBase.Monitor.AddValue("dyn", MemoryControl.GetAllocMem(66666)); GizmoSDK.GizmoBase.Monitor.AddValue("tex", Image.GetRegisteredImageData()); } #endif //SHOW_MEMORY #if SHOW_FPS if (_counter % 30 == 0) { GizmoSDK.GizmoBase.Monitor.AddValue("fps", 1 / _frameDurationTime); } #endif //SHOW_FPS } finally { Performance.Leave(); } }
public DteSourceFilesProvider([NotNull] IExportProvider exportProvider) { _exportProvider = exportProvider; _performanceTracer = exportProvider.GetExportedValue <PerformanceTracer>(); _configuration = exportProvider.GetExportedValue <Configuration>(); }
public SourceFilesProvider(IConfiguration configuration, PerformanceTracer performanceTracer) { _configuration = configuration; _performanceTracer = performanceTracer; }