Ejemplo n.º 1
0
        private void OnLightCurveAddinItemClick(object sender, EventArgs eventArgs)
        {
            ToolStripDropDownItem item = sender as ToolStripDropDownItem;

            if (item != null &&
                item.Tag != null)
            {
                ITangraAddinAction addinAction = item.Tag as ITangraAddinAction;

                if (addinAction != null && m_AddinManager != null)
                {
                    Control waitCursorCtl = item.GetCurrentParent();

                    m_DelegatedLightCurveDataProvider = new MarshalByRefLightCurveDataProvider(m_LocalLightCurveDataProvider);
                    m_AddinManager.SetLightCurveDataProvider(m_DelegatedLightCurveDataProvider);

                    string addinActonName = string.Empty;

                    if (waitCursorCtl != null) waitCursorCtl.Cursor = Cursors.WaitCursor;

                    try
                    {
                        addinActonName = addinAction.DisplayName;
                        bool isEventTimeExtrator = addinAction.ActionType == AddinActionType.LightCurveEventTimeExtractor;
                        bool isEventTimeExtratorSupportsBinning = addinAction.ActionType == AddinActionType.LightCurveEventTimeExtractorSupportsBinning;
                        bool canExecuteAction = false;

                        if (isEventTimeExtrator || isEventTimeExtratorSupportsBinning)
                            canExecuteAction = (m_LocalLightCurveDataProvider as frmLightCurve).PrepareForLightCurveEventTimeExtraction(addinActonName, isEventTimeExtratorSupportsBinning);
                        else
                            canExecuteAction = true;

                        if (canExecuteAction)
                        {
                            UsageStats.Instance.AddinActionsInvoked++;
                            UsageStats.Instance.Save();

                            addinAction.Execute();
                        }
                    }
                    catch (AppDomainUnloadedException)
                    { }
                    catch (ObjectDisposedException)
                    { }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.GetFullStackTrace());

                        MessageBox.Show(
                            string.Format("{0}:\r\n\r\n{1} ({2})",
                                addinActonName,
                                ex is TargetInvocationException ? ex.InnerException.Message : ex.Message,
                                ex is TargetInvocationException ? ex.InnerException.GetType().Name : ex.GetType().Name),
                            "Error running add-in",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                    finally
                    {
                        if (waitCursorCtl != null) waitCursorCtl.Cursor = Cursors.Default;
                    }

                }
            }
        }
Ejemplo n.º 2
0
 internal void SetLightCurveDataProvider(ILightCurveDataProvider provider)
 {
     m_LocalLightCurveDataProvider = provider;
     m_DelegatedLightCurveDataProvider = null;
 }