eXpandFramework / eXpand

DevExpress XAF (eXpressApp) extension framework. 𝗹𝗶𝗻𝗸𝗲𝗱𝗶𝗻.𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸.𝗰𝗼𝗺, 𝘆𝗼𝘂𝘁𝘂𝗯𝗲.𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸.𝗰𝗼𝗺 and 𝘁𝘄𝗶𝘁𝘁𝗲𝗿 @𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 and or simply 𝗦𝘁𝗮𝗿/𝘄𝗮𝘁𝗰𝗵 this repository and get notified from 𝗚𝗶𝘁𝗛𝘂𝗯
http://expand.expandframework.com
Microsoft Public License
221 stars 115 forks source link

SequenceGenerator in combination with NonsecuredObjectSpace #988

Closed yunits closed 1 year ago

yunits commented 1 year ago

Hello Mr. Bekiaris, I have a small question:

When using your hangfire module, I have to create a new NonsecuredObjectSpace.

I also use your SequenceGenerator and it looks like there are no sequences generated, if creating Objects in NonsecuredObjectSpace.

How can I obtain next sequence?

apobekiaris commented 1 year ago

Without a sample I really cannot answer.

yunits commented 1 year ago

I found a workaround for myself but I guess it is not safe as it doesn't lock sequence table.

Therefore I created a sample without my workaround. DXApplication1.zip

Just run it, Create an Order and see that there is a sequence generated. Then create a new Job "Import Orders", Trigger and see there are no sequences generated.

yunits commented 1 year ago

Is it maybe a bug? Or do you need further informations?

apobekiaris commented 1 year ago

I did not really had the time to look at it, will do thnks

apobekiaris commented 1 year ago

your sample does not use a secured ObjectSpace in addition you use application.CreateNonSecuredObjectSpace(typeof(Order)) which it will create an updating objectspace and those are not monitor. use application.CreateObjectSpace(typeof(Order)) instead

yunits commented 1 year ago

my example was not fully correct. I forgot to include authentication with password I guess.

If using application.CreateObjectSpace(typeof(Order)) then authentication in code is needed, therefore I used NonSecuredObjectSpace.

Anyway, thanks for your response. I will authenticate in code.

apobekiaris commented 1 year ago

that's the reason I am asking repro samples to avoid missunderstanding and time spend in vain. Anyways post a better sample please

apobekiaris commented 1 year ago

in addition we have this test in the source

        [XpandTest]
        [TestCase(nameof(Platform.Win))]
        public void WhenObjectSpaceCreated(string platformName){
            var platform = GetPlatform(platformName);
            using var application = DefaultReactiveModule(platform).Application;
            using var exiTest = application.WhenObjectSpaceCreated().Test();

            application.CreateObjectSpace();
            application.CreateNonSecuredObjectSpace(typeof(R));

            exiTest.Items.Count.ShouldBe(2);
        }

it asserts that WhenObjectSpaceCreated which is used from the SequenceGenerator emit when CreateNonSecuredObjectSpace

yunits commented 1 year ago

Thanks, you already answered my question. NonSecuredObjectSpace can't be used with SequenceGenerator.

The fact that CreateObjectSpace has to be authenticated when using in a service is known. That has nothing to do with Xpand, therefore I won't bother you with that. Similar question asked here for example: https://supportcenter.devexpress.com/ticket/details/t1159809/manually-authenticate-an-user-in-an-service

apobekiaris commented 1 year ago

NonSecuredObjectSpace can't be used with SequenceGenerator.

I do not think this is correct assumption as per the unit test I posted

yunits commented 1 year ago

here you go with a new sample with authentication DXApplication4.zip I have created three jobs for testing purposes

  1. using NonSecuredObjectSpace (will create Orders without Sequence)
  2. using SecuredObjectSpace (nothing will happen)
  3. using SecuredObjectSpace with authentication (will create Orders without Sequence)
apobekiaris commented 1 year ago

they are now tested for both sequence generator and hangfire, docs include them as well

    [JobProvider]
    public class Job
    {
        public IServiceProvider ServiceProvider { get; }
        public Job() { }
        [ActivatorUtilitiesConstructor]
        public Job(IServiceProvider provider) => ServiceProvider = provider;

        [JobProvider]
        public async Task<bool> ImportOrdersAuthenticated() 
            => await ServiceProvider.RunWithStorageAsync(application 
                => application.UseObjectSpace("Admin", space => CreateOrders(space).FinallySafe(space.CommitChanges)))
                .ToObservable().To(true);

        private static IObservable<Order> CreateOrders(IObjectSpace space) 
            => Observable.Range(0, 10).Select(_ => space.CreateObject<Order>());

        [JobProvider]
        public async Task<bool> ImportOrdersAuthenticatedSequential() 
            => await ServiceProvider.RunWithStorageAsync(application =>
                    application.CommitChangesSequential(CreateOrders,
                        (factory, _) => application.UseObjectSpace("Admin",factory).SelectMany()))
                .ToObservable().To(true);

        [JobProvider]
        public async Task<bool> ImportOrdersFailed() 
            => await ServiceProvider.RunWithStorageAsync(application 
                    => application.UseObjectSpace(space => CreateOrders(space)
                        .FinallySafe(space.CommitChanges)))
                .ToObservable().To(true);

        [JobProvider]
        public async Task<bool> ImportOrdersNonSecured()
            => await ServiceProvider.RunWithStorageAsync(application 
                => application.UseNonSecuredObjectSpace(space => CreateOrders(space)
                        .FinallySafe(space.CommitChanges))
                .To(true));

        [JobProvider]
        public async Task<bool> ImportOrdersNonSecuredSequential()
            => await ServiceProvider.RunWithStorageAsync(application => application.CommitChangesSequential(CreateOrders,(factory, _) 
                    => application.UseNonSecuredObjectSpace(factory).SelectMany())
                .To(true));

        public void Failed()
        {
            throw new NotImplementedException();
        }

    }
yunits commented 1 year ago

@apobekiaris I used my existing sample to try to reproduce an issue. For that I just updated to 4.222.13. https://github.com/eXpandFramework/eXpand/issues/988#issuecomment-1516045038

Sequences are generated but SequenceStorage stays at same value, for example 100. Therefore, if you trigger a Job multiple times it would generate the following output 100 101 102 103.. and then 100 101 102 103..

apobekiaris commented 1 year ago

if you trigger a Job multiple times it would generate the following output

elab

yunits commented 1 year ago

@apobekiaris I guess this comment is for you, right?

apobekiaris commented 1 year ago

I meant post details e.g. how do u trigger the job or anything is related to this case

yunits commented 1 year ago

DXApplication4.zip

@apobekiaris Create a Job "Import orders Secured". Trigger. Go to orders and see the sequences generated. Trigger Job again. Go to orders and see the duplicate sequences, because sequence storage has not been incremented permanent.

yunits commented 1 year ago

is that what you need?

apobekiaris commented 1 year ago

looks so, but did not have the time to research it yet. I ll keep u posted

expand commented 1 year ago

The pre-release 4.222.11.0 in the Reactive.XAF lab branch includes commits that relate to this task:

To minimize version conflicts we recommend that you use the Xpand.XAF.Core.All, Xpand.XAF.Win.All, Xpand.XAF.Web.All packages. Doing so, all packages will be at your disposal and .NET will add a dependecy only to those packages that you actually use and not to all (see the Modules installation-registrations youtube video).

Released packages: Xpand.Extensions v.4.222.13
Xpand.Extensions.Blazor v.4.222.13
Xpand.Extensions.Mono.Cecil v.4.222.13
Xpand.Extensions.Office.Cloud v.4.222.13
Xpand.Extensions.Office.Cloud.Google.Blazor v.4.222.13
Xpand.Extensions.Reactive v.4.222.13
Xpand.Extensions.XAF v.4.222.13
Xpand.Extensions.XAF.Xpo v.4.222.13
Xpand.TestsLib v.4.222.13
Xpand.TestsLib.Blazor v.4.222.13
Xpand.TestsLib.Common v.4.222.13
Xpand.TestsLib.EasyTest v.4.222.13
Xpand.VersionConverter v.4.222.13
Xpand.XAF.Core.All v.4.222.13
Xpand.XAF.Modules.AutoCommit v.4.222.13
Xpand.XAF.Modules.Blazor v.4.222.13
Xpand.XAF.Modules.BulkObjectUpdate v.4.222.13
Xpand.XAF.Modules.CloneMemberValue v.4.222.13
Xpand.XAF.Modules.CloneModelView v.4.222.13
Xpand.XAF.Modules.Email v.4.222.13
Xpand.XAF.Modules.GridListEditor v.4.222.13
Xpand.XAF.Modules.HideToolBar v.4.222.13
Xpand.XAF.Modules.JobScheduler.Hangfire v.4.222.13
Xpand.XAF.Modules.JobScheduler.Notification v.4.222.13
Xpand.XAF.Modules.MasterDetail v.4.222.13
Xpand.XAF.Modules.ModelMapper v.4.222.13
Xpand.XAF.Modules.ModelViewInheritance v.4.222.13
Xpand.XAF.Modules.Office.Cloud.Google v.4.222.13
Xpand.XAF.Modules.Office.Cloud.Google.Calendar v.4.222.13
Xpand.XAF.Modules.Office.Cloud.Google.Tasks v.4.222.13
Xpand.XAF.Modules.Office.DocumentStyleManager v.4.222.13
Xpand.XAF.Modules.OneView v.4.222.13
Xpand.XAF.Modules.PositionInListView v.4.222.13
Xpand.XAF.Modules.ProgressBarViewItem v.4.222.13
Xpand.XAF.Modules.RazorView v.4.222.13
Xpand.XAF.Modules.Reactive v.4.222.13
Xpand.XAF.Modules.Reactive.Logger v.4.222.13
Xpand.XAF.Modules.Reactive.Logger.Client.Win v.4.222.13
Xpand.XAF.Modules.Reactive.Logger.Hub v.4.222.13
Xpand.XAF.Modules.Reactive.Rest v.4.222.13
Xpand.XAF.Modules.RefreshView v.4.222.13
Xpand.XAF.Modules.SequenceGenerator v.4.222.13
Xpand.XAF.Modules.Speech v.4.222.13
Xpand.XAF.Modules.SpellChecker v.4.222.13
Xpand.XAF.Modules.StoreToDisk v.4.222.13
Xpand.XAF.Modules.SuppressConfirmation v.4.222.13
Xpand.XAF.Modules.TenantManager v.4.222.13
Xpand.XAF.Modules.ViewEditMode v.4.222.13
Xpand.XAF.Modules.ViewItemValue v.4.222.13
Xpand.XAF.Modules.ViewWizard v.4.222.13
Xpand.XAF.Modules.Windows v.4.222.13
Xpand.XAF.Web.All v.4.222.13
Xpand.XAF.Win.All v.4.222.13

Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

If you do not use these packages directly but through a module of the main eXpandFramework project, please wait for the bot to notify you again when integration is finished or update the related packages manually.

Thanks a lot for your contribution.