/// <summary> /// Publication du modèle sur le serveur /// </summary> /// <param name="model"></param> public void PublishLocalModel(CandleModel model) { ILogger logger = ServiceLocator.Instance.GetService <ILogger>(); if (logger != null) { logger.BeginProcess(false, true); logger.BeginStep("Publish on remote server", LogType.Info); } try { // On récupère ses métadonnées ComponentModelMetadata data = model.MetaData; if (data != null) { //if( !data.IsLastVersion()) //{ // if (System.Windows.Forms.MessageBox.Show("You want to publish an older version than the server. Do you want to continue ?", "Warning", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) // return; //} ModelLoader.Save(model, data.GetFileName(PathKind.Absolute)); // On prend tout ce qu'il y a dans le repository local (==> Il faut que la publication locale // se fasse obligatoirement chaque fois avant ) string[] fileNames = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(data.GetFileName(PathKind.Absolute))); PublishZip(model, new List <string>(fileNames), ZipFileName); // Mise à jour des métadatas Metadatas.SetMetadataPublished(data, model); if (logger != null) { logger.Write("Publish on remote server", "Published on remote server ", LogType.Info); } } } catch (Exception ex) { if (logger != null) { logger.WriteError("Publish on remote server ", "Publish on remote server", ex); } } finally { if (logger != null) { logger.EndStep(); logger.EndProcess(); IIDEHelper ide = ServiceLocator.Instance.IDEHelper; if (ide != null) { ide.ShowErrorList(); } } } }
/// <summary> /// Generates the specified service provider. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="modelFileName">Name of the model file.</param> /// <param name="selectedElement">The selected element.</param> public static void Generate(IServiceProvider serviceProvider, string modelFileName, ICustomizableElement selectedElement) { if (modelFileName == null) { throw new ArgumentNullException("modelFileName"); } ILogger logger = ServiceLocator.Instance.GetService <ILogger>(); IIDEHelper ide = ServiceLocator.Instance.IDEHelper; Generator.s_serviceProvider = serviceProvider; try { // Sauvegarde de tous les documents ServiceLocator.Instance.ShellHelper.Solution.DTE.Documents.SaveAll(); CandleModel model = CandleModel.GetModelFromCurrentSolution(modelFileName); // Chargement du modèle //ModelLoader loader = ModelLoader.GetLoader(modelFileName, false); //if (loader == null || loader.Model == null) //{ // if (logger != null) // logger.Write("Generator", "unable to load the model", LogType.Error); // return; //} //CandleModel model = loader.Model; if (model.Component == null) { if (logger != null) { logger.Write("Generator", "model contains no software component.", LogType.Error); } return; } if (StrategyManager.GetInstance(model.Store).GetStrategies(null, true).Count == 0) { if (logger != null) { logger.Write("Generator", "No strategies configured.", LogType.Error); } return; } // CandleModel model = loader.Model; s_context = new GenerationContext(model, modelFileName, selectedElement != null ? selectedElement.Id : Guid.Empty); GenerationPass generationPassesSelected = GenerationPass.CodeGeneration | GenerationPass.MetaModelUpdate; try { // Demande des stratégies à executer if (selectedElement != null) { RunningStrategiesForm dlg = new RunningStrategiesForm(selectedElement.StrategiesOwner); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } s_context.SelectedStrategies = dlg.SelectedStrategies; generationPassesSelected = dlg.SelectedGenerationPasses; } if (logger != null) { logger.BeginProcess(true, true); } // Préparation de l'IDE ide.SetWaitCursor(); ide.DisplayProgress("Generate...", 1, 3); Microsoft.VisualStudio.Modeling.Validation.ValidationContext vc = new Microsoft.VisualStudio.Modeling.Validation.ValidationContext(Microsoft.VisualStudio.Modeling.Validation.ValidationCategories.Save, model); if (vc.CurrentViolations.Count > 0) { if (ide != null) { if (ide.ShowMessageBox("There is validation errors, continue generate ?", "Generation", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } } // Au cas ou cette passe a été forcé dans la boite de dialogue if ((generationPassesSelected & GenerationPass.ElementAdded) == GenerationPass.ElementAdded) { if (logger != null) { logger.BeginStep("Code Generation for the ElementAdded event", LogType.Info); } s_context.GenerationPass = GenerationPass.ElementAdded; using (Transaction transaction = model.Store.TransactionManager.BeginTransaction("Update metamodel")) { model.Component.GenerateCode(s_context); transaction.Commit(); } if (logger != null) { logger.EndStep(); } } // Mise à jour du méta modèle if ((generationPassesSelected & GenerationPass.MetaModelUpdate) == GenerationPass.MetaModelUpdate) { if (logger != null) { logger.BeginStep("1) Meta Model Update", LogType.Info); } s_context.GenerationPass = GenerationPass.MetaModelUpdate; using (Transaction transaction = model.Store.TransactionManager.BeginTransaction("Update metamodel")) { // On ne veut pas que les wizards soient appelés model.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo[StrategyManager.IgnoreStrategyWizards] = true; model.Component.GenerateCode(s_context); if (transaction.HasPendingChanges) { transaction.Commit(); } } if (logger != null) { logger.EndStep(); } } if (logger != null) { logger.BeginStep("1) Check references", LogType.Info); } // Vérification des dépendances ReferencesHelper.CheckReferences(true, vc, new ConfigurationMode(), ReferenceScope.Compilation, model); if (logger != null) { logger.EndStep(); } ide.DisplayProgress("Generate...", 2, 3); // Génération de code if ((generationPassesSelected & GenerationPass.CodeGeneration) == GenerationPass.CodeGeneration) { if (logger != null) { logger.BeginStep("2) Code Generation", LogType.Info); } s_context.GenerationPass = GenerationPass.CodeGeneration; model.Component.GenerateCode(s_context); if (logger != null) { logger.EndStep(); } } } finally { Mapper.Instance.Save(); } //if (logger != null) // logger.BeginStep("Generation epilogue", LogType.Debug); //if (logger != null) // logger.EndStep(); } catch (Exception ex) { if (logger != null) { logger.WriteError("Generator", "Generator", ex); } } finally { // On s'assure de faire disparaitre la progress bar ide.DisplayProgress("", 2, 0); if (logger != null) { logger.EndProcess(); } if (ide != null) { ide.ShowErrorList(); } } }
/// <summary> /// Copie du modèle dans le repository local et mise à jour du repository local /// avec les modèles des références externes du modèle et des artifacts /// </summary> /// <remarks> /// Cet événement se produit lors de la sauvegarde du modèle /// </remarks> /// <param name="model">Modèle à copier</param> /// <param name="fileName">Path du fichier contenant le modèle</param> private void PublishLocally(CandleModel model, string fileName) { Debug.Assert(model != null); Debug.Assert(fileName != null); ILogger logger = ServiceLocator.Instance.GetService <ILogger>(); if (logger != null) { logger.BeginProcess(false, true); logger.BeginStep("Local publication", LogType.Info); } try { IRepositoryProvider localProvider = RepositoryManager.Instance.GetLocalProvider(); Debug.Assert(localProvider != null); string sourceFolder = Path.GetDirectoryName(fileName); string folder = Path.GetDirectoryName(model.MetaData.GetFileName(PathKind.Absolute)); Utils.RemoveDirectory(folder); // D'abord le modele. try { fileName = localProvider.PublishModel(model, fileName, fileName); if (logger != null) { logger.Write("Local publication", "Publish model " + Path.GetFileName(fileName), LogType.Info); } } catch (Exception ex) { if (logger != null) { logger.WriteError("Local publication", "Publish model " + Path.GetFileName(fileName), ex); } } // Puis les diagrammes foreach (string diagramFile in Directory.GetFiles(sourceFolder, String.Format("{0}*.diagram", Path.GetFileName(fileName)))) { try { localProvider.PublishModel(model, diagramFile, diagramFile); if (logger != null) { logger.Write("Local publication", "Publish diagram file " + Path.GetFileName(diagramFile), LogType.Info); } } catch (Exception ex) { if (logger != null) { logger.WriteError("Local publication", "Publish diagram file " + Path.GetFileName(diagramFile), ex); } } } ReferencesCollection references = DSLFactory.Candle.SystemModel.Dependencies.ReferencesHelper.GetReferences(new ConfigurationMode(), ReferenceScope.Publish, sourceFolder, model); //if (model.SoftwareComponent != null) //{ // DateTime lastModified = File.GetLastWriteTime(fileName); // foreach (string referenceFileName in references) // { // if (File.Exists(referenceFileName) && lastModified < File.GetLastWriteTime(referenceFileName)) // { // upToDate = false; // break; // } // } //} // Ensuite les binaires et les artifacts foreach (string referenceFileName in references) { try { localProvider.PublishModel(model, referenceFileName, referenceFileName); if (logger != null) { logger.Write("Local publication", "Publish file " + Path.GetFileName(referenceFileName), LogType.Info); } // Il y a peut-être des fichiers additionnels string additionalFileName = Path.ChangeExtension(referenceFileName, ".xml"); if (File.Exists(additionalFileName)) { localProvider.PublishModel(model, additionalFileName, additionalFileName); } additionalFileName = Path.ChangeExtension(referenceFileName, ".pdb"); if (File.Exists(additionalFileName)) { localProvider.PublishModel(model, additionalFileName, additionalFileName); } } catch (Exception ex) { if (logger != null) { logger.WriteError("Local publication", "Publish file " + Path.GetFileName(referenceFileName), ex); } } } // On n'oublie pas de mettre à jour les metadata ComponentModelMetadata data = model.MetaData; Metadatas.Update(data, fileName); } finally { //if (!upToDate) // logger.Write("Local publication", "Some files are more recents than the models", LogType.Warning); if (logger != null) { logger.EndStep(); logger.EndProcess(); IIDEHelper ide = ServiceLocator.Instance.IDEHelper; if (ide != null) { ide.ShowErrorList(); } } } }
/// <summary> /// Publication d'un modele /// </summary> /// <param name="model">Modèle à publier</param> /// <param name="fileName">Fichier initial contenant le modèle</param> /// <param name="promptWarning">Indique si il faut demander une confirmation à l'utilisateur</param> /// <remarks> /// Tout est mis dans un fichier compréssé. /// </remarks> public void PublishModel(CandleModel model, string fileName, bool promptWarning) { // La publication copie tous les artifacts dans le repository local puis le contenu de ce repository // est ensuite publié sur le serveur distant. // On publie tjs sur le serveur principal. // TODO voir si on ne peut pas publier sur le serveur d'origine du modèle (metadata.ServerUrl) ???? IRepositoryProvider wsRepository = RepositoryManager.Instance.GetMainRemoteProvider(); PublishModelForm form = null; if (promptWarning) { IDialogService service = ServiceLocator.Instance.GetService <IDialogService>(); if (service != null) { form = service.CreatePublishModelForm(wsRepository != null); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } } } ILogger logger = ServiceLocator.Instance.GetService <ILogger>(); if (logger != null) { logger.BeginProcess(false, true); } try { // Sauvegarde ServiceLocator.Instance.ShellHelper.Solution.DTE.Documents.SaveAll(); Generator.NotifyPublishEvents(model, fileName, PublishEventType.BeforeLocal); // On copie d'abord en local PublishLocally(model, fileName); // Certaines strategies peuvent effectuer des actions lors de la publication Generator.NotifyPublishEvents(model, fileName, PublishEventType.AfterLocal); bool publishOnServer = true; if (form == null || !form.PublishOnServer) { if (logger != null) { logger.Write("Custom strategy publishing actions", String.Format("Model {0} published locally.", Path.GetFileName(fileName)), LogType.Info); } publishOnServer = false; } if (publishOnServer) { Generator.NotifyPublishEvents(model, fileName, PublishEventType.BeforeServer); // Publication du repository local PublishLocalModel(model); Generator.NotifyPublishEvents(model, fileName, PublishEventType.AfterServer); } // Increment du numero de version du serveur using (Transaction transaction = model.Store.TransactionManager.BeginTransaction("Increment model number")) { model.Version++; transaction.Commit(); } // On sauvegarde la modif ServiceLocator.Instance.ShellHelper.Solution.DTE.Documents.SaveAll(); Generator.NotifyPublishEvents(model, fileName, PublishEventType.EndPublish); } catch { Generator.NotifyPublishEvents(model, fileName, PublishEventType.PublishFailed); if (logger != null) { logger.Write("PublishModel", "Model publication stopped", LogType.Error); } } finally { if (logger != null) { logger.EndProcess(); } IIDEHelper ide = ServiceLocator.Instance.IDEHelper; if (ide != null) { ide.ShowErrorList(); } } }