public static void Test()
        {
            var      p  = new Person("Magesh", "Kuppan");
            IWelcome iw = p;

            iw.Greet();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace);

            MyMethodClass method  = new MyMethodClass();
            IWelcome      welcome = method;

            method.Completed += method_Completed;
            Console.WriteLine(welcome.Greeting("Polaris"));
            Marshal.ReleaseComObject(method);

            try
            {
                Console.WriteLine(welcome.Greeting("Polaris"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            //Type t = Type.GetTypeFromProgID("PlsInteropCOMServerLib.MyMethodClass");
            //dynamic o = Activator.CreateInstance(t);
            //Console.WriteLine(t.ToString());

            Console.ReadKey();
        }
        public static void InvokeIWelcome()
        {
            // If the object — as in this case — offers multiple interfaces, a variable of the other interface can be
            // declared, and by using a simple assignment with the cast operator, the wrapper class does a
            // QueryInterface() with the COM object to return the second interface pointer.

            IWelcome welcome = comObj;

            Alert.Show(welcome.Greeting("Heya! I'm Greeting() invoked from the COM!!"));
        }
示例#4
0
        static void Main(string[] args)
        {
            var      obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("John"));
            //
            IMath math = (IMath)obj;
            int   x    = math.Add(3, 5);

            Console.WriteLine(x);
            //释放内存
            Marshal.ReleaseComObject(math);
        }
示例#5
0
        static void Main(string[] args)
        {
            COMDemo  obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("Stephanie"));

            IMath math;

            math = (IMath)welcome;
            int x = math.Add(4, 5);

            Console.WriteLine(x);
        }
示例#6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              IWelcome welcome)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc(Configuration);

            app.Run(async(context) =>
            {
                var welcomemsg = welcome.WelcomeMessage();
                await context.Response.WriteAsync(welcomemsg);
            });
        }
示例#7
0
        private static void Main()
        {
            var      obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("Stephanie"));

            obj.Completed += () => Console.WriteLine("Calculation completed");

            var math = (IMath)welcome;
            var x    = math.Add(4, 5);

            Console.WriteLine(x);

            Marshal.ReleaseComObject(math);
        }
示例#8
0
文件: Program.cs 项目: zilo312/aa
        static void Main()
        {
            COMDemo  obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("Christian"));

            obj.Completed += () => Console.WriteLine("Calculation completed");
            //delegate
            //{
            //   Console.WriteLine("Calculation completed");
            //};

            IMath math;

            math = (IMath)welcome;
            int x = math.Add(4, 5);

            Console.WriteLine(x);

            Marshal.ReleaseComObject(math);
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration configuration, IWelcome welcome)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //var builder = new ConfigurationBuilder().AddJsonFile(path);
            //var configuration = builder.Build();

            /*app.Run(async (context) =>
             * {
             *  //await context.Response.WriteAsync("Hello World!");
             *  var msg = configuration["WelcomeMsg"];
             *  await context.Response.WriteAsync(msg);
             *  //await context.Response.WriteAsync("Hello World!");
             * });*/
            //要将程序发布到linux系统下需配置反向代理的内容
            //if(env.IsProduction())一般在生产环境下采用下面的UseForwardedHeaders策略
            //{

            //}
            app.UseForwardedHeaders(new ForwardedHeadersOptions {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.Use(next =>
            {
                return(async context =>
                {
                    if (context.Request.Path.StartsWithSegments("/first"))
                    {
                        await context.Response.WriteAsync("First");
                    }
                    else
                    {
                        await next(context);
                    }
                });
            });
            app.UseWelcomePage(new WelcomePageOptions
            {
                Path = "/welcome"
            });

            app.UseStatusCodePages();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
            });


            app.Run(async(context) =>
            {
                context.Response.ContentType = "text/plain;charset=utf-8";
                var msg = welcome.GetWelcomeMsg();
                await context.Response.WriteAsync(msg);
            });
            //app.UseWelcomePage();
        }
示例#10
0
 public HomeController(IWelcome welcome)
 {
     _welcome = welcome;
 }