Esempio n. 1
0
        /// <summary>
        /// Generate one GrainReference class for each Grain Type in the inputLib file
        /// and output one GrainClient.dll under outputLib directory
        /// </summary>
        private bool CreateGrainClient(CodeGenOptions options)
        {
            PlacementStrategy.Initialize();

            // Load input assembly
            ConsoleText.WriteLine("");
            var assemblyName  = AssemblyName.GetAssemblyName(options.InputLib.FullName);
            var grainAssembly = (Path.GetFileName(options.InputLib.FullName) != "Orleans.dll")
                                    ? Assembly.LoadFrom(options.InputLib.FullName)
                                    : Assembly.Load(assemblyName);

            // special case Orleans.dll because there is a circular dependency.

            // Create sources directory
            if (!Directory.Exists(options.SourcesDir))
            {
                Directory.CreateDirectory(options.SourcesDir);
            }

            // Generate source
            var outputFileName = Path.Combine(
                options.SourcesDir,
                Path.GetFileNameWithoutExtension(options.InputLib.Name) + ".codegen.cs");

            ConsoleText.WriteStatus("Orleans-CodeGen - Generating file {0}", outputFileName);

            var codeGenerator = RoslynCodeGenerator.Instance;

            using (var sourceWriter = new StreamWriter(outputFileName))
            {
                if (options.TargetLanguage != Language.CSharp)
                {
                    var message = "Compile-time code generation is supported for C# only. "
                                  + "Remove code generation from your project in order to use run-time code generation.";
                    ConsoleText.WriteLine("ERROR: " + message);
                    throw new NotSupportedException(message);
                }

                sourceWriter.WriteLine("#if !EXCLUDE_CODEGEN");
                DisableWarnings(sourceWriter, suppressCompilerWarnings);
                sourceWriter.WriteLine(codeGenerator.GenerateSourceForAssembly(grainAssembly));
                RestoreWarnings(sourceWriter, suppressCompilerWarnings);
                sourceWriter.WriteLine("#endif");
            }

            ConsoleText.WriteStatus("Orleans-CodeGen - Generated file written {0}", outputFileName);

            // Copy intermediate file to permanent location, if newer.
            ConsoleText.WriteStatus(
                "Orleans-CodeGen - Updating IntelliSense file {0} -> {1}",
                outputFileName,
                options.CodeGenFile);
            UpdateIntellisenseFile(options.CodeGenFile, outputFileName);

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Generate one GrainReference class for each Grain Type in the inputLib file
        /// and output one GrainClient.dll under outputLib directory
        /// </summary>
        private bool CreateGrainClient(CodeGenOptions options)
        {
            PlacementStrategy.Initialize();

            // Load input assembly
            // special case Orleans.dll because there is a circular dependency.
            var assemblyName  = AssemblyName.GetAssemblyName(options.InputLib.FullName);
            var grainAssembly = (Path.GetFileName(options.InputLib.FullName) != "Orleans.dll")
                                    ? Assembly.LoadFrom(options.InputLib.FullName)
                                    : Assembly.Load(assemblyName);

            // Create sources directory
            if (!Directory.Exists(options.SourcesDir))
            {
                Directory.CreateDirectory(options.SourcesDir);
            }

            // Generate source
            var outputFileName = Path.Combine(
                options.SourcesDir,
                Path.GetFileNameWithoutExtension(options.InputLib.Name) + ".codegen.cs");

            ConsoleText.WriteStatus("Orleans-CodeGen - Generating file {0}", outputFileName);

            var codeGenerator = RoslynCodeGenerator.Instance;

            SerializationManager.RegisterBuiltInSerializers();
            using (var sourceWriter = new StreamWriter(outputFileName))
            {
                sourceWriter.WriteLine("#if !EXCLUDE_CODEGEN");
                DisableWarnings(sourceWriter, suppressCompilerWarnings);
                sourceWriter.WriteLine(codeGenerator.GenerateSourceForAssembly(grainAssembly));
                RestoreWarnings(sourceWriter, suppressCompilerWarnings);
                sourceWriter.WriteLine("#endif");
            }

            ConsoleText.WriteStatus("Orleans-CodeGen - Generated file written {0}", outputFileName);

            // Copy intermediate file to permanent location, if newer.
            ConsoleText.WriteStatus(
                "Orleans-CodeGen - Updating IntelliSense file {0} -> {1}",
                outputFileName,
                options.CodeGenFile);
            UpdateIntellisenseFile(options.CodeGenFile, outputFileName);

            return(true);
        }
Esempio n. 3
0
        public OutsideRuntimeClient(ClientConfiguration cfg, GrainFactory grainFactory, bool secondary = false)
        {
            this.grainFactory = grainFactory;

            if (cfg == null)
            {
                Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object.");
                throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg");
            }

            this.config = cfg;

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(config);
            }
            StatisticsCollector.Initialize(config);
            SerializationManager.Initialize(cfg.SerializationProviders, cfg.FallbackSerializationProvider);
            logger    = LogManager.GetLogger("OutsideRuntimeClient", LoggerType.Runtime);
            appLogger = LogManager.GetLogger("Application", LoggerType.Application);

            BufferPool.InitGlobalBufferPool(config);
            this.handshakeClientId = GrainId.NewClientId();

            try
            {
                LoadAdditionalAssemblies();

                PlacementStrategy.Initialize();

                callbacks    = new ConcurrentDictionary <CorrelationId, CallbackData>();
                localObjects = new ConcurrentDictionary <GuidId, LocalObjectData>();

                if (!secondary)
                {
                    UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnhandledException);
                }
                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                // Ensure SerializationManager static constructor is called before AssemblyLoad event is invoked
                SerializationManager.GetDeserializer(typeof(String));

                clientProviderRuntime     = new ClientProviderRuntime(grainFactory, null);
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                                        .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                var localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, config.DNSHostName, localAddress, handshakeClientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                config.CheckGatewayProviderSettings();

                var generation          = -SiloAddress.AllocateNewGeneration(); // Client generations are negative
                var gatewayListProvider = GatewayProviderFactory.CreateGatewayListProvider(config)
                                          .WithTimeout(initTimeout).Result;
                transport = new ProxiedMessageCenter(config, localAddress, generation, handshakeClientId, gatewayListProvider);

                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }