Esempio n. 1
0
        static MDKProjectOptions Load(XDocument document, XmlNameTable nameTable, string fileName)
        {
            var nsm = new XmlNamespaceManager(nameTable);

            nsm.AddNamespace("m", Xmlns);

            // Check if this is a template options file
            var versionElement = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKVersion", nsm);
            var versionStr     = (string)versionElement;

            if (versionStr == "$mdkversion$")
            {
                return(new MDKProjectOptions(fileName, false));
            }
            Version.TryParse(versionStr, out var version);

            var namespaceElement = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKNamespace", nsm);
            var ns                   = ((string)namespaceElement)?.Trim();
            var minifyElement        = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKMinify/m:Enabled", nsm);
            var minify               = ((string)minifyElement ?? "no").Trim().Equals("yes", StringComparison.CurrentCultureIgnoreCase);
            var trimTypesElement     = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKTrimTypes/m:Enabled", nsm);
            var trimTypes            = ((string)trimTypesElement ?? "no").Trim().Equals("yes", StringComparison.CurrentCultureIgnoreCase);
            var ignoredFolders       = document.XPathSelectElements("./m:Project/m:PropertyGroup/m:MDKIgnore/m:Folder", nsm).Select(e => (string)e).ToArray();
            var ignoredFiles         = document.XPathSelectElements("./m:Project/m:PropertyGroup/m:MDKIgnore/m:File", nsm).Select(e => (string)e).ToArray();
            var excludeFromDeployAll = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKExcludeFromDeployAll", nsm) != null;

            var result = new MDKProjectOptions(fileName, true)
            {
                Version              = version,
                Namespace            = ns,
                Minify               = minify,
                TrimTypes            = trimTypes,
                ExcludeFromDeployAll = excludeFromDeployAll
            };

            if (ignoredFolders.Length > 0)
            {
                foreach (var item in ignoredFolders)
                {
                    result.IgnoredFolders.Add(item);
                }
            }
            if (ignoredFiles.Length > 0)
            {
                foreach (var item in ignoredFiles)
                {
                    result.IgnoredFiles.Add(item);
                }
            }
            result.HasChanges = false;
            return(result);
        }
Esempio n. 2
0
 MDKProjectProperties(string fileName, string name, MDKProjectOptions options, MDKProjectPaths paths)
 {
     FileName = fileName;
     Name     = name;
     Options  = options;
     if (Options != null)
     {
         Options.PropertyChanged += OnOptionsPropertyChanged;
     }
     Paths = paths;
     if (Paths != null)
     {
         Paths.PropertyChanged += OnPathsPropertyChanged;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Loads script information from the given project file.
        /// </summary>
        /// <param name="projectFileName">The file name of this project</param>
        /// <param name="projectName">The display name of this project</param>
        /// <returns></returns>
        public static MDKProjectProperties Load([NotNull] string projectFileName, string projectName = null, Action <string> echo = null)
        {
            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(projectFileName));
            }

            if (!File.Exists(projectFileName) || Regex.IsMatch(projectFileName, @"\w+://"))
            {
                echo?.Invoke($"{projectFileName} does not exist, or it's a network file (not supported)");
                return(new MDKProjectProperties(projectFileName, null, null, null));
            }

            var fileName = Path.GetFullPath(projectFileName);
            var name     = projectName ?? Path.GetFileNameWithoutExtension(projectFileName);
            var legacyOptionsFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options"));
            var mdkOptionsFileName    = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options.props"));
            var mdkPathsFileName      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.paths.props"));

            MDKProjectOptions options = null;
            MDKProjectPaths   paths   = null;

            if (File.Exists(mdkOptionsFileName) /* && File.Exists(mdkPathsFileName)*/)
            {
                options = MDKProjectOptions.Load(mdkOptionsFileName);
                paths   = MDKProjectPaths.Load(mdkPathsFileName);

                echo?.Invoke($"{projectName ?? projectFileName} is a valid MDK project.");
                return(new MDKProjectProperties(projectFileName, name, options, paths));
            }

            if (File.Exists(legacyOptionsFileName))
            {
                echo?.Invoke($"{projectName ?? projectFileName} is a legacy MDK project.");
                ImportLegacy_1_1(projectFileName, ref options, mdkOptionsFileName, ref paths, mdkPathsFileName);
                if (options != null && paths != null)
                {
                    return(new MDKProjectProperties(projectFileName, name, options, paths));
                }
            }

            echo?.Invoke($"{projectName ?? projectFileName} not an MDK project.");
            return(new MDKProjectProperties(projectFileName, null, null, null));
        }
Esempio n. 4
0
        /// <summary>
        /// Loads script information from the given project file.
        /// </summary>
        /// <param name="projectFileName">The file name of this project</param>
        /// <param name="projectName">The display name of this project</param>
        /// <returns></returns>
        public static MDKProjectProperties Load([NotNull] string projectFileName, string projectName = null)
        {
            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(projectFileName));
            }

            if (!File.Exists(projectFileName) || Regex.IsMatch(projectFileName, @"\w+://"))
            {
                return(new MDKProjectProperties(projectFileName, null, null, null));
            }

            var fileName = Path.GetFullPath(projectFileName);
            var name     = projectName ?? Path.GetFileNameWithoutExtension(projectFileName);
            var legacyOptionsFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options"));
            var mdkOptionsFileName    = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options.props"));
            var mdkPathsFileName      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.paths.props"));

            MDKProjectOptions options = null;
            MDKProjectPaths   paths   = null;

            if (File.Exists(mdkOptionsFileName) /* && File.Exists(mdkPathsFileName)*/)
            {
                options = MDKProjectOptions.Load(mdkOptionsFileName);
                paths   = MDKProjectPaths.Load(mdkPathsFileName);

                return(new MDKProjectProperties(projectFileName, name, options, paths));
            }

            if (File.Exists(legacyOptionsFileName))
            {
                ImportLegacy_1_1(projectFileName, ref options, mdkOptionsFileName, ref paths, mdkPathsFileName);
                if (options != null && paths != null)
                {
                    return(new MDKProjectProperties(projectFileName, name, options, paths));
                }
            }

            return(new MDKProjectProperties(projectFileName, null, null, null));
        }
Esempio n. 5
0
 static partial void ImportLegacy_1_1(string legacyOptionsFileName, ref MDKProjectOptions options, string optionsFileName, ref MDKProjectPaths paths, string pathsFileName);