Exemplo n.º 1
0
        /// <summary>
        /// Affichage d'une trace
        /// </summary>
        /// <param name="origin">Décrit qui est à l'origine du message</param>
        /// <param name="message">Le message.</param>
        /// <param name="messageType">Le type du message.</param>
        public void Write(string origin, string message, LogType messageType)
        {
            if (_wnd != null && messageType != LogType.Debug) // sauf debug
            {
                _wnd.AddText(message, messageType);
            }

            try
            {
                IIDEHelper ide = ServiceLocator.Instance.IDEHelper;
                if (ide != null)
                {
                    if (messageType == LogType.Error)
                    {
                        ide.LogError(false, message, 0, 0, origin);
                    }
                    if (messageType == LogType.Warning)
                    {
                        ide.LogError(true, message, 0, 0, origin);
                    }

                    if (messageType != LogType.Debug || CandleSettings.GenerationTraceEnabled)
                    {
                        string pad = new string(' ', _tab);
                        ide.LogMessage(String.Concat(pad, message), origin);
                    }
                }
            }
            catch {// TODO créer un logger pour le repository
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Création de l'instance de la strategie contenu dans le manifest
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="manifest">Manifest contenant la stratégie</param>
        /// <returns></returns>
        public StrategyBase AddStrategy(CandleElement owner, StrategyManifest manifest)
        {
            InternalPackage package = GetPackage(manifest.PackageName);

            if (package == null)
            {
                return(null);
            }

            StrategyBase strategy = package.CreateStrategyInstance(manifest.StrategyTypeName, manifest.StrategyConfiguration);

            if (strategy != null)
            {
                strategy.Owner = GetStrategyOwnerName(owner);

                // Vérification des doublons
                foreach (StrategyBase other in _strategies)
                {
                    if (other.Owner == strategy.Owner && other.StrategyId == strategy.StrategyId)
                    {
                        return(other);
                    }
                }
                try
                {
                    strategy.OnLoading(this, new EventArgs());
                    _strategies.Add(strategy);
                }
                catch (Exception ex)
                {
                    IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                    if (ide != null)
                    {
                        ide.ShowMessageBox("Error when loading strategy " + strategy.DisplayName + " : " + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK);
                        ide.LogError(false, "Error when loading strategy " + strategy.DisplayName + " : " + ex.Message, 0, 0, "StrategyManager");
                    }
                }
            }

            return(strategy);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Chargement
        /// </summary>
        /// <param name="store">The store.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static StrategyManager Load(Store store, string fileName)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (String.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            StrategyManager sm = null;

            try
            {
                using (StreamReader reader = new StreamReader(fileName))
                {
                    // Désérialization de la description
                    XmlSerializer serializer = new XmlSerializer(typeof(StrategyManager));
                    sm = (StrategyManager)serializer.Deserialize(reader);

                    // Lecture et chargement des types
                    List <Type> types = new List <Type>();
                    foreach (StrategyTypeReference str in sm.StrategyTypes)
                    {
                        InternalPackage package = sm.GetPackage(str.PackageName);
                        if (package != null)
                        {
                            Type type = package.GetStrategyType(str.StrategyTypeName);
                            if (type != null)
                            {
                                types.Add(type);
                            }
                        }
                    }

                    // D'abord chargement de la stratégie de nommage
                    if (sm.NamingStrategyNode != null)
                    {
                        using (XmlNodeReader nr = new XmlNodeReader(sm.NamingStrategyNode))
                        {
                            serializer         = new XmlSerializer(typeof(BaseNamingStrategy), types.ToArray());
                            sm._namingStrategy = (INamingStrategy)serializer.Deserialize(nr);
                        }
                    }

                    // Chargement des strategies
                    if (sm.StrategiesNode != null)
                    {
                        using (XmlNodeReader nr = new XmlNodeReader(sm.StrategiesNode))
                        {
                            serializer     = new XmlSerializer(typeof(StrategyCollection), types.ToArray());
                            sm._strategies = (StrategyCollection)serializer.Deserialize(nr);
                        }

                        foreach (StrategyBase strategy in sm._strategies)
                        {
                            try
                            {
                                strategy.OnLoading(sm, new EventArgs());
                                StrategyPackage package = sm.GetPackage(strategy.PackageName) as StrategyPackage;
                                if (package != null)
                                {
                                    strategy.StrategyFolder = package.PackageFolder;
                                }
                            }
                            catch (Exception ex)
                            {
                                IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                                if (ide != null)
                                {
                                    ide.ShowMessageBox("Error when loading strategy " + strategy.DisplayName + " : " + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK);
                                    ide.LogError(false, "Error when loading strategy " + strategy.DisplayName + " : " + ex.Message, 0, 0, "StrategyManager");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string        text = ex.Message;
                XmlException  xex  = ex as XmlException;
                StringBuilder sb   = new StringBuilder(ex.Message);
                if (xex != null)
                {
                    sb.AppendFormat(" line={0}, column={1}", xex.LineNumber, xex.LinePosition);
                }
                Exception iex = ex.InnerException;
                while (iex != null)
                {
                    sb.Append(" - ");
                    sb.Append(iex.Message);
                    iex = iex.InnerException;
                }
                text = sb.ToString();
                if (logger != null)
                {
                    logger.WriteError("StrategyManager", String.Format("Loading error {0}", text), ex);
                }
                IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                if (ide != null)
                {
                    ide.ShowMessage("Error when reading the strategies file (see error in the task list). A new empty file will be initialized. The current strategies file will be saved with a .bak extension");
                }
                try
                {
                    // Sauvegarde du fichier en erreur
                    if (File.Exists(fileName))
                    {
                        Utils.CopyFile(fileName, fileName + ".bak");
                    }
                }
                catch { }
            }

            if (sm == null)
            {
                // Génération d'un fichier par défaut
                sm          = new StrategyManager();
                sm.FileName = fileName;
                sm.Save(store);
            }
            else
            {
                sm.FileName = fileName;
            }

            return(sm);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Création d'une dépendance avec une assembly importée
        /// </summary>
        /// <param name="asm">The asm.</param>
        internal void InsertDependencies(Assembly asm)
        {
            // Gestion des dépendances
            List <AssemblyName> referencedAssemblies = GetAssemblyListToCreate(asm);

            if (referencedAssemblies.Count == 0)
            {
                return;
            }

            // On va demander de faire le mapping entre l'assembly et les modèles
            // Fenetre permettant de trouver le lien entre une assembly et son modèle
            ReferencedAssembliesForm form = new ReferencedAssembliesForm(this, referencedAssemblies.ToArray());

            if (form.ShowDialog() == DialogResult.OK)
            {
                // Création des composants externes
                List <ExternalComponent> externalComponents = new List <ExternalComponent>();
                foreach (ComponentMetadataMap map in form.SelectedAssemblyBindings)
                {
                    if (!map.AlreadyExists)
                    {
                        externalComponents.Add(map.CreateComponent(Component.Model));
                    }
                }

                // Puis création des relations avec eux
                foreach (ExternalComponent externalComponent in externalComponents)
                {
                    // Pour l'instant, on ne crée des références qu'avec des composants binaires
                    if (externalComponent == null || externalComponent.MetaData == null ||
                        externalComponent.MetaData.ComponentType != ComponentType.Library)
                    {
                        continue;
                    }

                    if (externalComponent.Ports.Count == 1)
                    {
                        if (ExternalServiceReference.GetLink(this, externalComponent.Ports[0]) == null)
                        {
                            ExternalServiceReference esr =
                                new ExternalServiceReference(this, externalComponent.Ports[0]);
                            esr.Scope = ReferenceScope.Runtime;
                        }
                    }
                    else if (externalComponent.Ports.Count > 1)
                    {
                        string assemblyName = asm.GetName().Name;
                        foreach (ExternalPublicPort port in externalComponent.Ports)
                        {
                            if (Utils.StringCompareEquals(port.Name, assemblyName) ||
                                Utils.StringCompareEquals(port.Parent.Name, assemblyName))
                            {
                                if (ExternalServiceReference.GetLink(this, port) == null)
                                {
                                    ExternalServiceReference esr = new ExternalServiceReference(this, port);
                                    esr.Scope = ReferenceScope.Runtime;
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                        ide.LogError(false, String.Format("Can not create relationship between {0} and {1}", this.Name, externalComponent.Name), 0, 0, "Import");
                    }
                }
            }
        }