示例#1
0
        protected Tuple <App, PermissionCheckBase> GetAppRequiringPermissionsOrThrow(int appId, List <Grants> grants, List <ItemIdentifier> items)
        {
            var appMan = new AppRuntime(appId, Log);

            // build list of type names
            var typeNames = items.Select(item => {
                var typeName = item.ContentTypeName;
                if (string.IsNullOrEmpty(typeName) && item.EntityId != 0)
                {
                    var existing = appMan.Entities.Get(item.EntityId);
                    typeName     = existing.Type.StaticName;
                }
                return(typeName);
            }).ToList();

            // make sure we have at least one entry, so the checks will work
            if (typeNames.Count == 0)
            {
                typeNames.Add(null);
            }

            // go through all the groups, assign relevant info so that we can then do get-many
            Tuple <App, PermissionCheckBase> set = null;

            // this will run at least once with null, and the last one will be returned in the set
            typeNames.ForEach(tn => set = GetAppRequiringPermissionsOrThrow(appId, grants, tn));

            return(set);
        }
示例#2
0
        public string Entity(int?appId = null, string entity = null)
        {
            if (UrlParamsIncomplete(appId, entity, out var message))
            {
                return(message);
            }

            Log.Add($"debug app entity metadata for {appId} and entity {entity}");
            var appRead = new AppRuntime(appId.Value, Log);

            IEntity ent;

            if (int.TryParse(entity, out var entityId))
            {
                ent = appRead.Entities.Get(entityId);
            }
            else if (Guid.TryParse(entity, out var entityGuid))
            {
                ent = appRead.Entities.Get(entityGuid);
            }
            else
            {
                throw Http.BadRequest("can't use entityid - must be number or guid");
            }

            var ser  = new JsonSerializer(appRead.Package, Log);
            var json = ser.Serialize(ent);

            var msg = h1($"Entity Debug for {entity} in {appId}\n")
                      + ToBr("\n\n\n")
                      + Tag("textarea", json, " rows='20' cols='100' ");

            return(msg);
        }
示例#3
0
        /// <summary>
        /// Creates the <see cref="IApp"/> instance.
        /// </summary>
        /// <param name="configurator">The instance of <see cref="IObjectContainerConfigurator"/> to be extended.</param>
        /// <returns>The <see cref="IApp"/> instance.</returns>
        public static IApp Create(this IObjectContainerConfigurator configurator)
        {
            var configSource = configurator.Configure();
            var appInstance  = AppRuntime.Create(configSource);

            return(appInstance);
        }
        public SynchronizationServiceProc()
        {
            this.ServiceName  = "TinyLibraryCQRS Synchronization Service";
            this.EventLog.Log = "Application";

            this.CanShutdown = true;
            this.CanStop     = true;

            AppConfigSource configSource = new AppConfigSource();
            IApp            application  = AppRuntime.Create(configSource);

            application.Initialize += (s, e) =>
            {
                UnityContainer     c = e.ObjectContainer.GetWrappedContainer <UnityContainer>();
                IMessageDispatcher eventDispatcher = MessageDispatcher.CreateAndRegister(configSource, typeof(MessageDispatcher));
                c.RegisterInstance <IMessageDispatcher>(eventDispatcher);
            };
            application.Start();

            messageDispatcher = AppRuntime.Instance.CurrentApplication.ObjectContainer.GetService <IMessageDispatcher>();

            timer.Interval = this.Interval;
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);

            worker.WorkerSupportsCancellation = true;
            worker.WorkerReportsProgress      = false;
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        }
        public void InitializeInterceptorsTests_MockSingleInterceptorTest()
        {
            Helper.ClearApp(AppRuntime.Instance);
            bool a = false;
            bool b = false;

            MockInterceptorA.InterceptOccur += (s, e) =>
            {
                a = true;
            };
            MockInterceptorB.InterceptOccur += (s, e) =>
            {
                b = true;
            };

            RegularConfigSource configSource = (RegularConfigSource)Helper.ConfigSource_GeneralInterception;

            configSource.AddInterceptor("a", typeof(MockInterceptorA));
            configSource.AddInterceptor("b", typeof(MockInterceptorB));
            configSource.AddInterceptorRef(typeof(MessageDispatcher), typeof(MessageDispatcher).GetMethod("Clear", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance), "a");
            IApp app = AppRuntime.Create(configSource);

            app.Initialize += (s, e) =>
            {
                UnityContainer c = e.ObjectContainer.GetWrappedContainer <UnityContainer>();
                c.RegisterType <IMessageDispatcher, MessageDispatcher>();
            };
            app.Start();
            IMessageDispatcher dispatcher = app.ObjectContainer.GetService <IMessageDispatcher>();

            dispatcher.Clear();
            Assert.IsTrue(a);
            Assert.IsFalse(b);
        }
示例#6
0
        public string Stats(int?appId = null)
        {
            if (UrlParamsIncomplete(appId, out var message))
            {
                return(message);
            }

            Log.Add($"debug app-internals for {appId}");
            var appRead = new AppRuntime(appId.Value, Log);
            var pkg     = appRead.Package;

            var msg = h1($"App internals for {appId}");

            try
            {
                Log.Add("general stats");
                msg += p(
                    ToBr($"AppId: {pkg.AppId}\n"
                         + $"Timestamp: {pkg.CacheTimestamp}\n"
                         + $"Update Count: {pkg.CacheUpdateCount}\n"
                         + $"Dyn Update Count: {pkg.DynamicUpdatesCount}\n"
                         + "\n")
                    );
            }
            catch { /* ignore */ }

            return(msg);
        }
        public void SnapshotDomainRepositoryTests_SaveAggregateRootAndPublishToDirectBusTest()
        {
            IConfigSource configSource = Helper.ConfigSource_Repositories_SnapshotDomainRepository_DirectBus;
            IApp          application  = AppRuntime.Create(configSource);

            application.Initialize += new System.EventHandler <AppInitEventArgs>(Helper.AppInit_Repositories_SnapshotDomainRepository_DirectBus);
            application.Start();

            SourcedCustomer customer = new SourcedCustomer();
            Guid            id       = customer.ID;

            customer.ChangeName("Qingyang", "Chen");
            using (IDomainRepository domainRepository = application.ObjectContainer.GetService <IDomainRepository>())
            {
                domainRepository.Save <SourcedCustomer>(customer);
                domainRepository.Commit();
            }
            int cnt = Helper.ReadRecordCountFromSQLExpressCQRSTestDB(Helper.CQRSTestDB_Table_Snapshots);

            Assert.AreEqual <int>(1, cnt);
            using (IDomainRepository domainRepository = application.ObjectContainer.GetService <IDomainRepository>())
            {
                SourcedCustomer sourcedCustomer = null;
                sourcedCustomer = domainRepository.Get <SourcedCustomer>(id);
                Assert.AreEqual <string>("Qingyang", sourcedCustomer.FirstName);
                Assert.AreEqual <string>("Chen", sourcedCustomer.LastName);
            }
        }
        public void EventSourcedDomainRepositoryTests_SaveAndLoadAggregateRootTest()
        {
            IConfigSource configSource = Helper.ConfigSource_Repositories_EventSourcedDomainRepositoryWithMSMQBusButWithoutSnapshotProvider;
            IApp          app          = AppRuntime.Create(configSource);

            app.Initialize += Helper.AppInit_Repositories_EventSourcedDomainRepositoryWithMSMQBusButWithoutSnapshotProvider;
            app.Start();

            SourcedCustomer customer = new SourcedCustomer();

            customer.ChangeName("sunny", "chen");
            customer.ChangeEmail("*****@*****.**");
            Assert.AreEqual <long>(3, customer.Version);
            using (IDomainRepository domainRepository = app.ObjectContainer.GetService <IDomainRepository>())
            {
                domainRepository.Save <SourcedCustomer>(customer);
                domainRepository.Commit();
            }
            Assert.AreEqual <long>(3, customer.Version);

            using (IDomainRepository domainRepository2 = app.ObjectContainer.GetService <IDomainRepository>())
            {
                SourcedCustomer cust = domainRepository2.Get <SourcedCustomer>(customer.ID);
                Assert.AreEqual <long>(3, cust.Version);
                Assert.AreEqual <string>("sunny", cust.FirstName);
                Assert.AreEqual <string>("chen", cust.LastName);
                Assert.AreEqual <string>("*****@*****.**", cust.Email);
            }
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_Generators;

            application = AppRuntime.Create(configSource);
            application.Start();
        }
        public void SnapshotDomainRepositoryTests_SaveAggregateRootButFailPublishToMSMQTest()
        {
            IConfigSource configSource = Helper.ConfigSource_Repositories_SnapshotDomainRepository_SaveButFailPubToMSMQ;
            IApp          application  = AppRuntime.Create(configSource);

            application.Initialize += new System.EventHandler <AppInitEventArgs>(Helper.AppInit_Repositories_SnapshotDomainRepository_SaveButFailPubToMSMQ);
            application.Start();

            SourcedCustomer customer = new SourcedCustomer();
            Guid            id       = customer.ID;

            customer.ChangeName("Qingyang", "Chen");
            IDomainRepository domainRepository = null;

            try
            {
                using (domainRepository = application.ObjectContainer.GetService <IDomainRepository>())
                {
                    domainRepository.Save <SourcedCustomer>(customer);
                    domainRepository.Commit();
                }
            }
            catch { }
            int cnt = Helper.ReadRecordCountFromSQLExpressCQRSTestDB(Helper.CQRSTestDB_Table_Snapshots);

            Assert.AreEqual <int>(0, cnt);
        }
示例#11
0
        public TestInit(string ddd)
        {
            if (ddd == "")
            {
            }

            IConfigSource configSource = new DefaultConfig();

            configSource.Config.Application.AppProvider     = "CommonFrameWork.Application.DefaultApp,CommonFrameWork";
            configSource.Config.Application.ObjectContainer = "CommonFrameWork.Extensions.Autofac.AutofacObjectContainer,CommonFrameWork.Extensions.Autofac";

            //configSource.Config.Application.SerializationProvider = "CommonFrameWork.Extensions.NewTonSoft.NewTonSoftSerializer,CommonFrameWork.Extensions.NewTonSoft";

            configSource.Config.Application.Assemblies = Utils.GetAllAssemblies("Project.Domain.ModuleManager");


            configSource.Config.Application.LogProvider = "CommonFrameWork.Extensions.Log4Net.Log4NetLoggerFactory,CommonFrameWork.Extensions.Log4Net";


            var application = AppRuntime.Create(configSource).UseMassTransit();

            //application.Starting += Add;
            //application.Started += Add2;
            //application.Stopping += Add3;

            application.Start();
        }
示例#12
0
        //| <include path='docs/doc[@for="Assert.Fail"]/*' />
        public static void Fail(String conditionString, String message)
        {
            // Run through the list of filters backwards (the last filter in the list
            // is the default filter. So we're guaranteed that there will be at least
            // one filter to handle the assert.

            int iTemp = iNumOfFilters;

            while (iTemp > 0)
            {
                AssertFilters iResult = ListOfFilters [--iTemp].AssertFailure(conditionString, message);

                if (iResult == AssertFilters.FailDebug)
                {
#if SINGULARITY_KERNEL
                    DebugStub.Break();
#elif SINGULARITY_PROCESS
                    VTable.DebugBreak();
#endif
                    break;
                }
                else if (iResult == AssertFilters.FailTerminate)
#if SINGULARITY_KERNEL
                { Kernel.Shutdown(-1); }
#elif SINGULARITY_PROCESS
                { AppRuntime.Stop(-1); }
        public void EventSourcedDomainRepositoryTests_SaveAggregateRootTest()
        {
            IConfigSource configSource = Helper.ConfigSource_Repositories_EventSourcedDomainRepositoryWithMSMQBusButWithoutSnapshotProvider;
            IApp          app          = AppRuntime.Create(configSource);

            app.Initialize += Helper.AppInit_Repositories_EventSourcedDomainRepositoryWithMSMQBusButWithoutSnapshotProvider;
            app.Start();

            SourcedCustomer customer = new SourcedCustomer();

            customer.ChangeName("sunny", "chen");
            Assert.AreEqual <long>(2, customer.Version);
            using (IDomainRepository domainRepository = app.ObjectContainer.GetService <IDomainRepository>())
            {
                domainRepository.Save <SourcedCustomer>(customer);
                domainRepository.Commit();
            }
            Assert.AreEqual <long>(2, customer.Version);
            int recordCnt = Helper.ReadRecordCountFromSQLExpressCQRSTestDB(Helper.CQRSTestDB_Table_DomainEvents);

            Assert.AreEqual <int>(2, recordCnt);
            int msgCnt = Helper.GetMessageQueueCount(Helper.EventBus_MessageQueue);

            Assert.AreEqual <int>(2, msgCnt);
        }
示例#14
0
        public Dictionary <Guid, int> SaveMany([FromUri] int appId, [FromBody] List <BundleWithHeader <EntityWithLanguages> > items, [FromUri] bool partOfPage = false)
        {
            // log and do security check
            Log.Add($"save many started with a#{appId}, i⋮{items.Count}, partOfPage:{partOfPage}");

            var appRead = new AppRuntime(appId, Log);

            #region check if it's an update, and do more security checks - shared with UiController.Save
            // basic permission checks
            var permCheck = new SaveHelpers.Security(SxcInstance, Log)
                            .DoPreSaveSecurityCheck(appId, items);

            var foundItems = items.Where(i => i.EntityId != 0 && i.EntityGuid != Guid.Empty)
                             .Select(i => i.EntityGuid != Guid.Empty
                    ? appRead.Entities.Get(i.EntityGuid) // prefer guid access if available
                    : appRead.Entities.Get(i.EntityId)   // otherwise id
                                     );
            if (foundItems.Any(i => i != null) && !permCheck.EnsureAll(GrantSets.UpdateSomething, out var exception))
            {
                throw exception;
            }
            #endregion

            return(new SaveHelpers.DnnPublishing(SxcInstance, Log)
                   .SaveWithinDnnPagePublishing(appId, items, partOfPage,
                                                forceSaveAsDraft => SaveOldFormatKeepTillReplaced(appId, items, partOfPage, forceSaveAsDraft),
                                                permCheck));
        }
示例#15
0
        public IEnumerable <object> GetAll(int appId)
        {
            Log.Add($"get all a#{appId}");
            var tm = TemplateManager(appId);

            var attributeSetList = new AppRuntime(tm.ZoneId, tm.AppId, Log).ContentTypes.FromScope(Settings.AttributeSetScope).ToList();
            var templateList     = tm.GetAllTemplates().ToList();

            Log.Add($"attrib list count:{attributeSetList.Count}, template count:{templateList.Count}");
            var templates = from c in templateList
                            select new
            {
                Id = c.TemplateId,
                c.Name,
                ContentType          = MiniCTSpecs(attributeSetList, c.ContentTypeStaticName, c.ContentDemoEntity),
                PresentationType     = MiniCTSpecs(attributeSetList, c.PresentationTypeStaticName, c.PresentationDemoEntity),
                ListContentType      = MiniCTSpecs(attributeSetList, c.ListContentTypeStaticName, c.ListContentDemoEntity),
                ListPresentationType = MiniCTSpecs(attributeSetList, c.ListPresentationTypeStaticName, c.ListPresentationDemoEntity),
                TemplatePath         = c.Path,
                c.IsHidden,
                c.ViewNameInUrl,
                c.Guid
            };

            return(templates);
        }
示例#16
0
    public void PlayVideoAction()
    {
        WKStaticFunction.WKMessageLog("Play Video");

        AppRuntime appRuntime = _FSMCaller as AppRuntime;

        appRuntime.SetTransition(TRANSITION.TRANSITION_TO_VIDEOTUTORIALSTATE);
    }
示例#17
0
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_Buses_EventSourcedDomainRepositoryWithDirectCommandBusButWithoutSnapshotProvider;

            application             = AppRuntime.Create(configSource);
            application.Initialize += new EventHandler <AppInitEventArgs>(Helper.AppInit_Buses_EventSourcedDomainRepositoryWithDirectCommandBusButWithoutSnapshotProvider);
            application.Start();
        }
示例#18
0
        private IAttributeDefinition Definition(int appId, string contentType, string fieldName)
        {
            // try to find attribute definition - for later extra security checks
            var appRead = new AppRuntime(appId, Log);
            var type    = appRead.ContentTypes.Get(contentType);

            return(type[fieldName]);
        }
示例#19
0
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_ExceptionHandling;

            application             = AppRuntime.Create(configSource);
            application.Initialize += Helper.AppInit_ExceptionHandling_InvalidStorage;
            application.Start();
        }
示例#20
0
        protected void Application_Start(object sender, EventArgs e)
        {
            IConfigSource appConfigSource = new AppConfigSource();
            IApp          application     = AppRuntime.Create(appConfigSource);

            application.Initialize += new EventHandler <AppInitEventArgs>(application_Initialize);
            application.Start();
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_EventStore_SqlExpress;

            application             = AppRuntime.Create(configSource);
            application.Initialize += new System.EventHandler <AppInitEventArgs>(Helper.AppInit_EventStore_SqlExpress);
            application.Start();
        }
示例#22
0
        protected void Application_Start(object sender, EventArgs e)
        {
            IConfigSource configSource = new AppConfigSource();
            App           application  = AppRuntime.Create(configSource);

            application.AppInitEvent += new App.AppInitHandle(application_AppInitEvent);
            application.Start();
        }
示例#23
0
        public static void StartBDDD(TestContext context)
        {
            ManualConfigSource configSource = ConfigHelper.GetManualConfigSource();

            application = AppRuntime.Create(configSource);
            application.AppInitEvent += application_AppInitEvent;
            application.Start();
        }
示例#24
0
        public static void StartApp()
        {
            IConfigSource configSource = new AppConfigSource();
            App           application  = AppRuntime.Create(configSource);

            application.AppInitEvent += new App.AppInitHandle(application_AppInitEvent);
            application.Start();
        }
示例#25
0
 public AdamAppContext(ITenant tenant, App app, SxcInstance sxcInstance, Log parentLog) : base("Adm.ApCntx", parentLog, "starting")
 {
     Tenant        = tenant;
     _app          = app;
     AppRuntime    = new AppRuntime(app, null);
     SxcInstance   = sxcInstance;
     EnvironmentFs = Factory.Resolve <IEnvironmentFileSystem>();
 }
示例#26
0
    private void StartAction()
    {
        WKStaticFunction.WKMessageLog("Start on Click");

        AppRuntime appRuntime = _FSMCaller as AppRuntime;

        appRuntime.SetTransition(TRANSITION.TRANSITION_TO_ARSTATE);
    }
示例#27
0
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_AggregateRootVersion;

            application             = AppRuntime.Create(configSource);
            application.Initialize += new System.EventHandler <AppInitEventArgs>(Helper.AppInit_Repositories_EventSourcedDomainRepositoryWithDirectEventBusButWithoutSnapshotProvider);
            application.Start();
        }
示例#28
0
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_Repositories_RegularEventPublisherDomainRepository_MSMQ;

            application             = AppRuntime.Create(configSource);
            application.Initialize += new EventHandler <AppInitEventArgs>(Helper.AppInit_Repositories_RegularEventPublisherDomainRepository_MSMQ);
            application.Start();
        }
示例#29
0
        public static void MyClassInitialize(TestContext testContext)
        {
            IConfigSource configSource = Helper.ConfigSource_Repositories_NHibernateRepository;

            application             = AppRuntime.Create(configSource);
            application.Initialize += new EventHandler <AppInitEventArgs>(Helper.AppInit_Repositories_NHibernateRepository);
            application.Start();
        }
示例#30
0
        public void GetContainerFromFile()
        {
            AppRuntime.Create(ConfigHelper.GetAppConfigSource()).Start();

            var context = ServiceLocator.Instance.GetService <IRepositoryContext>();

            Assert.IsNotNull(context);
        }
 public InProcessRelayWorkerConfigurator(AppRuntime appRuntime)
 {
     _appRuntime = appRuntime;
 }
示例#32
0
 public AppConfigurator(AppRuntime appRuntime)
 {
     AppRuntime = appRuntime;
 }