public static async Task <OrleansSolutionManager> CreateFromTestAsync(SolutionGrain solutionGrain, IGrainFactory grainFactory, string testName)
        {
            var manager = new OrleansSolutionManager(solutionGrain, grainFactory);
            await manager.LoadTestAsync(testName);

            return(manager);
        }
        public static async Task <OrleansSolutionManager> CreateFromSourceAsync(SolutionGrain solutionGrain, IGrainFactory grainFactory, string source)
        {
            var manager = new OrleansSolutionManager(solutionGrain, grainFactory);
            await manager.LoadSourceAsync(source);

            return(manager);
        }
Example #3
0
        public async Task InitializeOnDemandOrleansAnalysis()
        {
            SolutionAnalyzer.MessageCounter = 0;
            //GrainClient.ClientInvokeCallback = OnClientInvokeCallBack;

            // For orleans we cannot use the strategy to create a solution
            // The solution grain creates an internal strategy and contain an internal
            // solution manager. We obtain the solution grain that handles everything
            var solutionGrain = OrleansSolutionManager.GetSolutionGrain(GrainClient);

            this.SolutionManager = solutionGrain;

            if (this.source != null)
            {
                await solutionGrain.SetSolutionSourceAsync(this.source);
            }
            else if (this.testName != null)
            {
                await solutionGrain.SetSolutionFromTestAsync(this.testName);
            }
            else if (this.solutionPath != null)
            {
                await solutionGrain.SetSolutionPathAsync(this.solutionPath);

                Logger.LogWarning(GrainClient.Logger, "SolutionAnalyzer", "InitializeOnDemandOrleansAsync", "Exit SetSolutionPath");
            }
            else
            {
                throw new Exception("We need a solutionPath, source code or testName to analyze");
            }
        }
        public static async Task <OrleansProjectCodeProvider> CreateFromTestAsync(IGrainFactory grainFactory, string testName, string assemblyName)
        {
            var solutionGrain = OrleansSolutionManager.GetSolutionGrain(grainFactory);
            var rtaGain       = OrleansRtaManager.GetRtaGrain(grainFactory);
            var provider      = new OrleansProjectCodeProvider(grainFactory, solutionGrain, rtaGain);
            await provider.LoadTestAsync(testName, assemblyName);

            return(provider);
        }
        public static async Task <OrleansProjectCodeProvider> CreateFromProjectAsync(IGrainFactory grainFactory, string projectPath)
        {
            var solutionGrain = OrleansSolutionManager.GetSolutionGrain(grainFactory);
            var rtaGain       = OrleansRtaManager.GetRtaGrain(grainFactory);
            var provider      = new OrleansProjectCodeProvider(grainFactory, solutionGrain, rtaGain);
            await provider.LoadProjectAsync(projectPath);

            return(provider);
        }
Example #6
0
        //private SolutionState State;

        //private Task WriteStateAsync()
        //{
        //	return TaskDone.Done;
        //}

        //private Task ClearStateAsync()
        //{
        //	return TaskDone.Done;
        //}

        public override async Task OnActivateAsync()
        {
            //this.State = new SolutionState();

            await StatsHelper.RegisterActivation("SolutionGrain", this.GrainFactory);

            Logger.OrleansLogger = this.GetLogger();
            Logger.LogInfo(this.GetLogger(), "SolutionGrain", "OnActivate", "Enter");

            this.projectsReadyCount = 0;

            //Task.Run(async () =>
            //await Task.Factory.StartNew(async () =>
            //{
            try
            {
                if (!string.IsNullOrEmpty(this.State.SolutionPath))
                {
                    this.solutionManager = await OrleansSolutionManager.CreateFromSolutionAsync(this, this.GrainFactory, this.State.SolutionPath);
                }
                else if (!string.IsNullOrEmpty(this.State.Source))
                {
                    this.solutionManager = await OrleansSolutionManager.CreateFromSourceAsync(this, this.GrainFactory, this.State.Source);
                }
                else if (!string.IsNullOrEmpty(this.State.TestName))
                {
                    this.solutionManager = await OrleansSolutionManager.CreateFromTestAsync(this, this.GrainFactory, this.State.TestName);
                }

                //if (this.solutionManager != null)
                //{
                //	await this.WaitForAllProjects();
                //}
            }
            catch (Exception ex)
            {
                var inner = ex;
                while (inner is AggregateException)
                {
                    inner = inner.InnerException;
                }

                Logger.LogError(this.GetLogger(), "SolutionGrain", "OnActivate", "Error:\n{0}\nInner:\n{1}", ex, inner);
                throw ex;
            }
            //});

            Logger.LogInfo(this.GetLogger(), "SolutionGrain", "OnActivate", "Exit");
        }
Example #7
0
        public override async Task OnActivateAsync()
        {
            await StatsHelper.RegisterActivation("EffectsDispatcherGrain", this.GrainFactory);

            this.isDispatchingEffects = false;
            this.status             = EffectsDispatcherStatus.Inactive;
            this.lastProcessingTime = DateTime.UtcNow;             // DateTime.MinValue; // DateTime.MaxValue;
            this.solutionGrain      = OrleansSolutionManager.GetSolutionGrain(this.GrainFactory);
            this.effectsDispatcher  = new OrleansEffectsDispatcherManager(this.GrainFactory, this.solutionGrain);

            this.subscriptionManager = new ObserverSubscriptionManager <IAnalysisObserver>();

            var streamProvider = this.GetStreamProvider(AnalysisConstants.StreamProvider);
            var stream         = streamProvider.GetStream <PropagationEffects>(this.GetPrimaryKey(), AnalysisConstants.StreamNamespace);
            //await stream.SubscribeAsync(this);

            // Explicit subscription code
            var subscriptionHandles = await stream.GetAllSubscriptionHandles();

            if (subscriptionHandles != null && subscriptionHandles.Count > 0)
            {
                var tasks = new List <Task>();

                foreach (var subscriptionHandle in subscriptionHandles)
                {
                    var task = subscriptionHandle.ResumeAsync(this);
                    //await task;
                    tasks.Add(task);
                }

                await Task.WhenAll(tasks);
            }
            else
            {
                await stream.SubscribeAsync(this);
            }

            var period = TimeSpan.FromMilliseconds(AnalysisConstants.DispatcherTimerPeriod);

            this.timer = this.RegisterTimer(this.OnTimerTick, null, period, period);

            await base.OnActivateAsync();
        }
        private async Task CreateMethodEntityAsync(MethodDescriptor methodDescriptor)
        {
            // This is a private method. We must not register this as a grain callee
            // await StatsHelper.RegisterMsg("MethodEntityGrain::CreateMethodEntity", this.GrainFactory);

            this.solutionGrain = OrleansSolutionManager.GetSolutionGrain(this.GrainFactory);

            this.State.MethodDescriptor = methodDescriptor;
            var methodDescriptorToSearch = methodDescriptor.BaseDescriptor;

            var codeProviderGrain = await solutionGrain.GetProjectCodeProviderAsync(methodDescriptorToSearch);

            // This wrapper caches some of the queries to codeProvider
            //this.codeProvider = new ProjectCodeProviderWithCache(codeProviderGrain);
            this.codeProvider = codeProviderGrain;

            //Logger.LogWarning(this.GetLogger(), "MethodEntityGrain", "CreateMethodEntity", "{0} calls to proivder {1}", methodDescriptor, this.codeProvider);
            var sw = new Stopwatch();

            sw.Start();

            this.methodEntity = (MethodEntity)await codeProvider.CreateMethodEntityAsync(methodDescriptorToSearch);

            sw.Stop();

            Logger.LogInfo(this.GetLogger(), "MethodEntityGrain", "CreateMethodEntity", "{0};call to provider;{1};ms;{2};ticks", methodDescriptor, sw.ElapsedMilliseconds, sw.ElapsedTicks);

            if (methodDescriptor.IsAnonymousDescriptor)
            {
                this.methodEntity = this.methodEntity.GetAnonymousMethodEntity((AnonymousMethodDescriptor)methodDescriptor);
            }

            //// this is for RTA analysis
            //await solutionGrain.AddInstantiatedTypesAsync(this.methodEntity.InstantiatedTypes);

            // This take cares of doing the progation of types
            this.methodEntityPropagator = new MethodEntityWithPropagator(methodEntity, codeProvider);

            await this.WriteStateAsync();

            //Logger.LogWarning(this.GetLogger(), "MethodEntityGrain", "CreateMethodEntity", "Exit {0}", methodDescriptor);
        }
Example #9
0
        public async Task SetSolutionFromTestAsync(string testName)
        {
            await StatsHelper.RegisterMsg("SolutionGrain::SetSolutionFromTest", this.GrainFactory);

            Logger.LogVerbose(this.GetLogger(), "SolutionGrain", "SetSolutionFromTest", "Enter");

            this.State.TestName     = testName;
            this.State.SolutionPath = null;
            this.State.Source       = null;

            await this.WriteStateAsync();

            this.projectsReadyCount = 0;

            //Task.Run(async () =>
            //await Task.Factory.StartNew(async () =>
            //{
            try
            {
                this.solutionManager = await OrleansSolutionManager.CreateFromTestAsync(this, this.GrainFactory, this.State.TestName);

                //await this.WaitForAllProjects();
            }
            catch (Exception ex)
            {
                var inner = ex;
                while (inner is AggregateException)
                {
                    inner = inner.InnerException;
                }

                Logger.LogError(this.GetLogger(), "SolutionGrain", "SetSolutionFromTest", "Error:\n{0}\nInner:\n{1}", ex, inner);
                throw ex;
            }
            //});

            Logger.LogVerbose(this.GetLogger(), "SolutionGrain", "SetSolutionFromTest", "Exit");
        }