Exemple #1
0
        private static bool LoadProviderAsService()
        {
            ServiceLoader <SelectorProvider> sl = ServiceLoader.Load(typeof(SelectorProvider), ClassLoader.SystemClassLoader);
            IEnumerator <SelectorProvider>   i  = sl.Iterator();

            for (;;)
            {
                try
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    if (!i.hasNext())
                    {
                        return(false);
                    }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    Provider_Renamed = i.next();
                    return(true);
                }
                catch (ServiceConfigurationError sce)
                {
                    if (sce.Cause is SecurityException)
                    {
                        // Ignore the security exception, try the next provider
                        continue;
                    }
                    throw sce;
                }
            }
        }
 /// <summary>
 /// Initializes the <see cref="ViewModelBase"/> class.
 /// </summary>
 static ViewModelBase()
 {
     if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
     {
         ServiceLoader.LoadDesignTimeServices();
     }
 }
Exemple #3
0
        /// <summary>
        /// 导入数据的具体操作
        /// </summary>
        /// <param name="import"></param>
        /// <param name="info"></param>
        /// <param name="logonInfo"></param>
        protected override void Import(EmployeesImportDetail import, EmployeeInfo info, TokenLogonInfo logonInfo)
        {
            EmployeeService employeeService = ServiceLoader.GetService <EmployeeService>();

            // 新增导入的数据
            employeeService.Create(info, logonInfo);
        }
Exemple #4
0
            public virtual Void Run()
            {
                ServiceLoader <Driver> loadedDrivers   = ServiceLoader.Load(typeof(Driver));
                IEnumerator <Driver>   driversIterator = loadedDrivers.Iterator();

                /* Load these drivers, so that they can be instantiated.
                 * It may be the case that the driver class may not be there
                 * i.e. there may be a packaged driver with the service class
                 * as implementation of java.sql.Driver but the actual class
                 * may be missing. In that case a java.util.ServiceConfigurationError
                 * will be thrown at runtime by the VM trying to locate
                 * and load the service.
                 *
                 * Adding a try catch block to catch those runtime errors
                 * if driver not available in classpath but it's
                 * packaged as service and that service is there in classpath.
                 */
                try
                {
                    while (driversIterator.MoveNext())
                    {
                        driversIterator.Current;
                    }
                }
                catch (Throwable)
                {
                    // Do nothing
                }
                return(null);
            }
Exemple #5
0
        /// <summary>
        /// 排重的检查
        /// </summary>
        /// <param name="import"></param>
        /// <param name="info"></param>
        protected override void RepeatCheck(EmployeesImportDetail import, EmployeeInfo info)
        {
            string fail = string.Empty;
            // 判断是否已经导入过
            EmployeeService employeeService = ServiceLoader.GetService <EmployeeService>();

            if (!string.IsNullOrEmpty(import.Code) && employeeService.SearchQueryable().Where(e => e.Code == import.Code).Count() > 0)
            {
                fail += $"编码为{import.Code}的员工已经导入过,终止再次导入";
            }
            if (!string.IsNullOrEmpty(import.LogonAccount) && employeeService.SearchQueryable().Where(e => e.LogonAccount == import.LogonAccount).Count() > 0)
            {
                fail += $"编码为{import.Code}的{import.Name}员工登陆账号({import.LogonAccount})已存在,终止再次导入";
            }
            if (!string.IsNullOrEmpty(fail))
            {
                import.ImportState   = ImportState.Fail;
                import.FailureReason = fail;
                return;
            }
            else
            {
                import.ImportState   = ImportState.Check;
                import.FailureReason = string.Empty;
            }
        }
Exemple #6
0
 private void startAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!ServiceLoader.AreAllAutoStartServicesRunning && !ServiceLoader.IsStartingService)
     {
         ServiceLoader.AutoStartServices(DisplayServiceError);
     }
 }
Exemple #7
0
 private void stopAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!ServiceLoader.AreAllServicesStopped)
     {
         ServiceLoader.StopAllServices();
     }
 }
Exemple #8
0
 private void LoadFormats()
 {
     foreach (var format in ServiceLoader <IChemFormatMatcher> .Load())
     {
         formats.Add(format);
     }
 }
Exemple #9
0
        /// <summary>
        /// Constructs a new file system that is identified by a <seealso cref="URI"/>
        ///
        /// <para> This method first attempts to locate an installed provider in exactly
        /// the same manner as the <seealso cref="#newFileSystem(URI,Map) newFileSystem(URI,Map)"/>
        /// method. If none of the installed providers support the URI scheme then an
        /// attempt is made to locate the provider using the given class loader. If a
        /// provider supporting the URI scheme is located then its {@link
        /// FileSystemProvider#newFileSystem(URI,Map) newFileSystem(URI,Map)} is
        /// invoked to construct the new file system.
        ///
        /// </para>
        /// </summary>
        /// <param name="uri">
        ///          the URI identifying the file system </param>
        /// <param name="env">
        ///          a map of provider specific properties to configure the file system;
        ///          may be empty </param>
        /// <param name="loader">
        ///          the class loader to locate the provider or {@code null} to only
        ///          attempt to locate an installed provider
        /// </param>
        /// <returns>  a new file system
        /// </returns>
        /// <exception cref="IllegalArgumentException">
        ///          if the pre-conditions for the {@code uri} parameter are not met,
        ///          or the {@code env} parameter does not contain properties required
        ///          by the provider, or a property value is invalid </exception>
        /// <exception cref="FileSystemAlreadyExistsException">
        ///          if the URI scheme identifies an installed provider and the file
        ///          system has already been created </exception>
        /// <exception cref="ProviderNotFoundException">
        ///          if a provider supporting the URI scheme is not found </exception>
        /// <exception cref="ServiceConfigurationError">
        ///          when an error occurs while loading a service provider </exception>
        /// <exception cref="IOException">
        ///          an I/O error occurs creating the file system </exception>
        /// <exception cref="SecurityException">
        ///          if a security manager is installed and it denies an unspecified
        ///          permission required by the file system provider implementation </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static FileSystem newFileSystem(java.net.URI uri, Map<String,?> env, ClassLoader loader) throws java.io.IOException
        public static FileSystem newFileSystem <T1>(URI uri, Map <T1> env, ClassLoader loader)
        {
            String scheme = uri.Scheme;

            // check installed providers
            foreach (FileSystemProvider provider in FileSystemProvider.InstalledProviders())
            {
                if (scheme.EqualsIgnoreCase(provider.Scheme))
                {
                    return(provider.NewFileSystem(uri, env));
                }
            }

            // if not found, use service-provider loading facility
            if (loader != null)
            {
                ServiceLoader <FileSystemProvider> sl = ServiceLoader.Load(typeof(FileSystemProvider), loader);
                foreach (FileSystemProvider provider in sl)
                {
                    if (scheme.EqualsIgnoreCase(provider.Scheme))
                    {
                        return(provider.NewFileSystem(uri, env));
                    }
                }
            }

            throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
        }
Exemple #10
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     //if (MessageBox.Show("是否确认退出?", "", MessageBoxButtons.YesNo) == DialogResult.No)
     //    e.Cancel = true;
     //注意判断关闭事件Reason来源于窗体按钮,否则用菜单退出时无法退出!
     if (e.CloseReason == CloseReason.UserClosing)
     {
         e.Cancel           = true;                      //取消"关闭窗口"事件
         this.WindowState   = FormWindowState.Minimized; //使关闭时窗口向右下角缩小的效果
         notifyIcon.Visible = true;
         //this.ShowInTaskbar = true;  //显示在系统任务栏
         this.Hide();
         return;
     }
     try
     {
         ServiceLoader.LoadService <IUdpMsgService>().Stop();
         hostZKService.Close();
         menjincontrolerservice.Close();
     }
     catch (Exception)
     {
     }
     if (RunMutex != null)
     {
         RunMutex.Close();
     }
 }
Exemple #11
0
        static void Bind()
        {
            try
            {
                List <SlfServiceProvider> providersList = ServiceLoader <SlfServiceProvider> .Load();

                if (providersList != null && providersList.Count > 1)
                {
                    _provider = providersList[0];
                    _provider.Initialize();
                    _initializationState = SuccessfulInitialization;
                    FixSubstituteLoggers();
                    ((SubstituteLoggerFactory)SubstProvider.LoggerFactory).Clear();
                }
                else
                {
                    _initializationState = NopFallbackInitialization;
                }
            }
            catch (Exception e)
            {
                FailedBinding(e);
                throw new Exception("Unexpected initialization failure.", e);
            }
        }
Exemple #12
0
        public async Task Run()
        {
            ServiceLoader.RegisterServices(
                typeof(ServiceOne),
                typeof(ServiceTwo)
                );

            var ress = await sp.Create <ServiceOne>().MethodOne(new MethodRequestOne {
                Text = "Hi there!"
            })
                       .Next((res) => sp.Create <ServiceTwo>().MethodTwo(new MethodRequestTwo {
                Text = res.Text + " Hello "
            }))
                       .Next((res) => sp.Create <ServiceTwo>().MethodThree(new MethodRequestThree {
                Text = res.Text + " there!"
            }))
                       .OnError((error) =>
            {
                Console.WriteLine("ERROR!!! " + error.Description);
                return(Task.FromResult(new Response <MethodResponseThree>(error)));
            });

            if (ress.HasError)
            {
                Console.WriteLine("Returned error " + ress.Error.Description);
            }
            else
            {
                Console.WriteLine("Returned " + ress.Result.Text);
            }
        }
Exemple #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .AddJsonOptions(opt => {
                opt.SerializerSettings.DateFormatString = "yyyy-MM-dd";
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddCors();

            services.AddDbContext <Money2Context>(options => options.UseMySql(Configuration.GetConnectionString("Money2Database")));

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,

                    ValidIssuer      = JwtConfig.Issuer,
                    ValidAudience    = JwtConfig.Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(JwtConfig.SecretKey)
                };
            });

            ServiceLoader.Load(services);
        }
Exemple #14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            ServiceLoader.ConfigureServices(services);

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "QDot API",
                    Description    = "QDot C# exercise",
                    TermsOfService = "None"
                });

                //Set the comments path for the swagger json and ui.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "QDotAPI.xml");
                c.IncludeXmlComments(xmlPath);
            });

            // Register the IConfiguration instance which MyOptions binds against.
            services.Configure <InfraestructureSettings>(Configuration.GetSection("infraestructureSettings"));
            services.Configure <ApiClientSettings>(Configuration.GetSection("apiClientSettings"));
        }
Exemple #15
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(HttpGlobalExceptionFilter));
            });

            ServiceLoader.ConfigureServices(services, Configuration);

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "QDot Location API",
                    Description    = "API for searching US zip codes locations",
                    TermsOfService = "None"
                });

                //Set the comments path for the swagger json and ui.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "QDot.Location.API.xml");
                c.IncludeXmlComments(xmlPath);
            });
        }
Exemple #16
0
        protected internal virtual void lookUpContainerSpecifics()
        {
            if (this.containerSpecifics == null)
            {
                ServiceLoader <ContainerSpecifics> serviceLoader = ServiceLoader.load(typeof(ContainerSpecifics));
                IEnumerator <ContainerSpecifics>   it            = serviceLoader.GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                if (it.hasNext())
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    ContainerSpecifics containerSpecifics = it.next();

                    this.containerSpecifics = containerSpecifics;

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    if (it.hasNext())
                    {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        LOGGER.warning("There is more than one test runtime container implementation present on the classpath. " + "Using " + containerSpecifics.GetType().FullName);
                    }
                }
                else
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new Exception("Could not find container provider SPI that implements " + typeof(ContainerSpecifics).FullName);
                }
            }
        }
Exemple #17
0
        public override sealed void Enable(ServiceArgs args)
        {
            this.PlatformLoader = args.PlatformLoader;
            this.ServiceLoader  = args.ServiceLoader;

            base.Enable(args);
        }
Exemple #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldServiceLoaderFindCypherEngineProvider()
        public virtual void ShouldServiceLoaderFindCypherEngineProvider()
        {
            // WHEN
            ServiceLoader <QueryEngineProvider> services = ServiceLoader.load(typeof(QueryEngineProvider));

            // THEN
            assertTrue(Iterables.single(services) is CommunityCypherEngineProvider);
        }
 public static IServiceCollection AddInProcProxyClient(this IServiceCollection services, params Type[] hostedServices)
 {
     ServiceLoader.RegisterServices(hostedServices);
     return(services
            .AddTransient <IServiceProxy, InProcServiceProxy>()
            .AddTransient <ServiceLoader>()
            .AddTransient <ServiceProxy>());
 }
        static public TencentConfigInfo Load()
        {
            TencentConfigService service = ServiceLoader.GetService <TencentConfigService>();

            return(service.Load(new TokenLogonInfo {
                Id = "", Name = "系统自动"
            }));
        }
Exemple #21
0
        private void toolStripACTimeZones_Click(object sender, EventArgs e)
        {
            var udpmsgservice = ServiceLoader.LoadService <IUdpMsgService>();

            udpmsgservice.Stop();
            //MenJin.ACTimeZonesManage frm = new CardSolutionHost.MenJin.ACTimeZonesManage();
            //frm.ShowDialog();
        }
Exemple #22
0
        public ResultView Login(string id)
        {
            DepartmentService departmentService = ServiceLoader.GetService <DepartmentService>();
            var dep = departmentService._SearchById(id);

            return(ResultView.Success());
            //return new LoginResult { Token = token };
        }
Exemple #23
0
        /// <summary>
        /// 默认自动注册
        /// </summary>
        static ParseTreeVisitorFactory()
        {
            var sqlParserConfigurations = ServiceLoader.Load <ISqlParserConfiguration>();

            foreach (var sqlParserConfiguration in sqlParserConfigurations)
            {
                SQL_PARSER_CONFIGURATIONS.Add(sqlParserConfiguration.GetDataSourceName(), sqlParserConfiguration);
            }
        }
Exemple #24
0
        void App_Startup(object sender, StartupEventArgs e)
        {
            //HACK - how to force all TextBoxes to select their text on focus
            EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus), true);
            ServiceLoader.LoadRunTimeServices();
            var w = new Shell();

            w.Show();
        }
        /// <summary>
        /// 默认自动注册
        /// </summary>
        static DatabaseTypes()
        {
            var databaseTypes = ServiceLoader.Load <IDatabaseType>();

            foreach (var databaseType in databaseTypes)
            {
                DATABASE_TYPES.Add(databaseType.GetName(), databaseType);
            }
        }
Exemple #26
0
        public void ShouldLoadTypeImplementationsHavingTheirTypeNameAsTheServiceName()
        {
            var loader = new ServiceLoader();
            IEnumerable <IServiceInfo> list = loader.Load(hostAssembly);

            var expectedService = new ServiceInfo(typeof(IPerson), typeof(Person), "Person");
            var serviceList     = new List <IServiceInfo>(list);

            Assert.IsTrue(serviceList.Contains(expectedService));
        }
        public void UpdateAdmin()
        {
            var employeeService = ServiceLoader.GetService <EmployeeService>();

            if (employeeService.SearchQueryable().Count() > 0)
            {
                ApiException.ThrowBadRequest("系统中拥有用户信息,无密码初始化失败。您可以通过管理员账号登陆后再初始化");
            }
            Init();
        }
        /// <summary>
        /// 删除时的检查
        /// </summary>
        /// <param name="info"></param>
        protected override void DeleteRemoveCheck(RoleInfo info)
        {
            //如果角色下有员工信息,不允许删除
            EmployeeService employeeService = ServiceLoader.GetService <EmployeeService>();

            if (employeeService.CountByRoleId(info.Id.ToString()) > 0)
            {
                throw ApiException.BadRequest("角色下有员工信息,不允许删除");
            }
        }
 /// <summary>
 /// 部门更新的后置处理
 /// </summary>
 /// <param name="depInfo">新的部门信息</param>
 /// <param name="oldInfo">旧的部门信息</param>
 /// <param name="logonInfo"></param>
 internal static void OnDepartmentUpdated(DepartmentInfo depInfo, DepartmentInfo oldInfo, TokenLogonInfo logonInfo)
 {
     // 更新员工信息
     ThreadPool.QueueUserWorkItem(h =>
     {
         EmployeeService service = ServiceLoader.GetService <EmployeeService>();
         // 更新所有的员工信息
         service.UpdateByDepartmentInfo(depInfo, oldInfo);
     });
 }
Exemple #30
0
 protected override void RegisterViews()
 {
     base.RegisterViews();
     ServiceLoader.RegisterService <IMenuView, MenuView, IMenuViewModel, MenuViewModel>(RolodexService.Menu);
     ServiceLoader.RegisterService <ILoginView, LoginView, ILoginViewModel, LoginViewModel>(RolodexService.Login);
     ServiceLoader.RegisterService <IStatusesView, StatusesView, IStatusesViewModel, StatusesViewModel>(RolodexService.Statuses);
     ServiceLoader.RegisterService <ICompaniesView, CompaniesView, ICompaniesViewModel, CompaniesViewModel>(RolodexService.Companies);
     ServiceLoader.RegisterService <ICompanyEditView, CompanyEditView, ICompanyEditViewModel, CompanyEditViewModel>(RolodexService.CompanyEdit);
     ServiceLoader.LoadService(RolodexService.Login);
 }
 public MuffinArgs(PlatformLoader platformLoader, ServiceLoader serviceLoader, MuffinLoader muffinLoader)
 {
     this.PlatformLoader = platformLoader;
     this.ServiceLoader = serviceLoader;
     this.MuffinLoader = muffinLoader;
 }
 public ServiceArgs(PlatformLoader platformLoader, ServiceLoader serviceLoader)
 {
     this.PlatformLoader = platformLoader;
     this.ServiceLoader = serviceLoader;
 }
 private void InitLoaders()
 {
     this.PlatformLoader = new PlatformLoader();
     this.ServiceLoader = new ServiceLoader();
     this.MuffinLoader = new MuffinLoader();
 }
Exemple #34
0
        private static void FindVdsDisk(string serverName, Func<Disk, bool> compareFunc, out AdvancedDisk advancedDisk, out Pack diskPack)
        {
            advancedDisk = null;
            diskPack = null;

            ServiceLoader serviceLoader = new ServiceLoader();
            Service vds = serviceLoader.LoadService(serverName);
            vds.WaitForServiceReady();

            foreach (Disk disk in vds.UnallocatedDisks)
            {
                if (compareFunc(disk))
                {
                    advancedDisk = (AdvancedDisk) disk;
                    break;
                }
            }

            if (advancedDisk == null)
            {
                vds.HardwareProvider = false;
                vds.SoftwareProvider = true;

                foreach (SoftwareProvider provider in vds.Providers)
                    foreach (Pack pack in provider.Packs)
                        foreach (Disk disk in pack.Disks)
                            if (compareFunc(disk))
                            {
                                diskPack = pack;
                                advancedDisk = (AdvancedDisk) disk;
                                break;
                            }
            }
        }