コード例 #1
0
        public void ShouldReplaceOldBindingWithGivenBinding()
        {
            Core.IoC.Resolver = new NinjectDependencyResolver();
            Core.IoC.Resolver.Register <IStub, StubImplOne>();
            Core.IoC.Resolver.Register <IStub, StubImplOne>();
            Core.IoC.Resolver.Register <IStub, StubImplTwo>();

            IStub stub = Core.IoC.Resolver.Resolve <IStub>();

            Assert.IsInstanceOf <StubImplTwo>(stub, "Stub should have been instance of StubImplTwo.");
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: Daoting/dt
        /// <summary>
        /// 应用程序启动
        /// </summary>
        /// <typeparam name="T">存根类型</typeparam>
        /// <param name="p_launchArgs">启动参数</param>
        /// <param name="p_shareInfo">接收分享的内容描述</param>
        /// <returns></returns>
        public static async Task Launch <T>(string p_launchArgs, ShareInfo p_shareInfo)
            where T : IStub
        {
            // 非null表示app已启动过
            if (Kit.Stub != null)
            {
                // 带参数启动
                if (!string.IsNullOrEmpty(p_launchArgs))
                {
                    Kit.RunAsync(() => LaunchFreely(p_launchArgs));
                }
                Window.Current.Activate();

                if (p_shareInfo != null)
                {
                    Kit.RunAsync(() => Kit.Stub.ReceiveShare(p_shareInfo));
                }
                return;
            }

            IStub stub = Activator.CreateInstance <T>();

            Kit.Startup(stub, new DefaultCallback());

            // 加载资源
            var res = Application.Current.Resources;

            res.MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("ms-appx:///Dt.Base/Themes/Generic.xaml")
            });
#if WASM
            // 自定义图标字体库,因Global.xaml中前缀无效无法定义
            res["IconFont"] = new FontFamily("DtIcon");
            res["Symbols"]  = new FontFamily("Symbols");
#endif

            InputManager.Init();
            NotifyManager.Init();
            _launchArgs = p_launchArgs;

            // 设置WinUI模式与PhoneUI模式切换的回调方法
            // 此处调用会通过SysVisual的静态构造方法创建整个系统可视树
            SysVisual.UIModeChanged = OnUIModeChanged;

            // 从存根启动,因uno中无法在一个根UI的Loaded事件中切换到另一根UI,所以未采用启动页方式
            await stub.OnStartup();

            if (p_shareInfo != null)
            {
                stub.ReceiveShare(p_shareInfo);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: lovecruel/hprose1.x-dotnet
        static void Main(string[] args)
        {
            HproseClient client = HproseClient.Create("tcp://127.0.0.1:4321");

            client.Filter = new MyClientFilter();
            IStub stub = client.UseService <IStub>();

            Console.WriteLine(stub.Inc());
            Console.WriteLine(stub.Inc());
            Console.WriteLine(stub.Inc());
            Console.WriteLine(stub.Inc());
            Console.ReadKey();
        }
コード例 #4
0
        /// <summary>
        /// 系统初始化
        /// </summary>
        /// <param name="p_stub">系统存根</param>
        /// <param name="p_callback"></param>
        internal static void Startup(IStub p_stub, ICallback p_callback)
        {
            Stub     = p_stub;
            Callback = p_callback;
            if (Stub.SerializeTypes != null)
            {
                SerializeTypeAlias.Merge(Stub.SerializeTypes);
            }

            var app = Application.Current;

            app.Suspending += OnSuspending;
            app.Resuming   += OnResuming;

            // 异常处理
#if UWP
            app.UnhandledException += OnUwpUnhandledException;
#elif ANDROID
            Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += OnAndroidUnhandledException;
#elif IOS
            // 在iOS项目的Main函数处理
#elif WASM
            //TaskScheduler.UnobservedTaskException += (s, e) => OnUnhandledException(e.Exception);
            AppDomain.CurrentDomain.UnhandledException += (s, e) => OnUnhandledException(e.ExceptionObject as Exception);
#endif

            // 创建本地文件存放目录
            if (!Directory.Exists(CachePath))
            {
                Directory.CreateDirectory(CachePath);
            }
            if (!Directory.Exists(DataPath))
            {
                Directory.CreateDirectory(DataPath);
            }

#if WASM
            // .net5.0 只能引用 SQLite3Provider_sqlite3,DllImport("sqlite3")
            // 默认为 SQLite3Provider_e_sqlite3 引用时出错!
            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
#else
            // 初始化不同平台的包绑定!V2支持类型和属性的绑定
            // 内部调用 SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
            SQLitePCL.Batteries_V2.Init();
#endif

            // 打开状态库
            AtState.OpenDb();
        }
コード例 #5
0
ファイル: Session.cs プロジェクト: jtruty/semantria-sdk
        private int Update <T>(QueryMethod method, List <T> items, string configId = null)
        {
            string tag = this.GetTag <T>();

            string url = String.Format("{0}/{1}.{2}", _host, tag, _format);

            if (!String.IsNullOrEmpty(configId))
            {
                url = String.Format("{0}/{1}.{2}?config_id={3}", _host, tag, _format, configId);
            }

            string data = null;

            if (method == QueryMethod.DELETE)
            {
                IStub <T> xstub = this.GetStub <T>(items) as IStub <T>;
                xstub.ToKeys();
                if (_format == "xml")
                {
                    data = _serializer.Serialize(xstub);
                    data = xstub.ConvertTag(data);
                }
                else
                {
                    data = _serializer.Serialize(xstub.Keys);
                }
            }
            else
            {
                object stub = items;
                if (_format == "xml")
                {
                    stub = this.GetStub <T>(items);
                }
                data = _serializer.Serialize(stub);
            }

            AuthResponse authResponse = this.RunRequest(method, url, data);

            return(this.ProcessPostResponse <T>(authResponse));
        }
        public void ShouldImportMultipleTimes()
        {
            DirectoryCompositionInitializer.SatisfyImports(this);
            var import1 = StubImport;

            StubImport = null;

            DirectoryCompositionInitializer.SatisfyImports(this);
            var import2 = StubImport;

            // ---

            import1.ShouldBeInstanceOfType<Stub>();
            import2.ShouldBeInstanceOfType<Stub>();
            import1.ShouldNotBe(import2);
        }