Beispiel #1
0
 public static IListerHandlerBuilder GetListerHandlerBuilder(string wrapperAssembly)
 {
     try {
         TcPluginLoadingInfo loadingInfo = FindPluginLoadingInfoByWrapperFileName(wrapperAssembly);
         if (loadingInfo != null)
         {
             TcPlugin plugin = loadingInfo.Plugin;
             if (plugin != null && plugin is ListerPlugin)
             {
                 IListerHandlerBuilder lhBuilder = null;
                 string guiType = plugin.Settings["guiType"];
                 if (String.IsNullOrEmpty(guiType) ||
                     guiType.Equals(ListerPlugin.WFListerHandlerBuilderName))
                 {
                     lhBuilder = new WFListerHandlerBuilder();
                 }
                 else if (guiType.Equals(ListerPlugin.WPFListerHandlerBuilderName))
                 {
                     lhBuilder = new WPFListerHandlerBuilder();
                 }
                 if (lhBuilder != null)
                 {
                     lhBuilder.Plugin = (ListerPlugin)plugin;
                     return(lhBuilder);
                 }
             }
         }
     } catch { }
     return(null);
 }
Beispiel #2
0
        public static void FillLoadingInfo(TcPlugin plugin)
        {
            TcPluginLoadingInfo loadingInfo =
                FindPluginLoadingInfoByWrapperFileName(plugin.WrapperFileName);

            if (loadingInfo != null)
            {
                loadingInfo.PluginNumber = plugin.PluginNumber;
                if (plugin.Password != null)
                {
                    loadingInfo.CryptoNumber = plugin.Password.GetCryptoNumber();
                    loadingInfo.CryptoFlags  = plugin.Password.GetFlags();
                }
                if (plugin is FsPlugin)
                {
                    loadingInfo.UnloadExpired = ((FsPlugin)plugin).UnloadExpired;
                }
            }
        }
Beispiel #3
0
        public static PluginLifetimeStatus CheckPluginLifetimeStatus(Exception ex)
        {
            Boolean pluginDisconnected =
                (ex is RemotingException) && (ex.Message.EndsWith(LifetimeExpiredMsgEnd));

            if (!pluginDisconnected)
            {
                return(PluginLifetimeStatus.Active);
            }

            string pluginWrapperFile        = Assembly.GetCallingAssembly().Location;
            TcPluginLoadingInfo loadingInfo = FindPluginLoadingInfoByWrapperFileName(pluginWrapperFile);

            if (loadingInfo == null)
            {
                return(PluginLifetimeStatus.NotLoaded);
            }

            StackTrace stackTrace = new StackTrace(true);

#if TRACE
            string category = loadingInfo.PluginNumber.ToString(CultureInfo.InvariantCulture);
            string text;
#endif
            var stackFrames = stackTrace.GetFrames();
            if (stackFrames != null)
            {
                foreach (StackFrame sf in stackFrames)
                {
                    Type declaringType = sf.GetMethod().DeclaringType;
                    if (declaringType != null &&
                        (declaringType.FullName.StartsWith("OY.TotalCommander.WfxWrapper") &&
                         !sf.GetMethod().Name.Equals("ProcessException")))
                    {
#if TRACE
                        text = String.Format(TraceMsg15, declaringType.FullName.Substring(29), sf.GetMethod().Name);
                        TraceError(text, category);
#endif
                        break;
                    }
                }
            }

            // Plugin remote object has expired, try to unload plugin AppDomain
            loadingInfo.LifetimeStatus = PluginLifetimeStatus.Expired;
            if (loadingInfo.UnloadExpired)
            {
                AppDomain pluginDomain = loadingInfo.Domain;
                try {
                    AppDomain.Unload(pluginDomain);
#if TRACE
                    text = "Plugin Lifetime Expired - Plugin \"" + pluginWrapperFile + "\" was disconnected from TC.";
                    TraceError(text, category);
#endif
                    MessageBox.Show(
                        "Plugin " + Path.GetFileNameWithoutExtension(pluginWrapperFile)
                        + " has expired and was disconnected From TC.",
                        "Plugin disconnected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    OpenTcPluginHome();
                    loadingInfo.LifetimeStatus = PluginLifetimeStatus.PluginUnloaded;
                } catch (Exception e) {
#if TRACE
                    text = "Unload ERROR: " + e.Message;
                    TraceError(text, category);
#endif
                }
            }
            else
            {
                MessageBox.Show(
                    "Plugin " + Path.GetFileNameWithoutExtension(pluginWrapperFile) + " has expired.",
                    "Plugin expired", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(loadingInfo.LifetimeStatus);
        }
Beispiel #4
0
        public static TcPlugin GetTcPlugin(string wrapperAssembly, PluginType pluginType)
        {
            pluginSettings = GetPluginSettings(wrapperAssembly);
#if TRACE
            writeTrace = Convert.ToBoolean(pluginSettings["writeTrace"]);
            TraceOut(String.Format(TraceMsg1, wrapperAssembly), TraceMsg2);
#endif
            TcPlugin tcPlugin;
            try {
                string pluginAssembly = pluginSettings["pluginAssembly"];
                if (String.IsNullOrEmpty(pluginAssembly))
                {
                    pluginAssembly = Path.ChangeExtension(wrapperAssembly, ".dll");
                }
                string wrapperFolder = Path.GetDirectoryName(wrapperAssembly);
                if (!Path.IsPathRooted(pluginAssembly))
                {
                    pluginAssembly = Path.Combine(wrapperFolder, pluginAssembly);
                }
#if TRACE
                TraceOut(pluginAssembly, TraceMsg3);
#endif
                string pluginFolder = Path.GetDirectoryName(pluginAssembly);
                pluginSettings["pluginFolder"] = pluginFolder;
                string    pluginAssemblyName = Path.GetFileNameWithoutExtension(pluginAssembly);
                string    title = pluginSettings["pluginTitle"] ?? pluginAssemblyName;
                AppDomain pluginDomain;
                bool      useSeparateDomain = !Convert.ToBoolean(pluginSettings["startInDefaultDomain"]);
                if (useSeparateDomain)
                {
                    pluginDomain = CreatePluginAppDomain(pluginAssembly, title);
                }
                else
                {
                    pluginDomain = MainDomain;
                    MainDomain.AssemblyResolve += MainDomainResolveEventHandler;
#if TRACE
                    TraceOut(null, "Load into Default AppDomain.");
#endif
                }

                string pluginClassName = pluginSettings["pluginClass"];
                // Create object implemented required TC plugin interface.
                tcPlugin = CreateTcPluginStub(pluginDomain, pluginAssembly, pluginType, null, ref pluginClassName);
                if (tcPlugin == null)
                {
                    if (String.IsNullOrEmpty(pluginClassName))
                    {
                        throw new InvalidOperationException(ErrorMsg2);
                    }
                }
                else
                {
                    tcPlugin.MainDomain = MainDomain;
#if TRACE
                    TraceOut(String.Format(TraceMsg6, tcPlugin.Title, pluginClassName),
                             String.Format(TraceMsg7, TcUtils.PluginNames[pluginType]));
#endif
                }
                // File System plugins only - try to load content plugin associated with current FS plugin
                if (pluginType == PluginType.FileSystem)
                {
                    string contentAssembly = pluginSettings.ContainsKey("contentAssembly") ?
                                             pluginSettings["contentAssembly"] : pluginAssembly;
                    if (!String.IsNullOrEmpty(contentAssembly))
                    {
                        if (!Path.IsPathRooted(contentAssembly))
                        {
                            contentAssembly = Path.Combine(wrapperFolder, contentAssembly);
                        }
                        string contentClassName = pluginSettings["contentClass"];
#if TRACE
                        TraceOut(contentAssembly, TraceMsg8);
#endif

                        // Create object implemented Content plugin interface.
                        // Full FS plugin class name (with assembly name)
                        // is passed as "masterClassName" parameter.
                        string fullPluginClassName = pluginClassName + ", " + pluginAssembly;
                        try {
                            ContentPlugin cntPlugin = (ContentPlugin)CreateTcPluginStub(pluginDomain,
                                                                                        contentAssembly, PluginType.Content, fullPluginClassName, ref contentClassName);
                            FsPlugin fsPlugin = (FsPlugin)tcPlugin;
                            if (fsPlugin != null)
                            {
                                if (cntPlugin == null)
                                {
                                    if (String.IsNullOrEmpty(contentClassName))
                                    {
                                        // No implementation for Content plugin interface
#if TRACE
                                        TraceOut(null, TraceMsg9);
#endif
                                    }
                                    else if (pluginClassName.Equals(contentClassName))
                                    {
                                        // Content plugin interface is implemented in found FS plugin class
                                        try {
                                            cntPlugin = (ContentPlugin)tcPlugin;
                                            cntPlugin.PluginNumber = fsPlugin.PluginNumber;
                                            fsPlugin.ContentPlgn   = cntPlugin;
#if TRACE
                                            TraceOut(null, TraceMsg10);
#endif
                                        } catch (InvalidCastException) { }
                                    }
                                }
                                else
                                {
                                    cntPlugin.PluginNumber = fsPlugin.PluginNumber;
                                    fsPlugin.ContentPlgn   = cntPlugin;
#if TRACE
                                    TraceOut(String.Format(TraceMsg11, contentClassName), TraceMsg12);
#endif
                                }
                            }
                        } catch (Exception ex) {
#if TRACE
                            TraceOut(String.Format(TraceMsg13, contentClassName, ex.Message), String.Empty);
#endif
                        }
                    }
                }
                if (useSeparateDomain)
                {
                    tcPlugin.TcPluginEventHandler += HandleTcPluginEvent;
                }
                else
                {
                    tcPlugin.TcPluginEventHandler += TcCallback.HandleTcPluginEvent;
                }
                tcPlugin.WrapperFileName = wrapperAssembly;
                TcPluginLoadingInfo loadingInfo = FindPluginLoadingInfoByWrapperFileName(wrapperAssembly);
                if (loadingInfo == null)
                {
                    loadedPlugins.Add(new TcPluginLoadingInfo(wrapperAssembly, tcPlugin, pluginDomain));
                }
                else
                {
                    if (loadingInfo.LifetimeStatus == PluginLifetimeStatus.PluginUnloaded)
                    {
                        tcPlugin.PluginNumber = loadingInfo.PluginNumber;
                        tcPlugin.CreatePassword(loadingInfo.CryptoNumber, loadingInfo.CryptoFlags);

                        loadingInfo.LifetimeStatus = PluginLifetimeStatus.Active;
                        loadingInfo.Plugin         = tcPlugin;
                        loadingInfo.Domain         = pluginDomain;
#if TRACE
                        TraceOut(String.Format(TraceMsg14, tcPlugin.Title), String.Empty);
#endif
                    }
                }
            } finally {
#if TRACE
                writeTrace = false;
#endif
            }
            return(tcPlugin);
        }