Beispiel #1
0
 public HandlerFactory(IAssemblyBuilder builder, INodeServices nodeServices,
                       params Assembly[] defaultDependencies)
 {
     _builder             = builder;
     _nodeServices        = nodeServices;
     _defaultDependencies = defaultDependencies ?? GetRuntimeAssemblies();
 }
Beispiel #2
0
 public HandlerFactory(IAssemblyBuilder builder, INodeServices nodeServices,
                       IEnumerable <Assembly> defaultDependencies)
 {
     _builder             = builder;
     _nodeServices        = nodeServices;
     _defaultDependencies = defaultDependencies ?? GetRuntimeAssemblies();
 }
        /// <summary>
        /// Tries to create the specified assembly on Transloadit. Bored instance is requested at first. If there is one, then it will
        /// be used to proceed the request, which can be completed on a bored instance.
        /// </summary>
        /// <param name="assembly">Specified assembly which will be tried to be created.
        /// Please use TransloaditAssemblyBuilder to create a new assembly</param>
        /// <returns>Represents the whole result of the request. 
        /// Response object will be created everytime, please use its properties to get the detailed result on the request</returns>
        public TransloaditResponse InvokeAssembly(IAssemblyBuilder assembly)
        {
            TransloaditRequest request = Request();
            assembly.SetAuthKey(Key);

            request.Method = ApiRequestMethods.RequestMethod.Get;
            request.Path = TransloaditRequest.BoredInstancePath;

            TransloaditResponse boredInstance = (TransloaditResponse)RequestAndExecute(request);

            string host = request.Host;
            if (boredInstance.Success)
            {
                host = (string)boredInstance.Data["api2_host"];
            }

            TransloaditRequest invokeRequest = Request();
            invokeRequest.Host = host;
            invokeRequest.Method = ApiRequestMethods.RequestMethod.Post;
            invokeRequest.Path = TransloaditRequest.AssemblyRoot;

            DateTime expirationDateTime = DateTime.UtcNow;

            double expirationMinutes = 120;
            expirationDateTime = expirationDateTime.AddMinutes(expirationMinutes);
            assembly.SetAuthExpires(expirationDateTime);

            string paramValue = (string)assembly.ToJsonString();
            string signatureValue = GetSignature(paramValue);

            invokeRequest.Data = assembly.ToApiData();
            invokeRequest.Data.Fields.Add("signature", signatureValue);

            return invokeRequest.Execute();
        }
        public ModuleBuilderAdapter(ModuleBuilder moduleBuilder)
            : base(ArgumentUtility.CheckNotNull("moduleBuilder", moduleBuilder).SetCustomAttribute)
        {
            Assertion.IsTrue(moduleBuilder.Assembly is AssemblyBuilder);

            _moduleBuilder   = moduleBuilder;
            _assemblyBuilder = new AssemblyBuilderAdapter(((AssemblyBuilder)moduleBuilder.Assembly), moduleBuilder);
        }
        private string SaveToDisk(IAssemblyBuilder assemblyBuilder, IEnumerable <CustomAttributeDeclaration> assemblyAttributes)
        {
            foreach (var attribute in assemblyAttributes)
            {
                assemblyBuilder.SetCustomAttribute(attribute);
            }

            return(assemblyBuilder.SaveToDisk());
        }
Beispiel #6
0
        /// <summary>
        /// Initialises a new instance of the <see cref="TypeFactory"/> class.
        /// </summary>
        /// <param name="assemblyName">The assembly name.</param>
        /// <param name="moduleName">The module name.</param>
        public TypeFactory(string assemblyName, string moduleName)
        {
            Utility.ThrowIfArgumentNullEmptyOrWhitespace(assemblyName, nameof(assemblyName));
            Utility.ThrowIfArgumentNullEmptyOrWhitespace(moduleName, nameof(moduleName));

            this.assemblyCache   = new AssemblyBuilderCache();
            this.assemblyBuilder = this.assemblyCache.GetOrCreateAssemblyBuilder(assemblyName);
            this.moduleBuilder   = this.assemblyBuilder.NewDynamicModule(moduleName);
        }
Beispiel #7
0
        private void OnCodeGenerationStarted(IAssemblyBuilder assemblyBuilder)
        {
            _assemblyBuilder = assemblyBuilder;
            EventHandler handler = _codeGenerationStartedInternal ?? CodeGenerationStarted;

            if (handler != null)
            {
                handler(this, null);
            }
        }
 internal virtual void GenerateCodeCore(IAssemblyBuilder assemblyBuilder)
 {
     OnCodeGenerationStarted(assemblyBuilder);
     assemblyBuilder.AddCodeCompileUnit(this, GeneratedCode);
     assemblyBuilder.GenerateTypeFactory(
         String.Format(
             CultureInfo.InvariantCulture,
             "{0}.{1}",
             Host.DefaultNamespace,
             Host.DefaultClassName
             )
         );
 }
Beispiel #9
0
        public bool BuildProject(string Configuration)
        {
            bool bresult;

            IAssemblyBuilder builder = (IAssemblyBuilder)Activator.CreateInstance(typeof(BS), new object[] { ProjectFilePath, ProjectFilePath });

            if (!(bresult = builder.BuildProject()))
            {
                logger.Error("build project failure: {0}", builder.Log);
            }
            lastBuildLog = builder.Log;

            return(bresult);
        }
Beispiel #10
0
        public bool BuildProject(string Configuration, out AssemblyBinaryBuildResult bin)
        {
            bool bresult;

            bin = null;

            IAssemblyBuilder builder = (IAssemblyBuilder)Activator.CreateInstance(typeof(BS), new object[] { ProjectFilePath, Configuration });

            if (bresult = builder.BuildProject())
            {
                bin = AssemblyBinaryBuildResult.FromFile(builder.BuildResultDll, builder.BuildResultSymbols, builder.BuildResultAssets);
            }
            else
            {
                logger.Error("build project failure: {0}", builder.Log);
            }
            lastBuildLog = builder.Log;

            return(bresult);
        }
        /// <summary>
        /// Tries to create the specified assembly on Transloadit. Bored instance is requested at first. If there is one, then it will
        /// be used to proceed the request, which can be completed on a bored instance.
        /// </summary>
        /// <param name="assembly">Specified assembly which will be tried to be created.
        /// Please use TransloaditAssemblyBuilder to create a new assembly</param>
        /// <returns>Represents the whole result of the request.
        /// Response object will be created everytime, please use its properties to get the detailed result on the request</returns>
        public TransloaditResponse InvokeAssembly(IAssemblyBuilder assembly)
        {
            TransloaditRequest request = Request();

            assembly.SetAuthKey(Key);

            request.Method = ApiRequestMethods.RequestMethod.Get;
            request.Path   = TransloaditRequest.BoredInstancePath;

            TransloaditResponse boredInstance = (TransloaditResponse)RequestAndExecute(request);

            string host = request.Host;

            if (boredInstance.Success)
            {
                host = (string)boredInstance.Data["api2_host"];
            }

            TransloaditRequest invokeRequest = Request();

            invokeRequest.Host   = host;
            invokeRequest.Method = ApiRequestMethods.RequestMethod.Post;
            invokeRequest.Path   = TransloaditRequest.AssemblyRoot;

            DateTime expirationDateTime = DateTime.UtcNow;

            double expirationMinutes = 120;

            expirationDateTime = expirationDateTime.AddMinutes(expirationMinutes);
            assembly.SetAuthExpires(expirationDateTime);

            string paramValue     = (string)assembly.ToJsonString();
            string signatureValue = GetSignature(paramValue);

            invokeRequest.Data = assembly.ToApiData();
            invokeRequest.Data.Fields.Add("signature", signatureValue);

            return(invokeRequest.Execute());
        }
        /// <summary>
        /// Tries to create the specified assembly on Transloadit. Bored instance is requested at first. If there is one, then it will
        /// be used to proceed the request, which can be completed on a bored instance.
        /// </summary>
        /// <param name="assembly">Specified assembly which will be tried to be created.
        /// Please use TransloaditAssemblyBuilder to create a new assembly</param>
        /// <returns>Represents the whole result of the request. 
        /// Response object will be created everytime, please use its properties to get the detailed result on the request</returns>
        /// <exception cref="Transloadit.Config.Exceptions.ConfigNotSetException">
        /// Thrown when the config is not set before invoke an assembly
        /// </exception>
        public TransloaditResponse InvokeAssembly(IAssemblyBuilder assembly)
        {
            if (config == null)
            {
                throw new Config.Exceptions.ConfigNotSetException();
            }

            TransloaditRequest request = Request();
            assembly.SetAuthKey(Key);

            bool useBoredInstance = false;
            bool.TryParse(Config.UseBoredInstance, out useBoredInstance);
            if (useBoredInstance)
            {
                request.Method = ApiRequestMethods.RequestMethod.Get;
                request.Path = TransloaditRequest.BoredInstancePath;

                TransloaditResponse boredInstance = (TransloaditResponse)RequestAndExecute(request);

                if (boredInstance.Success)
                {
                    request.Host = (string)boredInstance.Data["api2_host"];
                }
            }

            request.Method = ApiRequestMethods.RequestMethod.Post;
            request.Path = TransloaditRequest.AssemblyRoot;

            DateTime expirationDateTime = DateTime.UtcNow;

            double expirationMinutes = 120;
            double.TryParse(Config.AuthExpire, out expirationMinutes);
            expirationDateTime = expirationDateTime.AddMinutes(expirationMinutes);
            assembly.SetAuthExpires(expirationDateTime);

            if (Config.DefaultTemplateID.Length > 0 && !assembly.HasTemplateID())
            {
                assembly.SetTemplateID(Config.DefaultTemplateID);
            }

            string paramValue = (string)assembly.ToJsonString();
            string signatureValue = GetSignature(paramValue);

            request.Data = assembly.ToApiData();
            request.Data.Fields.Add("signature", signatureValue);

            return request.Execute();
        }
Beispiel #13
0
 public HandlerFactory(IAssemblyBuilder builder, INodeServices nodeServices,
                       params Assembly[] defaultDependencies) : this(builder, nodeServices, defaultDependencies.AsEnumerable())
 {
 }
 private void OnCodeGenerationStarted(IAssemblyBuilder assemblyBuilder)
 {
     _assemblyBuilder = assemblyBuilder;
     EventHandler handler = _codeGenerationStartedInternal ?? CodeGenerationStarted;
     if (handler != null)
     {
         handler(this, null);
     }
 }
 internal virtual void GenerateCodeCore(IAssemblyBuilder assemblyBuilder)
 {
     OnCodeGenerationStarted(assemblyBuilder);
     assemblyBuilder.AddCodeCompileUnit(this, GeneratedCode);
     assemblyBuilder.GenerateTypeFactory(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", Host.DefaultNamespace, Host.DefaultClassName));
 }
Beispiel #16
0
 public HandlerFactory(IAssemblyBuilder builder, IEnumerable <Assembly> defaultDependencies)
 {
     _builder             = builder;
     _defaultDependencies = defaultDependencies ?? Runtime.GetRuntimeAssemblies();
 }
Beispiel #17
0
 public HandlerFactory(IAssemblyBuilder builder, params Assembly[] defaultDependencies)
 {
     _builder             = builder;
     _defaultDependencies = defaultDependencies ?? Runtime.GetRuntimeAssemblies();
 }