protected override void Arrange() { _configValueProvider = A.Fake <IConfigValueProvider>(); A.CallTo(() => _configValueProvider.GetValue(A <string> ._)).Returns("5"); _clientAppRepo = A.Fake <IClientAppRepo>(); _defaultApplicationCreator = A.Fake <IDefaultApplicationCreator>(); _sandboxProvisioner = A.Fake <ISandboxProvisioner>(); _clientCreator = new ClientCreator(_configValueProvider, _clientAppRepo, _defaultApplicationCreator, _sandboxProvisioner); _user = A.Fake <User>(); A.CallTo(() => _user.ApiClients).Returns( new List <ApiClient> { A.Fake <ApiClient>(), A.Fake <ApiClient>(), A.Fake <ApiClient>(), A.Fake <ApiClient>(), A.Fake <ApiClient>() }); }
public void AddClients() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("---------\nCreating Clients:"); IFix clientCreator = new ClientCreator(ConnectionString); clientCreator.SaveToDatabaseSequentially(); Console.ResetColor(); }
protected override void Arrange() { const int VendorId = 444; const SandboxType SandboxType = SandboxType.Minimal; var defaultApplicationCreator = A.Fake <IDefaultApplicationCreator>(); var application = new Application { ApplicationName = "Application.ApplicationName" }; application.CreateApplicationEducationOrganization(111); application.CreateApplicationEducationOrganization(222); application.CreateApplicationEducationOrganization(333); A.CallTo( () => defaultApplicationCreator.FindOrCreateUpdatedDefaultSandboxApplication(VendorId, SandboxType)) .Returns(application); ApiClient apiClient = new ApiClient { Name = "ApiClient.Name" }; var clientAppRepo = A.Fake <IClientAppRepo>(); var user = new User { Vendor = new Vendor { VendorId = VendorId } }; var sandboxClientCreateModel = new SandboxInitializationModel { Name = "SandboxInitializationModel.Name", SandboxType = SandboxType }; A.CallTo( () => clientAppRepo.SetupDefaultSandboxClient( sandboxClientCreateModel.Name, sandboxClientCreateModel.SandboxType, null, null, user.UserId, application.ApplicationId)).Returns(apiClient); var clientAppConfigValueProviderRepo = A.Fake <IConfigValueProvider>(); var sandboxProvisioner = A.Fake <ISandboxProvisioner>(); var creator = new ClientCreator(clientAppConfigValueProviderRepo, clientAppRepo, defaultApplicationCreator, sandboxProvisioner); _apiClient = creator.CreateNewSandboxClient(sandboxClientCreateModel, user); }
void Start() { currentRating = startingRating; highestRating = startingRating; clientsForToday = clientsForFirstDay; inventoryComponent = inventory.GetComponent <Inventory>(); recipe = new List <Slot>(); clientCreator = clientCreatorObject.GetComponent <ClientCreator>(); currentRecipeFlavorText.text = "0"; nextDayTime = initialInstructionsDisplay; nextClientTime = initialInstructionsDisplay; instructionMenu.SetActive(true); }
/// <summary> /// 创建 TCP 服务客户端套接字 /// </summary> internal override void Create() { bool isErrorLog = false, isReceiveAsync = false; socketError = SocketError.Success; do { if (checkCreate() == 0) return; if (isSleep) { isSleep = false; Thread.Sleep(ClientCreator.CommandClient.TryCreateSleep); if (checkCreate() == 0) return; } try { Socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); #if !MONO Socket.ReceiveBufferSize = ClientCreator.CommandClient.ReceiveBufferPool.Size; Socket.SendBufferSize = ClientCreator.CommandClient.SendBufferPool.Size; #endif Socket.Connect(ipAddress, port); if (checkCreate() == 0) return; #if DOTNET2 if (onReceiveAsyncCallback == null) onReceiveAsyncCallback = onReceive; #else if (receiveAsyncEventArgs == null) { receiveAsyncEventArgs = SocketAsyncEventArgsPool.Get(); receiveAsyncEventArgs.Completed += onReceive; } #endif if (ReceiveBuffer.Buffer == null) ClientCreator.CommandClient.ReceiveBufferPool.Get(ref ReceiveBuffer); if (Sender == null) SetSender(new ClientSocketSender(this)); receiveBufferSize = ReceiveBuffer.PoolBuffer.Pool.Size; receiveCount = receiveIndex = 0; ReceiveType = TcpServer.ClientSocketReceiveType.CommandIdentity; #if DOTNET2 Socket.BeginReceive(ReceiveBuffer.Buffer, ReceiveBuffer.StartIndex, receiveBufferSize, SocketFlags.None, out socketError, onReceiveAsyncCallback, Socket); if (socketError == SocketError.Success) #else #if !DotNetStandard Interlocked.Exchange(ref receiveAsyncLock, 1); #endif receiveAsyncEventArgs.SetBuffer(ReceiveBuffer.Buffer, ReceiveBuffer.StartIndex, receiveBufferSize); if (Socket.ReceiveAsync(receiveAsyncEventArgs)) #endif { #if !DOTNET2 && !DotNetStandard Interlocked.Exchange(ref receiveAsyncLock, 0); #endif isReceiveAsync = true; if (verifyMethod(ClientCreator.CommandClient)) { if (ClientCreator.OnSocketVerifyMethod(this)) { if (isErrorLog) { ClientCreator.CommandClient.Log.Add(AutoCSer.Log.LogType.Debug, ClientCreator.Attribute.ServerName + " 客户端 TCP 连接成功 " + ipAddress.ToString() + ":" + port.toString()); } return; } } if (Socket != null) { #if DotNetStandard AutoCSer.Net.TcpServer.CommandBase.CloseClientNotNull(Socket); #else Socket.Dispose(); #endif Socket = null; } return; } } catch (Exception error) { if (!isErrorLog) { isErrorLog = true; ClientCreator.CommandClient.Log.Add(AutoCSer.Log.LogType.Debug, error, ClientCreator.Attribute.ServerName + " 客户端 TCP 连接失败 " + ipAddress.ToString() + ":" + port.toString()); } } if (isReceiveAsync) return; CreateSleep(); } while (true); }
/// <summary> /// 创建 TCP 服务客户端套接字 /// </summary> internal override void Create() { bool isErrorLog = false; socketError = SocketError.Success; do { if (checkCreate() == 0) return; if (isSleep) { isSleep = false; Thread.Sleep(ClientCreator.CommandClient.FristTryCreateSleep); } try { Socket = new Socket(IpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); #if !MONO Socket.ReceiveBufferSize = ClientCreator.CommandClient.ReceiveBufferPool.Size; Socket.SendBufferSize = ClientCreator.CommandClient.SendBufferPool.Size; #endif Socket.Connect(IpAddress, Port); if (checkCreate() == 0) return; if (onReceiveAsyncCallback == null) onReceiveAsyncCallback = onReceive; #if !DOTNET2 if (receiveAsyncEventArgs == null) { receiveAsyncEventArgs = SocketAsyncEventArgsPool.Get(); receiveAsyncEventArgs.Completed += onReceiveAsyncCallback; } #endif if (ReceiveBuffer.Buffer == null) ClientCreator.CommandClient.ReceiveBufferPool.Get(ref ReceiveBuffer); if (Sender == null) SetSender(new ClientSocketSender(this)); receiveBufferSize = ReceiveBuffer.PoolBuffer.Pool.Size; receiveCount = receiveIndex = 0; ReceiveType = TcpServer.ClientSocketReceiveType.CommandIdentityAgain; #if DOTNET2 Socket.BeginReceive(ReceiveBuffer.Buffer, ReceiveBuffer.StartIndex, receiveBufferSize, SocketFlags.None, out socketError, onReceiveAsyncCallback, Socket); if (socketError == SocketError.Success) #else #if !DotNetStandard Interlocked.Exchange(ref receiveAsyncLock.Lock, 1); #endif receiveAsyncEventArgs.SetBuffer(ReceiveBuffer.Buffer, ReceiveBuffer.StartIndex, receiveBufferSize); if (Socket.ReceiveAsync(receiveAsyncEventArgs)) #endif { #if !DOTNET2 && !DotNetStandard receiveAsyncLock.Exit(); #endif if (verifyMethod() && ClientCreator.OnSocketVerifyMethod(this)) { if (isErrorLog) { ClientCreator.CommandClient.Log.Debug(ClientCreator.Attribute.ServerName + " 客户端 TCP 连接成功 " + IpAddress.ToString() + ":" + Port.toString(), LogLevel.Debug | LogLevel.AutoCSer); } ClientCreator.VerifyCount = 0; return; } } ++ClientCreator.VerifyCount; } catch (Exception error) { if (!isErrorLog) { isErrorLog = true; ClientCreator.CommandClient.Log.Exception(error, ClientCreator.Attribute.ServerName + " 客户端 TCP 连接失败 " + IpAddress.ToString() + ":" + Port.toString(), LogLevel.Exception | LogLevel.AutoCSer); } } if (Sender != null) { VerifyMethodSleep(); return; } ClientCreator.VerifyCount = 0; CreateSleep(); } while (true); }