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


C# Session.Close方法代码示例

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


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

示例1: sendAddOrClose

        static void sendAddOrClose(Session<SessionData3> session)
        {
            Console.WriteLine("sendAddOrClose");
            if (RandomHelper.NextRandomInt(0, 6) == 2) {
                session.Close();
            }
            else {
                session.Data.a = RandomHelper.NextRandomInt(0, 1000000);
                session.Data.b = RandomHelper.NextRandomInt(0, 10000000);

                var sent = session.Data.a + "," + session.Data.b;
                session.Send(Encoding.Default.GetBytes(sent));
                Console.WriteLine("[messager2_DataSend], " + sent);
                Console.OpenStandardOutput().Flush();
            }
        }
开发者ID:ceeji,项目名称:CeejiCommonLibrary,代码行数:16,代码来源:MessagerTest2.cs

示例2: InvokeCustomAction

        public 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.IsNullOrWhiteSpace(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(CultureInfo.InvariantCulture,
                        "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:notgerry,项目名称:oneget,代码行数:98,代码来源:CustomActionProxy.cs

示例3: Decode


//.........这里部分代码省略.........
                                }
                                foundUrl = true;
                            }

                            if (!foundKey && !foundServerSign && oneline.Contains(WEBSOCK_CLIENT_HEADER_SIGN + ":"))
                            {
                                acceptKey = ComputeWebSocketHandshakeSecurityHash09(oneline.Substring(oneline.IndexOf(":") + 2));
                                foundKey = true;
                            }
                        }

                        if (acceptKey != null && acceptKey.Length > 0)
                            handshakeMsg = String.Format(WEBSOCK_HANDSHAKE_REPLY_MSG, acceptKey);

                        stream.Position = orgpos + checkedlen;

                        netMsg.ReceivingState = WebMessage.STATE_READY;
                        if (stack.Count > 0) stack.Pop();

                        netMsg.MessageContent = headerContent;
                        netMsg.MessageType = WebMessage.MSG_TYPE_HANDSHAKE;
                        output.Add(netMsg);
                        total++;

                        netMsg = new WebMessage();
                        netMsg.VirtualHeaderSize = 2;
                        stack.Push(netMsg);

                        if (handshakeMsg != null && handshakeMsg.Length > 0)
                            session.Send(handshakeMsg);
                    }
                    else
                    {
                        if (curpos > m_MaxMsgSize) session.Close();
                        else stream.Position = orgpos;
                        return false;
                    }
                }

                if (netMsg.ReceivingState == WebMessage.STATE_WAIT_FOR_BODY
                    && stream.Length - stream.Position >= netMsg.ContentSize)
                {
                    Byte[] bytes = new Byte[netMsg.ContentSize];
                    stream.Read(bytes, 0, netMsg.ContentSize);

                    netMsg.RawContent = bytes;

                    netMsg.ReceivingState = WebMessage.STATE_READY;
                    if (stack.Count > 0) stack.Pop();

                    output.Add(netMsg);
                    total++;

                    netMsg = new WebMessage();
                    netMsg.VirtualHeaderSize = 2;
                    stack.Push(netMsg);
                }

            }

            while (netMsg.ReceivingState == WebMessage.STATE_WAIT_FOR_HEADER
                    && stream.Length - stream.Position >= netMsg.VirtualHeaderSize)
            {
                if (netMsg.ReceivingState == WebMessage.STATE_WAIT_FOR_HEADER)
                {
                    if (stream.Length - stream.Position >= netMsg.VirtualHeaderSize)
开发者ID:joelam789,项目名称:sharp-network,代码行数:67,代码来源:MessageCodec.cs

示例4: messager_IncomingConnectionEstablished

        static void messager_IncomingConnectionEstablished(Messager<SessionData> sender, Session<SessionData> e)
        {
            Console.WriteLine("New Connection, Time = {0}, EndPoint = {1}", e.BeginTime, e.EndPoint);
            e.Data.Messager = new TcpMessager<SessionData2>();
            e.Data.Messager.DataReceived += (m, conn, data) => {
                sender.Send(e, data);
            };
            e.Data.Messager.SendError += Messager_SendError;
            e.Data.Messager.SessionEnded += (m, conn) => {
                Console.WriteLine("Connection Closed");
                e.Data.Messager = null;
                e.Close();
            };
            e.Data.Messager.Connect(new IPEndPoint(System.Net.IPAddress.Parse("121.201.7.41"), 80), (m, conn, ex) => {
                if (conn != null) {
                    e.Data.Connection = conn;

                    lock (e.Data) {
                        if (e.Data.Buffer != null) {
                            conn.Send(new ArraySegment<byte>(e.Data.Buffer, 0, e.Data.Buffer.Length));
                        }
                    }
                }
            });
        }
开发者ID:ceeji,项目名称:CeejiCommonLibrary,代码行数:25,代码来源:TcpMessagerTest.cs


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