Ejemplo n.º 1
0
        private void Ready()
        {
            Receive <AnalysisRequest>(r =>
            {
                Console.WriteLine("WORKING");

                //System.Diagnostics.Debugger.Launch();

                var self   = Self;
                var sender = Sender;

                Task.Run <AnalysisDocument>(() =>
                {
                    var analyzer           = new PackageAnalyzer();
                    analyzer.UsedTypesOnly = r.UsedTypesOnly;
                    analyzer.AllEdges      = r.AllEdges;
                    analyzer.CreateClustersForNamespaces = r.CreateClustersForNamespaces;

                    if (r.PackagesToAnalyze != null)
                    {
                        analyzer.PackagesToAnalyze.AddRange(r.PackagesToAnalyze);
                    }

                    var spec = SpecUtils.Deserialize(SpecUtils.Unzip(r.Spec));
                    return(analyzer.Execute(spec, myCTS.Token));
                }, myCTS.Token)
                .ContinueWith <object>(x =>
                {
                    if (x.IsCanceled || x.IsFaulted)
                    {
                        // https://github.com/akkadotnet/akka.net/issues/1409
                        // -> exceptions are currently not serializable in raw version
                        //return x.Exception;
                        return(new Finished {
                            Error = x.Exception.Dump()
                        });
                    }

                    Console.WriteLine("Writing response ...");

                    var serializer = new AnalysisDocumentSerializer();
                    serializer.Serialize(x.Result, r.OutputFile);

                    return(new Finished {
                        ResponseFile = r.OutputFile
                    });
                }, TaskContinuationOptions.ExecuteSynchronously)
                .PipeTo(self, sender);

                Become(Working);
            });
        }
Ejemplo n.º 2
0
        internal async Task <AnalysisDocument> Analyse(AnalysisRequest request, CancellationToken cancellationToken)
        {
            StartActorSystemOnDemand();

            var remoteAddress = Address.Parse("akka.tcp://CodeInspection@localhost:2525");

            var actor = mySystem.ActorOf(Props.Create(() => new PackageAnalysisActor())
                                         .WithDeploy(Deploy.None.WithScope(new RemoteScope(remoteAddress))));

            Action ShutdownAction = () =>
            {
                mySystem.Stop(actor);
                //actor.Tell(Kill.Instance);

                if (File.Exists(request.OutputFile))
                {
                    File.Delete(request.OutputFile);
                }
            };

            cancellationToken.Register(() =>
            {
                actor.Tell(new Cancel());
                ShutdownAction();
            });

            request.Spec = SpecUtils.Zip(request.Spec);

            var response = await actor.Ask(request);

            try
            {
                if ((response is FailureResponse))
                {
                    throw new Exception(((FailureResponse)response).Error);
                }

                var serializer = new AnalysisDocumentSerializer();
                return(serializer.Deserialize((string)response));
            }
            finally
            {
                ShutdownAction();
            }
        }