当前位置: 首页>>代码示例>>C#>>正文


C# Session.Close方法代码示例

本文整理汇总了C#中Microsoft.Deployment.WindowsInstaller.Session.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Close方法的具体用法?C# Session.Close怎么用?C# Session.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Deployment.WindowsInstaller.Session的用法示例。


在下文中一共展示了Session.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeCustomAction

        internal static int InvokeCustomAction(int sessionHandle, string entryPoint,
            IntPtr remotingDelegatePtr)
        {
            Session session = null;
            string assemblyName, className, methodName;
            MethodInfo method;

            try
            {
                MsiRemoteInvoke remotingDelegate = (MsiRemoteInvoke)
                    Marshal.GetDelegateForFunctionPointer(
                        remotingDelegatePtr, typeof(MsiRemoteInvoke));
                RemotableNativeMethods.RemotingDelegate = remotingDelegate;

                sessionHandle = RemotableNativeMethods.MakeRemoteHandle(sessionHandle);
                session = new Session((IntPtr) sessionHandle, false);
                if (String.IsNullOrEmpty(entryPoint))
                {
                    throw new ArgumentNullException("entryPoint");
                }

                if (!CustomActionProxy.FindEntryPoint(
                    session,
                    entryPoint,
                    out assemblyName,
                    out className,
                    out methodName))
                {
                    return (int) ActionResult.Failure;
                }
                session.Log("Calling custom action {0}!{1}.{2}", assemblyName, className, methodName);

                method = CustomActionProxy.GetCustomActionMethod(
                    session,
                    assemblyName,
                    className,
                    methodName);
                if (method == null)
                {
                    return (int) ActionResult.Failure;
                }
            }
            catch (Exception ex)
            {
                if (session != null)
                {
                    try
                    {
                        session.Log("Exception while loading custom action:");
                        session.Log(ex.ToString());
                    }
                    catch (Exception) { }
                }
                return (int) ActionResult.Failure;
            }

            try
            {
                // Set the current directory to the location of the extracted files.
                Environment.CurrentDirectory =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                object[] args = new object[] { session };
                if (DebugBreakEnabled(new string[] { entryPoint, methodName }))
                {
                    string message = String.Format(
                        "To debug your custom action, attach to process ID {0} (0x{0:x}) and click OK; otherwise, click Cancel to fail the custom action.",
                        System.Diagnostics.Process.GetCurrentProcess().Id
                        );

                    MessageResult button = NativeMethods.MessageBox(
                        IntPtr.Zero,
                        message,
                        "Custom Action Breakpoint",
                        (int)MessageButtons.OKCancel | (int)MessageIcon.Asterisk | (int)(MessageBoxStyles.TopMost | MessageBoxStyles.ServiceNotification)
                        );

                    if (MessageResult.Cancel == button)
                    {
                        return (int)ActionResult.UserExit;
                    }
                }

                ActionResult result = (ActionResult) method.Invoke(null, args);
                session.Close();
                return (int) result;
            }
            catch (InstallCanceledException)
            {
                return (int) ActionResult.UserExit;
            }
            catch (Exception ex)
            {
                session.Log("Exception thrown by custom action:");
                session.Log(ex.ToString());
                return (int) ActionResult.Failure;
            }
        }
开发者ID:jonnybest,项目名称:coapp,代码行数:98,代码来源:CustomActionProxy.cs


注:本文中的Microsoft.Deployment.WindowsInstaller.Session.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。