예제 #1
0
        private void ValidatePropfile()
        {
            var result = ValidateXml.ValidateProfileFile(txtFile.Text);

            txtResult.Clear();
            if (result.HasErrors)
            {
                foreach (var strError in result.Errors)
                {
                    txtResult.AppendText(strError + Environment.NewLine);
                }
            }
            else
            {
                txtResult.Text = Properties.Resources.ValidatePluginSuccess;
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="profile"/> from <paramref name="FileName"/>
        /// </summary>
        /// <param name="FileName">The FileName to the xml that represents the profile</param>
        /// <returns><see cref="profile"/> instance</returns>
        /// <exception cref="System.Exception">If there are Validation errors with the xml</exception>
        public static profile FromFile(string FileName)
        {
            ValidationResult vResult = ValidateXml.ValidateProfileFile(FileName);

            if (vResult.HasErrors == true)
            {
                var ex = new System.Exception(vResult.ToString());
                throw ex;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(profile));

            System.IO.StreamReader reader = new System.IO.StreamReader(FileName);
            var p = (profile)serializer.Deserialize(reader);

            reader.Close();
            p.File = FileName;
            return(p);
        }
예제 #3
0
        /// <summary>
        /// Saves a profile to disk
        /// </summary>
        /// <param name="p">The profile to save</param>
        /// <exception cref="Exceptions.ProfileVersionException">If Profile min version is greater than scrip version</exception>
        public static void SaveProfile(profile p)
        {
            lock (ProfileLock)
            {
                if (p.FullMinVersion > ScriptVersion)
                {
                    throw new Exceptions.ProfileVersionException(Properties.Resources.ErrorProfileMinVersionNewer);
                }
                string sFile = Path.Combine(AppCommon.Instance.PathProfiles, p.name + ".xml");

                if (string.IsNullOrEmpty(p.codeLanguage.paths.mainData))
                {
                    p.codeLanguage.paths.mainData = p.name;
                }
                else
                {
                    if (p.codeLanguage.paths.mainData.IndexOf(Path.DirectorySeparatorChar) > -1)
                    {
                        if (!Directory.Exists(p.codeLanguage.paths.mainData))
                        {
                            p.codeLanguage.paths.mainData = p.name;
                        }
                        else
                        {
                            sFile = Path.Combine(p.codeLanguage.paths.mainData, p.name + ".xml");
                        }
                    }
                    else
                    {
                        p.codeLanguage.paths.mainData = p.name;
                    }
                }
                // check for an existing profile before overwriting
                if (File.Exists(sFile))
                {
                    // test the existing profile to see if it is valid
                    // test to see if the current existing file is a valid plugin
                    ValidationResult vFile = ValidateXml.ValidateProfileFile(sFile);
                    if (vFile.HasErrors == false)
                    {
                        // now that we have an existing plugin and it is valid lets check is version against the current plugin version.
                        var ExistingProfile = profile.FromFile(sFile);
                        if (ExistingProfile.FullVersion >= p.FullVersion)
                        {
                            // The existing plugin version is newer or the same as this plugin version
                            // skip, not a newer version.
                            return;
                        }
                        else
                        {
                            ExistingProfile = null;
                        }
                    }
                }

                XmlSerializer writer = new XmlSerializer(typeof(profile));
                FileStream    file   = File.Create(sFile);
                writer.Serialize(file, p);
                file.Close();
            }
        }