Exemplo n.º 1
0
        /// <summary>
        /// Called when [deactivated].
        /// </summary>
        /// <param name="finish">if set to <c>true</c> [finish].</param>
        /// <returns></returns>
        public override bool OnDeactivated(bool finish)
        {
            Wizard.SetUserData(_strategiesKey, _initialStrategy);

            string template = SelectedModel;

            if (template != null)
            {
                string temp = Path.GetTempFileName();
                try
                {
                    if (
                        RepositoryManager.Instance.GetFileFromRepository(RepositoryCategory.Configuration, template,
                                                                         temp))
                    {
                        ModelLoader loader = ModelLoader.GetLoader(temp, false);
                        if (loader != null && loader.Model != null)
                        {
                            Wizard.SetUserData(_strategiesKey, loader.Model.StrategyTemplate);
                        }
                    }
                }
                finally
                {
                    Utils.DeleteFile(temp);
                }
            }

            return(base.OnDeactivated(finish));
        }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StringBuilder sb = new StringBuilder();

            ComponentModelMetadata metadata = CandleRepositoryController.Instance.GetMetadata(Request["id"], Request["version"]);
            if (metadata != null)
            {
                ModelLoader loader = ModelLoader.GetLoader(metadata);
                if (loader != null && loader.Model != null)
                {
                    if (loader.Model.SoftwareComponent != null)
                    {
                        foreach (ServiceContract contract in loader.Model.SoftwareComponent.PublicContracts)
                        {
                            sb.AppendLine(@"<div class=""Contract"">");

                            // Nom du contrat
                            sb.AppendLine(String.Format(@"<div class=""ContractHeader"">{0}</div>", contract.FullName));
                            // Description
                            sb.AppendLine(String.Format(@"<div class=""ContractDescription"">{0}</div>", Server.HtmlEncode(contract.Comment)));

                            foreach (Operation op in contract.Operations)
                            {
                                // Operation
                                sb.AppendLine(@"<div class=""ContractOperation"">");
                                sb.AppendLine(String.Format(@"<div class=""ContractOperationHeader"">{0} {1}({2})</div>", Server.HtmlEncode(op.FullTypeName), op.Name, op.CreateParametersDefinition()));
                                sb.AppendLine(String.Format(@"<div class=""ContractOperationDesc"">{0}</div>", Server.HtmlEncode(op.Comment)));

                                // Arguments
                                sb.AppendLine(@"<div class=""ContractArguments"">");

                                sb.AppendLine(@"<div class=""ContractArgumentsHeader"">");
                                sb.AppendLine(@"<div class=""ContractArgumentsHeaderType"">Type</div>");
                                sb.AppendLine(@"<div class=""ContractArgumentsHeaderName"">Name</div>");
                                sb.AppendLine(@"<div class=""ContractArgumentsHeaderDesc"">Description</div>");
                                sb.AppendLine(@"</div>");

                                foreach (Argument arg in op.Arguments)
                                {
                                    sb.AppendLine(@"<div class=""ContractArgumentItem"">");
                                    sb.AppendLine(String.Format(@"<div class=""ContractArgumentItemType"">{0}</div>", Server.HtmlEncode(arg.FullTypeName)));
                                    sb.AppendLine(String.Format(@"<div class=""ContractArgumentItemName"">{0}</div>", arg.Name));
                                    sb.AppendLine(String.Format(@"<div class=""ContractArgumentItemDesc"">{0}</div>", Server.HtmlEncode(arg.Comment)));
                                    sb.AppendLine("</div>");
                                }
                                sb.AppendLine(@"</div></div>");
                            }
                        }
                    }
                }
            }
            lbCode.Text = sb.ToString();
        }
    }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetLastVersionCommand"/> class.
 /// </summary>
 /// <param name="metadata">The metadata.</param>
 /// <param name="force">if set to <c>true</c> [force].</param>
 public GetLastVersionCommand(ComponentModelMetadata metadata, bool force)
 {
     if (metadata != null)
     {
         this._force = force;
         ModelLoader loader = ModelLoader.GetLoader(metadata);
         if (loader != null)
         {
             _externalModel = loader.Model;
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets all dependencies.
        /// </summary>
        /// <returns></returns>
        public static List <DependencyGraphVisitor.RelationShip> GetAllDependencies()
        {
            List <CandleModel> models = new List <CandleModel>();

            foreach (ComponentModelMetadata md in RepositoryManager.Instance.ModelsMetadata.Metadatas)
            {
                ModelLoader loader = ModelLoader.GetLoader(md);
                if (loader != null && loader.Model != null)
                {
                    models.Add(loader.Model);
                }
            }
            return(GetDependencies(models.ToArray()));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Création de l'arbre d'héritage
        /// </summary>
        /// <returns></returns>
        private void CreateInheritanceTree()
        {
            // C'est la racine
            _classInheritanceRootNode = new ClassInheritanceNode(null, false);

            // On commence par charger les modèles référencés
            foreach (ExternalComponent sys in _modelsLayer.Component.Model.ExternalComponents)
            {
                ModelLoader proxy = ModelLoader.GetLoader(sys);
                if (proxy != null && proxy.DataLayer != null)
                {
                    CreateInheritanceTreeFromModel(proxy.DataLayer, _classInheritanceRootNode, true);
                }
            }

            // Puis le modèle en cours
            CreateInheritanceTreeFromModel(_modelsLayer, _classInheritanceRootNode, false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Publication
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void publish_Click(object sender, EventArgs e)
        {
            TreeNode node = _treeCtrl.SelectedNode;
            ComponentModelMetadata item = GetSelectedData();

            if (item != null)
            {
                ModelLoader loader = ModelLoader.GetLoader(item.GetFileName(PathKind.Absolute), true);
                if (loader != null && loader.Model != null)
                {
                    RepositoryManager.Instance.ModelsMetadata.PublishLocalModel(loader.Model);
                    if (node != null)
                    {
                        node.EnsureVisible();
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Execute the command
        /// </summary>
        public void Exec()
        {
            if (_model == null)
            {
                ModelLoader loader = ModelLoader.GetLoader(_fileName, true);
                if (loader != null)
                {
                    _model = loader.Model;
                }
            }

            if (!String.IsNullOrEmpty(_model.Path) && _model.Version != null && !String.IsNullOrEmpty(_model.Name))
            {
                RepositoryManager.Instance.ModelsMetadata.PublishModel(_model, _fileName, true);
            }
            else
            {
                ServiceLocator.Instance.IDEHelper.ShowMessage("The path, version and name properties must be provided to publish the model");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Liste des artifacts d'un modèle
        /// </summary>
        /// <param name="metadata"></param>
        /// <returns></returns>
        public List <string> GetArtifacts(ComponentModelMetadata metadata)
        {
            ComponentSig  sig = new ComponentSig(metadata);
            List <string> artifacts;

            if (!_artifactsCache.TryGetValue(sig, out artifacts))
            {
                ModelLoader loader = ModelLoader.GetLoader(metadata);
                if (loader != null && loader.Model != null)
                {
                    ReferenceWalker  walker  = new ReferenceWalker(ReferenceScope.Publish, new ConfigurationMode("*"));
                    ReferenceVisitor visitor = new ReferenceVisitor(ReferenceScope.Publish);
                    walker.Traverse(visitor, loader.Model);
                    artifacts = new List <string>();
                    foreach (string artifactFileName in visitor.References)
                    {
                        artifacts.Add(Path.GetFileName(artifactFileName));
                    }
                }
                _artifactsCache.Add(sig, artifacts);
            }
            return(artifacts);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Mise à jour des métadata à partir du modèle
        /// </summary>
        /// <param name="item">Metadata à mettre à jour</param>
        /// <param name="fileName">Fichier contenant le modèle</param>
        internal static void UpdateMetadata(ComponentModelMetadata item, string fileName)
        {
            item.ModelFileName = System.IO.Path.GetFileName(fileName);
            ModelLoader loader = null;

            try
            {
                // Chargement du modèle pour récupèrer les metadata
                ModelLoader.ClearCache(fileName);
                loader = ModelLoader.GetLoader(fileName, true);

                item.Id              = loader.Model.Id;
                item.Version         = loader.Model.Version ?? new VersionInfo();
                item.Name            = loader.Model.Name;
                item.Path            = loader.Model.Path;
                item.DocUrl          = loader.Model.Url ?? String.Empty;
                item.TestBaseAddress = loader.Model.BaseAddress ?? String.Empty;
                item.Description     = loader.Model.Comment ?? String.Empty;
                item.ComponentType   = loader.Model.ComponentType;
                item.Location        = RepositoryLocation.Local; // Toujours
                //item.ServerVersion = item.version.Revision;
                item.Visibility = loader.Model.Visibility;
                //item.LocalVersion = -1;
            }
            catch (Exception ex)
            {
                try
                {
                    // On essaye de déduire le n° de version à partir du nom de fichier.
                    // Idem pour l'id
                    string   v     = System.IO.Path.GetDirectoryName(fileName);
                    string[] parts = v.Split(System.IO.Path.DirectorySeparatorChar);
                    if (parts.Length > 2)
                    {
                        item.Version = VersionInfo.TryParse(parts[parts.Length - 1]);
                        item.Id      = new Guid(parts[parts.Length - 2]);
                    }
                }
                catch
                {
                    item.Id      = Guid.NewGuid();
                    item.Version = new VersionInfo();
                }

                item.DocUrl = String.Empty;
                if (ModelLoader.LastSerializationResult != null && ModelLoader.LastSerializationResult.Failed)
                {
                    StringBuilder sb = new StringBuilder(ex.Message);
                    foreach (SerializationMessage msg in ModelLoader.LastSerializationResult)
                    {
                        sb.AppendLine(String.Format("{0} at {1},{2}", msg.Message, msg.Line, msg.Column));
                    }
                    item.Description = sb.ToString();
                }
                else
                {
                    item.Description = ex.Message;
                }
                item.ServerVersion = -1;
                item.Location      = RepositoryLocation.Local; // Toujours
                item.Name          = String.Format("Loading error : {0}", System.IO.Path.GetFileNameWithoutExtension(fileName));
                item.Path          = "????";
                item.Visibility    = Visibility.Public;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Publication d'un modele en tant que template
        /// </summary>
        /// <param name="modelFileName"></param>
        /// <param name="remoteName"></param>
        /// <param name="strategiesFileName"></param>
        /// <param name="remoteStrategiesFileName"></param>
        /// <remarks>
        /// Tout est mis dans un fichier compréssé.
        /// </remarks>
        public void PublishModelAsTemplate(string modelFileName, string remoteName, string strategiesFileName, string remoteStrategiesFileName)
        {
            ILogger             logger             = ServiceLocator.Instance.GetService <ILogger>();
            IRepositoryProvider repositoryProvider = RepositoryManager.Instance.GetMainRemoteProvider();

            // On peut publier en local ou à distance
            PublishModelForm form    = null;
            IDialogService   service = ServiceLocator.Instance.GetService <IDialogService>();

            if (service != null)
            {
                form = service.CreatePublishModelForm(repositoryProvider != null);
                if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }
            }

            // Choix du provider de publication
            if (form == null || !form.PublishOnServer)
            {
                repositoryProvider = RepositoryManager.Instance.GetLocalProvider();
            }

            if (logger != null)
            {
                logger.BeginProcess(false, true);
                logger.BeginStep("Publish as template", LogType.Info);
            }

            try
            {
                // Le fichier des strategies
                if (!String.IsNullOrEmpty(remoteStrategiesFileName))
                {
                    remoteStrategiesFileName = Path.GetFileName(remoteStrategiesFileName);
                    if (repositoryProvider != null)
                    {
                        repositoryProvider.PublishFile(strategiesFileName, RepositoryCategory.Configuration, String.Format("Strategies/{0}{1}", remoteStrategiesFileName, StrategyManager.DefaultStrategiesFileNameExtension));
                    }
                }

                // Le modèle
                if (remoteName != null)
                {
                    remoteName = Path.GetFileName(remoteName);

                    // Le fichier modèle
                    string tempFile = Path.GetTempFileName();
                    try
                    {
                        File.Copy(modelFileName, tempFile, true);
                        ModelLoader loader = ModelLoader.GetLoader(tempFile, false);
                        using (Transaction transaction = loader.Model.Store.TransactionManager.BeginTransaction("set properties"))
                        {
                            // Modification du nom pour qu'on puisse le remplacer lors de l'initialisation (voir LayerNameChangeRule)
                            loader.Model.Component.Namespace = "?";
                            loader.Model.Component.Name      = "?";
                            loader.Model.Name = String.Empty;

                            loader.Model.StrategyTemplate = Path.GetFileName(remoteStrategiesFileName);

                            foreach (SoftwareLayer layer in loader.Model.SoftwareComponent.Layers)
                            {
                                layer.Namespace = "?";
                            }

                            // Le fichier stratégie associé
                            if (!String.IsNullOrEmpty(remoteStrategiesFileName))
                            {
                                loader.Model.StrategyTemplate = Path.GetFileNameWithoutExtension(remoteStrategiesFileName);
                            }

                            transaction.Commit();
                        }

                        loader.Save(tempFile);

                        if (repositoryProvider != null)
                        {
                            repositoryProvider.PublishFile(tempFile, RepositoryCategory.Configuration, String.Format("Models/{0}{1}", remoteName, ModelConstants.FileNameExtension));
                        }
                    }
                    finally
                    {
                        File.Delete(tempFile);
                    }

                    // Liste des diagrammes dans le repository local
                    string diagramFilter = String.Format("{0}.diagram", Path.GetFileName(modelFileName));
                    foreach (string diagramFile in Directory.GetFiles(Path.GetDirectoryName(modelFileName), diagramFilter))
                    {
                        if (repositoryProvider != null)
                        {
                            repositoryProvider.PublishFile(diagramFile, RepositoryCategory.Configuration, String.Format("Models/{0}{1}{2}", remoteName, ModelConstants.FileNameExtension, ".diagram"));
                        }
                    }
                }

                if (logger != null)
                {
                    logger.Write("Publish template", "published", LogType.Info);
                }
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.WriteError("Publish template", "Publish template", ex);
                }
            }
            finally
            {
                if (logger != null)
                {
                    logger.EndStep();
                    logger.EndProcess();
                }
            }
        }