Пример #1
0
        private void GenerateStupidFemalePersona(int siteId)
        {
            var stupidPerson = new StupidPersonalDataGenerator().GeneratePersonalData(UserGenderEnum.Female);

            PersonaInfo persona = new PersonaInfo
            {
                PersonaDisplayName     = stupidPerson.FirstName + " " + stupidPerson.LastName + " (female)",
                PersonaName            = "Persona-" + Guid.NewGuid(),
                PersonaSiteID          = siteId,
                PersonaPointsThreshold = 100,
                PersonaEnabled         = true
            };

            persona.Insert();

            var rule = new RuleInfo
            {
                RuleScoreID     = persona.PersonaScoreID,
                RuleDisplayName = "Is female",
                RuleName        = "Rule-" + Guid.NewGuid(),
                RuleValue       = 1000,
                RuleType        = RuleTypeEnum.Attribute,
                RuleParameter   = "ContactGender",
                RuleCondition   = "<condition><attribute name=\"ContactGender\"><value>2</value></attribute><wherecondition>ContactGender = 2</wherecondition></condition>",
                RuleSiteID      = siteId
            };

            rule.Insert();
        }
Пример #2
0
        private void GenerateDisabledPersona(int siteId)
        {
            var stupidPerson = new StupidPersonalDataGenerator().GeneratePersonalData();

            PersonaInfo persona = new PersonaInfo
            {
                PersonaDisplayName     = stupidPerson.FirstName + " " + stupidPerson.LastName + " (disabled)",
                PersonaName            = "Persona-" + Guid.NewGuid(),
                PersonaSiteID          = siteId,
                PersonaPointsThreshold = 100,
                PersonaEnabled         = false
            };

            persona.Insert();
        }
        private void GenerateStupidMalePersona(int siteId)
        {
            var stupidPerson = new StupidPersonalDataGenerator().GeneratePersonalData(UserGenderEnum.Male);

            PersonaInfo persona = new PersonaInfo
            {
                PersonaDisplayName = stupidPerson.FirstName + " " + stupidPerson.LastName + " (male)",
                PersonaName = "Persona-" + Guid.NewGuid(),
                PersonaSiteID = siteId,
                PersonaPointsThreshold = 100,
                PersonaEnabled = true
            };
            persona.Insert();

            var rule = new RuleInfo
            {
                RuleScoreID = persona.PersonaScoreID,
                RuleDisplayName = "Is male",
                RuleName = "Rule-" + Guid.NewGuid(),
                RuleValue = 1000,
                RuleType = RuleTypeEnum.Attribute,
                RuleParameter = "ContactGender",
                RuleCondition = "<condition><attribute name=\"ContactGender\"><value>1</value></attribute><wherecondition>ContactGender = 1</wherecondition></condition>",
                RuleSiteID = siteId
            };
            rule.Insert();
        }
        private void GenerateDisabledPersona(int siteId)
        {
            var stupidPerson = new StupidPersonalDataGenerator().GeneratePersonalData();

            PersonaInfo persona = new PersonaInfo
            {
                PersonaDisplayName = stupidPerson.FirstName + " " + stupidPerson.LastName + " (disabled)",
                PersonaName = "Persona-" + Guid.NewGuid(),
                PersonaSiteID = siteId,
                PersonaPointsThreshold = 100,
                PersonaEnabled = false
            };
            persona.Insert();
        }
        public void Generate(GenerationOptions options)
        {
            try
            {
                if (options.GenerateContactStatuses)
                {
                    if (ContactStatusInfoProvider.GetContactStatuses().OnSite(mSiteId).Any())
                    {
                        Information("Contact statuses already exists");
                    }
                    else
                    {
                        new SampleContactStatusesGenerator(mSiteId).Generate();
                        Information("Contact statuses generated");
                    }
                }
                if (options.ContactsCount > 0)
                {
                    if (options.ContactsWithRealNames && options.ContactsCount > 100)
                    {
                        Error("Contacts where not generated. \"Contacts with real names\" setting shouldn't be used for generating more than 100 contacts at once.");
                    }
                    else
                    {
                        IPersonalDataGenerator personalDataGenerator = options.ContactsWithRealNames ?
                            new RealPersonalDataGenerator() :
                            (IPersonalDataGenerator)new StupidPersonalDataGenerator();
                        SampleContactsGenerator generator = new SampleContactsGenerator(personalDataGenerator, mSiteId);
                        var batch = 10000;
                        var count = options.ContactsCount;
                        while (count > batch)
                        {
                            generator.Generate(batch);
                            count -= batch;
                        }
                        generator.Generate(count);
                        Information(options.ContactsCount + " contacts generated");
                    }
                }
                if (options.GenerateMergedContacts)
                {
                    var personalDataGenerator = new StupidPersonalDataGenerator();
                    var generator = new SampleContactsGenerator(personalDataGenerator, mSiteId);
                    generator.GenerateMergedContacts();
                    Information(options.ContactsCount + " merged contacts generated");
                }
                if (options.GenerateContactRelationships)
                {
                    var generator = new ContactRelationshipsGenerator();
                    int generated = generator.GenerateContactRelationships(SiteContext.CurrentSite);
                    Information(generated + " relationships between contact and user generated");
                }
                if (options.GeneratePersonas)
                {
                    ISamplePersonasGenerator personaGenerator = options.ContactsWithRealNames ?
                        new RealPersonasGenerator() :
                        (ISamplePersonasGenerator)new StupidPersonasGenerator();
                    personaGenerator.GeneratePersonas(mSiteId);
                    Information("Sample personas generated");
                }
                if (options.GenerateContactGroups > 0)
                {
                    int generatedCGs = new SampleContactGroupsGenerator().GenerateContactGroups(options.GenerateContactGroups);

                    Information(generatedCGs + " contact groups generated");
                }
                if (options.ScoresCount > 0)
                {
                    new SampleScoresGenerator().GenerateScores(options.ScoresCount, mSiteId);
                    Information(options.ScoresCount + " scores generated");
                }
                if (options.ActivitiesForEachExistingContactCount > 0)
                {
                    var contacts = ContactInfoProvider.GetContacts().OnSite(mSiteId);

                    var documents = DocumentHelper.GetDocuments()
                                                  .PublishedVersion()
                                                  .OnSite(mSiteId)
                                                  .ToList();

                    int activitiesGenerated = 0;
                    contacts.ForEachPage(page => activitiesGenerated += new SampleActivitiesGenerator().GenerateActivitiesForContacts(page, options.ActivitiesForEachExistingContactCount, documents), 10000);

                    Information(activitiesGenerated + " activities generated");
                }
            }
            catch (Exception e)
            {
                Error(e.Message);
            }
        }