コード例 #1
0
ファイル: Updater.cs プロジェクト: mcaltindal33/TicariOfis
        private PermissionPolicyRole CreateDefaultRole()
        {
            PermissionPolicyRole defaultRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Default"));

            if (defaultRole == null)
            {
                defaultRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                defaultRole.Name = "Default";

                defaultRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.Read, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/MyDetails", SecurityPermissionState.Allow);
                defaultRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Deny);
                defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.Create, SecurityPermissionState.Allow);
                defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.Create, SecurityPermissionState.Allow);
            }
            return(defaultRole);
        }
コード例 #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
        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();
        }
コード例 #4
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();
        }
コード例 #5
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();

            PermissionPolicyRole adminRole   = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", SecurityStrategy.AdministratorRoleName));
            PermissionPolicyRole userRole    = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Users"));
            PermissionPolicyRole canteenRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "CanteenUsers"));
            PermissionPolicyRole staffRole   = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "StaffUsers"));
            Profile admin       = ObjectSpace.FindObject <Profile>(new BinaryOperator("UserName", "Tertius"));
            Profile baseUser    = ObjectSpace.FindObject <Profile>(new BinaryOperator("UserName", "Sara"));
            Profile canteenUser = ObjectSpace.FindObject <Profile>(new BinaryOperator("UserName", "Frik"));
            Profile staffUser   = ObjectSpace.FindObject <Profile>(new BinaryOperator("UserName", "Piet"));

            Telephone rdTelephoneNumber = ObjectSpace.FindObject <Telephone>(CriteriaOperator.Parse("TelephoneNumber == '0814669402'"));

            if (rdTelephoneNumber == null)
            {
                rdTelephoneNumber = ObjectSpace.CreateObject <Telephone>();
                rdTelephoneNumber.TelephoneNumber = "0814669402";
                rdTelephoneNumber.DateCreated     = DateTime.Now;
                rdTelephoneNumber.Active          = true;
                rdTelephoneNumber.TelephoneType   = ((TelephoneType)1);
                rdTelephoneNumber.Customer        = null;
            }

            if (admin == null)
            {
                admin          = ObjectSpace.CreateObject <Profile>();
                admin.UserName = "******";
                admin.SetPassword("1234");

                //Profile Class Fields
                admin.Surname        = "Liebenberg";
                admin.Name           = "Tertius";
                admin.Title          = "Mr.";
                admin.Initials       = "T";
                admin.EmailAddress   = "*****@*****.**";
                admin.BuildingNumber = 2;
                admin.Floor          = 2;
            }

            if (baseUser == null)
            {
                baseUser          = ObjectSpace.CreateObject <Profile>();
                baseUser.UserName = "******";
                baseUser.SetPassword("");

                //Profile Class Fields
                baseUser.Surname        = "Verster";
                baseUser.Name           = "Sara";
                baseUser.Title          = "Ms.";
                baseUser.Initials       = "S";
                baseUser.EmailAddress   = "*****@*****.**";
                baseUser.BuildingNumber = 1;
                baseUser.Floor          = 2;
            }

            if (canteenUser == null)
            {
                canteenUser          = ObjectSpace.CreateObject <Profile>();
                canteenUser.UserName = "******";
                canteenUser.SetPassword("Cantina");

                //Profile Class Fields
                canteenUser.Surname        = "Pogenpoel";
                canteenUser.Name           = "Frik Gerhardus";
                canteenUser.Title          = "Mr.";
                canteenUser.Initials       = "FG";
                canteenUser.EmailAddress   = "*****@*****.**";
                canteenUser.BuildingNumber = 1;
                canteenUser.Floor          = 1;
            }

            if (staffUser == null)
            {
                staffUser          = ObjectSpace.CreateObject <Profile>();
                staffUser.UserName = "******";
                staffUser.SetPassword("Staffer");

                //Profile Class Fields
                staffUser.Surname        = "Boela";
                staffUser.Name           = "Pieter";
                staffUser.Title          = "Mr.";
                staffUser.Initials       = "P";
                staffUser.EmailAddress   = "*****@*****.**";
                staffUser.BuildingNumber = 2;
                staffUser.Floor          = 1;
            }

            if (adminRole == null)
            {
                adminRole      = ObjectSpace.CreateObject <PermissionPolicyRole>();
                adminRole.Name = SecurityStrategy.AdministratorRoleName;
                /** Setting the 'IsAdministrative = true ' allows the user with Admin role to have full access to all objects of all types.*/
                adminRole.IsAdministrative = true;
            }

            if (userRole == null)
            {
                userRole                  = ObjectSpace.CreateObject <PermissionPolicyRole>();
                userRole.Name             = "Users";
                userRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault;
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                userRole.AddTypePermission <Profile>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                userRole.AddObjectPermission <Profile>(SecurityOperations.ReadOnlyAccess, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                userRole.AddMemberPermission <Profile>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow);
                userRole.AddMemberPermission <Profile>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow);
                userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, 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);
            }

            if (canteenRole == null)
            {
                canteenRole                  = ObjectSpace.CreateObject <PermissionPolicyRole>();
                canteenRole.Name             = "CanteenUsers";
                canteenRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault;
                canteenRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                canteenRole.AddTypePermission <Profile>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                canteenRole.AddObjectPermission <Profile>(SecurityOperations.ReadOnlyAccess, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                canteenRole.AddMemberPermission <Profile>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow);
                canteenRole.AddMemberPermission <Profile>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow);
                canteenRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow);
                canteenRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                canteenRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                canteenRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
            }

            if (staffRole == null)
            {
                staffRole                  = ObjectSpace.CreateObject <PermissionPolicyRole>();
                staffRole.Name             = "StaffUsers";
                staffRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault;
                staffRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                staffRole.AddTypePermission <Profile>(SecurityOperations.FullAccess, SecurityPermissionState.Deny);
                staffRole.AddObjectPermission <Profile>(SecurityOperations.ReadOnlyAccess, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
                staffRole.AddMemberPermission <Profile>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow);
                staffRole.AddMemberPermission <Profile>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow);
                staffRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow);
                staffRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                staffRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                staffRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
            }

            admin.Roles.Add(adminRole);
            baseUser.Roles.Add(userRole);
            canteenUser.Roles.Add(canteenRole);
            staffUser.Roles.Add(staffRole);
            ObjectSpace.CommitChanges();
        }
コード例 #6
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();
        }
コード例 #7
0
        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            UpdateAnalysisCriteriaColumn();

            // 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.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[]));
            }
            if (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)
            {
                contactJohn            = ObjectSpace.CreateObject <Contact>();
                contactJohn.FirstName  = "John";
                contactJohn.LastName   = "Nilsen";
                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[]));
            }
            if (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)
            {
                contactJanete = ObjectSpace.CreateObject <Contact>();
                contactJanete.TitleOfCourtesy = TitleOfCourtesy.Miss;
                contactJanete.FirstName       = "Janete";
                contactJanete.LastName        = "Limeira";
                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[]));
            }
            if (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)
            {
                contactKarl            = ObjectSpace.CreateObject <Contact>();
                contactKarl.FirstName  = "Karl";
                contactKarl.LastName   = "Jablonski";
                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[]));
            }
            if (LocationIsEmpty(contactKarl))
            {
                if (contactKarl.Location == null)
                {
                    contactKarl.Location = ObjectSpace.CreateObject <Location>();
                }

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

            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.Email           = "catherine_ [email protected]";
                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[]));
            }
            if (LocationIsEmpty(contactCatherine))
            {
                if (contactCatherine.Location == null)
                {
                    contactCatherine.Location = ObjectSpace.CreateObject <Location>();
                }

                contactCatherine.Location.Contact   = contactCatherine;
                contactCatherine.Location.Latitude  = 40.711510;
                contactCatherine.Location.Longitude = -73.967212;
            }

            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.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[]));
            }
            if (LocationIsEmpty(contactPaul))
            {
                if (contactPaul.Location == null)
                {
                    contactPaul.Location = ObjectSpace.CreateObject <Location>();
                }

                contactPaul.Location.Contact   = contactPaul;
                contactPaul.Location.Latitude  = 40.759613;
                contactPaul.Location.Longitude = -73.914252;
            }

            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.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[]));
            }
            if (LocationIsEmpty(contactElizabeth))
            {
                if (contactElizabeth.Location == null)
                {
                    contactElizabeth.Location = ObjectSpace.CreateObject <Location>();
                }

                contactElizabeth.Location.Contact   = contactElizabeth;
                contactElizabeth.Location.Latitude  = 40.700600;
                contactElizabeth.Location.Longitude = -73.937210;
            }

            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.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[]));
            }
            if (LocationIsEmpty(contactDaniel))
            {
                if (contactDaniel.Location == null)
                {
                    contactDaniel.Location = ObjectSpace.CreateObject <Location>();
                }

                contactDaniel.Location.Contact   = contactDaniel;
                contactDaniel.Location.Latitude  = 40.711640;
                contactDaniel.Location.Longitude = -73.924246;
            }

            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...");
            #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.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;Navigate;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Navigate;Create", SecurityPermissionState.Deny);
                userRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Navigate;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();
        }