public void InitOrDie(IAppBuilder app)
        {
            IStorageService storage = ServiceFactory.Get <IStorageService>();
            IItemFactory    factory = ServiceFactory.Get <IItemFactory>();

            ItemFactory.Register <IDefectConfiguration, DefectConfiguration>();
            ItemFactory.Register <IIssueConfiguration, IssueConfiguration>();
            ItemFactory.Register <IMailConfiguration, MailConfiguration>();

            IConfigurationService conf = storage.GetConfiguration();

            IMailConfiguration mailConf = factory.GetNew <IMailConfiguration>();

            storage.Store(mailConf);

            IDefectConfiguration defetctConf = factory.GetNew <IDefectConfiguration>();

            storage.Store(defetctConf);

            IIssueConfiguration issueConf = factory.GetNew <IIssueConfiguration>();

            storage.Store(issueConf);

            IConfigurationService conf2 = storage.GetConfiguration();
        }
        public string Save(IDefect model)
        {
            WorkItem defect;

            using (TfsTeamProjectCollection service = Service)
            {
                WorkItemStore workItemStore = service.GetService <WorkItemStore>();
                Project       project       = workItemStore.Projects[TeamProjectName];

                // Create the work item.
                defect = project
                         .WorkItemTypes[Config.WorkItemType]
                         .NewWorkItem();

                // int ? Id { get; }
                defect.Title = model.Title;

                if (model.AutoAssign)
                {
                    Autoassign(workItemStore, defect);
                }
                else
                {
                    defect.AreaPath = model.AreaPath;
                    //defect.IterationPath = model.Iteration;

                    // moved to current/<unique node>
                    defect.IterationPath = GetCurrentIterationPath(workItemStore);
                }

                defect.State       = model.State;
                defect.Description = model.Description;

                defect.Fields[DefectField.DefectSystem.FieldName()].Value = model.SurveySystem;
                defect.Fields[DefectField.DefectID.FieldName()].Value     = model.DefectID;
                defect.Fields[DefectField.FoundIn.FieldName()].Value      = model.FoundIn;
                defect.Fields[DefectField.Agenzia.FieldName()].Value      = model.Agency;
                defect.Fields[DefectField.environment.FieldName()].Value  = model.Environment;
                defect.Fields[DefectField.DefectType.FieldName()].Value   = model.DefectType;
                defect.Fields[DefectField.Severity.FieldName()].Value     =
                    defect.Fields[DefectField.Severity.FieldName()].AllowedValues[(short)model.Severity];

                // Comments
                defect.History = "Created on " + DateTime.Now.Date.ToShortDateString() + " by " + workItemStore.UserIdentityName;

                if (!string.IsNullOrEmpty(model.IMailItemUniqueId))
                {
                    IAttachment att = Mail.GetAsAttachment(Factory.GetNew <IMailItem>(model.IMailItemUniqueId));
                    defect.Attachments.Add(ToAttachment(att,
                                                        comment: "Uploaded by " + workItemStore.UserIdentityName + " with Allianz.Vita.Quality Tool",
                                                        fileName: model.Title.Replace('/', '-') + ".eml"));
                }

                // Links is read only

                // Save the new
                if (!defect.IsValid())
                {
                    throw new ApplicationException("Errore in inserimento Defect " + defect.Title);
                }

                Mail.Complete(Factory.GetNew <IMailItem>(model.IMailItemUniqueId));

                defect.Save();
            }

            return(defect != null?defect.Id.ToString() : string.Empty);
        }