protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { Debug.Assert((EndAction != null && EndActionWait == null) || (EndAction == null && EndActionWait != null), "Set only one of EndAction, EndActionWait"); if (EndActionWait != null) { var innerAction = EndActionWait(client, asyncResult); if (innerAction != null) { innerAction.ActionSuccess += RaiseActionSuccess; innerAction.ActionFailed += RaiseActionFailed; } else { RaiseActionSuccess(); } } else if (EndAction != null) { // When error occures, OnError is called EndAction(client, asyncResult); RaiseActionSuccess(); } CloseScreen(); }
public static MySectorServiceClient GetCheckedInstance() { Debug.Assert(HasCredentials, "Set credential prior getting instance method"); Debug.Assert(m_url != null, "Set URL prior getting instance method"); try { // Make sure to create only one instance lock (m_syncRoot) { if (!IsInstanceValid) { SafeClose(); m_instance = PrepareInstance(); m_instance.LoginCompleted += client_LoginCompleted; m_instance.LoginAsync(MyMwcFinalBuildConstants.SERVER_PROTOCOL_VERSION); } return(m_instance); } } catch (Exception e) { throw new MyServiceException("Error occured during initialization of server connection", e); } }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { byte[] result = client.EndLoadCheckpoint(asyncResult); m_checkpoint = MyMwcObjectBuilder_Base.FromBytes<MyMwcObjectBuilder_Checkpoint>(result); //if (m_checkpoint.SectorObjectBuilder == null) // Server told us to use cache //{ // LoadSector(); // return; //} MyGuiScreenGamePlay.StoreLastLoadedCheckpoint(m_checkpoint); m_loadCheckpointSuccessfulAction(m_checkpoint); CloseScreen(); } catch (FaultException<MyCustomFault> faultException) { if (faultException.Detail.ErrorCode == MyCustomFaultCode.CheckpointTemplateNotExists) { HandleNonexistentCheckpoint(); } else { // Handled by base class throw faultException; } } }
/// <summary> /// Login always creates new instance /// </summary> public static IAsyncResult BeginLoginStatic() { // Make sure to create only one instance lock (m_syncRoot) { SafeClose(); m_instance = PrepareInstance(); return(m_instance.BeginLogin(MyMwcFinalBuildConstants.SERVER_PROTOCOL_VERSION, null, m_instance)); } }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { Vector3 newShipPosition; byte[] result = client.EndTravelToSector(out newShipPosition, asyncResult); var sectorBuilder = MyMwcObjectBuilder_Base.FromBytes<MyMwcObjectBuilder_Sector>(result); m_enterSectorSuccessfulAction(sectorBuilder, newShipPosition); CloseScreen(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { if (MySectorServiceClient.HasCredentials && MySectorServiceClient.HasUrl) { AddAction(client.BeginLogout(null, client), OnLogoutCompleted); } else { CloseScreen(); } }
protected override void ServiceProgressStart(MySectorServiceClient client) { if (!MySession.PlayerShip.IsDead()) { SaveSector(client); } else { this.CloseScreen(); } }
protected override void ServiceProgressStart(MySectorServiceClient client) { if (m_loadGlobal) { AddAction(client.BeginLoadSectorIdentifiers(m_sectorType, null, client)); } else { AddAction(client.BeginLoadUserSectorIdentifiers(null, client)); } }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { if (m_loadGlobal) { m_successAction(client.EndLoadSectorIdentifiers(asyncResult)); } else { m_successAction(client.EndLoadUserSectorIdentifiers(asyncResult)); } this.CloseScreen(); }
void OnLogoutCompleted(IAsyncResult result, MySectorServiceClient client) { try { client.EndLogout(result); } catch (Exception e) // We don't care about exceptions here, just log exception { MyMwcLog.WriteLine(e); } HandleLogout(); }
static void client_LoginCompleted(object sender, LoginCompletedEventArgs e) { lock (m_syncRoot) { MySectorServiceClient client = (MySectorServiceClient)sender; client.LoginCompleted -= client_LoginCompleted; if (e.Error != null) { // On error, close client SafeClose(); } } }
public static void HardClose() { lock (m_syncRoot) { if (m_instance != null) { try { m_instance.Abort(); } catch (Exception) { } m_instance = null; } } }
public static void SafeClose() { // We want to close instance, but when it fails we dont care lock (m_syncRoot) { if (m_instance != null) { try { m_instance.Close(); } catch (Exception) { } m_instance = null; } } }
private void SaveSector(MySectorServiceClient client) { if (m_pause) { if (!MinerWars.AppCode.App.MyMinerGame.IsPaused()) { MinerWars.AppCode.App.MyMinerGame.SwitchPause(); } } m_checkpoint.CurrentSector = m_sectorIdentifier; //if (MyLocalCache.CanBeSaved(m_checkpoint)) //{ // MyLocalCache.Save(m_checkpoint); // m_checkpoint.SectorObjectBuilder = null; //} AddAction(client.BeginSaveCheckpoint(m_checkpoint.ToBytes(), m_savePlayer, null, client)); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { List<MyMwcUserDetail> users; var sectorIdentifiers = client.EndSelectSandbox(out users, asyncResult); m_responseHandler(sectorIdentifiers, users); if (m_openAfterSuccessfulEnter.GetState() != MyGuiScreenState.HIDDEN && m_openAfterSuccessfulEnter.GetState() != MyGuiScreenState.HIDING) { if (m_openAfterSuccessfulEnter.GetState() != MyGuiScreenState.OPENED) { MyGuiManager.AddScreen(m_openAfterSuccessfulEnter); } } else { //this screen should be unhide automaticaly //m_openAfterSuccessfulEnter.UnhideScreen(); } CloseScreen(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { int version = 0; AddAction(client.BeginTravelToSector(m_travelType, m_targetSectorPosition, m_currentShipPosition, version, null, client)); }
public static void HardClose() { lock (m_syncRoot) { if (m_instance != null) { try { m_instance.Abort(); } catch (Exception) { } m_instance = null; } } }
public static void SafeClose() { // We want to close instance, but when it fails we dont care lock (m_syncRoot) { if (m_instance != null) { try { m_instance.Close(); } catch (Exception) { } m_instance = null; } } }
public static MySectorServiceClient GetCheckedInstance() { Debug.Assert(HasCredentials, "Set credential prior getting instance method"); Debug.Assert(m_url != null, "Set URL prior getting instance method"); try { // Make sure to create only one instance lock (m_syncRoot) { if (!IsInstanceValid) { SafeClose(); m_instance = PrepareInstance(); m_instance.LoginCompleted += client_LoginCompleted; m_instance.LoginAsync(MyMwcFinalBuildConstants.SERVER_PROTOCOL_VERSION); } return m_instance; } } catch (Exception e) { throw new MyServiceException("Error occured during initialization of server connection", e); } }
public static MySectorServiceClient PrepareInstance() { MyMwcLog.WriteLine("Creating sector service client, url: " + m_url); // create the URI which is used as the service endpoint Uri tcpBaseAddress = new Uri(String.Format("net.tcp://{0}", m_url)); if (MyFakes.TEST_DNS_UNAVAILABLE) { tcpBaseAddress = new Uri("d23>?<'12`/.,;'l,;l"); // Non sense URL } // create the net.tcp binding for the service endpoint NetTcpBinding ntcBinding = new NetTcpBinding(); ntcBinding.Security.Mode = SecurityMode.None; ntcBinding.MaxBufferPoolSize = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_POOL_SIZE; ntcBinding.MaxBufferSize = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.MaxConnections = MyMwcNetworkingConstants.MAX_WCF_CONNECTIONS; ntcBinding.MaxReceivedMessageSize = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.ReaderQuotas.MaxArrayLength = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.ReaderQuotas.MaxBytesPerRead = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.SendTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_SEND; ntcBinding.ReceiveTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_INACTIVITY; ntcBinding.CloseTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_CLOSE; ntcBinding.OpenTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_OPEN; ntcBinding.Security.Mode = SecurityMode.Message; ntcBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; ntcBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; ntcBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None; ntcBinding.ReliableSession = new OptionalReliableSession() { Enabled = true, InactivityTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_DISCONNECT, Ordered = false }; if (MyFakes.MWBUILDER) { var msgSize = 16 * 1024 * 1024; ntcBinding.MaxConnections = 1; ntcBinding.MaxBufferSize = msgSize; ntcBinding.MaxBufferPoolSize = (int)(msgSize * 1.2f); ntcBinding.MaxReceivedMessageSize = msgSize; ntcBinding.ReaderQuotas.MaxArrayLength = msgSize; } var decoratedBinding = MyCustomBinding.DecorateBinding(ntcBinding); InstanceContext instanceContext = new InstanceContext(new MySectorServerCallback()); MySectorServiceClient client = new MySectorServiceClient(instanceContext, decoratedBinding, new EndpointAddress(tcpBaseAddress, EndpointIdentity.CreateDnsIdentity(MyMwcNetworkingConstants.WCF_SECTOR_SERVER_CN))); if (MyMwcFinalBuildConstants.IS_DEVELOP) // On develop log WCF calls { client.Endpoint.Behaviors.Add(new MyLoggingBehavior()); } client.ClientCredentials.UserName.UserName = m_username; client.ClientCredentials.UserName.Password = m_passwordHash; client.ClientCredentials.ServiceCertificate.Authentication.CustomCertificateValidator = new MyCertificateValidator(MyMwcNetworkingConstants.WCF_SECTOR_SERVER_HASH); client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.Custom; client.InnerChannel.Faulted += new EventHandler(InnerChannel_Faulted); client.InnerChannel.Closed += new EventHandler(InnerChannel_Closed); return client; }
/// <summary> /// Login always creates new instance /// </summary> public static IAsyncResult BeginLoginStatic() { // Make sure to create only one instance lock (m_syncRoot) { SafeClose(); m_instance = PrepareInstance(); return m_instance.BeginLogin(MyMwcFinalBuildConstants.SERVER_PROTOCOL_VERSION, null, m_instance); } }
public static MySectorServiceClient PrepareInstance() { MyMwcLog.WriteLine("Creating sector service client, url: " + m_url); // create the URI which is used as the service endpoint Uri tcpBaseAddress = new Uri(String.Format("net.tcp://{0}", m_url)); if (MyFakes.TEST_DNS_UNAVAILABLE) { tcpBaseAddress = new Uri("d23>?<'12`/.,;'l,;l"); // Non sense URL } // create the net.tcp binding for the service endpoint NetTcpBinding ntcBinding = new NetTcpBinding(); ntcBinding.Security.Mode = SecurityMode.None; ntcBinding.MaxBufferPoolSize = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_POOL_SIZE; ntcBinding.MaxBufferSize = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.MaxConnections = MyMwcNetworkingConstants.MAX_WCF_CONNECTIONS; ntcBinding.MaxReceivedMessageSize = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.ReaderQuotas.MaxArrayLength = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.ReaderQuotas.MaxBytesPerRead = MyMwcNetworkingConstants.MAX_WCF_MESSAGE_SIZE; ntcBinding.SendTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_SEND; ntcBinding.ReceiveTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_INACTIVITY; ntcBinding.CloseTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_CLOSE; ntcBinding.OpenTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_OPEN; ntcBinding.Security.Mode = SecurityMode.Message; ntcBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; ntcBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; ntcBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None; ntcBinding.ReliableSession = new OptionalReliableSession() { Enabled = true, InactivityTimeout = MyMwcNetworkingConstants.WCF_TIMEOUT_DISCONNECT, Ordered = false }; if (MyFakes.MWBUILDER) { var msgSize = 16 * 1024 * 1024; ntcBinding.MaxConnections = 1; ntcBinding.MaxBufferSize = msgSize; ntcBinding.MaxBufferPoolSize = (int)(msgSize * 1.2f); ntcBinding.MaxReceivedMessageSize = msgSize; ntcBinding.ReaderQuotas.MaxArrayLength = msgSize; } var decoratedBinding = MyCustomBinding.DecorateBinding(ntcBinding); InstanceContext instanceContext = new InstanceContext(new MySectorServerCallback()); MySectorServiceClient client = new MySectorServiceClient(instanceContext, decoratedBinding, new EndpointAddress(tcpBaseAddress, EndpointIdentity.CreateDnsIdentity(MyMwcNetworkingConstants.WCF_SECTOR_SERVER_CN))); if (MyMwcFinalBuildConstants.IS_DEVELOP) // On develop log WCF calls { client.Endpoint.Behaviors.Add(new MyLoggingBehavior()); } client.ClientCredentials.UserName.UserName = m_username; client.ClientCredentials.UserName.Password = m_passwordHash; client.ClientCredentials.ServiceCertificate.Authentication.CustomCertificateValidator = new MyCertificateValidator(MyMwcNetworkingConstants.WCF_SECTOR_SERVER_HASH); client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.Custom; client.InnerChannel.Faulted += new EventHandler(InnerChannel_Faulted); client.InnerChannel.Closed += new EventHandler(InnerChannel_Closed); return(client); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { client.EndSaveCheckpoint(asyncResult); MyEditorActions.ResetActionHistory(); var handler = Saved; if (handler != null) { handler(this); } } catch (FaultException<MyCustomFault> faultException) { if (faultException.Detail.ErrorCode == MyCustomFaultCode.SectorNameExists) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.CantSaveSectorNameExists, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null)); } else { throw faultException; // Causes parent to call OnError } } CloseScreen(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { AddAction(client.BeginLoadCheckpoint(m_sessionType, m_sessionStartType, m_userId, m_sectorPosition, m_checkpointName, null, client)); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { var response = client.EndLoadObjectGroups(asyncResult); List<MyMwcObjectBuilder_ObjectGroup> groups = new List<MyMwcObjectBuilder_ObjectGroup>(); List<MyMwcObjectBuilder_Base> entities = new List<MyMwcObjectBuilder_Base>(); var fakeEndpoint = new System.Net.IPEndPoint(0, MyClientServer.LoggedPlayer.GetUserId()); var sectorGroupBuilder = MyMwcObjectBuilder_Base.FromBytes<MyMwcObjectBuilder_SectorObjectGroups>(response); if (sectorGroupBuilder == null) { throw new InvalidOperationException("Cannot deserialize SectorObjectGroups object builder"); } MyGuiManager.AddScreen(new MyGuiScreenEditorLoadGroup(sectorGroupBuilder.Groups, sectorGroupBuilder.Entities)); } catch (Exception) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PleaseTryAgain, MyTextsWrapperEnum.MessageBoxNetworkErrorCaption, MyTextsWrapperEnum.Ok, null)); } CloseScreen(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { // Send save request and wait for callback AddAction(client.BeginLoadObjectGroups(m_sectorIdentifier.SectorType, m_sectorIdentifier.UserId, m_sectorIdentifier.Position, null, client)); }
// Override default behaviour - default behaviour logs exception, aborts client and closes screen protected override void OnError(Exception exception, MySectorServiceClient client) { MySectorServiceClient.SafeClose(); MyMwcLog.WriteLine(exception); // log exception ShowRetryDialog(); CloseScreen(); }
protected override void OnError(Exception exception, MySectorServiceClient client) { MyMwcLog.WriteLine(exception); // log exception if (EnableRetry) { ShowRetryDialog(exception); } else { RaiseActionFailed(exception); if (ShowErrorMessage) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, ErrorMessageText, ErrorCaptionText, MyTextsWrapperEnum.Ok, null)); } CloseScreen(); if (OnErrorReturnToMainMenu) { MyGuiManager.BackToMainMenu(); } } }
protected override void ServiceProgressStart(MySectorServiceClient client) { AddAction(BeginAction(client)); }
protected override void OnError(Exception exception, MySectorServiceClient asyncState) { // It's same like when logout succeded HandleLogout(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { AddAction(client.BeginSelectSandbox(m_selectSandboxType, m_findPlayerName, null, client)); }