コード例 #1
0
        internal void Execute(GenerationContext context, string outputFile)
        {
            writer = new SafeStreamWriter(outputFile, false);
            try
            {
                this.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                this.WriteLine("<hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.0\">");
                this.WriteLine("");

                CandleModel model = context.Model;
                if (model == null || !model.SoftwareComponent.IsDataLayerExists)
                {
                    return;
                }
                _modelsLayer = model.SoftwareComponent.DataLayer;

                _inheritanceTree = new ClassInheritanceTree(_modelsLayer);
                foreach (ClassInheritanceNode childNode in _inheritanceTree.Root.childs)
                {
                    GenerateClassMapping(childNode, 1, 1);
                }
                _inheritanceTree = null;

                this.WriteLine("");
                this.WriteLine("</hibernate-mapping>");
            }
            finally
            {
                writer.Close();
            }
        }
コード例 #2
0
        /// <summary>
        /// Sauvegarde du fichier de mapping
        /// </summary>
        public void Save()
        {
            if (_filePath == null)
            {
                return;
            }

            ServiceLocator.Instance.ShellHelper.EnsureCheckout(_filePath);
            ServiceLocator.Instance.ShellHelper.EnsureDocumentIsNotInRDT(_filePath);

            using (SafeStreamWriter writer = new SafeStreamWriter(_filePath))
            {
                XmlSerializer ser = new XmlSerializer(typeof(MapperConfiguration));
                ser.Serialize(writer, _config);
            }
        }
コード例 #3
0
ファイル: StrategyManager.cs プロジェクト: malain/candle
        /// <summary>
        /// Sauvegarde des stratégies
        /// </summary>
        /// <param name="store"></param>
        public void Save(Store store)
        {
            if (_fileName == null)
            {
                return;
            }
            SuspendWatcher(false);
            try
            {
                _strategyTypes = _strategies.GetTypes(this.NamingStrategy);
                List <Type> types = new List <Type>();
                foreach (StrategyTypeReference t in _strategyTypes)
                {
                    types.Add(t.StrategyType);
                }

                // sérialization des stratégies
                this.StrategiesNode = SerializeFragment(typeof(StrategyCollection), types, _strategies);

                // sérialization de la stratégie de nommage
                this.NamingStrategyNode = SerializeFragment(typeof(BaseNamingStrategy), types, NamingStrategy);

                ServiceLocator.Instance.ShellHelper.EnsureDocumentIsNotInRDT(_fileName);

                // Sérialization du document avec les noeuds à jour
                using (SafeStreamWriter writer = new SafeStreamWriter(_fileName))
                {
                    // Désérialization de la description
                    XmlSerializer serializer = new XmlSerializer(typeof(StrategyManager));
                    serializer.Serialize(writer, this);
                }
                ServiceLocator.Instance.ShellHelper.AddFileToSolution(_fileName);
            }
            catch (Exception ex)
            {
                ServiceLocator.Instance.IDEHelper.ShowError("Unable to save the strategies file - " + ex.Message);
            }
            finally
            {
                SuspendWatcher(true);
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes the safe output file.
        /// </summary>
        /// <param name="outputFile">The output file.</param>
        /// <param name="data">The data.</param>
        /// <param name="encoding">The encoding.</param>
        private static void WriteSafeOutputFile(string outputFile, string data, Encoding encoding)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.Write("Writing generated file", String.Concat("Save template generation result in " + outputFile), LogType.Debug);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(outputFile));

            // Ecriture dans le fichier de sortie
            ServiceLocator.Instance.ShellHelper.EnsureCheckout(outputFile);

            encoding = new UTF8Encoding(false, true);
            using (SafeStreamWriter writer = new SafeStreamWriter(outputFile, false, encoding))
            {
                writer.Write(data);
            }
        }