public static void Main() { if (SingleInstance <App> .InitializeAsFirstInstance("{E17EF702-0CDB-4CC2-808A-EE33BAA03B34}")) { var application = new App(); // parse requested Uri if present StackHashUri stackHashUri = null; if (StackHashUri.TryParse(Environment.GetCommandLineArgs(), out stackHashUri)) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, string.Format(CultureInfo.CurrentCulture, "Command line requests navigation to {0}", stackHashUri.RawUri)); application.CurrentStackHashUri = stackHashUri; } application.InitializeComponent(); application.Run(); // Allow single instance code to perform cleanup operations SingleInstance <App> .Cleanup(); } }
public static bool TryParse(string uriString, out StackHashUri uri) { List <string> dummyList = new List <string>(); dummyList.Add("dummy"); dummyList.Add(uriString); return(TryParse(dummyList, out uri)); }
private void menuItemCopyProductUrl_Click(object sender, RoutedEventArgs e) { DisplayProduct productInfo = listViewProducts.SelectedItem as DisplayProduct; if (productInfo != null) { Clipboard.SetText(StackHashUri.CreateUriString(UserSettings.Settings.CurrentContextId, productInfo.Id)); } }
private void menuItemCopyCabUrl_Click(object sender, RoutedEventArgs e) { if ((_clientLogic.CurrentCab != null) && (_clientLogic.CurrentEventPackage != null)) { Clipboard.SetText(StackHashUri.CreateUriString(UserSettings.Settings.CurrentContextId, _clientLogic.CurrentEventPackage.ProductId, _clientLogic.CurrentEventPackage.Id, _clientLogic.CurrentEventPackage.EventTypeName, _clientLogic.CurrentCab.Id)); } }
private void menuItemCopyEventUrl_Click(object sender, RoutedEventArgs e) { DisplayEventPackage eventPackage = listViewEvents.SelectedItem as DisplayEventPackage; if (eventPackage != null) { Clipboard.SetText(StackHashUri.CreateUriString(UserSettings.Settings.CurrentContextId, eventPackage.ProductId, eventPackage.Id, eventPackage.EventTypeName)); } }
private void menuItemCopyCabUrl_Click(object sender, RoutedEventArgs e) { ClientLogic clientLogic = this.DataContext as ClientLogic; Debug.Assert(clientLogic != null); DisplayCab selectedCab = listViewCabs.SelectedItem as DisplayCab; if ((selectedCab != null) && (clientLogic.CurrentEventPackage != null)) { Clipboard.SetText(StackHashUri.CreateUriString(UserSettings.Settings.CurrentContextId, clientLogic.CurrentEventPackage.ProductId, clientLogic.CurrentEventPackage.Id, clientLogic.CurrentEventPackage.EventTypeName, selectedCab.Id)); } }
/// <summary /> public bool SignalExternalCommandLineArgs(IList <string> args) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Other instance activation..."); // only take action if no owned windows are active if (this.MainWindow.OwnedWindows.Count == 0) { // activate the main window if (this.MainWindow != null) { if (this.MainWindow.WindowState == WindowState.Minimized) { this.MainWindow.WindowState = WindowState.Normal; } this.MainWindow.Activate(); } // parse the requested Uri (if present) and request navigation StackHashUri stackHashUri = null; if (StackHashUri.TryParse(args, out stackHashUri)) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, string.Format(CultureInfo.CurrentCulture, "Other instance requests navigation to {0}", stackHashUri.RawUri)); this.CurrentStackHashUri = stackHashUri; if (StackHashUriNavigationRequest != null) { StackHashUriNavigationRequest(this, EventArgs.Empty); } } } else { DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Other instance activation ignored as owned windows exist"); } return(true); }
/// <summary> /// Trys to parse a StackHashUri from command line arguments /// </summary> /// <param name="args">Command line arguments</param> /// <param name="uri">Returns the StackHashUri</param> /// <returns>True if a Uri was parsed</returns> public static bool TryParse(IList <string> args, out StackHashUri uri) { uri = null; bool ret = false; StackHashUri candidateUri = new StackHashUri(); if ((args != null) && args.Count > 1) { if (args.Count == 2) { candidateUri.RawUri = args[1]; } else { // spaces may have broken the URI into separate command line arguments StringBuilder sb = new StringBuilder(); for (int arg = 1; arg < args.Count; arg++) { sb.Append(args[arg]); sb.Append(" "); } candidateUri.RawUri = sb.ToString().Trim(); } // chrome (at least) doesn't seem to pass the protocol part so add it if needed if (candidateUri.RawUri.IndexOf("//", StringComparison.OrdinalIgnoreCase) == 0) { candidateUri.RawUri = "stackhash:" + candidateUri.RawUri; } // process any escaped space characters candidateUri.RawUri = candidateUri.RawUri.Replace("%20", " "); // check for stackHash:// if (candidateUri.RawUri.IndexOf("stackhash://", StringComparison.OrdinalIgnoreCase) == 0) { string[] uribits = candidateUri.RawUri.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (uribits.Length >= 2) { int contextId; if (Int32.TryParse(uribits[1], out contextId)) { // we at least have a context Id to load candidateUri.ContextId = contextId; ret = true; // try to parse further... if (uribits.Length >= 3) { // Product Id int productId; if (Int32.TryParse(uribits[2], out productId)) { candidateUri.ProductId = productId; if (uribits.Length >= 4) { // Event Id int eventId; string[] eventbits = uribits[3].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if ((eventbits.Length == 2) && (Int32.TryParse(eventbits[0], out eventId))) { candidateUri.EventId = eventId; candidateUri.EventType = eventbits[1]; if (uribits.Length >= 5) { // Cab Id int cabId; if (Int32.TryParse(uribits[4], out cabId)) { candidateUri.CabId = cabId; } } } } } } } } } } if (ret) { uri = candidateUri; } return(ret); }