Exemplo n.º 1
0
        private static Tpn.TypeProblem2.Member GetMember(Tpn.IStaticScope scope, ISetUpContext context, Tpn.IHavePossibleMembers possibleScope, NameKey nameKey)
        {
            // TODO
            // there needs to be a case about being directly in a type

            // this handles this case
            // type example{
            // x;
            // type inner { x;} y;
            //}
            // and this case
            // 1 =: x;
            // object {x =: x; 2 =: y;}
            // in object the LHS x is resolves up
            // the RHS x resolves to create a new member
            if ((context.EnclosingSetUp is WeakAssignOperationPopulateScope &&
                 context.Parent.Is(out var parent) &&
                 (parent is ObjectDefinitionPopulateScope)) || context.EnclosingSetUp is TypeDefinitionPopulateScope)
            {
                if (!(scope is Tpn.IHavePublicMembers havePublicMember))
                {
                    // this should only be used in object and type definitions
                    throw new NotImplementedException("this should be an ierror");
                }

                return(context.TypeProblem.CreatePublicMember(scope, havePublicMember, nameKey));;
            }
Exemplo n.º 2
0
        public override async Task SetUp(
            ISetUpContext context,
            Action <string, string> reportError)
        {
            // --------------------------
            // Add default settings to dictionary store
            // --------------------------

            try
            {
                var siteSettings = await _siteSettingsStore.GetAsync() ?? new SiteSettings();

                siteSettings.SiteName  = context.SiteName;
                siteSettings.SuperUser = context.AdminUsername;
                siteSettings.ApiKey    = _keyGenerator.GenerateKey();
                siteSettings.HomeRoute = new HomeRoute();
                await _siteSettingsStore.SaveAsync(siteSettings);
            }
            catch (Exception ex)
            {
                reportError(ex.Message, ex.StackTrace);
            }

            // --------------------------
            // Apply default permissions to default roles for new feature
            // --------------------------

            await _defaultRolesManager.UpdateDefaultRolesAsync(new Permissions());
        }
Exemplo n.º 3
0
        async Task ConfigureDefaultUsers(ISetUpContext context, Action <string, string> reportError)
        {
            try
            {
                // create super user
                var result1 = await _userManager.CreateAsync(new User()
                {
                    Email                   = context.AdminEmail,
                    UserName                = context.AdminUsername,
                    PhotoColor              = _userColorProvider.GetColor(),
                    EmailConfirmed          = true,
                    IsVerified              = true,
                    IsVerifiedUpdatedUserId = 1,
                    IsVerifiedUpdatedDate   = DateTimeOffset.UtcNow
                }, context.AdminPassword);

                if (!result1.Succeeded)
                {
                    foreach (var error in result1.Errors)
                    {
                        reportError(error.Code, error.Description);
                    }
                }

                // create default plato bot

                var result2 = await _userManager.CreateAsync(new User()
                {
                    Email                   = "*****@*****.**",
                    UserName                = "******",
                    DisplayName             = "Plato Bot",
                    Biography               = "I'm not a real person. I'm a bot that keeps an eye on things.",
                    EmailConfirmed          = true,
                    IsVerified              = true,
                    IsVerifiedUpdatedUserId = 1,
                    IsVerifiedUpdatedDate   = DateTimeOffset.UtcNow,
                    PhotoUrl                = "/images/bot.png",
                    PhotoColor              = _userColorProvider.GetColor(),
                    UserType                = UserType.Bot
                }, context.AdminPassword);

                if (!result2.Succeeded)
                {
                    foreach (var error in result2.Errors)
                    {
                        reportError(error.Code, error.Description);
                    }
                }
            }
            catch (Exception ex)
            {
                reportError(ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 4
0
        public async Task <string> SetUpAsync(ISetUpContext context)
        {
            var initialState = _shellSettings.State;

            try
            {
                return(await SetUpInternalAsync(context));
            }
            catch (Exception ex)
            {
                context.Errors.Add(ex.Message, ex.Message);
                _shellSettings.State = initialState;
                throw;
            }
        }
Exemplo n.º 5
0
        public override async Task SetUp(ISetUpContext context, Action <string, string> reportError)
        {
            using (var builder = _schemaBuilder)
            {
                // configure
                Configure(builder);

                // User reputations
                UserReputations(builder);

                var errors = await _schemaManager.ExecuteAsync(builder.Statements);

                foreach (var error in errors)
                {
                    reportError(error, $"SetUp within {this.GetType().FullName} - {error}");
                }
            }
        }
Exemplo n.º 6
0
        async Task ConfigureSuperUser(ISetUpContext context, Action <string, string> reportError)
        {
            // Get newly installed administrator role
            var role = await _roleManager.FindByNameAsync(DefaultRoles.Administrator);

            // Get newly created administrator user
            var user = await _userManager.FindByNameAsync(context.AdminUsername);

            // Add our administrator user to the administrator role
            var dirty = false;

            if (role != null && user != null)
            {
                if (!await _userManager.IsInRoleAsync(user, role.Name))
                {
                    var result = await _userManager.AddToRoleAsync(user, role.Name);

                    if (!result.Succeeded)
                    {
                        foreach (var error in result.Errors)
                        {
                            reportError(error.Code, error.Description);
                        }
                    }
                    dirty = true;
                }
            }

            if (dirty)
            {
                var result = await _userManager.UpdateAsync(user);

                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        reportError(error.Code, error.Description);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public override async Task SetUp(ISetUpContext context, Action <string, string> reportError)
        {
            // Build schema
            using (var builder = _schemaBuilder)
            {
                // configure
                Configure(builder);

                // user schema
                Users(builder);

                // photo schema
                UserPhoto(builder);

                // banner schema
                UserBanner(builder);

                // user logins schema
                UserLogin(builder);

                // meta data schema
                UserData(builder);

                var errors = await _schemaManager.ExecuteAsync(builder.Statements);

                foreach (var error in errors)
                {
                    reportError(error, $"SetUp within {this.GetType().FullName} - {error}");
                }
            }

            // Configure default users
            await ConfigureDefaultUsers(context, reportError);

            // Configure administrator
            await ConfigureSuperUser(context, reportError);
        }
Exemplo n.º 8
0
        public override async Task SetUp(ISetUpContext context, Action <string, string> reportError)
        {
            // --------------------------
            // Build core schema
            // --------------------------

            using (var builder = _schemaBuilder)
            {
                // configure
                Configure(builder);

                // features schema
                Features(builder);

                // Did any errors occur?

                var errors = await _schemaManager.ExecuteAsync(builder.Statements);

                foreach (var error in errors)
                {
                    reportError(error, $"SetUp within {this.GetType().FullName} - {error}");
                }
            }
        }
Exemplo n.º 9
0
        public override async Task SetUp(ISetUpContext context, Action <string, string> reportError)
        {
            using (var builder = _schemaBuilder)
            {
                // configure
                Configure(builder);

                // roles
                Roles(builder);

                // user roles
                UserRoles(builder);

                var errors = await _schemaManager.ExecuteAsync(builder.Statements);

                foreach (var error in errors)
                {
                    reportError(error, $"SetUp within {this.GetType().FullName} - {error}");
                }
            }

            // Install default roles & permissions on first set-up
            await _defaultRolesManager.InstallDefaultRolesAsync();
        }
Exemplo n.º 10
0
        public ISetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            // this is a bit werid
            // it creates member possibly on parent for code like
            // type {x;y;}
            // or
            // object {1 =: x; 2 =: y;}
            // the second is really bad tho, if you had:
            // 1 =: x;
            // object {1 =: x; 2 =: y;}
            // the possible member for x in the object would not result in a real member

            // {48146F3A-6D75-4F24-B857-BED24CE846EA}
            // here is a painful situaltion
            // 1 =: x;
            // object {x =: x; 2 =: y;}
            // in object the LHS x is resolves up
            // the RHS x resolves to create a new member

            if (!(scope is Tpn.IHavePossibleMembers possibleScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var nameKey = new NameKey(memberName);
            var member  = GetMember(scope, context, possibleScope, nameKey);

            return(new SetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member>(new MemberResolveReferance(nameKey), OrType.Make <Tpn.TypeProblem2.Member, IError>(member)));
        }
Exemplo n.º 11
0
        public ISetUpResult <IBox <WeakGenericMethodDefinition>, Tpn.TypeProblem2.Method> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();
            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var box = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();

            var(method, realizedInput, realizedOutput) = context.TypeProblem.CreateGenericMethod(
                scope,
                x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                x => output.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                parameterName,
                new WeakMethodDefinitionConverter(box),
                genericParameters.Select(x => new Tpn.TypeAndConverter(x, new WeakTypeDefinitionConverter())).ToArray());

            var nextElements = elements.Select(x => x.TransformInner(y => y.Run(method, context.CreateChildContext(this)).Resolve)).ToArray();

            // I think for the type I return a method type
            // they already have generic parameters

            // the question is how does look up work?
            // we aren't looking up something with a fix number of generic parameters...
            // I can't throw a bunch of stuff in the primitive scope
            // it's not just about how many parameters they have but also how those parameters turn into output
            // so we have to end up with a factory behind a cache

            // there is also a problem with how you name our type parameters
            // generic-method [T] [T,T] is the same as generic-method [T1] [T1,T1]
            // stituations like: generic-method [T1] [T1,generic-method [T] [T1,T]] make this makes this more complex
            // type combining is common is tac
            // generic types can do it type [T1] X {T1 t} and type [T] X{T t} are the same
            // types can do it too type X {int a} and type Y {int a}
            // for types, they just end up being assignable to each other
            // I don't think generic types really work... in the example above those would both be registered under NameKey("X") and the second one you try to add would throw

            // if I can count on them to combine later maybe I should just make the type here
            // there will still be look up tho, members


            // {8E138F8D-53AA-4D6A-B337-64CAFED23391}
            //var value = context.TypeProblem.CreateValue(method, new DoubleGenericNameKey(
            //    new NameKey("method"),
            //    genericParameters,
            //    new IOrType<IKey, IError>[] {
            //        realizedInput.TransformInner(x=>x.Key()),
            //        realizedOutput.TransformInner(x=>x.Key()),
            //    })); ;


            //// {C28BDF52-A848-4D0A-824A-7F2943BCFE53}
            //var inputMember = context.TypeProblem.GetInput(value);
            //context.TypeProblem.IsAssignedTo(inputMember, method.Input.GetOrThrow()/*lazy GetOrThrow*/);

            //var returnsMember = context.TypeProblem.GetReturns(value);
            //context.TypeProblem.IsAssignedTo(method.Returns.GetOrThrow()/*lazy GetOrThrow*/, returnsMember);

            //var dict =context.TypeProblem.HasGenerics(value, genericParameters);
            //foreach (var key in genericParameters)
            //{
            //    context.TypeProblem.AssertIs(dict[key], method.Generics[key]/*lazy GetOrThrow*/);
            //}


            //var returnsMember = context.TypeProblem.GetReturns(value);
            //context.TypeProblem.IsAssignedTo(method.Returns.GetOrThrow()/*lazy GetOrThrow*/, returnsMember);

            return(new SetUpResult <IBox <WeakGenericMethodDefinition>, Tpn.TypeProblem2.Method>(new GenericMethodDefinitionResolveReferance(method, nextElements, box), OrType.Make <Tpn.TypeProblem2.Method, IError>(method)));
        }
Exemplo n.º 12
0
        public ISetUpResult <IBox <WeakObjectDefinition>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var key = new ImplicitKey(Guid.NewGuid());

            var box     = new Box <IReadOnlyList <IOrType <IBox <WeakAssignOperation>, IError> > >();
            var myScope = context.TypeProblem.CreateObjectOrModule(scope, key, new WeakObjectConverter(box), new WeakScopeConverter());

            // {6B83A7F1-0E28-4D07-91C8-57E6878E97D9}
            // module has similar code
            //foreach (var element in elements)
            //{
            //    element.Switch(
            //        y =>
            //        {
            //            list.Add(OrType.Make<IResolve<IBox<IFrontendCodeElement>>, IError>(y.Run(myScope, context).Resolve));
            //        },
            //        y =>
            //        {
            //            // it is a bit weird that types are not used at all
            //            y.Run(myScope, context);
            //        },
            //        y =>
            //        {
            //            // this is also a bit wierd, these errors are anything that was not parsed
            //            // they are not really related to the assignments they are bing placed next to
            //            list.Add(OrType.Make<IResolve<IBox<IFrontendCodeElement>>, IError>(y));
            //        });
            //}


            var nextElements = elements.Select(x =>
                                               x.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve)).ToArray();

            var value = context.TypeProblem.CreateValue(runtimeScope, key);

            // ugh! an object is a type
            //

            return(new SetUpResult <IBox <WeakObjectDefinition>, Tpn.IValue>(new ResolveReferanceObjectDefinition(myScope, nextElements, box), OrType.Make <Tpn.IValue, IError>(value)));
        }
Exemplo n.º 13
0
        public ISetUpResult <IBox <WeakTryAssignOperation>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var box = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();

            // we create a new scope because the member we are assigning in to only exists in that scope
            // 5 is Cat c { ... }
            // is really
            // { 5 is Cat c { ... }}

            var myScope = context.TypeProblem.CreateScope(scope, new WeakBlockDefinitionConverter(box));

            var nextLeft  = left.TransformInner(x => x.Run(myScope, context.CreateChildContext(this)));
            var nextRight = right.TransformInner(x => x.Run(myScope, context.CreateChildContext(this)));
            var nextblock = block.TransformInner(x => x.Run(myScope, context.CreateChildContext(this)));

            if (nextLeft.Is1(out var nextLeft1) && nextLeft1.SetUpSideNode.Is1(out var node1) && nextRight.Is1(out var nextRight1) && nextRight1.SetUpSideNode.Is1(out var node2))
            {
                if (node1 is not Tpn.ICanAssignFromMe canAssignFromMe)
                {
                    // todo I need real error handling
                    // probably I need somewhere to stuff additional errors
                    throw new NotImplementedException($"can not assign from {nextLeft1.SetUpSideNode}");
                }

                if (node2 is not Tpn.ICanBeAssignedTo canBeAssignedTo)
                {
                    // todo I need real error handling
                    throw new NotImplementedException($"can not assign to {nextRight1.SetUpSideNode}");
                }
            }
Exemplo n.º 14
0
        public ISetUpResult <IBox <WeakConstantNumber>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var value = context.TypeProblem.CreateValue(runtimeScope, new NameKey("number"));

            return(new SetUpResult <IBox <WeakConstantNumber>, Tpn.IValue>(new ConstantNumberResolveReferance(dub), OrType.Make <Tpn.IValue, IError>(value)));
        }
Exemplo n.º 15
0
        public ISetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var type          = context.TypeProblem.CreateType(scope, key, new WeakTypeDefinitionConverter());
            var typeReference = context.TypeProblem.CreateTypeReference(scope, key.SwitchReturns <IKey>(x => x, x => x), new WeakTypeReferenceConverter());

            foreach (var element in elements)
            {
                if (element.Is1(out var setUp))
                {
                    setUp.Run(type, context.CreateChildContext(this));
                }
            }
            return(new SetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference>(new TypeReferanceResolveReference(typeReference), OrType.Make <Tpn.TypeProblem2.TypeReference, IError>(typeReference)));
        }
Exemplo n.º 16
0
        public ISetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            if (intoInitScope)
            {
                scope = scope.EnterInitizaionScopeIfNessisary();
            }

            var nextLeft  = left.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));
            var nextRight = right.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));
            var value     = keyMaker(scope, context.CreateChildContext(this), nextLeft, nextRight);

            return(new SetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue>(new BinaryResolveReferance <TFrontendCodeElement, TCodeElement>(
                                                                                 nextLeft.TransformInner(x => x.Resolve),
                                                                                 nextRight.TransformInner(x => x.Resolve),
                                                                                 make), value));
        }
Exemplo n.º 17
0
        public ISetUpResult <IBox <WeakPathOperation>, Tpn.TypeProblem2.Member> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            var nextLeft = left.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));

            var member = nextLeft.SwitchReturns(
                good =>
                name.SwitchReturns(
                    actualName =>
            {
                if (good.SetUpSideNode.Is1(out var nodeLeft) && nodeLeft is Tpn.IValue value)
                {
                    return(OrType.Make <Tpn.TypeProblem2.Member, IError>(context.TypeProblem.CreateHopefulMember(
                                                                             value,
                                                                             new NameKey(actualName))));
                }
Exemplo n.º 18
0
        public ISetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var type = this.type.Run(scope, context.CreateChildContext(this));


            var member = context.TypeProblem.CreateMember(scope, memberName, type.SetUpSideNode.TransformInner(x => x.Key()));


            return(new SetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member>(new MemberDefinitionResolveReferance(access, memberName), OrType.Make <Tpn.TypeProblem2.Member, IError>(member)));
        }
Exemplo n.º 19
0
 public abstract Task SetUp(ISetUpContext context, Action <string, string> reportError);
Exemplo n.º 20
0
        public ISetUpResult <IBox <WeakMethodDefinition>, Tpn.TypeProblem2.Method> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();
            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }


            var box       = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();
            var converter = new WeakMethodDefinitionConverter(box);

            var(method, realizedInput, realizedOutput) = context.TypeProblem.CreateMethod(scope,
                                                                                          x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                                                                                          x => output.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                                                                                          parameterName,
                                                                                          converter);

            var nextElements = elements.Select(x => x.TransformInner(y => y.Run(method, context.CreateChildContext(this)).Resolve)).ToArray();

            //var value = context.TypeProblem.CreateTransientMember(runtimeScope, new GenericNameKey(new NameKey("method"), new IOrType<IKey, IError>[] {
            //        realizedInput.TransformInner(x=>x.Key()),
            //        realizedOutput.TransformInner(x=>x.Key()),
            //    }), "result-of-" + method.DebugName);

            //// TODO write a test
            //// {C28BDF52-A848-4D0A-824A-7F2943BCFE53}
            //// follow throw methods should work now.
            ////
            //// x > method [infer; infer] input { input return; } =: chicken c
            ////
            //// chicken need to flow through the method to x,
            ////
            //// C28BDF52-A848-4D0A-824A-7F2943BCFE53
            //// ... I think with my new type problem changes were method's become nodes and enter the type probelm
            //// I can clean this up quite a bit
            ////
            //// I think I have cleaned this up, just leaning it here until I get all my tests fixed

            //var inputMember = context.TypeProblem.GetInput(value);
            //context.TypeProblem.IsAssignedTo(inputMember, method.Input.GetOrThrow()/*lazy GetOrThrow*/);

            //var returnsMember = context.TypeProblem.GetReturns(value);
            //context.TypeProblem.IsAssignedTo(method.Returns.GetOrThrow()/*lazy GetOrThrow*/, returnsMember);


            return(new SetUpResult <IBox <WeakMethodDefinition>, Tpn.TypeProblem2.Method>(new MethodDefinitionResolveReferance(method, nextElements, box), OrType.Make <Tpn.TypeProblem2.Method, IError>(method)));
        }
Exemplo n.º 21
0
        public ISetUpResult <IBox <WeakEntryPointDefinition>, Tpn.TypeProblem2.Method> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            //var box = new Box<IOrType<IResolve<IBox<IFrontendCodeElement>>, IError>[]>();

            //var inputBox = new Box<IResolve<IBox<WeakMemberReference>>>();
            //var outputBox = new Box<IResolve<IBox<IFrontendType<IVerifiableType>>>>();

            //var innerScope = context.TypeProblem.CreateScope(scope, new WeakEntryPointConverter(box, inputBox, outputBox));
            //context.TypeProblem.HasEntryPoint(scope, innerScope);

            //inputBox.Fill(parameterDefinition.Run(innerScope, context.CreateChildContext(this)).Resolve);
            //outputBox.Fill(output.Run(innerScope, context.CreateChildContext(this)).Resolve);

            //if (!(scope is Tpn.IScope runtimeScope))
            //{
            //    throw new NotImplementedException("this should be an IError");
            //}


            var box       = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();
            var converter = new WeakEntryPointConverter(box);

            var(method, realizedInput, realizedOutput) = context.TypeProblem.CreateMethod(
                scope,
                x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                x => output.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                parameterName,
                converter);

            var converted = elements.Select(x => x.TransformInner(y => y.Run(method, context.CreateChildContext(this)).Resolve)).ToArray();

            return(new SetUpResult <IBox <WeakEntryPointDefinition>, Tpn.TypeProblem2.Method> (new EntryPointDefinitionResolveReferance(method, box, converted), OrType.Make <Tpn.TypeProblem2.Method, IError>(method)));
        }
Exemplo n.º 22
0
        public override async Task SetUp(
            ISetUpContext context,
            Action <string, string> reportError)
        {
            // --------------------------
            // Build core schema
            // --------------------------

            var dictionaryTable = new SchemaTable()
            {
                Name    = "DictionaryEntries",
                Columns = new List <SchemaColumn>()
                {
                    new SchemaColumn()
                    {
                        PrimaryKey = true,
                        Name       = "Id",
                        DbType     = DbType.Int32
                    },
                    new SchemaColumn()
                    {
                        Name   = "[Key]",
                        Length = "255",
                        DbType = DbType.String
                    },
                    new SchemaColumn()
                    {
                        Name   = "[Value]",
                        Length = "max",
                        DbType = DbType.String
                    },
                    new SchemaColumn()
                    {
                        Name   = "CreatedUserId",
                        DbType = DbType.Int32
                    },
                    new SchemaColumn()
                    {
                        Name   = "CreatedDate",
                        DbType = DbType.DateTimeOffset
                    },
                    new SchemaColumn()
                    {
                        Name   = "ModifiedUserId",
                        DbType = DbType.Int32
                    },
                    new SchemaColumn()
                    {
                        Name     = "ModifiedDate",
                        DbType   = DbType.DateTimeOffset,
                        Nullable = true
                    }
                }
            };

            var documentTable = new SchemaTable()
            {
                Name    = "DocumentEntries",
                Columns = new List <SchemaColumn>()
                {
                    new SchemaColumn()
                    {
                        PrimaryKey = true,
                        Name       = "Id",
                        DbType     = DbType.Int32
                    },
                    new SchemaColumn()
                    {
                        Name   = "[Type]",
                        Length = "500",
                        DbType = DbType.String
                    },
                    new SchemaColumn()
                    {
                        Name   = "[Value]",
                        Length = "max",
                        DbType = DbType.String
                    },
                    new SchemaColumn()
                    {
                        Name   = "CreatedDate",
                        DbType = DbType.DateTimeOffset
                    },
                    new SchemaColumn()
                    {
                        Name   = "CreatedUserId",
                        DbType = DbType.Int32
                    },
                    new SchemaColumn()
                    {
                        Name   = "ModifiedDate",
                        DbType = DbType.DateTimeOffset
                    },
                    new SchemaColumn()
                    {
                        Name     = "ModifiedUserId",
                        DbType   = DbType.Int32,
                        Nullable = true
                    }
                }
            };

            using (var builder = _schemaBuilder)
            {
                // Build dictionary store
                // --------------------------

                builder
                .Configure(options =>
                {
                    options.ModuleName = "Plato.Core";
                    options.Version    = Version;
                });
                builder.TableBuilder.CreateTable(dictionaryTable);

                builder.ProcedureBuilder.CreateDefaultProcedures(dictionaryTable)
                .CreateProcedure(
                    new SchemaProcedure("SelectDictionaryEntryByKey", StoredProcedureType.SelectByKey)
                    .ForTable(dictionaryTable).WithParameter(new SchemaColumn()
                {
                    Name   = "[Key]",
                    Length = "255",
                    DbType = DbType.String
                }));

                builder.ProcedureBuilder.CreateDefaultProcedures(dictionaryTable)
                .CreateProcedure(
                    new SchemaProcedure("DeleteDictionaryEntryByKey", StoredProcedureType.DeleteByKey)
                    .ForTable(dictionaryTable).WithParameter(new SchemaColumn()
                {
                    Name   = "[Key]",
                    Length = "255",
                    DbType = DbType.String
                }));

                // Build document store
                // --------------------------

                builder
                .Configure(options =>
                {
                    options.ModuleName = "Plato.Core";
                    options.Version    = Version;
                });

                builder.TableBuilder.CreateTable(documentTable);

                builder.ProcedureBuilder
                .CreateDefaultProcedures(documentTable)
                .CreateProcedure(
                    new SchemaProcedure("SelectDocumentEntryByType", StoredProcedureType.SelectByKey)
                    .ForTable(documentTable)
                    .WithParameter(new SchemaColumn()
                {
                    Name   = "[Type]",
                    Length = "500",
                    DbType = DbType.String
                }));

                // Did any errors occur?

                var errors = await _schemaManager.ExecuteAsync(builder.Statements);

                foreach (var error in errors)
                {
                    reportError(error, $"SetUp within {this.GetType().FullName} - {error}");
                }
            }
        }
Exemplo n.º 23
0
        public ISetUpResult <IBox <WeakGenericTypeDefinition>, Tpn.IExplicitType> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            // oh geez here is a mountain.
            // I generic types are erased
            // what on earth does this return?
            var myScope = context.TypeProblem.CreateGenericType(
                scope,
                OrType.Make <NameKey, ImplicitKey>(nameKey),
                genericParameters.Select(x => new Tpn.TypeAndConverter(x, new WeakTypeDefinitionConverter())).ToArray(),
                new WeakTypeDefinitionConverter());
            var nextLines = lines.Select(x => x.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve)).ToArray();

            return(new SetUpResult <IBox <WeakGenericTypeDefinition>, Tpn.IExplicitType>(new GenericTypeDefinitionResolveReferance(myScope, nextLines), OrType.Make <Tpn.IExplicitType, IError>(myScope)));
        }
Exemplo n.º 24
0
        public ISetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            // return should never be in an object init
            // but other trailing operations might
            if (intoInitScope)
            {
                scope = scope.EnterInitizaionScopeIfNessisary();
            }

            var nextLeft = left.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));

            return(new SetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue>(
                       new TrailingResolveReferance <TFrontendCodeElement, TCodeElement>(nextLeft.TransformInner(x => x.Resolve), make),
                       getReturnedValue(scope, context, nextLeft)));
        }
Exemplo n.º 25
0
        public ISetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var type = context.TypeProblem.CreateTypeReference(scope, key, new WeakTypeReferenceConverter());

            return(new SetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference>(new TypeReferanceResolveReference(
                                                                                                                 type), OrType.Make <Tpn.TypeProblem2.TypeReference, IError>(type)));
        }
Exemplo n.º 26
0
        public ISetUpResult <IBox <WeakBlockDefinition>, Tpn.IScope> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var box          = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();
            var myScope      = context.TypeProblem.CreateScope(scope, new WeakBlockDefinitionConverter(box));
            var nextElements = Elements.Select(or => or.TransformInner(y => y.Run(scope, context.CreateChildContext(this)).Resolve)).ToArray();

            return(new SetUpResult <IBox <WeakBlockDefinition>, Tpn.IScope>(new ResolveReferanceBlockDefinition(myScope, nextElements, box), OrType.Make <Tpn.IScope, IError>(myScope)));
        }
Exemplo n.º 27
0
        public ISetUpResult <IBox <WeakImplementationDefinition>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            // TODO this is so painful, I think I need to look in to implementations having special treatment...
            // maybe they need to be a generic on the tpn
            // altho to the tpn they really are not special
            // but here they might maybe convert to an implementation not a method that returns a method
            // idk! 🤷‍😭

            IIsPossibly <(IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>)> pair =
                Possibly.IsNot <(IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>)>();

            var innerBox = new Box <Tpn.TypeProblem2.Method>();

            Tpn.TypeProblem2.Method?myInner = null;

            var linesBox = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();

            IOrType <IKey, IError>?realizedInputKey  = null;
            IOrType <IKey, IError>?realizedOutputKey = null;

            IOrType <IResolve <IBox <IFrontendCodeElement> >, IError>[]? nextElements = null;

            var(outer, realizeContext, _) = context.TypeProblem.CreateMethod(
                scope,
                x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                x => {
                var(inner, realizedInput, realizedOutput) = context.TypeProblem.CreateMethod(
                    x,
                    y => parameterDefinition.Run(y, context.CreateChildContext(this)).SetUpSideNode,
                    y => output.Run(y, context.CreateChildContext(this)).SetUpSideNode,
                    parameterName,
                    new WeakMethodDefinitionConverter(
                        linesBox));
                myInner = inner;
                innerBox.Fill(inner);
                nextElements = elements.Select(z => z.TransformInner(w => w.Run(inner, context.CreateChildContext(this)).Resolve)).ToArray();

                realizedInputKey  = realizedInput.TransformInner(y => y.Key());
                realizedOutputKey = realizedOutput.TransformInner(y => y.Key());

                var outputTypeRef = context.TypeProblem.CreateTypeReference(scope, new GenericNameKey(new NameKey("method"), new[] {
                    realizedInputKey,
                    realizedOutputKey,
                }), new WeakTypeReferenceConverter());

                return(OrType.Make <TypeProblem2.TypeReference, IError>(outputTypeRef));
            },
                contextName,
                new WeakImplementationDefinitionConverter(
                    new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >(Array.Empty <IOrType <IBox <IFrontendCodeElement>, IError> >()),
                    innerBox));

            if (realizedInputKey == null)
            {
                throw new NullReferenceException(nameof(realizedInputKey));
            }
            if (realizedOutputKey == null)
            {
                throw new NullReferenceException(nameof(realizedOutputKey));
            }
            if (nextElements == null)
            {
                throw new NullReferenceException(nameof(nextElements));
            }
            if (myInner == null)
            {
                throw new NullReferenceException(nameof(myInner));
            }

            var innerValue = context.TypeProblem.CreateValue(outer,
                                                             new GenericNameKey(new NameKey("method"), new[] {
                realizedInputKey,
                realizedOutputKey,
            }));

            innerValue.AssignTo(outer.Returns());


            var value = context.TypeProblem.CreateValue(runtimeScope, new GenericNameKey(new NameKey("method"), new[] {
                realizeContext.TransformInner(x => x.Key()),
                OrType.Make <IKey, IError>(new GenericNameKey(new NameKey("method"), new[] {
                    realizedInputKey,
                    realizedOutputKey,
                })),
            }));

            return(new SetUpResult <IBox <WeakImplementationDefinition>, Tpn.IValue>(new ImplementationDefinitionResolveReferance(
                                                                                         outer, myInner, nextElements, linesBox), OrType.Make <Tpn.IValue, IError>(value)));
        }
Exemplo n.º 28
0
        // ------------

        async Task <string> SetUpInternalAsync(ISetUpContext context)
        {
            // Set state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while setting up.
            _shellSettings.State = TenantState.Initializing;

            var executionId = Guid.NewGuid().ToString("n");

            var shellSettings = new ShellSettings(_shellSettings.Configuration)
            {
                Location = context.SiteName.ToSafeFileName()
            };

            if (string.IsNullOrEmpty(shellSettings.DatabaseProvider))
            {
                var tablePrefix = context.DatabaseTablePrefix;
                if (!tablePrefix.EndsWith(ShellHelper.TablePrefixSeparator))
                {
                    tablePrefix += ShellHelper.TablePrefixSeparator;
                }
                shellSettings.DatabaseProvider = context.DatabaseProvider;
                shellSettings.ConnectionString = context.DatabaseConnectionString;
                shellSettings.TablePrefix      = tablePrefix;
            }

            using (var shellContext = _shellContextFactory.CreateMinimalShellContext(shellSettings))
            {
                using (var scope = shellContext.ServiceProvider.CreateScope())
                {
                    using (var dbContext = scope.ServiceProvider.GetRequiredService <IDbContext>())
                    {
                        // update dbContext confirmation
                        dbContext.Configure(options =>
                        {
                            options.ConnectionString = shellSettings.ConnectionString;
                            options.DatabaseProvider = shellSettings.DatabaseProvider;
                            options.TablePrefix      = shellSettings.TablePrefix;
                        });

                        var hasErrors = false;
                        void ReportError(string key, string message)
                        {
                            hasErrors           = true;
                            context.Errors[key] = message;
                        }

                        // Invoke modules to react to the setup event
                        var setupEventHandlers = scope.ServiceProvider.GetServices <ISetUpEventHandler>();
                        var logger             = scope.ServiceProvider.GetRequiredService <ILogger <SetUpService> >();

                        await setupEventHandlers.InvokeAsync(x => x.SetUp(context, ReportError), logger);

                        if (hasErrors)
                        {
                            return(executionId);
                        }
                    }
                }
            }

            // Report errors
            if (context.Errors.Count > 0)
            {
                return(executionId);
            }

            // Set defaults
            shellSettings.CreatedDate  = DateTimeOffset.Now;
            shellSettings.ModifiedDate = DateTimeOffset.Now;
            shellSettings.State        = TenantState.Running;

            // Update & recycle shell
            _platoHost
            .UpdateShell(shellSettings)
            .RecycleShell(shellSettings);

            return(executionId);
        }
Exemplo n.º 29
0
 public override Task SetUp(
     ISetUpContext context,
     Action <string, string> reportError)
 {
     return(Task.CompletedTask);
 }
Exemplo n.º 30
0
 public ISetUpResult <IBox <WeakRealizeMethodOperation>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
 {
     throw new NotImplementedException();
     //return new SetUpResult<IBox<WeakRealizeMethodOperation>, Tpn.IValue>(
     //    new RealizeMethodOperationResolveReferance(),
     //    getReturnedValue(scope, context, nextLeft));
 }