/// ------------------------------------------------------------------------------------ /// <summary> /// Links to lexicon. /// </summary> /// ------------------------------------------------------------------------------------ internal void LinkToLexicon() { CheckDisposed(); int hvo = m_hvoSelected; if (hvo == 0 && m_rghvo != null && m_rghvo.Count > 0) { hvo = m_rghvo[0]; } // REVIEW: THIS SHOULD NEVER HAPPEN, BUT IF IT DOES, SHOULD WE TELL THE USER ANYTHING? if (hvo == 0) { return; } FwLink link = FwLink.Create("Language Explorer", "lexiconEdit", m_cache.GetGuidFromId(hvo), m_cache.ServerName, m_cache.DatabaseName); if (Application.ProductName == link.ApplicationName) { Debug.Assert(m_mediator != null, "If we're linking to same app, then the program must pass in a mediator!"); m_mediator.SendMessage("FollowLink", link); } else { link.Activate(); } }
/// <summary> /// called by the FwLink, which may be running in another application. /// </summary> /// <param name="link"></param> public void Request(FwLink link) { if (OnLinkRequest != null) { //trigger the event on anyone who has subscribed to it OnLinkRequest(link); } }
public override bool Equals(object obj) { FwLink link = obj as FwLink; if (link == null) { return(false); } if (link == this) { return(true); } //just compare the URLs return(ToString() == link.ToString()); }
/// <summary> /// a factory method which creates the listener and makes it start listening. /// </summary> /// <param name="appName"></param> /// <returns></returns> public static FwLinkReceiver StartReceiving(string appName, LinkEventHandler handler) { s_appName = appName; s_port = 6000; //broker.RegisterAndGetPort(appName); FwLinkReceiver.OnLinkRequest += handler; try { //.Net 2.0 introduced a security boolean here. //If set to true here, then when we try to do the //ChannelServices.Activate, it hangs until the program quits //then launches the app again. ChannelServices.RegisterChannel(new TcpChannel(s_port), false); } catch { throw new ApplicationException(Strings.ListenerPortTaken); } //nb: to future maintainers, be careful about deciding to release this port during some kind of destructor //nb: "there is a time delay for the system to release the port. It // is about 2 minutes. After that the port is free and you can reuse it." RemotingConfiguration.ApplicationName = appName; RemotingConfiguration.RegisterWellKnownServiceType(typeof(FwLinkReceiver), "receiver", WellKnownObjectMode.Singleton ); //although we don't really need to use it, we create this object now //so that we can preload with appropriate properties. string path = FwLink.GetPortPath(s_port, appName); FwLinkReceiver listener = (FwLinkReceiver)Activator.GetObject(typeof(FwLinkReceiver), path); if (listener == null) { throw new ApplicationException(Strings.CannotCreateListener); } return(listener); }
/// <summary> /// Some comparisons don't care about the content of the property table, so we provide a method /// similar to Equals but not quite as demanding. /// </summary> /// <param name="lnk"></param> /// <returns></returns> public bool EssentiallyEquals(FwLink lnk) { if (lnk == null) { return(false); } if (lnk == this) { return(true); } if (lnk.m_appName != this.m_appName) { return(false); } if (lnk.m_toolName != this.m_toolName) { return(false); } if (lnk.m_server != this.m_server) { return(false); } if (lnk.m_database != this.m_database) { return(false); } if (lnk.m_targetGuid != this.m_targetGuid) { return(false); } // tag is optional, but if a tool uses it with content, it should consistently provide content. // therefore if one of these links does not have content, and the other does then // we'll assume they refer to the same link // (one link simply comes from a control with more knowledge then the other one) return(lnk.m_tag.Length == 0 || this.m_tag.Length == 0 || lnk.m_tag == this.m_tag); }
/// <summary> /// Attempts to find or launch application which matches the url, and passes the link to that application. /// </summary> /// <param name="url"></param> /// <returns></returns> public static bool Activate(string url) { FwLink link = new FwLink(url); return link.Activate(); }
/// <summary> /// Some comparisons don't care about the content of the property table, so we provide a method /// similar to Equals but not quite as demanding. /// </summary> /// <param name="lnk"></param> /// <returns></returns> public bool EssentiallyEquals(FwLink lnk) { if (lnk == null) return false; if (lnk == this) return true; if (lnk.m_appName != this.m_appName) return false; if (lnk.m_toolName != this.m_toolName) return false; if (lnk.m_server != this.m_server) return false; if (lnk.m_database != this.m_database) return false; if (lnk.m_targetGuid != this.m_targetGuid) return false; // tag is optional, but if a tool uses it with content, it should consistently provide content. // therefore if one of these links does not have content, and the other does then // we'll assume they refer to the same link // (one link simply comes from a control with more knowledge then the other one) return lnk.m_tag.Length == 0 || this.m_tag.Length == 0 || lnk.m_tag == this.m_tag; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="LinkListener"/> class. /// </summary> /// ----------------------------------------------------------------------------------- public LinkListener() { m_backStack = new LinkedList<FwLink>(); m_forwardStack = new LinkedList<FwLink>(); m_currentContext = null; }
public void OnIncomingLink(FwLink link) { CheckDisposed(); if (m_rgMainWindows.Count == 0) return; FwXWindow wnd = m_rgMainWindows[0] as FwXWindow; Debug.Assert(wnd != null); wnd.Invoke(wnd.IncomingLinkHandler, new Object[]{link}); }
/// <summary> /// /// </summary> /// <returns></returns> public bool OnHistoryBack(object unused) { CheckDisposed(); if (m_backStack.Count > 0) { if (m_currentContext!= null) { Push(m_forwardStack, m_currentContext); } m_fUsingHistory = true; m_lnkActive = Pop(m_backStack); FollowActiveLink(); } return true; }
private void Push(LinkedList<FwLink> stack, FwLink context) { stack.AddLast(context); while (stack.Count > kmaxDepth) stack.RemoveFirst(); }
/// <summary> /// /// </summary> /// <returns></returns> public bool OnAddContextToHistory(object _link) { CheckDisposed(); //Debug.WriteLineIf(RuntimeSwitches.linkListenerSwitch.TraceInfo, "OnAddContextToHistory(" + m_currentContext + ")", RuntimeSwitches.linkListenerSwitch.DisplayName); FwLink lnk = (FwLink)_link; if (lnk.EssentiallyEquals(m_currentContext)) { //Debug.WriteLineIf(RuntimeSwitches.linkListenerSwitch.TraceInfo, " Link equals current context.", RuntimeSwitches.linkListenerSwitch.DisplayName); return true; } if (m_currentContext != null && //not where we just came from via a "Back" call ((m_forwardStack.Count == 0) || (m_currentContext != m_forwardStack.Last.Value))) { //Debug.WriteLineIf(RuntimeSwitches.linkListenerSwitch.TraceInfo, " Pushing current to back: " + m_currentContext, RuntimeSwitches.linkListenerSwitch.DisplayName); Push(m_backStack, m_currentContext); } // Try to omit intermediate targets which are added to the stack when switching // tools. This doesn't work in OnFollowLink() because the behavior of following // the link is not synchronous even when SendMessage is used at the first two // levels of handling. if (m_fFollowingLink && lnk.EssentiallyEquals(m_lnkActive)) { int howManyAdded = m_backStack.Count - m_cBackStackOrig; for( ; howManyAdded > 1; --howManyAdded) { m_backStack.RemoveLast(); } m_fFollowingLink = false; m_cBackStackOrig = 0; m_lnkActive = null; } // The forward stack should be cleared by jump operations that are NOT spawned by // a Back or Forward (ie, history) operation. This is the standard behavior in // browsers, for example (as far as I know). if (m_fUsingHistory) { if (lnk.EssentiallyEquals(m_lnkActive)) { m_fUsingHistory = false; m_lnkActive = null; } } else { m_forwardStack.Clear(); } m_currentContext = lnk; return true; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. if (m_mediator != null) { m_mediator.RemoveColleague(this); m_mediator.PropertyTable.SetProperty("LinkListener", null, false); m_mediator.PropertyTable.SetPropertyPersistence("LinkListener", false); } if (m_backStack != null) m_backStack.Clear(); if (m_forwardStack != null) m_forwardStack.Clear(); } // Dispose unmanaged resources here, whether disposing is true or false. m_mediator = null; m_currentContext = null; m_backStack = null; m_forwardStack = null; m_isDisposed = true; }
/// <summary> /// Attempts to find or launch application which matches the url, and passes the link to that application. /// </summary> /// <param name="url"></param> /// <returns></returns> public static bool Activate(string url) { FwLink link = new FwLink(url); return(link.Activate()); }
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { m_link = FwLink.Create("phonologicalFeaturesAdvancedEdit", m_cache.LangProject.PhFeatureSystemOA.Guid, m_cache.ServerName, m_cache.DatabaseName); m_btnCancel.PerformClick(); DialogResult = DialogResult.Ignore; }
/// <summary> /// /// </summary> /// <returns></returns> public bool OnHistoryForward(object unused) { CheckDisposed(); if (m_forwardStack.Count > 0) { m_fUsingHistory = true; m_lnkActive = Pop(m_forwardStack); FollowActiveLink(); } return true; }
/// <summary> /// called by the FwLink, which may be running in another application. /// </summary> /// <param name="link"></param> public void Request(FwLink link) { if (OnLinkRequest != null ) { //trigger the event on anyone who has subscribed to it OnLinkRequest(link); } }
/// <summary> /// /// </summary> /// <returns></returns> public bool OnFollowLink(object lnk) { CheckDisposed(); m_fFollowingLink = true; m_cBackStackOrig = m_backStack.Count; m_lnkActive = lnk as FwLink; bool b = FollowActiveLink(); return b; }
public void HandleIncomingLink(FwLink link) { CheckDisposed(); FwXWindow fwxwnd = null; string server = link.Server.Replace(".", Environment.MachineName); // = FwLink.RestoreServerFromURL(link.Server).Replace(".", Environment.MachineName); Debug.Assert(server != null && server != String.Empty); string database = link.Database; Debug.Assert(database != null && database != String.Empty); string key = MakeKey(server, database); if (!m_caches.ContainsKey(key)) { // Add command line info. Dictionary<string, List<String>> oldTable = m_commandLineArgs; // Save original args. m_commandLineArgs = new Dictionary<string, List<String>>(); List<String> list = new List<String>(); list.Add(server); m_commandLineArgs.Add("c", list); list = new List<String>(); list.Add(database); m_commandLineArgs.Add("db", list); list = new List<String>(); list.Add(link.ToString()); m_commandLineArgs.Add("link", list); Form frm = ActiveForm; fwxwnd = (FwXWindow)NewMainWindow(null, false); AdjustNewWindowPosition(fwxwnd, frm); m_commandLineArgs = oldTable; // Restore oringinal args. } else { FdoCache cache = m_caches[key]; // Get window that uses the given DB. foreach (FwXWindow wnd in m_rgMainWindows) { if (wnd.Cache == cache) { fwxwnd = wnd; break; } } } fwxwnd.Mediator.SendMessage("FollowLink", link); bool topmost = fwxwnd.TopMost; fwxwnd.TopMost = true; fwxwnd.TopMost = topmost; fwxwnd.Activate(); }
private void m_lblLink2_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { if (m_obj2 != null) { m_linkJump = m_obj2 as FwLink; m_linkCmd = m_obj2 as ChooserCommand; if (m_linkJump != null) { btnCancel.PerformClick(); // No result as such, but we'll perform a jump. this.DialogResult = DialogResult.Ignore; } else if (m_linkCmd != null) { btnOK.PerformClick(); } else { Debug.Assert(m_linkJump != null && m_linkCmd != null); } } }