コード例 #1
0
        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
            exportCtrl    = Frame.GetController <ExportController>();
            webExportCtrl = Frame.GetController <WebExportController>();
            //ist der aktuelle Benutze admin??
            curUser = (PermissionPolicyUser)SecuritySystem.CurrentUser;
            int adminQuery = curUser.Roles.Where(t => t.IsAdministrative).Count();

            if (adminQuery <= 0)
            {
                if (exportCtrl != null)
                {
                    exportCtrl.Active[Key] = false;
                }

                if (webExportCtrl != null)
                {
                    webExportCtrl.Active[Key] = false;
                }
            }
        }
コード例 #2
0
        private void CreateUser()
        {
            PermissionPolicyUser user = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (user == null)
            {
                user          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user.UserName = "******";
                user.IsActive = true;
            }

            PermissionPolicyRole role = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "UserRole"));

            if (role == null)
            {
                role = ObjectSpace.CreateObject <PermissionPolicyRole>();
                role.IsAdministrative = false;
                role.Name             = "UserRole";
                role.PermissionPolicy = DevExpress.Persistent.Base.SecurityPermissionPolicy.AllowAllByDefault;
                role.AddTypePermission <ObjectWithSecurity>(SecurityOperations.Read, DevExpress.Persistent.Base.SecurityPermissionState.Deny);
                role.AddObjectPermission <ObjectWithSecurity>(SecurityOperations.Read, "[User.Oid] = CurrentUserID()", DevExpress.Persistent.Base.SecurityPermissionState.Allow);
                role.Users.Add(user);
            }
        }
コード例 #3
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #4
0
        private static void CreateUsers(IObjectSpace objectSpace)
        {
            PermissionPolicyUser admin = objectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            admin          = objectSpace.CreateObject <PermissionPolicyUser>();
            admin.UserName = "******";
            admin.IsActive = true;
            admin.SetPassword("");
            PermissionPolicyRole role = objectSpace.CreateObject <PermissionPolicyRole>();

            role.IsAdministrative = true;
            admin.Roles.Add(role);

            PermissionPolicyUser user = objectSpace.CreateObject <PermissionPolicyUser>();

            user.UserName = "******";
            user.IsActive = true;
            PermissionPolicyRole userRole = objectSpace.CreateObject <PermissionPolicyRole>();

            userRole.Name = "Users";
            userRole.AddObjectPermission <Employee>(SecurityOperations.Read, "[IsManager] != true", SecurityPermissionState.Allow);
            user.Roles.Add(userRole);
            objectSpace.CommitChanges();
        }
コード例 #5
0
        public Persona LVerificarUsuario(string txtUser, string txtPassword)
        {
            PermissionPolicyUser Usuario = db.PermissionPolicyUser.First();

            if (Usuario != null)
            {
                Persona UsuarioRegistrado = db.Persona.FirstOrDefault(x => x.Oid.Equals(Usuario.Oid));
                string  password          = Usuario.StoredPassword;
                if (password == txtPassword)
                {
                    return(UsuarioRegistrado);
                }
                else
                {
                    Console.WriteLine("Contraseña incorrecta " + DateTime.Now.ToString());
                    return(null);
                }
            }
            else
            {
                Console.WriteLine("Usuario incorrecto " + DateTime.Now.ToString());
                return(null);
            }
        }
コード例 #6
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            Position developerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Developer'"));

            if (developerPosition == null)
            {
                developerPosition       = ObjectSpace.CreateObject <Position>();
                developerPosition.Title = "Developer";
            }
            Position managerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Manager'"));

            if (managerPosition == null)
            {
                managerPosition       = ObjectSpace.CreateObject <Position>();
                managerPosition.Title = "Manager";
            }

            Contact contactJohn = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'John' && LastName == 'Nilsen'"));

            if (contactJohn == null)
            {
                contactJohn           = ObjectSpace.CreateObject <Contact>();
                contactJohn.FirstName = "John";
                contactJohn.LastName  = "Nilsen";
                contactJohn.Email     = "*****@*****.**";
                contactJohn.Birthday  = new DateTime(1981, 10, 3);
                contactJohn.Position  = developerPosition;
            }
            PhoneNumber johnPhoneNumber_1 = ObjectSpace.FindObject <PhoneNumber>(CriteriaOperator.Parse("Number == '888-111-222'"));

            if (johnPhoneNumber_1 == null)
            {
                johnPhoneNumber_1        = ObjectSpace.CreateObject <PhoneNumber>();
                johnPhoneNumber_1.Number = "888-111-222";
                contactJohn.PhoneNumbers.Add(johnPhoneNumber_1);
            }
            PhoneNumber johnPhoneNumber_2 = ObjectSpace.FindObject <PhoneNumber>(CriteriaOperator.Parse("Number == '888-333-222'"));

            if (johnPhoneNumber_2 == null)
            {
                johnPhoneNumber_2        = ObjectSpace.CreateObject <PhoneNumber>();
                johnPhoneNumber_2.Number = "888-333-222";
                contactJohn.PhoneNumbers.Add(johnPhoneNumber_2);
            }

            ObjectSpace.CommitChanges();

            Contact contactMary = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Mary' && LastName == 'Tellitson'"));

            if (contactMary == null)
            {
                contactMary           = ObjectSpace.CreateObject <Contact>();
                contactMary.FirstName = "Mary";
                contactMary.LastName  = "Tellitson";
                contactMary.Email     = "*****@*****.**";
                contactMary.Birthday  = new DateTime(1980, 11, 27);
                contactMary.Position  = managerPosition;
            }
            PhoneNumber maryPhoneNumber_1 = ObjectSpace.FindObject <PhoneNumber>(CriteriaOperator.Parse("Number == '999-999-999'"));

            if (maryPhoneNumber_1 == null)
            {
                maryPhoneNumber_1        = ObjectSpace.CreateObject <PhoneNumber>();
                maryPhoneNumber_1.Number = "999-999-999";
                contactMary.PhoneNumbers.Add(maryPhoneNumber_1);
            }
            PhoneNumber maryPhoneNumber_2 = ObjectSpace.FindObject <PhoneNumber>(CriteriaOperator.Parse("Number == '999-999-777'"));

            if (maryPhoneNumber_2 == null)
            {
                maryPhoneNumber_2        = ObjectSpace.CreateObject <PhoneNumber>();
                maryPhoneNumber_2.Number = "999-999-777";
                contactMary.PhoneNumbers.Add(maryPhoneNumber_2);
            }

            ObjectSpace.CommitChanges();

            Company myOrg = ObjectSpace.FindObject <Company>(CriteriaOperator.Parse("Name == 'Demo Company'"));

            if (myOrg == null)
            {
                myOrg      = ObjectSpace.CreateObject <Company>();
                myOrg.Name = "Demo Company";
                myOrg.City = "DefaultCity";
            }
#if !DXCORE3
            CreateReport("OrdinalReport", OrdinalReportResource.ReportLayout, "ReportWithParametersObject", typeof(DemoParameters));
            ReportDataV2 reportData = CreateReport("SubreportCompany", SubreportCompanyLayout.ReportLayout);
            string       reportWithSubReportLayout = ReportWithSubReportLayout.ReportLayout.Replace("SubReportKEY", ObjectSpace.GetObjectHandle(reportData));
            ReportDataV2 simpleSubReportData       = CreateReport("SimpleSubReport", SimpleSubReportLayout.ReportLayout);
            string       reportWithSubReportDifferentEnumsLayout = ReportWithSubReportDifferentEnumsLayout.ReportLayout.Replace("SubReportKEY", ObjectSpace.GetObjectHandle(simpleSubReportData));
            CreateReport("ReportWithSecurity", ReportWithSecurity.ReportLayout);
            CreateReport("ReportWithSubReportDifferentEnums", reportWithSubReportDifferentEnumsLayout);
            CreateReport("ReportWithSubReport", reportWithSubReportLayout);
            CreateReport("ReportWithViewDataSource", ReportWithViewDataSourceLayout.ReportLayout);
            CreateReport("OrdinalReport", OrdinalReportResource.ReportLayout);
#else
            CreateReport("OrdinalReport", "OrdinalReport.repx");
            CreateReport("ReportWithSecurity", "ReportWithSecurity.repx");
            CreateReport("OrdinalReport", "OrdinalReport.repx", "ReportWithParametersObject", typeof(DemoParameters));
            ReportDataV2 simpleSubReportData = CreateReport("SimpleSubReport", "SimpleSubReport.repx");
            CreateReport("ReportWithSubReportDifferentEnums", "ReportWithSubReportDifferentEnums.repx", subReportUrl: ObjectSpace.GetObjectHandle(simpleSubReportData));
            ReportDataV2 reportData = CreateReport("SubreportCompany", "SubreportCompany.repx");
            CreateReport("ReportWithSubReport", "ReportWithSubReport.repx", subReportUrl: ObjectSpace.GetObjectHandle(reportData));
            CreateReport("ReportWithViewDataSource", "ReportWithViewDataSource.repx");
#endif
            CreateReportParameters();
            CreateReportMultiValueParameters();
            CreateReportWithBookmark();
            CreateUser();
            SimpleObjectWithEnum simpleObjectWithEnum = ObjectSpace.FindObject <SimpleObjectWithEnum>(CriteriaOperator.Parse("Name == 'One'"));
            if (simpleObjectWithEnum == null)
            {
                simpleObjectWithEnum            = ObjectSpace.CreateObject <SimpleObjectWithEnum>();
                simpleObjectWithEnum.Name       = "One";
                simpleObjectWithEnum.SimpleEnum = SimpleEnum.One;
            }
            ObjectWithSecurity objectWithSecurity = ObjectSpace.FindObject <ObjectWithSecurity>(new BinaryOperator("Name", "TestObject"));
            if (objectWithSecurity == null)
            {
                objectWithSecurity      = ObjectSpace.CreateObject <ObjectWithSecurity>();
                objectWithSecurity.Name = "TestObject";
                PermissionPolicyUser user = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));
                objectWithSecurity.User = user;
            }


            ObjectSpace.CommitChanges();
        }
コード例 #7
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            UpdateAnalysisCriteriaColumn();

            #region Create a User for the Simple Security Strategy
            //// If a simple user named 'Sam' doesn't exist in the database, create this simple user
            //SecuritySimpleUser adminUser = ObjectSpace.FindObject<SecuritySimpleUser>(new BinaryOperator("UserName", "Sam"));
            //if(adminUser == null) {
            //    adminUser = ObjectSpace.CreateObject<SecuritySimpleUser>();
            //    adminUser.UserName = "******";
            //}
            //// Make the user an administrator
            //adminUser.IsAdministrator = true;
            //// Set a password if the standard authentication type is used
            //adminUser.SetPassword("");
            #endregion

            #region Create Users for the Complex Security Strategy
            // If a user named 'Sam' doesn't exist in the database, create this user
            PermissionPolicyUser user1 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Sam"));
            if (user1 == null)
            {
                user1          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user1.UserName = "******";
                // Set a password if the standard authentication type is used
                user1.SetPassword("");
            }
            // If a user named 'John' doesn't exist in the database, create this user
            PermissionPolicyUser user2 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "John"));
            if (user2 == null)
            {
                user2          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user2.UserName = "******";
                // Set a password if the standard authentication type is used
                user2.SetPassword("");
            }

            // If a role with the Administrators name doesn't exist in the database, create this role
            UserRole adminRole = ObjectSpace.FindObject <UserRole>(new BinaryOperator("Name", "Administrators"));
            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <UserRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;

            // If a role with the Users name doesn't exist in the database, create this role
            UserRole userRole = ObjectSpace.FindObject <UserRole>(new BinaryOperator("Name", "Users"));

            if (userRole == null)
            {
                userRole                  = ObjectSpace.CreateObject <UserRole>();
                userRole.Name             = "Users";
                userRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault;
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyUser>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                userRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.ReadOnlyAccess, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow);
                userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);

                userRole.AddTypePermission <Contact>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Deny);
                userRole.AddTypePermission <Contact>("Delete;Navigate;Create", SecurityPermissionState.Allow);
                userRole.AddObjectPermission <Contact>(SecurityOperations.FullObjectAccess, "[UserRoles][].Count() = 0", SecurityPermissionState.Allow);
                userRole.AddObjectPermission <Contact>(SecurityOperations.ReadOnlyAccess, "StartsWith(FirstName, 'E')", SecurityPermissionState.Allow);
                userRole.AddObjectPermission <Contact>(SecurityOperations.FullObjectAccess, "UserRoles[Users[Oid = CurrentUserId()]]", SecurityPermissionState.Allow);
                //userRole.AddObjectPermission<Contact>(SecurityOperations.ReadWriteAccess, "\"bool\" : {\"must\" : [{\"terms\" : { \"userroles.name\" : ['users']}}]}", SecurityPermissionState.Allow);
            }

            // Add the Administrators role to the user1
            user1.Roles.Add(adminRole);
            // Add the Users role to the user2
            user2.Roles.Add(userRole);
            #endregion

            // PermissionPolicyRole defaultRole = CreateDefaultRole();

            Position developerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Developer'"));
            if (developerPosition == null)
            {
                developerPosition       = ObjectSpace.CreateObject <Position>();
                developerPosition.Title = "Developer";
            }
            Position managerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Manager'"));
            if (managerPosition == null)
            {
                managerPosition       = ObjectSpace.CreateObject <Position>();
                managerPosition.Title = "Manager";
            }

            Department devDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Development Department'"));
            if (devDepartment == null)
            {
                devDepartment        = ObjectSpace.CreateObject <Department>();
                devDepartment.Title  = "Development Department";
                devDepartment.Office = "205";
                devDepartment.Positions.Add(developerPosition);
                devDepartment.Positions.Add(managerPosition);
            }
            Department seoDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'SEO'"));
            if (seoDepartment == null)
            {
                seoDepartment        = ObjectSpace.CreateObject <Department>();
                seoDepartment.Title  = "SEO";
                seoDepartment.Office = "703";
                seoDepartment.Positions.Add(developerPosition);
                seoDepartment.Positions.Add(managerPosition);
            }
            ImageConverter imageConverter = new ImageConverter();
            Contact        contactMary    = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Mary' && LastName == 'Tellitson'"));
            if (contactMary == null)
            {
                contactMary            = ObjectSpace.CreateObject <Contact>();
                contactMary.FirstName  = "Mary";
                contactMary.LastName   = "Tellitson";
                contactMary.NickName   = "Emma";
                contactMary.SpouseName = "Harry";
                contactMary.Email      = "*****@*****.**";
                contactMary.Birthday   = new DateTime(1980, 11, 27);
                contactMary.Department = devDepartment;
                contactMary.Notes      = "In duties included control software components";
                contactMary.Position   = managerPosition;
                contactMary.Photo      = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Tellitson_Mary_Photo").Image, typeof(byte[]));
                contactMary.UserRoles.Add(userRole);
            }
            Contact contactJohn = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'John' && LastName == 'Nilsen'"));
            if (contactJohn == null)
            {
                contactJohn            = ObjectSpace.CreateObject <Contact>();
                contactJohn.FirstName  = "John";
                contactJohn.LastName   = "Nilsen";
                contactJohn.NickName   = "Eric";
                contactJohn.SpouseName = "Emma Watson";
                contactJohn.Email      = "*****@*****.**";
                contactJohn.Birthday   = new DateTime(1981, 10, 3);
                contactJohn.Department = devDepartment;
                contactJohn.Position   = developerPosition;
                contactJohn.Notes      = "In duties included development of software modules";
                contactJohn.Photo      = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Nilsen_John_Photo").Image, typeof(byte[]));
                contactJohn.UserRoles.Add(userRole);
                contactJohn.UserRoles.Add(adminRole);
            }
            Contact contactJanete = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Janete' && LastName == 'Limeira'"));
            if (contactJanete == null)
            {
                contactJanete = ObjectSpace.CreateObject <Contact>();
                contactJanete.TitleOfCourtesy = TitleOfCourtesy.Miss;
                contactJanete.FirstName       = "Janete";
                contactJanete.LastName        = "Limeira";
                contactJanete.NickName        = "Dieter";
                contactJanete.SpouseName      = "Monika";
                contactJanete.Email           = "*****@*****.**";
                contactJanete.Birthday        = new DateTime(1981, 12, 21);
                contactJanete.Department      = devDepartment;
                contactJanete.Position        = managerPosition;
                contactJanete.Notes           = "In duties included control software components";
                contactJanete.Photo           = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Limeira_Janete_Photo").Image, typeof(byte[]));
                contactJanete.UserRoles.Add(userRole);
                contactJanete.UserRoles.Add(adminRole);
            }
            Contact contactKarl = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Karl' && LastName == 'Jablonski'"));
            if (contactKarl == null)
            {
                contactKarl            = ObjectSpace.CreateObject <Contact>();
                contactKarl.FirstName  = "Karl";
                contactKarl.LastName   = "Jablonski";
                contactKarl.NickName   = "Herbert";
                contactKarl.SpouseName = "Erna";
                contactKarl.Email      = " [email protected]";
                contactKarl.Birthday   = new DateTime(1975, 12, 19);
                contactKarl.Department = devDepartment;
                contactKarl.Position   = developerPosition;
                contactKarl.Manager    = contactJanete;
                contactKarl.Notes      = "In duties included  development of software modules";
                contactKarl.Photo      = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Jablonski_Karl_Photo").Image, typeof(byte[]));
                contactKarl.UserRoles.Add(userRole);
                contactKarl.UserRoles.Add(adminRole);
            }
            Contact contactCatherine = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Catherine' && LastName == 'Dewey'"));
            if (contactCatherine == null)
            {
                contactCatherine = ObjectSpace.CreateObject <Contact>();
                contactCatherine.TitleOfCourtesy = TitleOfCourtesy.Miss;
                contactCatherine.FirstName       = "Catherine";
                contactCatherine.LastName        = "Dewey";
                contactCatherine.NickName        = "Frank";
                contactCatherine.SpouseName      = "Heike";
                contactCatherine.Email           = "*****@*****.**";
                contactCatherine.Birthday        = new DateTime(1993, 7, 9);
                contactCatherine.Department      = seoDepartment;
                contactCatherine.Position        = managerPosition;
                contactCatherine.Notes           = "In duties included control software components";
                contactCatherine.Photo           = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Dewey_Catherine_Photo").Image, typeof(byte[]));
                contactCatherine.UserRoles.Add(adminRole);
            }
            Contact contactPaul = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Paul' && LastName == 'Henriot'"));
            if (contactPaul == null)
            {
                contactPaul = ObjectSpace.CreateObject <Contact>();
                contactPaul.TitleOfCourtesy = TitleOfCourtesy.Mr;
                contactPaul.FirstName       = "Paul";
                contactPaul.LastName        = "Henriot";
                contactPaul.NickName        = "Lukas";
                contactPaul.SpouseName      = "Christiana";
                contactPaul.Email           = "*****@*****.**";
                contactPaul.Birthday        = new DateTime(1958, 1, 30);
                contactPaul.Department      = seoDepartment;
                contactPaul.Position        = developerPosition;
                contactPaul.Notes           = "In duties included  development of software modules";
                contactPaul.Photo           = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Henriot_Paul_Photo").Image, typeof(byte[]));
                contactPaul.UserRoles.Add(userRole);
                contactPaul.UserRoles.Add(adminRole);
            }
            Contact contactElizabeth = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Elizabeth' && LastName == 'Lincoln'"));
            if (contactElizabeth == null)
            {
                contactElizabeth = ObjectSpace.CreateObject <Contact>();
                contactElizabeth.TitleOfCourtesy = TitleOfCourtesy.Ms;
                contactElizabeth.FirstName       = "Elizabeth";
                contactElizabeth.LastName        = "Lincoln";
                contactElizabeth.NickName        = "Que";
                contactElizabeth.SpouseName      = "Alen NIx";
                contactElizabeth.Email           = "*****@*****.**";
                contactElizabeth.Birthday        = new DateTime(1988, 3, 14);
                contactElizabeth.Department      = seoDepartment;
                contactElizabeth.Position        = managerPosition;
                contactElizabeth.Manager         = contactCatherine;
                contactElizabeth.Notes           = "In duties included control software components";
                contactElizabeth.Photo           = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Lincoln_Elizabeth_Photo").Image, typeof(byte[]));
                contactElizabeth.UserRoles.Add(userRole);
                contactElizabeth.UserRoles.Add(adminRole);
            }

            Contact contactDaniel = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Daniel' && LastName == 'Tonini'"));
            if (contactDaniel == null)
            {
                contactDaniel            = ObjectSpace.CreateObject <Contact>();
                contactDaniel.FirstName  = "Daniel";
                contactDaniel.LastName   = "Tonini";
                contactDaniel.NickName   = "Alexander";
                contactDaniel.SpouseName = "keth";
                contactDaniel.Email      = "*****@*****.**";
                contactDaniel.Birthday   = new DateTime(1980, 12, 30);
                contactDaniel.Department = seoDepartment;
                contactDaniel.Notes      = "In duties included development of software modules";
                contactDaniel.Position   = developerPosition;
                contactDaniel.Manager    = contactElizabeth;
                contactDaniel.Photo      = (byte[])imageConverter.ConvertTo(ImageLoader.Instance.GetImageInfo("Tonini_Daniel_Photo").Image, typeof(byte[]));
                contactDaniel.UserRoles.Add(adminRole);
            }

            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Review reports'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject       = "Review reports";
                task.AssignedTo    = contactJohn;
                task.StartDate     = DateTime.Parse("May 03, 2008");
                task.DueDate       = DateTime.Parse("September 06, 2008");
                task.Status        = DevExpress.Persistent.Base.General.TaskStatus.InProgress;
                task.Priority      = Priority.High;
                task.EstimatedWork = 60;
                task.Description   = "Analyse the reports and assign new tasks to employees.";
            }

            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Fix breakfast'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject       = "Fix breakfast";
                task.AssignedTo    = contactMary;
                task.StartDate     = DateTime.Parse("May 03, 2008");
                task.DueDate       = DateTime.Parse("May 04, 2008");
                task.Status        = DevExpress.Persistent.Base.General.TaskStatus.Completed;
                task.Priority      = Priority.Low;
                task.EstimatedWork = 1;
                task.ActualWork    = 3;
                task.Description   = "The Development Department - by 9 a.m.\r\nThe R&QA Department - by 10 a.m.";
            }
            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Task1'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject       = "Task1";
                task.AssignedTo    = contactJohn;
                task.StartDate     = DateTime.Parse("June 03, 2008");
                task.DueDate       = DateTime.Parse("June 06, 2008");
                task.Status        = DevExpress.Persistent.Base.General.TaskStatus.Completed;
                task.Priority      = Priority.High;
                task.EstimatedWork = 10;
                task.ActualWork    = 15;
                task.Description   = "A task designed specially to demonstrate the PivotChart module. Switch to the Reports navigation group to view the generated analysis.";
            }
            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Task2'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject       = "Task2";
                task.AssignedTo    = contactJohn;
                task.StartDate     = DateTime.Parse("July 03, 2008");
                task.DueDate       = DateTime.Parse("July 06, 2008");
                task.Status        = DevExpress.Persistent.Base.General.TaskStatus.Completed;
                task.Priority      = Priority.Low;
                task.EstimatedWork = 8;
                task.ActualWork    = 16;
                task.Description   = "A task designed specially to demonstrate the PivotChart module. Switch to the Reports navigation group to view the generated analysis.";
            }
            UpdateStatus("CreateAnalysis", "", "Creating analysis reports in the database...");
            CreateDataToBeAnalysed();
            UpdateStatus("CreateSecurityData", "", "Creating users and roles in the database...");


            ObjectSpace.CommitChanges();
        }
コード例 #8
0
ファイル: Updater.cs プロジェクト: jjcolumb/XAFMainDemo
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            UpdateAnalysisCriteriaColumn();

            // PermissionPolicyRole defaultRole = CreateDefaultRole();

            UpdateStatus("CreateContacts", "", "Creating contacts, departments and positions in the database...");
            Position developerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Developer'"));

            if (developerPosition == null)
            {
                developerPosition       = ObjectSpace.CreateObject <Position>();
                developerPosition.Title = "Developer";
            }
            Position managerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Manager'"));

            if (managerPosition == null)
            {
                managerPosition       = ObjectSpace.CreateObject <Position>();
                managerPosition.Title = "Manager";
            }

            Department devDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Development Department'"));

            if (devDepartment == null)
            {
                devDepartment        = ObjectSpace.CreateObject <Department>();
                devDepartment.Title  = "Development Department";
                devDepartment.Office = "205";
                devDepartment.Positions.Add(developerPosition);
                devDepartment.Positions.Add(managerPosition);
            }
            Department seoDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'SEO'"));

            if (seoDepartment == null)
            {
                seoDepartment        = ObjectSpace.CreateObject <Department>();
                seoDepartment.Title  = "SEO";
                seoDepartment.Office = "703";
                seoDepartment.Positions.Add(developerPosition);
                seoDepartment.Positions.Add(managerPosition);
            }
            ObjectSpace.CommitChanges();
            try {
                DataTable employeesTable = GetEmployeesDataTable();
                foreach (DataRow employee in employeesTable.Rows)
                {
                    string  email   = Convert.ToString(employee["EmailAddress"]);
                    Contact contact = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("Email=?", email));
                    if (contact == null)
                    {
                        contact           = ObjectSpace.CreateObject <Contact>();
                        contact.Email     = email;
                        contact.FirstName = Convert.ToString(employee["FirstName"]);
                        contact.LastName  = Convert.ToString(employee["LastName"]);
                        contact.BirthDate = Convert.ToDateTime(employee["BirthDate"]);
                        contact.Photo     = Convert.FromBase64String(Convert.ToString(employee["ImageData"]));
                        string titleOfCourtesyText = Convert.ToString(employee["Title"]).ToLower();
                        if (!string.IsNullOrEmpty(titleOfCourtesyText))
                        {
                            titleOfCourtesyText = titleOfCourtesyText.Replace(".", "");
                            TitleOfCourtesy titleOfCourtesy;
                            if (Enum.TryParse <TitleOfCourtesy>(titleOfCourtesyText, true, out titleOfCourtesy))
                            {
                                contact.TitleOfCourtesy = titleOfCourtesy;
                            }
                        }
                        PhoneNumber phoneNumber = ObjectSpace.CreateObject <PhoneNumber>();
                        phoneNumber.Party     = contact;
                        phoneNumber.Number    = Convert.ToString(employee["Phone"]);
                        phoneNumber.PhoneType = "Work";

                        Address address = ObjectSpace.CreateObject <Address>();
                        contact.Address1      = address;
                        address.ZipPostal     = Convert.ToString(employee["PostalCode"]);
                        address.Street        = Convert.ToString(employee["AddressLine1"]);
                        address.City          = Convert.ToString(employee["City"]);
                        address.StateProvince = Convert.ToString(employee["StateProvinceName"]);
                        string  countryName = Convert.ToString(employee["CountryRegionName"]);
                        Country country     = ObjectSpace.FindObject <Country>(CriteriaOperator.Parse("Name=?", countryName), true);
                        if (country == null)
                        {
                            country      = ObjectSpace.CreateObject <Country>();
                            country.Name = countryName;
                        }
                        address.Country = country;

                        string     departmentTitle = Convert.ToString(employee["GroupName"]);
                        Department department      = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title=?", departmentTitle), true);
                        if (department == null)
                        {
                            department       = ObjectSpace.CreateObject <Department>();
                            department.Title = departmentTitle;
                            Random rnd = new Random();
                            department.Office = string.Format("{0}0{0}", rnd.Next(1, 7), rnd.Next(9));
                        }
                        contact.Department = department;

                        string   positionTitle = Convert.ToString(employee["JobTitle"]);
                        Position position      = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title=?", positionTitle), true);
                        if (position == null)
                        {
                            position       = ObjectSpace.CreateObject <Position>();
                            position.Title = positionTitle;
                            position.Departments.Add(department);
                        }
                        contact.Position = position;
                    }
                }
                ObjectSpace.CommitChanges();
            }
            catch (Exception e) {
                Tracing.Tracer.LogText("Cannot initialize contacts, departments and positions from the XML file.");
                Tracing.Tracer.LogError(e);
            }


            Contact contactMary = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Mary' && LastName == 'Tellitson'"));

            if (contactMary != null && LocationIsEmpty(contactMary))
            {
                if (contactMary.Location == null)
                {
                    contactMary.Location = ObjectSpace.CreateObject <Location>();
                }

                contactMary.Location.Contact   = contactMary;
                contactMary.Location.Latitude  = 40.620610;
                contactMary.Location.Longitude = -73.935242;
            }

            Contact contactJohn = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'John' && LastName == 'Nilsen'"));

            if (contactJohn != null && LocationIsEmpty(contactJohn))
            {
                if (contactJohn.Location == null)
                {
                    contactJohn.Location = ObjectSpace.CreateObject <Location>();
                }

                contactJohn.Location.Contact   = contactJohn;
                contactJohn.Location.Latitude  = 40.711510;
                contactJohn.Location.Longitude = -73.845252;
            }

            Contact contactJanete = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Janete' && LastName == 'Limeira'"));

            if (contactJanete != null && LocationIsEmpty(contactJanete))
            {
                if (contactJanete.Location == null)
                {
                    contactJanete.Location = ObjectSpace.CreateObject <Location>();
                }

                contactJanete.Location.Contact   = contactJanete;
                contactJanete.Location.Latitude  = 40.710410;
                contactJanete.Location.Longitude = -73.963262;
            }

            Contact contactKarl = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Karl' && LastName == 'Jablonski'"));

            if (contactKarl != null && LocationIsEmpty(contactKarl))
            {
                if (contactKarl.Manager == null)
                {
                    contactKarl.Manager = contactJanete;
                }
                if (contactKarl.Location == null)
                {
                    contactKarl.Location = ObjectSpace.CreateObject <Location>();
                }

                contactKarl.Location.Contact   = contactKarl;
                contactKarl.Location.Latitude  = 40.792613;
                contactKarl.Location.Longitude = -73.925142;
            }


            ObjectSpace.CommitChanges();


            UpdateStatus("CreatePayments", "", "Creating payments, resumes and scheduler events in the database...");
            IList <Contact> topTenContacts = ObjectSpace.GetObjects <Contact>();

            ObjectSpace.SetCollectionSorting(topTenContacts, new SortProperty[] { new SortProperty("LastName", DevExpress.Xpo.DB.SortingDirection.Ascending) });
            ObjectSpace.SetTopReturnedObjectsCount(topTenContacts, 10);
            string[] notes =
            {
                "works with customers until their problems are resolved and often goes an extra step to help upset customers be completely surprised by how far we will go to satisfy customers",
                "is very good at making team members feel included. The inclusion has improved the team's productivity dramatically",
                "is very good at sharing knowledge and information during a problem to increase the chance it will be resolved quickly",
                "actively elicits feedback from customers and works to resolve their problems",
                "creates an inclusive work environment where everyone feels they are a part of the team",
                "consistently keeps up on new trends in the industry and applies these new practices to every day work",
                "is clearly not a short term thinker - the ability to set short and long term business goals is a great asset to the company",
                "seems to want to achieve all of the goals in the last few weeks before annual performance review time, but does not consistently work towards the goals throughout the year",
                "does not yet delegate effectively and has a tendency to be overloaded with tasks which should be handed off to subordinates",
                "to be discussed with the top management..."
            };
            for (int i = 0; i < topTenContacts.Count; i++)
            {
                Contact contact = topTenContacts[i];
                Payment payment = ObjectSpace.FindObject <Payment>(CriteriaOperator.Parse("Contact=?", contact));
                if (payment == null)
                {
                    payment         = ObjectSpace.CreateObject <Payment>();
                    payment.Contact = contact;
                    payment.Hours   = new Random().Next(10, 40);
                    payment.Rate    = new Random().Next(30, 50) + new Random().Next(5, 20);
                }
                Resume resume = ObjectSpace.FindObject <Resume>(CriteriaOperator.Parse("Contact=?", contact));
                if (resume == null)
                {
                    resume = ObjectSpace.CreateObject <Resume>();
                    FileData file = ObjectSpace.CreateObject <FileData>();
                    try {
                        file.LoadFromStream(string.Format("{0}_Photo.png", contact.FullName), new MemoryStream(contact.Photo));
                    }
                    catch (Exception e) {
                        Tracing.Tracer.LogText("Cannot initialize FileData for the contact {0}.", contact.FullName);
                        Tracing.Tracer.LogError(e);
                    }
                    resume.File    = file;
                    resume.Contact = contact;
                }
                Contact reviewerContact = i < 5 ? contactMary : contactJanete;
                Note    note            = ObjectSpace.FindObject <Note>(CriteriaOperator.Parse("Contains(Text, ?)", contact.FullName));
                if (note == null)
                {
                    note          = ObjectSpace.CreateObject <Note>();
                    note.Author   = reviewerContact.FullName;
                    note.Text     = string.Format("<span style='color:#000000;font-family:Tahoma;font-size:8pt;'><b>{0}</b> \r\n{1}</span>", contact.FullName, notes[i]);
                    note.DateTime = DateTime.Now.AddDays(i * (-1));
                }
#if !EASYTEST
                Event appointment = ObjectSpace.FindObject <Event>(CriteriaOperator.Parse("Contains(Subject, ?)", contact.FullName));
                if (appointment == null)
                {
                    appointment             = ObjectSpace.CreateObject <Event>();
                    appointment.Subject     = string.Format("{0} - performance review", contact.FullName);
                    appointment.Description = string.Format("{0} \r\n{1}", contact.FullName, notes[i]);
                    appointment.StartOn     = note.DateTime.AddDays(5).AddHours(12);
                    appointment.EndOn       = appointment.StartOn.AddHours(2);
                    appointment.Location    = "101";
                    appointment.AllDay      = false;
                    appointment.Status      = 0;
                    appointment.Label       = i % 2 == 0 ? 2 : 5;
                    Resource reviewerContactResource = ObjectSpace.FindObject <Resource>(CriteriaOperator.Parse("Contains(Caption, ?)", reviewerContact.FullName));
                    if (reviewerContactResource == null)
                    {
                        reviewerContactResource         = ObjectSpace.CreateObject <Resource>();
                        reviewerContactResource.Caption = reviewerContact.FullName;
                        reviewerContactResource.Color   = reviewerContact == contactMary ? Color.AliceBlue : Color.LightCoral;
                    }
                    appointment.Resources.Add(reviewerContactResource);
                }
#endif
            }

            ObjectSpace.CommitChanges();

            UpdateStatus("CreateTasks", "", "Creating demo tasks in the database...");

#if EASYTEST
            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Review reports'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject            = "Review reports";
                task.AssignedTo         = contactJohn;
                task.StartDate          = DateTime.Parse("May 03, 2008");
                task.DueDate            = DateTime.Parse("September 06, 2008");
                task.Status             = DevExpress.Persistent.Base.General.TaskStatus.InProgress;
                task.Priority           = Priority.High;
                task.EstimatedWorkHours = 60;
                task.Description        = "Analyse the reports and assign new tasks to employees.";
            }

            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Fix breakfast'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject            = "Fix breakfast";
                task.AssignedTo         = contactMary;
                task.StartDate          = DateTime.Parse("May 03, 2008");
                task.DueDate            = DateTime.Parse("May 04, 2008");
                task.Status             = DevExpress.Persistent.Base.General.TaskStatus.Completed;
                task.Priority           = Priority.Low;
                task.EstimatedWorkHours = 1;
                task.ActualWorkHours    = 3;
                task.Description        = "The Development Department - by 9 a.m.\r\nThe R&QA Department - by 10 a.m.";
            }
            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Task1'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject            = "Task1";
                task.AssignedTo         = contactJohn;
                task.StartDate          = DateTime.Parse("June 03, 2008");
                task.DueDate            = DateTime.Parse("June 06, 2008");
                task.Status             = DevExpress.Persistent.Base.General.TaskStatus.Completed;
                task.Priority           = Priority.High;
                task.EstimatedWorkHours = 10;
                task.ActualWorkHours    = 15;
                task.Description        = "A task designed specially to demonstrate the PivotChart module. Switch to the Reports navigation group to view the generated analysis.";
            }
            if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Task2'")) == null)
            {
                DemoTask task = ObjectSpace.CreateObject <DemoTask>();
                task.Subject            = "Task2";
                task.AssignedTo         = contactJohn;
                task.StartDate          = DateTime.Parse("July 03, 2008");
                task.DueDate            = DateTime.Parse("July 06, 2008");
                task.Status             = DevExpress.Persistent.Base.General.TaskStatus.Completed;
                task.Priority           = Priority.Low;
                task.EstimatedWorkHours = 8;
                task.ActualWorkHours    = 16;
                task.Description        = "A task designed specially to demonstrate the PivotChart module. Switch to the Reports navigation group to view the generated analysis.";
            }
#endif
#if !EASYTEST
            IList <Contact>  contacts = ObjectSpace.GetObjects <Contact>();
            IList <DemoTask> taskList = GenerateTask(contacts);
            if (taskList.Count > 0)
            {
                Random rndGenerator = new Random();
                foreach (Contact contact in contacts)
                {
                    if (taskList.Count == 1)
                    {
                        contact.Tasks.Add(taskList[0]);
                    }
                    else if (taskList.Count == 2)
                    {
                        contact.Tasks.Add(taskList[0]);
                        contact.Tasks.Add(taskList[1]);
                    }
                    else
                    {
                        int index = rndGenerator.Next(1, taskList.Count - 2);
                        contact.Tasks.Add(taskList[index]);
                        contact.Tasks.Add(taskList[index - 1]);
                        contact.Tasks.Add(taskList[index + 1]);
                    }
                }
            }
#endif
            UpdateStatus("CreateAnalysis", "", "Creating analysis reports in the database...");
            CreateDataToBeAnalysed();
            UpdateStatus("CreateSecurityData", "", "Creating users and roles in the database...");
            #region Create a User for the Simple Security Strategy
            //// If a simple user named 'Sam' doesn't exist in the database, create this simple user
            //SecuritySimpleUser adminUser = ObjectSpace.FindObject<SecuritySimpleUser>(new BinaryOperator("UserName", "Sam"));
            //if(adminUser == null) {
            //    adminUser = ObjectSpace.CreateObject<SecuritySimpleUser>();
            //    adminUser.UserName = "******";
            //}
            //// Make the user an administrator
            //adminUser.IsAdministrator = true;
            //// Set a password if the standard authentication type is used
            //adminUser.SetPassword("");
            #endregion

            #region Create Users for the Complex Security Strategy
            // If a user named 'Sam' doesn't exist in the database, create this user
            PermissionPolicyUser user1 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Sam"));
            if (user1 == null)
            {
                user1          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user1.UserName = "******";
                // Set a password if the standard authentication type is used
                user1.SetPassword("");
            }
            // If a user named 'John' doesn't exist in the database, create this user
            PermissionPolicyUser user2 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "John"));
            if (user2 == null)
            {
                user2          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user2.UserName = "******";
                // Set a password if the standard authentication type is used
                user2.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));
            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;

            // If a role with the Users name doesn't exist in the database, create this role
            PermissionPolicyRole userRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Users"));
            if (userRole == null)
            {
                userRole                  = ObjectSpace.CreateObject <PermissionPolicyRole>();
                userRole.Name             = "Users";
                userRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault;
                userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyRole_ListView", SecurityPermissionState.Deny);
                userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyUser_ListView", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyUser>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                userRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.ReadOnlyAccess, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow);
                userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny);
            }

            // Add the Administrators role to the user1
            user1.Roles.Add(adminRole);
            // Add the Users role to the user2
            user2.Roles.Add(userRole);
            #endregion

            ObjectSpace.CommitChanges();
        }
コード例 #9
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);


            //        DodajStawke("23%", 23m);
            //        DodajStawke("07%", 7m);
            //        DodajStawke("03%", 3m);
            //        DodajStawke("0%", 0m);
            //        DodajStawke("ZW%", 0m);
            //        DodajStawke("NP%", 0m);
            //        ObjectSpace.CommitChanges();

            //        var stawki = ObjectSpace.GetObjectsQuery<StawkaVat>().ToList();

            //        var bogusUsluga = new Faker<Usluga>("pl")
            //            .CustomInstantiator(f => ObjectSpace.CreateObject<Usluga>())
            //            .RuleFor(o => o.Nazwa, f => f.Commerce.ProductName())
            //            .RuleFor(o => o.CenaJednostkowa, f => f.Random.Decimal(0.01m, 1000m))
            //            .RuleFor(o => o.StawkaVat, f => f.PickRandom(stawki));
            //        bogusUsluga.Generate(100);

            //        var bogusProdukt = new Faker<Produkt>("pl")
            //.CustomInstantiator(f => ObjectSpace.CreateObject<Produkt>())
            //.RuleFor(o => o.Nazwa, f => f.Commerce.ProductName())
            //.RuleFor(o => o.CenaJednostkowa, f => f.Random.Decimal(0.01m, 1000m))
            //.RuleFor(o => o.StawkaVat, f => f.PickRandom(stawki));
            //        bogusProdukt.Generate(100);


            //        var bogusTowar = new Faker<Towar>("pl")
            //        .CustomInstantiator(f => ObjectSpace.CreateObject<Towar>())
            //        .RuleFor(o => o.Nazwa, f => f.Commerce.ProductName())
            //        .RuleFor(o => o.CenaJednostkowa, f => f.Random.Decimal(0.01m, 1000m))
            //        .RuleFor(o => o.StawkaVat, f => f.PickRandom(stawki));
            //        bogusTowar.Generate(100);


            //        var bogusKlient = new Faker<Kontrahent>("pl")
            //         .CustomInstantiator(f => ObjectSpace.CreateObject<Kontrahent>())
            //        .RuleFor(o => o.Nazwa, f => f.Company.CompanyName());


            //            bogusKlient.Generate(100);

            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #10
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            UpdateStatus("CreateContacts", "", "Creating contacts, departments and positions in the database...");

            ObjectSpace.CommitChanges();
            try {
                CreateDepartments();
                CreateContacts();
            }
            catch (Exception e) {
                Tracing.Tracer.LogText("Cannot initialize contacts, departments and positions from the XML file.");
                Tracing.Tracer.LogError(e);
            }
            InitContactsLocation();


            UpdateStatus("CreatePayments", "", "Creating payments, resumes and scheduler events in the database...");
            IList <Contact> topTenContacts = ObjectSpace.GetObjects <Contact>();

            ObjectSpace.SetCollectionSorting(topTenContacts, new DevExpress.Xpo.SortProperty[] { new DevExpress.Xpo.SortProperty("LastName", DevExpress.Xpo.DB.SortingDirection.Ascending) });
            ObjectSpace.SetTopReturnedObjectsCount(topTenContacts, 10);
            string[] notes =
            {
                "works with customers until their problems are resolved and often goes an extra step to help upset customers be completely surprised by how far we will go to satisfy customers",
                "is very good at making team members feel included. The inclusion has improved the team's productivity dramatically",
                "is very good at sharing knowledge and information during a problem to increase the chance it will be resolved quickly",
                "actively elicits feedback from customers and works to resolve their problems",
                "creates an inclusive work environment where everyone feels they are a part of the team",
                "consistently keeps up on new trends in the industry and applies these new practices to every day work",
                "is clearly not a short term thinker - the ability to set short and long term business goals is a great asset to the company",
                "seems to want to achieve all of the goals in the last few weeks before annual performance review time, but does not consistently work towards the goals throughout the year",
                "does not yet delegate effectively and has a tendency to be overloaded with tasks which should be handed off to subordinates",
                "to be discussed with the top management..."
            };
            for (int i = 0; i < topTenContacts.Count; i++)
            {
                Contact contact = topTenContacts[i];
                if (ObjectSpace.FindObject <Paycheck>(CriteriaOperator.Parse("Contact=?", contact)) == null)
                {
                    PayrollSampleDataGenerator.GenerateContactPaychecks(ObjectSpace, contact);
                    ObjectSpace.CommitChanges();
                }
                Resume resume = ObjectSpace.FindObject <Resume>(CriteriaOperator.Parse("Contact=?", contact));
                if (resume == null)
                {
                    resume = ObjectSpace.CreateObject <Resume>();
                    FileData file = ObjectSpace.CreateObject <FileData>();
                    try {
                        Stream stream = FindContactResume(contact);
                        if (stream != null)
                        {
                            file.LoadFromStream(string.Format("{0}.pdf", contact.FullName), stream);
                        }
                    }
                    catch (Exception e) {
                        Tracing.Tracer.LogText("Cannot initialize FileData for the contact {0}.", contact.FullName);
                        Tracing.Tracer.LogError(e);
                    }
                    resume.File    = file;
                    resume.Contact = contact;
                }
                Contact reviewerContact = i < 5 ? FindTellitson() : FindJanete();
                Note    note            = ObjectSpace.FindObject <Note>(CriteriaOperator.Parse("Contains(Text, ?)", contact.FullName));
                if (note == null)
                {
                    note          = ObjectSpace.CreateObject <Note>();
                    note.Author   = reviewerContact.FullName;
                    note.Text     = string.Format("<span style='color:#000000;font-family:Tahoma;font-size:8pt;'><b>{0}</b> \r\n{1}</span>", contact.FullName, notes[i]);
                    note.DateTime = DateTime.Now.AddDays(i * (-1));
                }
            }

            ObjectSpace.CommitChanges();

            UpdateStatus("CreateTasks", "", "Creating demo tasks in the database...");

#if !EASYTEST
            IList <Contact>  contacts = ObjectSpace.GetObjects <Contact>();
            IList <DemoTask> taskList = GenerateTask(contacts);
            if (taskList.Count > 0)
            {
                Random rndGenerator = new Random();
                foreach (Contact contact in contacts)
                {
                    if (taskList.Count == 1)
                    {
                        contact.Tasks.Add(taskList[0]);
                    }
                    else if (taskList.Count == 2)
                    {
                        contact.Tasks.Add(taskList[0]);
                        contact.Tasks.Add(taskList[1]);
                    }
                    else
                    {
                        int index = rndGenerator.Next(1, taskList.Count - 2);
                        contact.Tasks.Add(taskList[index]);
                        contact.Tasks.Add(taskList[index - 1]);
                        contact.Tasks.Add(taskList[index + 1]);
                    }
                }
            }
#endif

            UpdateStatus("CreateAnalysis", "", "Creating analysis reports in the database...");
            UpdateStatus("CreateSecurityData", "", "Creating users and roles in the database...");
            #region Create a User for the Simple Security Strategy
            //// If a simple user named 'Sam' doesn't exist in the database, create this simple user
            //SecuritySimpleUser adminUser = ObjectSpace.FindObject<SecuritySimpleUser>(new BinaryOperator("UserName", "Sam"));
            //if(adminUser == null) {
            //    adminUser = ObjectSpace.CreateObject<SecuritySimpleUser>();
            //    adminUser.UserName = "******";
            //}
            //// Make the user an administrator
            //adminUser.IsAdministrator = true;
            //// Set a password if the standard authentication type is used
            //adminUser.SetPassword("");
            #endregion

            ObjectSpace.CommitChanges();
            #region Create Users for the Complex Security Strategy
            // If a user named 'Sam' doesn't exist in the database, create this user
            PermissionPolicyUser user1 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Sam"));
            if (user1 == null)
            {
                user1          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user1.UserName = "******";
                // Set a password if the standard authentication type is used
                user1.SetPassword("");
            }
            // If a user named 'John' doesn't exist in the database, create this user
            PermissionPolicyUser user2 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "John"));
            if (user2 == null)
            {
                user2          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                user2.UserName = "******";
                // Set a password if the standard authentication type is used
                user2.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));
            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;

            // If a role with the Users name doesn't exist in the database, create this role
            PermissionPolicyRole userRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Users"));
            if (userRole == null)
            {
                userRole                  = ObjectSpace.CreateObject <PermissionPolicyRole>();
                userRole.Name             = "Users";
                userRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault;
                userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyRole_ListView", SecurityPermissionState.Deny);
                userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyUser_ListView", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyUser>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                userRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.ReadOnlyAccess, "[ID] = CurrentUserId()", SecurityPermissionState.Allow);
                userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow);
                userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyNavigationPermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyActionPermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny);
            }

            // Add the Administrators role to the user1
            if (!user1.Roles.Contains(adminRole))
            {
                user1.Roles.Add(adminRole);
            }

            // Add the Users role to the user2
            if (!user2.Roles.Contains(userRole))
            {
                user2.Roles.Add(userRole);
            }
            #endregion

            ObjectSpace.CommitChanges();
        }
コード例 #11
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            #region Security
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));
            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();
            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));
            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));
            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            #endregion

            #region Location
            // Province
            using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MintaXAF.Module.DatabaseUpdate.Data.Province.json")))
            {
                dynamic lstProvince = JsonConvert.DeserializeObject(sr.ReadToEnd());
                foreach (var item in lstProvince.Province)
                {
                    Province province = ObjectSpace.FindObject <Province>(new BinaryOperator("Code", item.code.Value));
                    if (province == null)
                    {
                        province       = ObjectSpace.CreateObject <Province>();
                        province.Code  = item.code.Value;
                        province.Title = item.name_with_type.Value;
                        province.Save();
                    }
                }
            }
            // District
            using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MintaXAF.Module.DatabaseUpdate.Data.District.json")))
            {
                dynamic lstDistrict = JsonConvert.DeserializeObject(sr.ReadToEnd());
                foreach (var item in lstDistrict.District)
                {
                    District district = ObjectSpace.FindObject <District>(new BinaryOperator("Code", item.code.Value));
                    Province province = ObjectSpace.FindObject <Province>(new BinaryOperator("Code", item.parent_code.Value));
                    if (district == null && province != null)
                    {
                        district       = ObjectSpace.CreateObject <District>();
                        district.Code  = item.code.Value;
                        district.Title = item.name_with_type.Value;
                        province.Districts.Add(district);
                        district.Save();
                    }
                }
            }

            // Commune
            using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MintaXAF.Module.DatabaseUpdate.Data.Commune.json")))
            {
                dynamic lstCommune = JsonConvert.DeserializeObject(sr.ReadToEnd());
                foreach (var item in lstCommune.Commune)
                {
                    Commune  commune  = ObjectSpace.FindObject <Commune>(new BinaryOperator("Code", item.code.Value));
                    District district = ObjectSpace.FindObject <District>(new BinaryOperator("Code", item.parent_code.Value));
                    if (commune == null && district != null)
                    {
                        commune          = ObjectSpace.CreateObject <Commune>();
                        commune.Code     = item.code.Value;
                        commune.Title    = item.name_with_type.Value;
                        commune.Province = district.Province;
                        district.Communes.Add(commune);
                        commune.Save();
                    }
                }
            }
            #endregion

            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #12
0
 public static bool IsAuthenticationStandardEnabled(this PermissionPolicyUser user, IObjectSpace os)
 {
     return(false);
 }
コード例 #13
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            if (ObjectSpace.GetObjectsCount(typeof(Employee), null) == 0)
            {
                Employee Employee1 = ObjectSpace.CreateObject <Employee>();
                Employee1.EmployeeID = "001";
                Employee Employee2 = ObjectSpace.CreateObject <Employee>();
                Employee2.EmployeeID = "002";
            }

            if (ObjectSpace.GetObjectsCount(typeof(Product), null) == 0)
            {
                Product product = ObjectSpace.CreateObject <Product>();
                product.Name        = "Chai";
                product.Description = "is a tea beverage made by boiling black tea in milk and water with a mixture of aromatic herbs and spices[2]. Originating in India,[3] the beverage has gained worldwide popularity, becoming a feature in many coffee and tea houses. Although traditionally prepared as a decoction of green cardamom pods, cinnamon sticks, ground cloves, ground ginger, and black peppercorn together with black tea leaves, retail versions include tea bags for infusion, instant powdered mixtures, and concentrates.";
                for (int i = 0; i < 10; i++)
                {
                    Order order = ObjectSpace.CreateObject <Order>();
                    if (i % 2 == 0)
                    {
                        order.EmployeeID = "001";
                    }
                    else
                    {
                        order.EmployeeID = "002";
                    }
                    order.Product     = product;
                    order.Description = "Order " + i.ToString();
                }
                Order ExtraOrder = ObjectSpace.CreateObject <Order>();
                ExtraOrder.EmployeeID = "001";
                ExtraOrder.Product    = product;
            }
            if (ObjectSpace.GetObjectsCount(typeof(Person), null) == 0)
            {
                Person person = ObjectSpace.CreateObject <Person>();
                person.FirstName = "Jose";
                person.LastName  = "Ojeda";

                PhoneNumber RussianPhone = ObjectSpace.CreateObject <PhoneNumber>();
                RussianPhone.Number = "+7986532147";


                PhoneNumber SalvadoreanPhone = ObjectSpace.CreateObject <PhoneNumber>();
                SalvadoreanPhone.Number = "+5036532147";

                person.PhoneNumbers.Add(SalvadoreanPhone);
                person.PhoneNumbers.Add(RussianPhone);
            }



            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #14
0
ファイル: Updater.cs プロジェクト: mcaltindal33/XAF-Learn
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);

            Company company = ObjectSpace.FindObject <Company>(new BinaryOperator("Name", "Demo"));

            if (company == null)
            {
                company      = ObjectSpace.CreateObject <Company>();
                company.Name = "Demo";
                company.Code = "Demo";
            }

            Series series = ObjectSpace.FindObject <Series>(new BinaryOperator("Name", "Order"));

            if (series == null)
            {
                series      = ObjectSpace.CreateObject <Series>();
                series.Name = "Order";
                series.Code = "Order";
            }

            series = ObjectSpace.FindObject <Series>(new BinaryOperator("Name", "Invoice"));
            if (series == null)
            {
                series      = ObjectSpace.CreateObject <Series>();
                series.Name = "Invoice";
                series.Code = "Invoice";
            }
            series = ObjectSpace.FindObject <Series>(new BinaryOperator("Name", "Delivery"));
            if (series == null)
            {
                series      = ObjectSpace.CreateObject <Series>();
                series.Name = "Delivery";
                series.Code = "Delivery";
            }

            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #15
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);

            DodajKraje(ObjectSpace);

            var stawki = ObjectSpace.GetObjectsQuery <StawkaVat>().ToList();

            if (stawki.Count == 0)
            {
                stawki.Add(NowaStawka("23%", 23M));
                stawki.Add(NowaStawka("0%", 0M));
                stawki.Add(NowaStawka("7%", 7M));
                stawki.Add(NowaStawka("ZW", 0M));
            }

            var prodFaker = new Faker <Produkt>("pl")
                            .CustomInstantiator(f => ObjectSpace.CreateObject <Produkt>())
                            .RuleFor(o => o.Nazwa, f => f.Commerce.ProductName())
                            .RuleFor(o => o.Stawka, f => f.PickRandom(stawki))
                            .RuleFor(o => o.CenaSprzedazy, f => f.Random.Decimal(0.01M, 1000M));

            var products = prodFaker.Generate(1000);


            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #16
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            EmployeeRole adminEmployeeRole = ObjectSpace.FindObject <EmployeeRole>(
                new BinaryOperator("Name", SecurityStrategy.AdministratorRoleName));

            if (adminEmployeeRole == null)
            {
                adminEmployeeRole                  = ObjectSpace.CreateObject <EmployeeRole>();
                adminEmployeeRole.Name             = SecurityStrategy.AdministratorRoleName;
                adminEmployeeRole.IsAdministrative = true;
                adminEmployeeRole.Save();
            }
            SystemUsers adminEmployee = ObjectSpace.FindObject <SystemUsers>(
                new BinaryOperator("UserName", "Admin"));

            if (adminEmployee == null)
            {
                adminEmployee          = ObjectSpace.CreateObject <SystemUsers>();
                adminEmployee.UserName = "******";
                adminEmployee.SetPassword("");
                adminEmployee.EmployeeRoles.Add(adminEmployeeRole);
            }

            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #17
0
ファイル: Updater.cs プロジェクト: tylike/Ultra
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            var ElSalvador        = CreateCountry("El Salvador", "503");
            var Russia            = CreateCountry("Russia", "7");
            var Estonia           = CreateCountry("Estonia", "372");
            var Chile             = CreateCountry("Chile", "56");
            var DominicanRepublic = CreateCountry("Dominican Republic", "56");
            var Cuba = CreateCountry("Cuba", "53");

            CreateCustomer("Jaime Ricardo Macias", "000", ElSalvador);
            CreateCustomer("Douglas Coto", "001", ElSalvador);
            CreateCustomer("Walter Omar Gavarrete", "002", ElSalvador);

            CreateCustomer("Alexander Pushkin", "003", Russia);
            CreateCustomer("Peter Alexeyevich", "004", Russia);
            CreateCustomer("Anna Karenina", "005", Russia);

            CreateCustomer("Sander Tallinn", "006", Estonia);
            CreateCustomer("Voldermar", "007", Estonia);
            CreateCustomer("Peter", "008", Estonia);

            CreateCustomer("Luis Alarcon Ponce", "009", Chile);
            CreateCustomer("Cristobal Perez", "010", Chile);
            CreateCustomer("Jaime Pascal", "011", Chile);

            CreateCustomer("Pedro Hernandez", "012", DominicanRepublic);
            CreateCustomer("Yordi", "013", DominicanRepublic);

            CreateCustomer("Jose Javier Columbie", "014", Cuba);
            CreateCustomer("Yasmani", "015", Cuba);
            CreateCustomer("Yosbel", "016", Cuba);

            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #18
0
 public static bool IsAuthenticationStandardEnabled(this PermissionPolicyUser _)
 => false;
コード例 #19
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            var cnt = ObjectSpace.GetObjects <Contact>().Count;

            if (cnt > 0)
            {
                return;
            }
            for (int i = 0; i < 2; i++)
            {
                string contactName = "FirstName" + i;
                var    contact     = CreateObject <Contact>("FirstName", contactName);
                contact.LastName = "LastName" + i;
                contact.Age      = i * 10;
                for (int j = 0; j < 2; j++)
                {
                    string taskName = "Subject" + i + " - " + j;
                    var    task     = CreateObject <MyTask>("Subject", taskName);
                    task.AssignedTo = contact;
                }
            }
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";
            }
            adminRole.IsAdministrative = true;
            userAdmin.Roles.Add(adminRole);
            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }
コード例 #20
0
ファイル: Updater.cs プロジェクト: wquan8/Apollo11
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            //string name = "MyName";
            //DomainObject1 theObject = ObjectSpace.FindObject<DomainObject1>(CriteriaOperator.Parse("Name=?", name));
            //if(theObject == null) {
            //    theObject = ObjectSpace.CreateObject<DomainObject1>();
            //    theObject.Name = name;
            //}
            PermissionPolicyUser sampleUser = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "User"));

            if (sampleUser == null)
            {
                sampleUser          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                sampleUser.UserName = "******";
                sampleUser.SetPassword("");
            }
            PermissionPolicyRole defaultRole = CreateDefaultRole();

            sampleUser.Roles.Add(defaultRole);

            PermissionPolicyUser userAdmin = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Admin"));

            if (userAdmin == null)
            {
                userAdmin          = ObjectSpace.CreateObject <PermissionPolicyUser>();
                userAdmin.UserName = "******";
                // Set a password if the standard authentication type is used
                userAdmin.SetPassword("");
            }
            // If a role with the Administrators name doesn't exist in the database, create this role
            PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators"));

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = "Administrators";

                adminRole.IsAdministrative = true;
                userAdmin.Roles.Add(adminRole);

                //create the default objects
                Exchange bitstamp   = ObjectSpace.CreateObject <Exchange>();
                Exchange bitFinex   = ObjectSpace.CreateObject <Exchange>();
                Exchange quadrigacx = ObjectSpace.CreateObject <Exchange>();

                ExchangeType USDType = ObjectSpace.CreateObject <ExchangeType>();
                USDType.Name = "USD";
                ExchangeType CADType = ObjectSpace.CreateObject <ExchangeType>();
                CADType.Name = "CAD";

                bitstamp.Name           = "BitStamp";
                bitstamp.ExchangeType   = USDType;
                bitstamp.TradingFee     = Convert.ToDecimal(0.0025);
                bitFinex.Name           = "Bitfinex";
                bitFinex.TradingFee     = Convert.ToDecimal(0.0020);
                bitFinex.ExchangeType   = USDType;
                quadrigacx.Name         = "quadrigacx.com";
                quadrigacx.ExchangeType = CADType;
                quadrigacx.TradingFee   = Convert.ToDecimal(0.0050);

                ExchangeRate USDCAD = ObjectSpace.CreateObject <ExchangeRate>();
                USDCAD.Name          = "USDCAD";
                USDCAD.Rate          = Convert.ToDecimal(1.33);
                USDType.ExchangeRate = USDCAD;
                ExchangeRate CADUSD = ObjectSpace.CreateObject <ExchangeRate>();
                CADUSD.Name = "CADUSD";

                CADUSD.Rate          = Convert.ToDecimal(0.75);
                CADType.ExchangeRate = CADUSD;


                OrderType buy = ObjectSpace.CreateObject <OrderType>();
                buy.Name = "Buy";
                OrderType buy1 = ObjectSpace.CreateObject <OrderType>();
                buy1.Name = "Bid";
                OrderType sell = ObjectSpace.CreateObject <OrderType>();
                sell.Name = "Sell";
                OrderType sell1 = ObjectSpace.CreateObject <OrderType>();
                sell1.Name = "Ask";
                TradeType typeBuy = ObjectSpace.CreateObject <TradeType>();
                typeBuy.Name = "Buy";
                TradeType typeSell = ObjectSpace.CreateObject <TradeType>();
                typeSell.Name = "Sell";
            }
            ObjectSpace.CommitChanges(); //This line persists created object(s).
        }