Пример #1
0
        static void Main(string[] args)
        {
            int port = 5555;

            Console.WriteLine(string.Format("Client Başlatıldı. Port: {0}", port));
            Console.WriteLine("-----------------------------");

            ExampleSocket exampleSocket = new ExampleSocket(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port));

            exampleSocket.Start();

            Console.WriteLine("Göndermek için \"G\", basınız...");

            int count = 1;

            while (Console.ReadLine().ToUpper() == "G")
            {
                ExampleDTO exampleDTO = new ExampleDTO()
                {
                    Status  = string.Format("{0}. Alındı", count),
                    Message = string.Format("{0} ip numaralı client", GetLocalIPAddress())
                };

                exampleSocket.SendData(exampleDTO);
                count++;
            }

            Console.ReadLine();
        }
        public void SendData(ExampleDTO exampleDTO)
        {
            using (var ms = new MemoryStream())
            {
                new BinaryFormatter().Serialize(ms, exampleDTO);
                IList <ArraySegment <byte> > data = new List <ArraySegment <byte> >();

                data.Add(new ArraySegment <byte>(ms.ToArray()));


                _Socket.BeginSend(data, SocketFlags.None, out socketError,
                                  (asyncResult) =>
                {
                    int length = _Socket.EndSend(asyncResult, out socketError);

                    if (length <= 0 || socketError != SocketError.Success)
                    {
                        Console.WriteLine("Server bağlantısı koptu!");
                        return;
                    }
                }, null);

                if (socketError != SocketError.Success)
                {
                    Console.WriteLine("Server bağlantısı koptu!");
                }
            }
        }
        public async Task Delete(ExampleDTO example)
        {
            Example ex = await unitOfWork.Examples.Get(example.Id);

            await unitOfWork.Examples.Delete(ex);

            await unitOfWork.Save();
        }
Пример #4
0
        public void Edit(int id, [FromBody] ExampleViewModel example)
        {
            var serv = new ExampleDTO {
                Id = example.Id, Name = example.Name, Desc = example.Desc, Img = example.Img
            };

            studioService.EditExample(serv);
            studioService.Save();
        }
Пример #5
0
        public void Create([FromBody] ExampleViewModel example)
        {
            var serv = new ExampleDTO {
                Id = example.Id, Name = example.Name, Desc = example.Desc, Img = example.Img
            };

            studioService.CreateExample(serv);
            studioService.Save();
        }
        public async Task Insert(ExampleDTO example)
        {
            var b = _exampleActions.Calculate(example.Text);

            example.Result = b;
            example.Text  += "=" + b.ToString();
            await unitOfWork.Examples.Insert(mapper.Map <ExampleDTO, Example>(example));

            await unitOfWork.Save();
        }
        public bool Post([FromBody] ExampleDTO dto)
        {
            if (string.IsNullOrWhiteSpace(dto.Value))
            {
                return(false);
            }
            _sql.AddValues(dto.Value);

            return(true);
        }
Пример #8
0
        static void Main(string[] args)
        {
            // Create connection
            var cli = new OTcpClient("localhost", 1010);

            // Register client interface implementation
            cli.RegisterImplementation(new ClientLogigImplementation());
            // Set server error handler
            cli.SpecialMessageEvt += (message, o) => {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($">> {o}");
                Console.WriteLine($"<< {message}");
                Console.ResetColor();
            };
            // Create proxy
            var pc = cli.CreateProxy <IServerSide>();

            // Server calls
            Console.WriteLine($"pc.IntSumm(11, 33) = {pc.IntSumm(11, 33)}");
            Console.WriteLine($"pc.DoubleSumm(1.1, 3.3) = {pc.DoubleSumm(1.1, 3.3)}");
            Console.WriteLine($"pc.IntSummOfPower(11, 33) = {pc.IntSummOfPower(11, 33)}");

            Console.WriteLine($"pc.QuadraticEquation(1,2,3) = {QuadraticString(pc.QuadraticEquation(1,2,3))}");
            Console.WriteLine($"pc.QuadraticEquation(2,4,-7) = {QuadraticString(pc.QuadraticEquation(2,4,-7))}");
            Console.WriteLine($"pc.QuadraticEquation(1,6,9) = {QuadraticString(pc.QuadraticEquation(1,6,9))}");

            pc.WriteMessage("Hello server!");

            pc.NotImplemented();

            var dto = new ExampleDTO()
            {
                DateTimeValue = DateTime.Now,
                DoubleValue   = 11.33,
                IntegerValue  = 1133,
                StringValue   = "String message",
                IntList       = new int[100].ToList(),
                StreamValue   = new MemoryStream(new byte[5000])
            };

            var echoDto = pc.TestSerializer(dto);

            Console.WriteLine($"DTO {echoDto.DateTimeValue}");

            pc.Subscribe();

            while (true)
            {
                Console.Write("CLI > ");
                var seq    = Reader.Read(Console.ReadLine());
                var result = cli.Call(seq.Car());
                Console.WriteLine($"RES > {result ?? "null"}");
            }
        }
        public string Put([FromRoute] int id, [FromBody] ExampleDTO dto)
        {
            if (string.IsNullOrWhiteSpace(dto.Value) || id > _sql.GetAll().Count)
            {
                throw new Exception("Value cannot be null or empty, or your ID is higher than what we have available.");
            }

            _sql.UpdateValue(id, dto.Value);

            return(dto.Value);
        }
Пример #10
0
        public void CreateExample(ExampleDTO example)
        {
            Example serv = new Example
            {
                Id   = example.Id,
                Name = example.Name,
                Desc = example.Desc,
                Img  = example.Img
            };

            Database.Examples.Create(serv);
        }
Пример #11
0
        public void Add(ExampleDTO exampleDTO)
        {
            try
            {
                var example = mapper.Map <Example>(exampleDTO);

                exampleService.Add(example);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #12
0
        public ActionResult <ExampleDTO> Modify(ExampleDTO exampleDto)
        {
            var exampleEntity = _mapper.Map <ExampleEntity>(exampleDto);

            _logger.LogDebug("Modify");
            var result = _service.Modify(exampleEntity);

            _logger.LogDebug($"Modify success? {result != null}");

            return(result != null
                ? (ActionResult)Ok(_mapper.Map <ExampleDTO>(result))
                : NoContent());
        }
Пример #13
0
        public override void Send_ExampleDTO(ExampleDTO exampleDto)
        {
            if (ConectedClients.Count == 0)
            {
                return;                             // no sense to send data to no one
            }
            logger.Debug(string.Format("Sending ... {0}", exampleDto.ToString()));

            // put the needed hub server
            var context = GlobalHost.ConnectionManager.GetHubContext <ExampleHubServer>();

            context.Clients.All.Send_ExampleDTO(exampleDto);
        }
Пример #14
0
        public IExampleData GetSumData(IStatusCheckRequest payload)
        {
            if (payload.sumData.Equals("killatron19Ca"))
            {
                ExampleDTO Example = new ExampleDTO();

                Example.routine     = 17;
                Example.gummieBears = 4012;
                Example.recipients  = 4;
                Example.mode        = "giveaway";

                return(Example);
            }
            throw new ExampleStatusNotFound();
        }
Пример #15
0
        public bool metodoEliminar(ExampleDTO personaRequest)
        {
            try
            {
                var persona = new ExampleDTO
                {
                };

                //_exampleRepository.Delete(persona);
            }
            catch (SqlException ex)
            {
            }

            return(true);
        }
Пример #16
0
        static void Main(string[] args)
        {
            var cli = new OPipeClient("test-pipe");

            cli.RegisterImplementation(new ClientLogigImplementation());

            cli.SpecialMessageEvt += (message, o) => {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($">> {o}");
                Console.WriteLine($"<< {message}");
                Console.ResetColor();
            };

            // Create proxy
            var pc = cli.CreateProxy <IServerSide>();

            Console.WriteLine($"pc.IntSumm(11, 33) = {pc.IntSumm(11, 33)}");
            Console.WriteLine($"pc.DoubleSumm(1.1, 3.3) = {pc.DoubleSumm(1.1, 3.3)}");
            Console.WriteLine($"pc.IntSummOfPower(11, 33) = {pc.IntSummOfPower(11, 33)}");

            Console.WriteLine($"pc.QuadraticEquation(1,2,3) = {QuadraticString(pc.QuadraticEquation(1, 2, 3))}");
            Console.WriteLine($"pc.QuadraticEquation(2,4,-7) = {QuadraticString(pc.QuadraticEquation(2, 4, -7))}");
            Console.WriteLine($"pc.QuadraticEquation(1,6,9) = {QuadraticString(pc.QuadraticEquation(1, 6, 9))}");

            pc.WriteMessage("Hello server!");

            pc.NotImplemented();

            var dto = new ExampleDTO()
            {
                DateTimeValue = DateTime.Now,
                DoubleValue   = 11.33,
                IntegerValue  = 1133,
                StringValue   = "String message",
                IntList       = new int[100].ToList(),
                StreamValue   = new MemoryStream(new byte[5000])
            };

            var echoDto = pc.TestSerializer(dto);

            Console.WriteLine($"DTO {echoDto?.DateTimeValue}");

            Console.Write("Press Enter to continue...");
            Console.ReadLine();
        }
        public void Modify_ShouldReturn_ExampleDTO()
        {
            var entity = new ExampleDTO
            {
                Id          = 1,
                Name        = "Mock Name",
                Description = "Mock Description"
            };

            var result = controller.Modify(entity);

            Assert.Multiple(() =>
            {
                service.Verify(s => s.Modify(It.IsAny <ExampleEntity>()), Times.Once);
                Assert.NotNull(result);
                Assert.IsInstanceOf(typeof(OkObjectResult), result.Result);
            });
        }
        public async Task <ExampleDTO> Insert([FromBody] ExampleDTO exampleDTO)
        {
            try
            {
                await _exampleManager.Insert(exampleDTO);

                return(exampleDTO);
            }
            catch (Exception)
            {
                var c = new ExampleDTO {
                    Text = "Error"
                };
                await _exampleManager.Insert(c);

                return(c);
            }
        }
Пример #19
0
 public virtual void Send_ExampleDTO(ExampleDTO exampleDto)
 {
     logger.Debug("HubSync Sending ExampleDTO: " + exampleDto.ToString());
     Clients.All.Send_ExampleDTO(exampleDto);
 }
Пример #20
0
 void OnExampleDTOReceived(ExampleDTO exampleDTO)
 {
     Console.WriteLine(string.Format("Status: {0}", exampleDTO.Status));
     Console.WriteLine(string.Format("Message: {0}", exampleDTO.Message));
 }
Пример #21
0
 public HttpResponseMessage metodoEliminar(ExampleDTO personaRequest)
 {
     return(Request.CreateResponse(HttpStatusCode.Accepted, _ExampleAplicationService.metodoEliminar(personaRequest)));
 }
Пример #22
0
 public ExampleDTO TestSerializer(ExampleDTO dto)
 {
     return(dto);
 }
Пример #23
0
        static void Main(string[] args)
        {
            //string listenOnUrl = "http://*:8088"; // listen on all available interfaces, but must be started with admin priviledges

            string       listenOnUrl = "http://localhost:8088;http://127.0.0.1:8088";
            StartOptions options     = new StartOptions();

            string[] urls = listenOnUrl.Split(';');

            foreach (var item in urls)
            {
                options.Urls.Add(item);
            }

            /*
             * options.Urls.Add("http://localhost:8088");
             * options.Urls.Add("http://127.0.0.1:8088");
             * options.Urls.Add(string.Format("http://{0}:8088", Environment.MachineName));
             */
            ExampleHubServer hub = null;

            try
            {
                WebApp.Start <Startup>(options);

                hub = new ExampleHubServer();
                logger.Info("Server running !");

                // Make long polling connections wait a maximum of 110 seconds for a
                // response. When that time expires, trigger a timeout command and
                // make the client reconnect.
                GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);

                // Wait a maximum of 30 seconds after a transport connection is lost
                // before raising the Disconnected event to terminate the SignalR connection.
                GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30); //30

                // For transports other than long polling, send a keepalive packet every
                // 10 seconds.
                // This value must be no more than 1/3 of the DisconnectTimeout value.
                GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10); //10
            }
            catch (Exception)
            {
                throw;
            }

            for (int i = 0; i < 150; i++)
            {
                hub.Send_AddMessage("AdminUser", "message No." + i);
                ExampleDTO exampleDTO = new ExampleDTO()
                {
                    MyProperty1 = "Some prop 1",
                    MyProperty2 = "Some prop 2"
                };
                hub.Send_ExampleDTO(exampleDTO);

                // for eg. we can send heartbeat also..
                //hub.Send_Heartbeat();

                Thread.Sleep(5000);
            }

            logger.Info("Done with broadcasting");

            var key = Console.ReadLine();

            if (key == "quit")
            {
                //context.Clients.All.Send("Server closed", key);
                //hub.Send("serverClosed", key);
            }
        }
        public async Task Update(ExampleDTO example)
        {
            await unitOfWork.Examples.Update(mapper.Map <ExampleDTO, Example>(example));

            await unitOfWork.Save();
        }