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


C# Connection.Connect方法代码示例

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


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

示例1: buttonSubmit_Click

        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            using (Connection conn = new Connection("myConn"))
            {
                conn.Connect(textBoxServer.Text);
                conn.LogOn(textBoxUsername.Text, textBoxPassword.Text);

                DBObject dbObj = null;

                try
                {
                    int id = Convert.ToInt32(textBoxID.Text);
                    dbObj = conn.GetObject(new ObjectId(id));
                    if (dbObj == null) throw new Exception("Invalid object ID.");
                    if (!dbObj.IsGroup) throw new Exception("Object is not a group.");
                }

                catch (FormatException ex)
                {
                    MessageBox.Show("Enter a valid object ID.");
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }

                if (dbObj.ClassDefinition.Name == "CTemplateInstance") ProcessInstance(dbObj);
                else if (dbObj.ClassDefinition.Name == "CTemplate") ProcessTemplate(dbObj);

                conn.LogOff();
                conn.Disconnect();
            }
        }
开发者ID:RPayumo,项目名称:ClearSCADA_Utilities,代码行数:35,代码来源:ClearSCADA+Utilities.cs

示例2: GetPooldConncetion

 private Connection GetPooldConncetion()
 {
     Connection result = null;
     lock ((idle as ICollection).SyncRoot)
     {
         if (idle.Count>0)
             result = idle.Pop();
         if (result!=null && (int)(DateTime.Now - result.LastUseTime).TotalSeconds > FDFSConfig.Connection_LifeTime)
         {
             foreach (Connection conn in idle)
             {
                 conn.Close();
             }
             idle = new Stack<Connection>(maxConnection);
             result = null;
         }
     }
     lock ((inUse as ICollection).SyncRoot)
     {
         if (inUse.Count == maxConnection)
             return null;                    
         if (result == null)
         {
             result = new Connection();
             result.Connect(endPoint);
             result.Pool = this;
         }
         inUse.Add(result);
     }
     return result;
 }
开发者ID:HouZhiHouJue,项目名称:FastDFS.Net,代码行数:31,代码来源:ConnectionManager.cs

示例3: ImportFromSite

        private void ImportFromSite()
        {
            err.Clear();
            if (string.IsNullOrWhiteSpace(txtAccessPoint.Text))
            {
                err.SetError(txtAccessPoint, "主機位置不可空白");
                return;
            }

            Connection connection = new Connection();
            connection.EnableSecureTunnel= true;
            try
            {
                connection.Connect(txtAccessPoint.Text, txtContract.Text, txtUserName.Text, txtPassword.Text);
            }
            catch (Exception ex)
            {
                err.SetError(txtAccessPoint, "主機連線失敗 : \n" + ex.Message);
                return;
            }

            XmlHelper h = new XmlHelper();
            h.AddElement(".","ApplicationName","shared");
            Envelope env = new Envelope(h);
            
            env = connection.SendRequest("Server.ExportApplication", env);
            h = new XmlHelper(env.Body);
            Console.WriteLine(h.XmlString);
            this.Import(h.GetElement("."));
        }
开发者ID:lidonghao1116,项目名称:ProjectManager,代码行数:30,代码来源:ImportFromPhysicalForm.cs

示例4: GetConnection

        /// <summary>
        /// 用Passport連線至AccessPoint,並傳回對應的連線資訊;並且會放到連線區中,之後可重覆使用。OK
        /// </summary>
        /// <param name="AccessPoint"></param>
        /// <returns></returns>
        public static Tuple<Connection, string> GetConnection(string AccessPoint, string ContractName)
        {
            if (mConnections == null)
                mConnections = new Dictionary<string, Connection>();

            if (mTimers == null)
                mTimers = new List<Timer>();

            if (mConnections.ContainsKey(AccessPoint))
                return new Tuple<Connection, string>(mConnections[AccessPoint], string.Empty);

            try
            {
                #region Connection一開始會用Passport連線,之後強制使用Session連線,並定期送Request確保Session不會過期
                Connection vConnection = new Connection();
                vConnection.EnableSession = true;
                vConnection.Connect(AccessPoint, ContractName, FISCA.Authentication.DSAServices.AccessPoint, FISCA.Authentication.DSAServices.AccessPoint);

                //Timer mTimer = new Timer(x =>
                //{
                //    vConnection.SendRequest("DS.Base.Connect", new Envelope());
                //}, null, 9000 * 60, 9000 * 60);

                //mTimers.Add(mTimer);

                mConnections.Add(AccessPoint, vConnection);
                #endregion

                return new Tuple<Connection, string>(vConnection, string.Empty);
            }
            catch (Exception ve)
            {
                return new Tuple<Connection, string>(null, "無法連線至『" + AccessPoint + "』主機" + System.Environment.NewLine + "訊息:『" + ve.Message + "』");
            }
        }
开发者ID:ischool-desktop,项目名称:KHJH_CentralOffice,代码行数:40,代码来源:ContractServices.cs

示例5: Right

 public static void Right()
 {
     Connection connection = new Connection();
     connection.ConnectionString = "DataSource=//MyMachine";
     connection.Connect();
     connection.Disconnect();
 }
开发者ID:michaellperry,项目名称:Provable-APIs,代码行数:7,代码来源:4-Immutability.cs

示例6: btnTest_Click

        private void btnTest_Click(object sender, EventArgs e)
        {
            txtInfo.Text = string.Empty;
            txtUserInfo.Text = string.Empty;
            txtPassport.Text = string.Empty;

            Connection con = new Connection();
            con.EnableSession = false;
            con.EnableSecureTunnel = true;
            SecurityToken stt = null;
            try
            {
                stt = this.GetSecurityToken();
                con.Connect(MainForm.CurrentProject.DevSite.AccessPoint, _contract.Name, stt);
                txtInfo.Text = "連線成功";                
            }
            catch (Exception ex)
            {
                txtInfo.Text = "連線失敗 : \n" + ex.Message;
                return;
            }
                        
            try
            {
                Envelope env = con.SendRequest("DS.Base.Connect", new Envelope());
                txtUserInfo.Text = env.Headers["UserInfo"];
                xmlSyntaxLanguage1.FormatDocument(txtUserInfo.Document);
            }
            catch 
            {               
            }
        }
开发者ID:lidonghao1116,项目名称:ProjectManager,代码行数:32,代码来源:ContractTestForm.cs

示例7: Main

    /** A simple test case. Invoke with a number of group names.
     * Each member will cast the group name every second.
     */
    public static void Main(string[] args)
    {
        int i;
        ParseCmdLine (args);
        conn = new Connection ();
        conn.Connect();

        // Create an initial set of endpoints
        memb_a = new Member[nmembers];
        for(i=0; i<nmembers; i++)
            CreateEndpt (i);

        // The main loop
        while(true) {
            // While there are pending messages --- read them
            while (conn.Poll ()) {
                Message msg = conn.Recv ();
                HandleMsg(msg);
                Console.Out.Flush();
            }

            // Sleep for a while
            Thread.Sleep(sleep_timeout);

            // Generate some random actions, one for each member.
            for (i=0; i<nmembers; i++)
                RandAction(i);
        }
    }
开发者ID:Tipoca,项目名称:ensemble,代码行数:32,代码来源:Rand.cs

示例8: Main

 static void Main(string[] args)
 {
     myList<byte> msgs;
     string strmsg;
     Connection cc = new Connection();
     cc.Connect();
     Connection sc = new Connection("chat.facebook.com");
     sc.Connect();
     while (true)
     {
         strmsg = "";
         msgs = cc.GetMessages();
         if ((msgs != null) && (msgs.Count > 0))
         {
             strmsg = ConvertMsgToString(msgs);
             sc.Send(msgs);
         }
         msgs = sc.GetMessages();
         if ((msgs != null) && (msgs.Count > 0))
         {
             strmsg = ConvertMsgToString(msgs);
             cc.Send(msgs);
         }
         if (strmsg.Length > 0)
         {
             Console.WriteLine(strmsg);
         }
         if (strmsg.Contains("proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\""))
         {
             cc.StartTls();
             sc.StartTls();
         }
     }
 }
开发者ID:leader80,项目名称:xmpproxy,代码行数:34,代码来源:Program.cs

示例9: TryConnect

 internal Connection TryConnect()
 {
     Connection connection = new Connection();
     connection.EnableSession = false;
     connection.EnableSecureTunnel = true;
     connection.Connect(AccessPoint, ContractName, User, Password);
     return connection;
 }
开发者ID:lidonghao1116,项目名称:ProjectManager,代码行数:8,代码来源:DevSiteLoginInfo.cs

示例10: Register

 public void Register(UserMOD userMOD)
 {
     using (_conn = new Connection<UserMOD>())
     {
         _conn.Connect("mongodb://localhost", "napegada", "user")
              .Insert(userMOD);
     }
 }
开发者ID:nicholas-brandao,项目名称:napegada,代码行数:8,代码来源:UserREP.cs

示例11: GetByMail

 public UserMOD GetByMail(string mail)
 {
     using (_conn = new Connection<UserMOD>())
     {
         return _conn.Connect("mongodb://localhost", "napegada", "user")
                     .FindOne(Query.EQ("Mail", mail));
     }
 }
开发者ID:nicholas-brandao,项目名称:napegada,代码行数:8,代码来源:UserREP.cs

示例12: GetById

 public UserMOD GetById(ObjectId id)
 {
     using (_conn = new Connection<UserMOD>())
     {
         return _conn.Connect("mongodb://localhost", "napegada", "user")
                     .FindOne(Query.EQ("_id", id));
     }
 }
开发者ID:nicholas-brandao,项目名称:napegada,代码行数:8,代码来源:UserREP.cs

示例13: GetConnection

        protected Connection GetConnection()
        {
            // Open database connection
            string dsn = "Server=127.0.0.1;Port=3306;Initial Catalog=test;User Id=root;Password=;CharSet=utf8;Allow User Variables=True";

            Connection db = new Connection();
            db.Connect(dsn);
            return db;
        }
开发者ID:odan,项目名称:poco-query-builder,代码行数:9,代码来源:BaseTest.cs

示例14: IsUser

 public bool IsUser(UserMOD userMOD)
 {
     using (_conn = new Connection<UserMOD>())
     {
         return _conn.Connect("mongodb://localhost", "napegada", "user")
                 .AsQueryable<UserMOD>()
                 .Any(u => u.Mail.Equals(userMOD.Mail) && u.Password.Equals(userMOD.Password));
     }
 }
开发者ID:nicholas-brandao,项目名称:napegada,代码行数:9,代码来源:UserREP.cs

示例15: Update

 public void Update(UserMOD userMOD, ObjectId id)
 {
     using (_conn = new Connection<UserMOD>())
     {
         _conn.Connect("mongodb://localhost", "napegada", "user")
              .Update(Query<UserMOD>.EQ(u => u.Id, id), Update<UserMOD>.Set(u => u.NameFile, userMOD.NameFile)
                                                                        .Set(u => u.Password, userMOD.Password)
                                                                        .Set(u => u.Name, userMOD.Name));
     }
 }
开发者ID:nicholas-brandao,项目名称:napegada,代码行数:10,代码来源:UserREP.cs


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