Beispiel #1
0
        static ModuleBuilder CreateModuleForApiVersion(ApiVersion apiVersion)
        {
            var name            = new AssemblyName($"T{NewGuid().ToString( "n", InvariantCulture )}.DynamicModels");
            var assemblyBuilder = CurrentDomain.DefineDynamicAssembly(name, Run);

            return(assemblyBuilder.DefineDynamicModule("<module>"));
        }
Beispiel #2
0
        /// <summary>
        /// 加载程序集到当前运行域中
        /// </summary>
        /// <param name="assemblies">程序集.</param>
        /// <returns></returns>
        private Assembly[] LoadAssemblyIntoAppDomain(Assembly[] assemblies)
        {
            if (assemblies == null || assemblies.Length == 0)
            {
                return new Assembly[] { }
            }
            ;

            var result = new List <Assembly>(assemblies.Length);
            /*已加载的程序集*/
            var names = new List <Assembly>(100);

            names.AddRange(CurrentDomain.GetAssemblies());
            bool isNull = names == null || names.Count == 0;

            foreach (var assembly in assemblies)
            {
                try
                {
                    if (isNull || names.Find(o => o.FullName.Contains(assembly.FullName)) == null)
                    {
                        result.Add(CurrentDomain.Load(new AssemblyName(assembly.FullName)));
                    }
                }
                catch (BadImageFormatException ex)
                {
                    Trace.WriteLine(ex.ToString());
                }
            }

            return(result.ToArray());
        }
Beispiel #3
0
        public List <SecurityAgent> ReadAgentsFromDisk()
        {
            if (String.IsNullOrEmpty(IddsConfig.Instance.PluginsDirectory))
            {
                throw new ApplicationException("Application is not initialized.");
            }
            List <SecurityAgent> result = new List <SecurityAgent>();
            AppDomainSetup       setup  = AppDomain.CurrentDomain.SetupInformation;

            System.Security.Policy.Evidence adevidence = AppDomain.CurrentDomain.Evidence;
            CurrentDomain = AppDomain.CreateDomain("Cyberarms.Agents.Enumerator", adevidence, setup);

            foreach (string fileName in Directory.EnumerateFiles(IddsConfig.Instance.PluginsDirectory, "*.dll"))
            {
                if (!fileName.Contains(".Api.dll"))
                {
                    Type             tProxy = typeof(AgentLoaderProxy);
                    AgentLoaderProxy proxy  = (AgentLoaderProxy)CurrentDomain.CreateInstanceAndUnwrap(
                        tProxy.Assembly.FullName,
                        tProxy.FullName);
                    List <SecurityAgent> agents = proxy.GetSecurityAgents(fileName);
                    result.AddRange(agents);
                }
            }
            return(result);
        }
Beispiel #4
0
        public static void HandleException(this DevExpress.ExpressApp.XafApplication application, Exception exception)
        {
            try {
                var platform = application.GetPlatform();
                switch (platform)
                {
                case Platform.Win:
                    application.CallMethod("HandleException", exception);
                    break;

                case Platform.Web:
                    CurrentDomain.XAF().ErrorHandling().CallMethod("SetPageError", exception);
                    break;

                default:
                    application.GetPropertyValue("ExceptionService").CallMethod("HandleException", exception);
                    break;
                }
                Tracer.LogError(exception);
            }
            catch (Exception e) {
                Tracer.LogError(e);
                throw;
            }
        }
Beispiel #5
0
        public static IDomain Create([NotNull] IDomain domain)
        {
            if (domain is null)
            {
                throw new ArgumentNullException(nameof(domain));
            }

            CurrentDomain.ThrowIfAlreadyInitialized();
            CurrentDomain.Current = domain;
            return(Current);
        }
Beispiel #6
0
 public object Clone()
 {
     if (!IsInitialized())
     {
         return(new Domain(OutsideScope));
     }
     else
     {
         var d = new Domain(InitialDomain.ConvertAll(v => v), OutsideScope);
         d.CurrentDomain = CurrentDomain.ConvertAll(v => v);
         return(d);
     }
 }
Beispiel #7
0
        private double CalculateFrequencyRepeat()
        {
            double frequency = 0;

            for (int i = 0; i < DomainLength - 1; i++)
            {
                string gram = CurrentDomain.Substring(i, 2);  //2 - Размер граммы

                frequency += Regex.Matches(CurrentDomain, gram).Count;
            }

            return(frequency / (DomainLength - 1));
        }
Beispiel #8
0
        internal static IMvcCoreBuilder AddHal(this IMvcCoreBuilder @this, JsonSerializerSettings serializerSettings)
        {
            NewResourceBuilders(CurrentDomain
                                .GetAssemblies()
                                .SelectMany(assembly => assembly.GetTypes())
                                .Where(type => typeof(IResourceBuilder).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract)
                                .Select(type => CreateInstance(type) as IResourceBuilder)
                                .SelectMany(item => item?.Builders)
                                .ToDictionary(item => item.Key, item => item.Value));

            return(@this
                   .AddMvcOptions(options => options
                                  .OutputFormatters
                                  .Add(new HalJsonOutputFormatter(serializerSettings))));
        }
Beispiel #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public static void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <ITextService, TextService> ();
            services.AddScoped <ICategoriesService, CategoriesService> ();
            services.AddScoped <IIssueService, IssueService> ();
            services.AddScoped <IAuthorService, AuthorService> ();
            services.AddScoped <IMessageService, MessageService> ();
            services.AddScoped <ITashkeelFacade, TashkeelFacade> ();
            services.AddScoped <IChangelogService, ChangelogService> ();
            services.AddScoped <IWordOfTheDayService, WordOfTheDayService> ();

            services.AddDbContext <ApiContext> (options =>
                                                options.UseSqlServer(GetEnvironmentVariable("ASPNETCORE_CONNECTION_STRING") ??
                                                                     throw new InvalidOperationException()));

            services.AddAutoMapper(CurrentDomain.GetAssemblies());

            services.AddHttpClient();

            services.AddControllers(options => { options.ReturnHttpNotAcceptable = true; })
            .AddFluentValidation(ConfigurationExpression);

            services.AddCors(options => {
                options.AddPolicy(AllowSpecificOrigins, builder => {
                    builder.WithOrigins(GetEnvironmentVariable("ASPNETCORE_ORIGINS"));
                    builder.AllowAnyMethod();
                    builder.AllowAnyHeader();
                });
            });

            services.AddSwaggerGen(options => {
                options.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "OpenArabic", Version = "0.1.0"
                });
            });

            services.AddAuthentication(options => {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options => {
                options.Authority = GetEnvironmentVariable("ASPNETCORE_AUTHORITY");
                options.Audience  = GetEnvironmentVariable("ASPNETCORE_AUDIENCE");
            });

            services.AddAuthorization();

            services.AddHealthChecks();
        }
Beispiel #10
0
        } = false;                                                 // Is the command manager loaded
        #endregion

        #region Public Functions
        public static void Load()
        {
            Commands = new Dictionary <CommandAttribute, Command>();                                                               // Create the commands list

            foreach (Assembly assembly in CurrentDomain.GetAssemblies())                                                           // Loop all assemblies
            {
                foreach (Type _class in assembly.GetTypes())                                                                       // Loop all classes
                {
                    CommandAttribute attribute = (CommandAttribute)Attribute.GetCustomAttribute(_class, typeof(CommandAttribute)); // Get the command attribute

                    if (!_class.IsClass || !typeof(Command).IsAssignableFrom(_class) || attribute == null)                         // Check if the command is valid
                    {
                        continue;
                    }

                    Commands.Add(attribute, (Command)Activator.CreateInstance(_class)); // Add the command
                }
            }

            IsLoaded = true; // Set the isloaded
        }
Beispiel #11
0
 /**
  * Get the highest value in the domain.
  */
 public int MaxValue()
 {
     return(CurrentDomain.Max());
 }
Beispiel #12
0
 public static IDomain Create(String name)
 {
     CurrentDomain.ThrowIfAlreadyInitialized();
     return(Create(new AppData(name, AppVersion.Default)));
 }
Beispiel #13
0
 public static IDomain Create <TApp>(TApp app, IAppData data, GUIType type) where TApp : Application, new()
 {
     CurrentDomain.ThrowIfAlreadyInitialized();
     return(Create(data).Initialize(app, type));
 }
Beispiel #14
0
 public static IDomain Create(IAppData data)
 {
     CurrentDomain.ThrowIfAlreadyInitialized();
     return(Create(new InternalDomain(data)));
 }
Beispiel #15
0
 public static IDomain Create <TApp>(String name, GUIType type) where TApp : Application, new()
 {
     CurrentDomain.ThrowIfAlreadyInitialized();
     return(Create <TApp>(new AppData(name, AppVersion.Default), type));
 }
Beispiel #16
0
 /**
  * Get the index of a given value.
  * @return If the given value is in the domain, it returns its index, and -1 otherwise.
  */
 public int IndexOf(int value)
 {
     return(CurrentDomain.IndexOf(value));
 }
Beispiel #17
0
 /**
  * Get the lowest value in the domain.
  */
 public int MinValue()
 {
     return(CurrentDomain.Min());
 }
Beispiel #18
0
 /**
  * Deletes a given value from the set of current domain values.
  * @param value is the value to remove from the domain
  * @return True if and only if the value has been removed.
  */
 public bool RemoveValue(int value)
 {
     return(CurrentDomain.Remove(value));
 }