Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: private void HandleAuthResponse(OperationResponse operationResponse)
{
((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " on: " + this.NameServerAddress);
if (operationResponse.ReturnCode == 0)
{
if (this.State == ChatState.ConnectedToNameServer)
{
this.State = ChatState.Authenticated;
this.listener.OnChatStateChange(this.State);
if (operationResponse.Parameters.ContainsKey(ParameterCode.Secret))
{
if (this.CustomAuthenticationValues == null)
{
this.CustomAuthenticationValues = new AuthenticationValues();
}
this.CustomAuthenticationValues.Secret = operationResponse[ParameterCode.Secret] as string;
this.FrontendAddress = (string) operationResponse[ParameterCode.Address];
// we disconnect and status handler starts to connect to front end
this.chatPeer.Disconnect();
}
else
{
//TODO: error reaction!
}
}
else if (this.State == ChatState.ConnectingToFrontEnd)
{
this.msDeltaForServiceCalls = this.msDeltaForServiceCalls * 4; // when we arrived on chat server: limit Service calls some more
this.State = ChatState.ConnectedToFrontEnd;
this.listener.OnChatStateChange(this.State);
this.listener.OnConnected();
}
}
else
{
//((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " NS: " + this.NameServerAddress + " FrontEnd: " + this.frontEndAddress);
switch (operationResponse.ReturnCode)
{
case ErrorCode.InvalidAuthentication:
this.DisconnectedCause = ChatDisconnectCause.InvalidAuthentication;
break;
case ErrorCode.CustomAuthenticationFailed:
this.DisconnectedCause = ChatDisconnectCause.CustomAuthenticationFailed;
break;
case ErrorCode.InvalidRegion:
this.DisconnectedCause = ChatDisconnectCause.InvalidRegion;
break;
case ErrorCode.MaxCcuReached:
this.DisconnectedCause = ChatDisconnectCause.MaxCcuReached;
break;
case ErrorCode.OperationNotAllowedInCurrentState:
this.DisconnectedCause = ChatDisconnectCause.OperationNotAllowedInCurrentState;
break;
}
this.State = ChatState.Disconnecting;
this.chatPeer.Disconnect();
}
}
{
((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " on: " + this.NameServerAddress);
if (operationResponse.ReturnCode == 0)
{
if (this.State == ChatState.ConnectedToNameServer)
{
this.State = ChatState.Authenticated;
this.listener.OnChatStateChange(this.State);
if (operationResponse.Parameters.ContainsKey(ParameterCode.Secret))
{
if (this.CustomAuthenticationValues == null)
{
this.CustomAuthenticationValues = new AuthenticationValues();
}
this.CustomAuthenticationValues.Secret = operationResponse[ParameterCode.Secret] as string;
this.FrontendAddress = (string) operationResponse[ParameterCode.Address];
// we disconnect and status handler starts to connect to front end
this.chatPeer.Disconnect();
}
else
{
//TODO: error reaction!
}
}
else if (this.State == ChatState.ConnectingToFrontEnd)
{
this.msDeltaForServiceCalls = this.msDeltaForServiceCalls * 4; // when we arrived on chat server: limit Service calls some more
this.State = ChatState.ConnectedToFrontEnd;
this.listener.OnChatStateChange(this.State);
this.listener.OnConnected();
}
}
else
{
//((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " NS: " + this.NameServerAddress + " FrontEnd: " + this.frontEndAddress);
switch (operationResponse.ReturnCode)
{
case ErrorCode.InvalidAuthentication:
this.DisconnectedCause = ChatDisconnectCause.InvalidAuthentication;
break;
case ErrorCode.CustomAuthenticationFailed:
this.DisconnectedCause = ChatDisconnectCause.CustomAuthenticationFailed;
break;
case ErrorCode.InvalidRegion:
this.DisconnectedCause = ChatDisconnectCause.InvalidRegion;
break;
case ErrorCode.MaxCcuReached:
this.DisconnectedCause = ChatDisconnectCause.MaxCcuReached;
break;
case ErrorCode.OperationNotAllowedInCurrentState:
this.DisconnectedCause = ChatDisconnectCause.OperationNotAllowedInCurrentState;
break;
}
this.State = ChatState.Disconnecting;
this.chatPeer.Disconnect();
}
}