/// <summary> /// This is the connect function. This function must be called before talking to any remote tester. /// </summary> /// <param name="urlAddress"></param> /// <param name="userID"></param> /// <param name="password"></param> /// <param name="netTcp">true</param> /// <param name="tobj"></param> /// <param name="tobjStr"></param> /// <returns></returns> private UInt32 Connect(string urlAddress, string userID, string password, bool netTcp, bool tobj, bool tobjStr) { nlogger.Info("RemoteConnectLib::Connect start [url:{0}] [userID:{1}] [password:[2]][netTcp:{3}][tobj:{4}][tobjStr:{5}]", urlAddress, userID, password, netTcp, tobj, tobjStr); UInt32 retVal = 0; nlogger.Info("RemoteConnectLib::Connect [ConnectBusy:{0}]", _BusyConnecting); // TODO:Determine whether the connection has been made, or reconnect put to keep alive function. // _BusyConnecting keep only one connect operation in one class. if (!_BusyConnecting) { _BusyConnecting = true; // The reconnect uses these. _CurrentUrlAddress = urlAddress; _CurrentUserID = userID; _CurrentPassword = password; _CurrentNetTcpConnectFlag = netTcp; // Build the complete path string strUrl = MakeupCompleteUrl(urlAddress, netTcp); string strStreamUrl = MakeupCompleteStreamingUrl(strUrl, netTcp); nlogger.Info("RemoteConnectLib::Connect [strUrl:{0}] [strStreamUrl:{0}]", strUrl, strStreamUrl); // Add connect function try { // Init channel factory InitChannelFactory(strUrl, strStreamUrl, netTcp, tobj, tobjStr); nlogger.Info("RemoteConnectLib::Connect [Factory:{0}]", _Factory.ToString()); // Create channel and open service. if (tobj) { _TesterObject = _Factory.CreateChannel(); CommunicationState chanState = ((System.ServiceModel.ICommunicationObject)_TesterObject).State; if (chanState != CommunicationState.Opened) { ((System.ServiceModel.ICommunicationObject)_TesterObject).Open(); } } if (tobjStr) { // TODO : testObjectStreaming } } catch (WebException ex) { nlogger.Error("RemoteConnectLib::Connect Create Channel WebException [Exception :{0}]", ex.Message); retVal = (UInt32)ReturnValues.connectionBad; } catch (Exception ex) { // TODO : Add log information. nlogger.Error("RemoteConnectLib::Connect Create Channel exception [Exception :{0}]", ex.Message); retVal = (UInt32)ReturnValues.connectionBad; } // TODO : Add tester object streaming if (_Factory == null || _TesterObject == null) { nlogger.Error("RemoteConnectLib::Connect failed to attach event to remote server [URL:{0}]", strUrl); retVal = (UInt32)ReturnValues.connectionBad; } if (retVal != (UInt32)ReturnValues.connectionBad) { try { // This will add our proxy to testerObject's callback list. retVal = _TesterObject.Connect(userID, "", _OurName); //string what = ((System.ServiceModel.ICommunicationObject)Obj).State.ToString(); } catch (WebException ex) { nlogger.Error("RemoteConnectLib::Connect Create Channel WebException [Exception :{0}]", ex.Message); retVal = (UInt32)ReturnValues.connectionBad; } catch (Exception ex) { // TODO : Add log information. nlogger.Error("RemoteConnectLib::Connect Create Channel exception [Exception :{0}]", ex.Message); retVal = (UInt32)ReturnValues.connectionBad; } if ((retVal & (int)ReturnValues.bladeAccessBit) != 0) { string cached = urlAddress.Replace(":" + Constants.WcfBladePort.ToString() + "/TesterObject", ""); if (!Connections.ContainsKey(cached)) { Connections.Add(cached, this); } else { Connections[cached] = this; } _Connected = true; _KeepAliveArrived = true; } } } // TODO : no use now, but we can use it. // pop event to notify that we successfully connected to the wcf service. //if (retVal == (UInt32)Hitachi.Tester.Enums.ReturnValues.bladeAccessBit) //{ // EventHandler handler = ConnectedToRemote; // if (handler != null) // { // MethodInvoker del = delegate { handler(this, new EventArgs()); }; // del.BeginInvoke(null, null); // } //} _BusyConnecting = false; return(retVal); }