public HomeController(IDemoService demoService, IOptionsSnapshot <DemoSettings> demoSettings, ILogger <HomeController> logger, IConfiguration config)
 {
     _demoService = demoService;
     _settings    = demoSettings.Value;
     _logger      = logger;
     _config      = config;
 }
Ejemplo n.º 2
0
 public HomeController(
     IDemoService demoService,
     ILogger <HomeController> logger)
 {
     _service = demoService;
     _logger  = logger;
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //ServiceReference1.DemoServiceClient client = new ServiceReference1.DemoServiceClient();
            DemoRequest dr = new DemoRequest()
            {
                Foo = "A",
                Bar = "B"
            };


            //DemoResponse result = client.DoTheThing(dr);
            //Console.WriteLine($"{result.Baz}\t{result.Quux}");

            ChannelFactory <IDemoService> factory = new ChannelFactory <IDemoService>("test");
            IDemoService service = factory.CreateChannel();

            try
            {
                var result = service.DoTheThing(dr);
                Console.WriteLine($"{result.Baz}\t{result.Quux}");
            }
            catch (Exception)
            {
                throw;
            }



            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public GridViewModel(IDemoService demoService, IOFDialogue ioService)
        {
            _demoService = demoService;
            _ioService   = ioService;


            //try
            //{
            //    SQLiteDB.Init();
            //}
            //catch (Exception e)
            //{
            //    LogTo.ErrorException("Error initializing DB",e);
            //    throw;
            //}
            if (IsInDesignMode)
            {
            }
            else
            {
                if (Members.Count == 0)
                {
                    Members = SQLiteDB.GetAllMembers();
                    LogTo.Info("Getting Members INIT");
                }

                LogTo.Info("GridViewModel initialized");
            }
        }
Ejemplo n.º 5
0
        public ValuesController(Func <string, IDemoService> serviceAccessor)
        {
            this._serviceAccessor = serviceAccessor;

            _serviceA = _serviceAccessor("ServiceA");
            _serviceB = _serviceAccessor("ServiceB");
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="demoService"></param>
 /// <param name="memoryCache"></param>
 /// <param name="redisCache"></param>
 /// <param name="logger"></param>
 public DemoController(IDemoService demoService, ICacheService memoryCache, ICacheService redisCache, ILogger <DemoController> logger)
 {
     _demoService = demoService;
     _memoryCache = memoryCache;
     _redisCache  = redisCache;
     _logger      = logger;
 }
 public virtual void SetUp()
 {
     _testinghost    = new NonOrleansServiceTester <TestingHost <IDemoService> >();
     _insecureClient = _testinghost.GetServiceProxy <IDemoService>();
     Metric.ShutdownContext("Service");
     TracingContext.SetRequestID("1");
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // Client Channel Factory
            EndpointAddress serviceAddress = new EndpointAddress("http://localhost:3333/DemoService/");

            // Binding
            BasicHttpBinding httpBinding = new BasicHttpBinding();

            httpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
            httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            ChannelFactory <IDemoService> myChannelFacotry =
                new ChannelFactory <IDemoService>(httpBinding, serviceAddress);

            myChannelFacotry.Credentials.UserName.UserName = "******";
            myChannelFacotry.Credentials.UserName.Password = "******";

            // Proxy Erstellung
            IDemoService proxy = myChannelFacotry.CreateChannel();

            var ergebnis = proxy.Addition(2, 3);

            Console.WriteLine($"Ergebnis: {ergebnis.ToString()}");

            ((IClientChannel)proxy).Close();

            Console.ReadKey();
        }
Ejemplo n.º 9
0
        public DemoResponse DoTheThing(DemoRequest request)
        {
            request.Bar += "-Proxied";
            IDemoService service = factory.CreateChannel();

            using (OperationContextScope scope = new OperationContextScope((IContextChannel)service))
            {
                WebOperationContext woc = WebOperationContext.Current;
                woc.OutgoingRequest.ContentType = "application/json; charset=utf-8";
                var result = service.DoTheThing(request);
                try
                {
                    return(result);
                }
                finally
                {
                    if (result is System.ServiceModel.ICommunicationObject client)
                    {
                        if (client.State == System.ServiceModel.CommunicationState.Faulted)
                        {
                            client.Abort();
                        }
                        else
                        {
                            client.Close();
                        }
                    }
                }
            }
        }
 public DemoController(
     IDemoService demoService,
     IOptionsSnapshot <DemoSettings> demoSettings,
     IConfiguration configuration)
 {
     _demoService = demoService;
     _settings    = demoSettings.Value;
 }
Ejemplo n.º 11
0
        public DemoChannelProvider()
        {
            var endpoint = new EndpointAddress($"http://localhost:8888/RemoteQueryableDemo/DemoService");

            this.demoService = ChannelFactory <IDemoService> .CreateChannel(new BasicHttpBinding()
            {
                ReceiveTimeout = TimeSpan.FromSeconds(30)
            }, endpoint);
        }
Ejemplo n.º 12
0
 public DemoController
 (
     IDemoService DemoService,
     ILogger <DemoController> logger
 )
 {
     _demoService = DemoService;
     _logger      = logger;
 }
Ejemplo n.º 13
0
 public override void Close()
 {
     if (ChannelFactory == null)
     {
         return;
     }
     Channel = null;
     ChannelFactory.Close();
     ChannelFactory = null;
 }
Ejemplo n.º 14
0
 private readonly IOptions <Infrastructure.Dtos.Config.AppSettings> appSettings; //配置文件数据
 /// <summary>
 /// DemoController
 /// </summary>
 public TestController(DapperDBContext _context
                       , IDemoService _iDemoService,
                       AutoMapper.IMapper _modelMapper, IHostingEnvironment hostingEnv
                       , IOptions <Infrastructure.Dtos.Config.AppSettings> _appSettings)
 {
     context      = _context;
     iDemoService = _iDemoService;
     modelMapper  = _modelMapper;
     this.Log     = LogManager.GetLogger(Startup.Repository.Name, typeof(HomeController));
     appSettings  = _appSettings;
 }
Ejemplo n.º 15
0
        public virtual void SetUp()
        {
            _insecureClient      = _kernel.Get <IDemoService>();
            _exceptionSerializer = _kernel.Get <JsonExceptionSerializer>();

            Metric.ShutdownContext("Service");
            TracingContext.SetUpStorage();
            TracingContext.SetRequestID("1");

            _testinghost = new TestingHost <IDemoService>();
            _stopTask    = _testinghost.RunAsync(new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive));
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            Metric.ShutdownContext("Service");

            TracingContext.SetUpStorage();
            TracingContext.SetRequestID("1");


            var kernel = new TestingKernel <ConsoleLog>();

            _proxyInstance = kernel.Get <IDemoService>();
        }
Ejemplo n.º 17
0
        public async Task <int> OnExecute(
            ILogger <App> logger,
            IOptions <AppSettings> appSettings,
            IDemoService demoService)
        {
            logger.LogInformation($"AppSetting1: {appSettings.Value.AppSetting1}");
            logger.LogInformation($"Argument1: {Argument1}");
            logger.LogInformation($"Option1: {Option1}");

            await demoService.ExecuteAsync();

            return(Constants.OK);
        }
        public void DefaultThrowsException()
        {
            try {
                DynamicProxyInvoker target = new DynamicProxyInvoker();
                IDemoService        proxy1 = DynamicProxy.CreateInstance <IDemoService>(target);
                proxy1.Foo(0, "");

                Assert.Fail("a NotImplementedException should have been thrown, but didnt!");
            }
            catch (NotImplementedException ex) {
                Assert.AreEqual("There is no Implementation for Method Foo(bar, suffix)", ex.Message);
            }
        }
Ejemplo n.º 19
0
        public virtual void SetUp()
        {
            var kernel = new TestingKernel<ConsoleLog>();
            _insecureClient = kernel.Get<IDemoService>();
            _exceptionSerializer = kernel.Get<JsonExceptionSerializer>();

            Metric.ShutdownContext("Service");
            TracingContext.SetUpStorage();
            TracingContext.SetRequestID("1");

            _testinghost = new TestingHost<IDemoService>();
            _stopTask = _testinghost.RunAsync();
        }
        public static IActionResult Run(
            [HttpTrigger(
                 AuthorizationLevel.Anonymous,
                 "get", Route = "demo")
            ] HttpRequest req,
            [Inject] IDemoService demoService,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var res = demoService.GetResponse();

            return(new OkObjectResult(res));
        }
Ejemplo n.º 21
0
        public async Task Invoke(HttpContext httpContext)
        {
            IDemoService d = httpContext.RequestServices.GetService <IDemoService>();

            Console.WriteLine("FROM MIDDLEWARE GetService {0}", d.GetNum());

            Console.WriteLine($"Request for {httpContext.Request.Path} received ({httpContext.Request.ContentLength ?? 0} bytes)");

            try {
                await _next.Invoke(httpContext);
            }
            catch (Exception e) {
                await httpContext.Response.WriteAsync(String.Format("CAUGHT EXCEPTION {0}", e));
            }
        }
Ejemplo n.º 22
0
 public ValuesController(ILogger <ValuesController> logger, IDemoService demoService,
                         IServiceScopeFactory serviceScopeFactory, IUnitOfWorkManager unitOfWorkManager, IBackgroundJobManager backgroundJobManager,
                         IServiceProvider serviceProvider, IConfiguration configuration, ILocalEventBus localEventBus, ICapEventPublisher capEventPublisher)
 {
     _logger               = logger;
     _demoService          = demoService;
     _serviceProvider      = serviceProvider;
     _unitOfWorkManager    = unitOfWorkManager;
     _configuration        = configuration;
     _localEventBus        = localEventBus;
     _serviceScopeFactory  = serviceScopeFactory;
     _capEventPublisher    = capEventPublisher;
     _backgroundJobManager = backgroundJobManager;
     Logger = NullLogger <ValuesController> .Instance;//Controller 无法进行属性注入??
 }
        public void DynamicImplementationOfInterface()
        {
            DynamicProxyInvoker target = new DynamicProxyInvoker();

            target.DefineMethod("Foo",
                                (int bar, string suffix) => {
                return(bar.ToString() + " " + suffix);
            }
                                );

            IDemoService proxy1  = DynamicProxy.CreateInstance <IDemoService>(target);
            string       result1 = proxy1.Foo(123, "Hello");

            Assert.AreEqual("123 Hello", result1);
        }
        public void DefaultWithCustomFallback()
        {
            DynamicProxyInvoker target = new DynamicProxyInvoker();

            target.FallbackInvokeMethod = (method, args, names) => {
                Assert.AreEqual("Foo", method);
                Assert.AreEqual("booooo", args[1]);
                return("hihi");
            };

            IDemoService proxy1 = DynamicProxy.CreateInstance <IDemoService>(target);
            string       result = proxy1.Foo(0, "booooo");

            Assert.AreEqual("hihi", result);
        }
Ejemplo n.º 25
0
        static async Task Main(string[] args)
        {
            IHost host = Host.CreateDefaultBuilder()
                         .ConfigureServices((context, services) =>
            {
                services.AddSingleton <IEmployeeDataAccess, DemoEmployeeDataAccess>();
                services.AddTransient <IDemoService, DemoService>();
                services.AddLogging();
                services.AddMediatR(typeof(DemoEmployeeDataAccess).Assembly);
            })
                         .Build();

            IDemoService service = host.Services.GetService <IDemoService>();
            await service.RunAsync();

            host.Dispose();
        }
Ejemplo n.º 26
0
 public MainPageViewModel(IDemoService demoService)
 {
     this.demoService = demoService;
     IsActive         = true;
     if (Application.Current.MainWindow == null)
     {
         Message  = "...*";
         Messages = new Models.Messages();
         Messages.Add(new Message()
         {
             MessageId = Guid.NewGuid(), CreateAt = DateTime.Now, Text = "test"
         });
     }
     else
     {
         Message  = "...";
         Messages = demoService.Read();
     }
 }
Ejemplo n.º 27
0
        private static IDemoService CreateServiceProxyByCode()
        {
            WSHttpBinding binding = new WSHttpBinding();

            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Message.ClientCredentialType       = MessageCredentialType.Certificate;
            binding.Security.Message.NegotiateServiceCredential = false;

            EndpointAddress address = new EndpointAddress("http://localhost:8889/DemoService");
            ChannelFactory <IDemoService> factory = new ChannelFactory <IDemoService>(binding, address);

            factory.Credentials.UseIdentityConfiguration      = false;
            factory.Credentials.ClientCertificate.Certificate = Helpers.GetCertificate();
            factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
            factory.Credentials.ServiceCertificate.DefaultCertificate = Helpers.GetCertificate();

            IDemoService proxy = factory.CreateChannel();

            return(proxy);
        }
Ejemplo n.º 28
0
 public DemoController(IDemoService demoService, ISysUserService sysUserService)
 {
     this.demoService    = demoService;
     this.sysUserService = sysUserService;
 }
Ejemplo n.º 29
0
 public DemoController(IDemoService demoService, ISysLogService logService)
 {
     _demoService = demoService;
     _logService  = logService;
 }
 public RandomStringViewComponent(IDemoService demoService) // injected by ASP.NET Core built in dependency injection
 {
     _demoService = demoService;
 }