Пример #1
0
        public static bool Save(this MagicProperty mp, Boolean overwrite)
        {
            mp.Name = mp.Name.Replace(ConfigManager.SourceSeperator, '-');
            MagicProperty o = null;

            if (Program.Context.Magic.ContainsKey(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source))
            {
                o = Program.Context.Magic[mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source];
            }
            if (o != null && o.Category != mp.Category)
            {
                throw new Exception("Magic Property needs a unique name");
            }
            FileInfo file = SourceManager.GetFileName(mp.Name, mp.Source, ImportExtensions.MagicPropertyCleanname(Program.Context, mp.Category));

            if (file.Exists && (mp.FileName == null || !mp.FileName.Equals(file.FullName)) && !overwrite)
            {
                return(false);
            }
            using (TextWriter writer = new StreamWriter(file.FullName)) MagicProperty.Serializer.Serialize(writer, mp);
            mp.FileName = file.FullName;
            return(true);
        }