public void Parse(string file) { using (XmlTextReader rdr = new XmlTextReader(file)) { foreach (XmlData data in XmlData.Read(rdr)) { _version = data.File.profilerVersion; _driverVersion = data.File.driverVersion; if (_when > data.File.startTime) { _when = data.File.startTime; } CodeMetric metric = new CodeMetric(data); if (ByFile.AddMetric(metric)) //if this is a new statement { ByModule.AddMetric(metric); ByNamespace.AddMetric(metric); ByClass.AddMetric(metric); bool newMethod = ByMethod.AddMetric(metric); if (newMethod && Exclude(metric)) { metric.Excluded = true; } } } } }
private void AddSampleData(SurveyContext context) { var userManager = new ApplicationUserManager(new ApplicationUserStore(context)); var roleManager = new ApplicationRoleManager(new ApplicationRoleStore(context)); try { Project CurrentProject = null; var org = new Organisation() { Id = Guid.Parse("cfa81eb0-9fc7-4932-a3e8-1c822370d034"), // this is the ID on our production database Name = "OnRecord", TelNumber = "0209390499", AddressLine1 = "110 Kings road", AddressLine2 = "Regent street", Town = "London", County = "London", Postcode = "EC23 4AD", DefaultLanguageId = LanguagesRepository.English.Id, DefaultCalendarId = CalendarsRepository.Gregorian.Id, IsActive = true, SubscriptionEnabled = true, SubscriptionMonthlyRate = 6M }; context.Organisations.AddOrUpdate(org); var user = new OrgUser() { Id = Guid.Parse("b3c19356-d11d-48f2-a3a8-69392a7b4e7b"), OrganisationId = org.Id, IsRootUser = true, Email = "*****@*****.**", UserName = "******", TypeId = OrgUserTypesRepository.Administrator.Id, LastLogin = new DateTime(2015, 1, 1), IsWebUser = true, IsMobileUser = true }; userManager.AddOrUpdateUser(user, "Test1234"); OrgUserTypesRepository.Administrator.GetRoles().ToList().ForEach(role => userManager.AddToRole(user.Id, role)); context.SaveChanges(); org.RootUser = user; context.SaveChanges(); CurrentProject = new Project() { Id = Guid.Parse("cb7f09a2-1823-4f60-820e-3fedc462fe76"), Number = "123", Name = "Test Project 1", StartDate = new DateTime(2015, 1, 1), Flagged = true, OrganisationId = org.Id }; context.Projects.AddOrUpdate(CurrentProject); context.SaveChanges(); var dataList = new DataList() { Id = Guid.Parse("884505e1-97c8-4602-8c00-f75ae08d99ab"), OrganisationId = org.Id, Name = "Colors" }; context.DataLists.AddOrUpdate(dataList); context.DataListItems.AddOrUpdate(new DataListItem { Id = Guid.Parse("0a138f19-2e98-4030-b9e9-78527043c1c2"), DataListId = dataList.Id, Text = "Black", Value = 0, Order = 1 }); context.DataListItems.AddOrUpdate(new DataListItem { Id = Guid.Parse("32d75f9b-7da6-43b5-8f3f-b7830dc6e5f7"), DataListId = dataList.Id, Text = "White", Value = 1, Order = 2 }); context.DataListItems.AddOrUpdate(new DataListItem { Id = Guid.Parse("298cdd84-4cd1-481f-875e-c2c9adce43bc"), DataListId = dataList.Id, Text = "Blue", Value = 2, Order = 3 }); context.DataListItems.AddOrUpdate(new DataListItem { Id = Guid.Parse("8e63ad2d-6872-4e6d-86e6-55782450f991"), DataListId = dataList.Id, Text = "Red", Value = 3, Order = 4 }); context.SaveChanges(); var cat = new FormTemplateCategory() { Id = Guid.Parse("8DBFEC4D-96E0-4135-A726-D144D5707858"), Title = "Recordings", OrganisationId = org.Id }; context.FormTemplateCategories.AddOrUpdate(cat); context.SaveChanges(); var adviceThreadsCat = new FormTemplateCategory() { Id = Guid.Parse("F4284C22-1FB4-4187-AD0F-B8FEB059C842"), Title = "Advice Recordings", OrganisationId = org.Id }; context.FormTemplateCategories.AddOrUpdate(adviceThreadsCat); context.SaveChanges(); var template = new FormTemplate() { Id = Guid.Parse("52692cf5-fd17-4fc6-b72b-b65b7e8d4e98"), ProjectId = CurrentProject.Id, Code = "101", Title = "First Form", Description = "This is the first from.", Colour = "#ddff00", Version = 1.0, FormTemplateCategoryId = cat.Id, IsPublished = true, Discriminator = FormTemplateDiscriminators.RegularThread, OrganisationId = org.Id, CreatedById = user.Id }; context.FormTemplates.AddOrUpdate(template); context.SaveChanges(); var category1 = new MetricGroup() { Id = Guid.Parse("bedb627d-155d-4807-93dd-40cbb1fa335d"), Title = "First questions", FormTemplateId = template.Id, Order = template.GetMaxGroupOrder() }; template.AddGroup(category1); context.MetricGroups.AddOrUpdate(category1); var category2 = new MetricGroup() { Id = Guid.Parse("45ca1db0-820b-4271-8f26-7a75e7e73c80"), Title = "Second questions", FormTemplateId = template.Id, Order = template.GetMaxGroupOrder() }; template.AddGroup(category2); context.MetricGroups.AddOrUpdate(category2); var category3 = new MetricGroup() { Id = Guid.Parse("0b76ee76-405a-434a-9bca-4e5b3f1eb5e7"), Title = "Third questions", FormTemplateId = template.Id, Order = template.GetMaxGroupOrder() }; template.AddGroup(category3); context.MetricGroups.AddOrUpdate(category3); context.SaveChanges(); var metric1 = new FreeTextMetric() { Id = Guid.Parse("f6e5b494-d845-48dc-a783-e3e93b340b3a"), ShortTitle = "q1", Description = "What is the answer1", NumberOfLine = 1, MaxLength = 10, Order = category1.GetMaxMetricOrder(), Mandatory = true }; category1.AddMetric(metric1); context.FreeTextMetrics.AddOrUpdate(metric1); var metric2 = new FreeTextMetric() { Id = Guid.Parse("8a85e16c-9abb-4f99-83fc-564605bbd52f"), ShortTitle = "q2", Description = "What is the answer2", NumberOfLine = 3, Order = category1.GetMaxMetricOrder(), Mandatory = true }; category1.AddMetric(metric2); context.FreeTextMetrics.AddOrUpdate(metric2); var metric3 = new FreeTextMetric() { Id = Guid.Parse("b2f747bc-b403-47de-95c2-2efd8e1ebeb6"), ShortTitle = "q3", Description = "What is the answer3", NumberOfLine = 3, Order = category2.GetMaxMetricOrder() }; category2.AddMetric(metric3); context.FreeTextMetrics.AddOrUpdate(metric3); var metric4 = new FreeTextMetric() { Id = Guid.Parse("a8373528-0d92-4d91-bff0-5397700644c8"), ShortTitle = "q4", Description = "What is the answer4", NumberOfLine = 2, Order = category2.GetMaxMetricOrder() }; category2.AddMetric(metric4); context.FreeTextMetrics.AddOrUpdate(metric4); var metric5 = new FreeTextMetric() { Id = Guid.Parse("14531856-8b05-4711-850e-d0ac00173732"), ShortTitle = "q5", Description = "What is the answer5", NumberOfLine = 2, Order = category3.GetMaxMetricOrder() }; category3.AddMetric(metric5); context.FreeTextMetrics.AddOrUpdate(metric5); var metric6 = new RateMetric() { Id = Guid.Parse("ae9399eb-80b2-4944-be22-55b561f10bc5"), ShortTitle = "r1", Description = "What is the rate1", MinValue = 1, MaxValue = 5, DefaultValue = 1, Order = category1.GetMaxMetricOrder() }; category1.AddMetric(metric6); context.RateMetrics.AddOrUpdate(metric6); var metric7 = new DateMetric() { Id = Guid.Parse("68ce9679-14b5-4e00-97d6-38ad6db54f54"), ShortTitle = "d1", Description = "Date of Event", Order = category1.GetMaxMetricOrder(), HasTimeValue = false }; category1.AddMetric(metric7); context.DateMetrics.AddOrUpdate(metric7); var metric8 = new DichotomousMetric() { Id = Guid.Parse("e254bf53-2ddb-4817-a9d7-6d8513696a2f"), ShortTitle = "yn1", Description = "Are you ok?", Order = category1.GetMaxMetricOrder() }; category1.AddMetric(metric8); context.DichotomousMetrics.AddOrUpdate(metric8); context.SaveChanges(); // default advice thread template. var adviceTemplate = new FormTemplate() { Id = Guid.Parse("780f4d2d-524f-4714-a5b2-a43c8eaff3c3"), ProjectId = CurrentProject.Id, Code = "202", Title = "Advice Form", Description = "This is the default advice form.", Colour = "#08874b", DescriptionFormat = "{{comment}}", Version = 1.0, FormTemplateCategoryId = adviceThreadsCat.Id, IsPublished = true, Discriminator = FormTemplateDiscriminators.AdviceThread, OrganisationId = org.Id, CreatedById = user.Id }; context.FormTemplates.AddOrUpdate(adviceTemplate); context.SaveChanges(); var adviceFormCategory1 = new MetricGroup() { Id = Guid.Parse("3b940609-0e1c-4542-87be-f69f2b3faa79"), Title = "Advice Form", FormTemplateId = adviceTemplate.Id, Order = adviceTemplate.GetMaxGroupOrder() }; adviceTemplate.AddGroup(adviceFormCategory1); context.MetricGroups.AddOrUpdate(adviceFormCategory1); var adviceFormMetric1 = new FreeTextMetric() { Id = Guid.Parse("bbb60c5f-cc29-473f-994e-3a04d25c9b60"), ShortTitle = "Comment", Description = "Write your advice or comment here", NumberOfLine = 2, MaxLength = 500, Order = adviceFormCategory1.GetMaxMetricOrder(), Mandatory = true }; adviceFormCategory1.AddMetric(adviceFormMetric1); context.FreeTextMetrics.AddOrUpdate(adviceFormMetric1); var adviceFormMetric2 = new AttachmentMetric() { Id = Guid.Parse("a48e8139-4608-4b72-a85b-b9908714f242"), ShortTitle = "Attachments", Description = "Upload any supporting evidence or media", AllowMultipleFiles = true, Order = adviceFormCategory1.GetMaxMetricOrder() }; adviceFormCategory1.AddMetric(adviceFormMetric2); context.AttachmentMetrics.AddOrUpdate(adviceFormMetric2); context.SaveChanges(); //var data = new FilledForm() { Id = Guid.Parse("390f8abc-dc99-411a-a22f-8cf43313337a"), FormTemplateId = template.Id, ProjectId = CurrentProject.Id, FilledById = user.Id }; //context.FilledForms.AddOrUpdate(data); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("24bacf38-52ee-40e5-916c-a3f81a84eea5"), FilledFormId = data.Id, MetricId = metric1.Id, TextValue = "answer 1" }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("cdb38534-f412-4397-aa1e-51a587db402f"), FilledFormId = data.Id, MetricId = metric2.Id, TextValue = "answer 2" }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("b3d3dc58-5467-42ac-8d2a-3e327635a72d"), FilledFormId = data.Id, MetricId = metric3.Id, TextValue = "answer 3" }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("d3efb64f-8bf1-4916-9dd0-07fc11ec171e"), FilledFormId = data.Id, MetricId = metric4.Id, TextValue = "answer 4" }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("9a0e941e-f28a-4bf3-9a23-edeecf4368df"), FilledFormId = data.Id, MetricId = metric5.Id, TextValue = "answer 5" }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("a00e12d0-92a5-4737-9dd3-b83f8a71e320"), FilledFormId = data.Id, MetricId = metric6.Id, NumericValue = 3 }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("b2f46bdc-f987-4a2d-bcc7-bb7c4f592f21"), FilledFormId = data.Id, MetricId = metric7.Id, DateValue = DateTime.Now }); //context.FormValues.AddOrUpdate(new FormValue() { Id = Guid.Parse("747a6bbf-c439-40e4-a76e-d03b68ed1614"), FilledFormId = data.Id, MetricId = metric8.Id, BoolValue = true }); //context.SaveChanges(); var reportCat = new ReportTemplateCategory() { Id = Guid.Parse("00b2ea95-dcaf-480a-b470-6d012a5f1d6e"), OrganisationId = org.Id, Title = "First report category" }; context.ReportTemplateCategories.AddOrUpdate(reportCat); var reportTemplate = new ReportTemplate() { Id = Guid.Parse("04d3727c-738a-44b7-952d-7c74e2383c4b"), OrganisationId = org.Id, Name = "First sample report", CategoryId = reportCat.Id, Description = "", IsPublished = true }; context.ReportTemplates.AddOrUpdate(reportTemplate); context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }