Example #1
0
        private static void jsService(SyntaxNode node, ExcessCompilation compilation, Scope scope)
        {
            Debug.Assert(node is ClassDeclarationSyntax);
            var @class = node as ClassDeclarationSyntax;

            var serviceAttribute = @class
                                   .AttributeLists
                                   .Where(attrList => attrList
                                          .Attributes
                                          .Any(attr => attr.Name.ToString() == "Service"))
                                   .SingleOrDefault()
                                   ?.Attributes
                                   .FirstOrDefault(attr => attr.Name.ToString() == "Service");

            var model  = compilation.GetSemanticModel(node);
            var config = scope.GetServerConfiguration();
            var name   = @class.Identifier.ToString();
            var id     = Guid.NewGuid();
            var body   = string.Empty;

            Debug.Assert(config != null);
            if (serviceAttribute == null)
            {
                //functions
                var @namespace = @class.FirstAncestorOrSelf <NamespaceDeclarationSyntax>(
                    ancestor => ancestor is NamespaceDeclarationSyntax);

                if (@namespace != null)
                {
                    name = @namespace.Name.ToString();
                }

                body = functionalBody(@class, model);
                if (body.Any())
                {
                    config.AddFunctionalContainer(name, body);
                }
                return; //td: separate
            }
            else
            {
                var guidString = serviceAttribute
                                 .ArgumentList
                                 .Arguments
                                 .Single(attr => attr.NameColon.Name.ToString() == "id")
                                 .Expression
                                 .ToString();

                id   = Guid.Parse(guidString.Substring(1, guidString.Length - 2));
                body = concurrentBody(@class, config, model);
            }

            config.AddClientInterface(node.SyntaxTree, Templates
                                      .jsService(new
            {
                Name = name,
                Body = body,
                ID   = id
            }));
        }
Example #2
0
        private static void jsConcurrentClass(SyntaxNode node, ExcessCompilation compilation, Scope scope)
        {
            Debug.Assert(node is ClassDeclarationSyntax);
            var @class = node as ClassDeclarationSyntax;
            var model  = compilation.GetSemanticModel(node);
            var config = scope.GetServerConfiguration();

            Debug.Assert(config != null);

            var body = concurrentBody(@class, config, model);

            config.AddClientInterface(node.SyntaxTree, Templates
                                      .jsConcurrentClass(new
            {
                Name = @class.Identifier.ToString(),
                Body = body
            }));
        }