Adding a client-side event handler for TFS GetCompleted - visual-studio

I want to know when (using either Visual Studio, or TF.exe) the client triggers Get Latest Version. Because I want to trigger my scripted build process to behave differently when this has occurred.
I have already tried to create a WinForms application that implements an event handler, as below:
private void Form1_Load(object sender, EventArgs e)
{
var collections = RegisteredTfsConnections.GetProjectCollections();
var tpc = new TfsTeamProjectCollection(collections.First().Uri, CredentialCache.DefaultNetworkCredentials);
var vcServer = tpc.GetService<VersionControlServer>();
vcServer.GetCompleted += VcServer_GetCompleted;
vcServer.Getting += VcServer_Getting;
}
private void VcServer_GetCompleted(object sender, WorkspaceEventArgs e)
{
textBox1.AppendText("VcServer_GetCompleted" + Environment.NewLine);
}
private void VcServer_Getting(object sender, GettingEventArgs e)
{
textBox1.AppendText("VcServer_Getting" + Environment.NewLine);
}
But it would appear that these event handlers only listen to this instance of VersionControlServer, not globally on the client workstation.

Related

How does Windows.System.Configuration.Install.Installer work

I am trying to configure my installer so that it will close any instances of the application before installation starts and relaunch the application once installation has finished.
The MS documents provide and example similar to the one below and indicate that the [RunInstaller(true)] annotation specifies whether the Visual Studio Custom Action Installer or the Installutil.exe (Installer Tool) should be invoked when the assembly is installed.
Of course this could mean just about anything...
I am using the Visual Studio Project Installer NuGet package to create the install files (setup.exe and APP.msi files). When configuring the Project Installer there is an option set configure the Custom Actions - I assume this is what the documentation means.
However the Custom Actions has options to add things to the Install, Commit sections - what has to be added to these sections and how does this relate to the Installer class defined below.
This whole area of installation seems to be poorly documented and there seem to be so many options, none of which seem to work properly.
You would think closing any running instances before installing an update and then relaunching after completing the installation would be a no brainer but it seems anything but simple.
Appreciate any assistance with a working example of how this can be achieved.
namespace FocusBracketer
{
[RunInstaller(true)]
public partial class Installer: System.Configuration.Install.Installer
{
public Installer() : base()
{
InitializeComponent();
// Attach the 'BeforeInstall' event.
this.BeforeInstall += new InstallEventHandler(Installer_BeforeInstall);
// Attach the 'Committed' event.
this.Committed += new InstallEventHandler(Installer_Committed);
// Attach the 'Committing' event.
this.Committing += new InstallEventHandler(Installer_Committing);
}
// Event handler for 'BeforeInstall' event.
private void Installer_BeforeInstall(object sender, InstallEventArgs e)
{
Console.WriteLine("");
Console.WriteLine("BeforeInstall Event occurred.");
Console.WriteLine("");
}
// Event handler for 'AfterInstall' event.
private void Installer_AfterInstall(object sender, InstallEventArgs e)
{
Console.WriteLine("");
Console.WriteLine("AfterInstall Event occurred.");
Console.WriteLine("");
System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(this.Context.Parameters["AssemblyPath"]) + #"\FocusBracketer.exe");
}
// Event handler for 'Committing' event.
private void Installer_Committing(object sender, InstallEventArgs e)
{
Console.WriteLine("");
Console.WriteLine("Committing Event occurred.");
Console.WriteLine("");
}
// Event handler for 'Committed' event.
private void Installer_Committed(object sender, InstallEventArgs e)
{
Console.WriteLine("");
Console.WriteLine("Committed Event occurred.");
Console.WriteLine("");
}
// Override the 'Install' method.
public override void Install(IDictionary savedState)
{
base.Install(savedState);
}
// Override the 'Commit' method.
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
}
// Override the 'Rollback' method.
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
public static void Main()
{
Console.WriteLine("Usage : installutil.exe Installer.exe ");
}
}
}

Call UWP service on Shared project

I have a Xamarin app where I implemented a service to do some printing. I create that service on UWP app because it needs some dependencies of it.
UWP Service:
public class PrintUWPService
{
PrintManager printmgr = PrintManager.GetForCurrentView();
PrintDocument PrintDoc;
PrintDocument printDoc;
PrintTask Task;
private Windows.UI.Xaml.Controls.WebView ViewToPrint = new Windows.UI.Xaml.Controls.WebView();
public PrintUWPService()
{
printmgr.PrintTaskRequested += Printmgr_PrintTaskRequested;
}
public async void Print(WebView viewToPrint, string htmlSource)
{
ViewToPrint.NavigateToString(htmlSource);
if (PrintDoc != null)
{
printDoc.GetPreviewPage -= PrintDoc_GetPreviewPage;
printDoc.Paginate -= PrintDoc_Paginate;
printDoc.AddPages -= PrintDoc_AddPages;
}
printDoc = new PrintDocument();
try
{
printDoc.GetPreviewPage += PrintDoc_GetPreviewPage;
printDoc.Paginate += PrintDoc_Paginate;
printDoc.AddPages += PrintDoc_AddPages;
var showprint = await PrintManager.ShowPrintUIAsync();
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
PrintDoc = null;
GC.Collect();
}
private void Printmgr_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
{
var deff = args.Request.GetDeferral();
Task = args.Request.CreatePrintTask("Grocery List", OnPrintTaskSourceRequested);
deff.Complete();
}
async void OnPrintTaskSourceRequested(PrintTaskSourceRequestedArgs args)
{
var def = args.GetDeferral();
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
args.SetSource(printDoc.DocumentSource);
});
def.Complete();
}
private void PrintDoc_AddPages(object sender, AddPagesEventArgs e)
{
printDoc.AddPage(ViewToPrint);
printDoc.AddPagesComplete();
}
private void PrintDoc_Paginate(object sender, PaginateEventArgs e)
{
PrintTaskOptions opt = Task.Options;
printDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
}
private void PrintDoc_GetPreviewPage(object sender, GetPreviewPageEventArgs e)
{
printDoc.SetPreviewPage(e.PageNumber, ViewToPrint);
}
}
}
Then I create interface for it:
public interface IPrintUWPService
{
void Print(WebView viewToPrint, string htmlSource);
}
Now inside a class of my shared project I want to call this service as:
private readonly IPrintUWPService _printService = DependencyService.Get<IPrintUWPService>();
But it does not work. it says:
IPrintUWPService does not exist in the current context
So I try to access to UWP class as:
using MyCompany.ProjectName.App.UWP
But it says that "UWP" namespace does not exist. What am I doing wrong? is not possible call service on UWP project inside shared project? Regards
Call UWP DependencyService on Shared project
As #Jason mentioned in above comment, you need declare the interface in the Xamarin Forms project and implement it in the UWP client project.
And please note, after implementing the interface in each platform project, the platform implementations must be registered with the DependencyService, so that Xamarin.Forms can locate them at runtime. Use DependencyAttribute like the following.
[assembly: Dependency(typeof(UWP Client namesapce))]

Has anyone been able to see a crash attachment with Xamarin Forms and AppCenter.ms?

As far as I know I have followed exactly the instructions:
I have set everything up as suggested. Used my secret key, enabled crashes. Had the set up checked by another developer and see the crash happened in appcenter.ms but still I never see any attached information.
Here's an example:
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
try
{
UIApplication.Main(args, null, "AppDelegate");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Crashes.TrackError(ex,
new Dictionary<string, string> {
{"Main", "Exception"},
{"Device Model", DeviceInfo.Model },
});
throw;
}
}
}
No matter what, when and how my application crashes I still will not get the attached information.
I am wondering has anyone got the attached data for crashes to work with XF ?
We can use AppCenter only after it has been started which according to official documentation on iOS we do it in AppDelegate class in the method FinishedLaunching. But the point is the class Application in Main.cs file is called before AppDelegate class.
If you want to see the attached info then you can try it for example in a XAML code-behind file by manually throwing an exception. Here is an example for a button's click event:
private void TheButton1_OnClicked(object sender, EventArgs e)
{
try
{
throw new DivideByZeroException("Testing attached info!");
}
catch (Exception exception)
{
Crashes.TrackError(exception,
new Dictionary<string, string> {{"Device Model", "My device model" }});
}
}
The attached info on TrackError() method i.e properties dictionary works on both Android and iOS. To see that info you need to go through this in App Center's panel:
From left panel choose Diagnostics.
From Groups section choose your specific group.
From tabs in top section choose Reports.
Choose your specific device.
The attached info is In Stacktrace tab and in Error properties section.
Just to correct, the additional data you attach with exception in TrackError method are mostly in catch blocks or generated exception in TrackError methods, so it will only displayed with those manually logged(TrackError) exceptions.
Crashes are exceptions that are not handled and logged automatically by appcenter so if you look in crash reports there will not be any attached data available.
Additional data sent with exception as properties can be found in reports section of error on appcenter.
I am sure you have initialized Crash service in OnStart method of App.xaml.cs class with correct app secrets and required platforms(android/ios).
I was able to track the crashes. The only difference is am tracking it from the native projects.
For Android in the MainActivity:
protected override void OnCreate(Bundle savedInstanceState)
{
...
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;
...
}
private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
{
var newExc = new Exception("UnhandledExceptionRaiser", e.Exception as Exception);
LogUnhandledException(newExc);
}
private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
{
var newExc = new Exception("TaskSchedulerOnUnobservedTaskException", unobservedTaskExceptionEventArgs.Exception);
LogUnhandledException(newExc);
}
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
var newExc = new Exception("CurrentDomainOnUnhandledException", unhandledExceptionEventArgs.ExceptionObject as Exception);
LogUnhandledException(newExc);
}
internal static void LogUnhandledException(Exception exception)
{
try
{
Crashes.TrackError(exception);
...
}
catch (Exception ex)
{
// just suppress any error logging exceptions
}
}
For iOS in the AppDelegate:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
...
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
...
}
private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
{
var newExc = new Exception("TaskSchedulerOnUnobservedTaskException", unobservedTaskExceptionEventArgs.Exception);
LogUnhandledException(newExc);
}
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
var newExc = new Exception("CurrentDomainOnUnhandledException", unhandledExceptionEventArgs.ExceptionObject as Exception);
LogUnhandledException(newExc);
}
internal static void LogUnhandledException(Exception exception)
{
try
{
...
}
catch
{
// just suppress any error logging exceptions
}
}

Eventhandler is fired more than once

I have a problem with two of my EventHandlers, they work the same, so here is one:
private void Form1_Load(object sender, EventArgs e)
{
webBrowserWebsite.Url = new System.Uri(textBoxURL.Text, System.UriKind.Absolute);
webBrowserWebsite.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowserWebsite_DocumentCompleted);
}
void webBrowserWebsite_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + #"\CurrentData.wfd");
sw.Write(webBrowserWebsite.Document.Body.InnerText);
sw.Close();
}
The problem is, that the EventHandler fires multiple times, it doesn't stop!
Why is it doing this?
Thanks in advance
The code that you have written won't compile (your StreamWriter in your EventHandler isn't assigned to anything) and without more context as to how you are calling this, it is difficult to say for certain.
But the most likely reason is you are calling Form1_Load multiple times, but using the same webBrowserWebsite object. Each time the form loads, you are adding a new Event Handler. And since you aren't showing any code showing where you removing the event handler, I'm guessing it fires once for each time you call Form_Load.
Depending on your design, you are better off adding the event handler in the constructor so it is only added once regardless of the number of times you load the form.
public Form1()
{
webBrowserWebsite.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowserWebsite_DocumentCompleted);
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowserWebsite.Url = new System.Uri(textBoxURL.Text, System.UriKind.Absolute);
}
Or remove the event handler in the event handler:
void webBrowserWebsite_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + #"\CurrentData.wfd");
sw.Write(webBrowserWebsite.Document.Body.InnerText);
sw.Close();
webBrowserWebsite.DocumentCompleted -= webBrowserWebsite_DocumentCompleted;
}
Also, since StreamWriter implements IDisposible, you should be putting it inside of a using block or at least calling sw.Dispose() at the end of the method

Are there any exception logging components in Windows Phone applications?

Are there any exception logging components in Windows Phone applications? Do you have any suggestions about logging records in Windows Phone applications?
For logging to Visual Studio while running, you can use Debug.Write.
As far as logging exceptions to a file, WP7Contrib has an exception logging library that is available as part of WP7Contrib.Core on NuGet. WP7Contrib.Core's only dependencies are the Rx libraries.
Edit: You can use the WP7Contrib logging library like this:
private ILogManager logManager = new LoggingService();
private void Application_Launching(object sender, LaunchingEventArgs e)
{
logManager.Enable();
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
logManager.Enable();
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
logManager.Disable();
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
logManager.Disable();
}
Edit 2:
Having said that, I'd probably just use an extention method:
// App.xaml.cs
private ILogManager logManager = new LoggingService();
public App()
{
logManager.Attach(PhoneApplicationService.Current);
}
// LogManagerExtensions.cs
public static class LogManagerExtensions
{
public static void Attach(this ILogManager logManager, PhoneApplicationService appService)
{
appService.Launching += (s,e) => logManager.Enable();
appService.Activated += (s,e) => logManager.Enable();
appService.Deactivated += (s,e) => logManager.Disable();
appService.Closing += (s,e) => logManager.Disable();
}
}
NLog is quite good
And a somewhat older
Silverlight and WP7 Exception Handling and Logging building blockk
I saw Telerik are talking about releasing RadDiagnostics soon. I'm planning to get a look at it in the next app I release. Details from http://blogs.telerik.com/blogs/posts/12-02-01/introducing-raddiagnostics-for-windows-phone.aspx
well.you can try WP7Contrib OpenSource Project At CodePlex[http://wp7contrib.codeplex.com/] and get Exception Log Record in the Windows phone Application.
if you did't want to use opensource Project 。 you can define Component by yourself. Store Exception record as file in Isolated Storage。

Resources