示例#1
0
        /// <summary>
        /// Liste des manifestes locaux
        /// </summary>
        /// <param name="includeInternals">if set to <c>true</c> [include internals].</param>
        /// <returns></returns>
        public static ManifestCollection GetLocalManifests(bool includeInternals)
        {
            ManifestCollection manifests        = new ManifestCollection();
            DirectoryInfo      strategiesFolder = new DirectoryInfo(RepositoryManager.ResolvePath(RepositoryCategory.Strategies, String.Empty));

            if (strategiesFolder.Exists)
            {
                foreach (FileInfo fi in strategiesFolder.GetFiles("*.zip"))
                {
                    StrategyPackage package = new StrategyPackage(fi.Name);
                    foreach (StrategyManifest mf in package.Manifests)
                    {
                        manifests.Add(mf);
                    }
                }

                // Les fichiers manifest seuls
                // COMMENT: pour l'instant, le internalManifest ne serailize pas ces propriétés. Il
                // faut le faire.
                //foreach (FileInfo fi in strategiesFolder.GetFiles(String.Concat("*", StrategyPackage.ManifestExtension)))
                //{
                //    StrategyManifest manifest = new InternalManifest();
                //    manifest.FileName = fi.Name;
                //    manifests.Add(manifest);
                //}
            }

            if (includeInternals)
            {
                manifests.AddRange(GetInternalManifests());
            }

            return(manifests);
        }
示例#2
0
        /// <summary>
        /// Liste des manifestes internes
        /// </summary>
        /// <returns></returns>
        public static ManifestCollection GetInternalManifests()
        {
            ManifestCollection manifests = new ManifestCollection();
            List <Type>        types     = StrategyPackage.FindAllTypes <StrategyBase>(typeof(StrategyBase).Assembly);

            foreach (Type strategyType in types)
            {
                InternalManifest manifest = new InternalManifest((StrategyBase)Activator.CreateInstance(strategyType));
                manifests.Add(manifest);
            }
            return(manifests);
        }
示例#3
0
        /// <summary>
        /// Renvoi le package associé au manifest en s'assurant qu'il soit à jour.
        /// </summary>
        /// <param name="packageName">Nom du package ou vide si strategyInterne</param>
        /// <returns></returns>
        public InternalPackage GetPackage(string packageName)
        {
            if (String.IsNullOrEmpty(packageName))
            {
                if (_internalPackage == null)
                {
                    _internalPackage = new InternalPackage();
                }
                return(_internalPackage);
            }

            StrategyPackage package = Packages.Find(delegate(StrategyPackage p) { return(Utils.StringCompareEquals(p.Name, packageName)); });

            if (package == null)
            {
                package = new StrategyPackage(packageName);
                Packages.Add(package);
            }
            if (package.Synchronize())
            {
                return(package);
            }
            return(null);
        }
示例#4
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);
        }