コード例 #1
0
ファイル: NpmSerialize.cs プロジェクト: ashlabs/npm.net
        /// <summary>
        /// Deserialize the parsed json results to a package for immediate children only
        /// </summary>
        /// <param name="parent">Parent list for this object</param>
        /// <param name="dependentPath">list of parents delimited by "/"</param>
        /// <param name="listObj">dictionary at root of package</param>
        protected void InstalledDependenciesFromDictionary(
                                                    List<INpmInstalledPackage> parent,
                                                    string dependentPath,
                                                    Dictionary<string, object> listObj)
        {
            if (listObj.ContainsKey("dependencies"))
            {
                IDictionary<string, object> dependDict = null;
                object dependencyObj;
                if (listObj.TryGetValue("dependencies", out dependencyObj))
                {
                    dependDict = dependencyObj as IDictionary<string, object>;
                }

                if (dependDict != null && dependDict.Count > 0)
                {
                    foreach (KeyValuePair<string, object> pair in dependDict)
                    {
                        Dictionary<string, object> val = pair.Value as Dictionary<string, object>;
                        if (val != null)
                        {
                            NpmInstalledPackage installed = new NpmInstalledPackage();
                            installed.Name = pair.Key;
                            installed.DependentPath = dependentPath;
                            if (val.ContainsKey("version"))
                            {
                                installed.Version = val["version"] as string;
                            }

                            if (val.ContainsKey("missing"))
                            {
                                installed.IsMissing = true;
                            }

                            if (val.ContainsKey("invalid"))
                            {
                                installed.IsOutdated = true;
                            }

                            if (val.ContainsKey("dependencies"))
                            {
                                installed.HasDependencies = true;
                            }

                            parent.Add(installed);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: NpmSerialize.cs プロジェクト: ashlabs/npm.net
        /// <summary>
        /// Deserialize the parsed json results and try to match package
        /// </summary>
        /// <param name="package">Package that has name to match</param>
        /// <param name="name">name of package</param>
        /// <param name="dependentPath">list of parents delimited by "/"</param>
        /// <param name="listObj">dictionary at root of package</param>
        /// <returns>Installed package object</returns>
        /// <remarks>This is called recursively as a dependency is a package</remarks>
        protected NpmInstalledPackage MatchPackageFromDictionary(
                                                    INpmPackage package,
                                                    string name,
                                                    string dependentPath,
                                                    Dictionary<string, object> listObj)
        {
            // if name matches and not missing, create package and return it
            if (package.Name == name && !listObj.ContainsKey("missing"))
            {
                NpmInstalledPackage installed = new NpmInstalledPackage();
                installed.Name = name;
                installed.DependentPath = dependentPath;
                if (listObj.ContainsKey("version"))
                {
                    installed.Version = listObj["version"] as string;
                }

                if (listObj.ContainsKey("invalid"))
                {
                    installed.IsOutdated = true;
                }

                if (listObj.ContainsKey("dependencies"))
                {
                    installed.HasDependencies = true;
                }

                return installed;
            }

            // look in the dependencies
            if (listObj.ContainsKey("dependencies"))
            {
                IDictionary<string, object> dependDict = null;
                object dependencyObj;
                if (listObj.TryGetValue("dependencies", out dependencyObj))
                {
                    dependDict = dependencyObj as IDictionary<string, object>;
                }

                if (dependDict != null && dependDict.Count > 0)
                {
                    string mypath = string.IsNullOrWhiteSpace(dependentPath) ?
                                                        name :
                                                        dependentPath + "/" + name;
                    foreach (KeyValuePair<string, object> pair in dependDict)
                    {
                        Dictionary<string, object> val = pair.Value as Dictionary<string, object>;
                        if (val != null)
                        {
                            NpmInstalledPackage installed = this.MatchPackageFromDictionary(package, pair.Key, mypath, val);
                            if (installed != null)
                            {
                                return installed;
                            }
                        }
                    }
                }
            }

            return null;
        }
コード例 #3
0
ファイル: NpmSerialize.cs プロジェクト: ashlabs/npm.net
        /// <summary>
        /// Build installed package list from Dictionary based on install json
        /// </summary>
        /// <param name="parent">Parent list for this object</param>
        /// <param name="child">Child object is dictionary from json deserialize</param>
        protected static void InstalledPackagesFromInstalledDictionary(
                                            List<INpmInstalledPackage> parent,
                                            object child)
        {
            Dictionary<string, object> childObj = child as Dictionary<string, object>;
            if (childObj == null)
            {
                return;
            }

            NpmInstalledPackage installed = new NpmInstalledPackage();
            if (childObj.ContainsKey("what"))
            {
                NpmSerialize.FillPackageFromNameVersion(installed, childObj["what"] as string);
            }

            if (childObj.ContainsKey("parentDir"))
            {
                string parentDirectory = childObj["parentDir"] as string;
                if (parentDirectory != null)
                {
                    installed.DependentPath = NpmSerialize.ConvertPathToDepends(parentDirectory);
                }
            }
            else
            {
                installed.DependentPath = string.Empty;
            }

            installed.IsMissing = false;
            installed.IsOutdated = false;

            if (childObj.ContainsKey("children"))
            {
                ArrayList array = childObj["children"] as ArrayList;
                if (array != null && array.Count > 0)
                {
                    installed.HasDependencies = true;

                    foreach (object item in array)
                    {
                        NpmSerialize.InstalledPackagesFromInstalledDictionary(parent, item);
                    }
                }
            }

            parent.Add(installed);
        }
コード例 #4
0
ファイル: NpmSerialize.cs プロジェクト: ashlabs/npm.net
        /// <summary>
        /// Deserialize the parsed json results to a package
        /// </summary>
        /// <param name="parent">Parent list for this object</param>
        /// <param name="name">name of package</param>
        /// <param name="dependentPath">list of parents delimited by "/"</param>
        /// <param name="listObj">dictionary at root of package</param>
        /// <remarks>This is called recursively as a dependency is a package</remarks>
        protected void InstalledPackageFromDictionary(
                                                    List<INpmInstalledPackage> parent,
                                                    string name,
                                                    string dependentPath,
                                                    Dictionary<string, object> listObj)
        {
            NpmInstalledPackage installed = new NpmInstalledPackage();
            if (!string.IsNullOrWhiteSpace(name))
            {
                // if node has no name, then do not add it.
                installed.Name = name;
                installed.DependentPath = dependentPath;
                if (listObj.ContainsKey("version"))
                {
                    installed.Version = listObj["version"] as string;
                }

                if (listObj.ContainsKey("missing"))
                {
                    installed.IsMissing = true;
                }

                if (listObj.ContainsKey("invalid"))
                {
                    installed.IsOutdated = true;
                }

                if (listObj.ContainsKey("dependencies"))
                {
                    installed.HasDependencies = true;
                }

                parent.Add(installed);
            }

            if (listObj.ContainsKey("dependencies"))
            {
                IDictionary<string, object> dependDict = null;
                object dependencyObj;
                if (listObj.TryGetValue("dependencies", out dependencyObj))
                {
                    dependDict = dependencyObj as IDictionary<string, object>;
                }

                if (dependDict != null && dependDict.Count > 0)
                {
                    string parentName = string.IsNullOrWhiteSpace(name) ? "." : name;
                    string mypath = string.IsNullOrWhiteSpace(dependentPath) ?
                                                        parentName :
                                                        dependentPath + "/" + parentName;
                    foreach (KeyValuePair<string, object> pair in dependDict)
                    {
                        Dictionary<string, object> val = pair.Value as Dictionary<string, object>;
                        if (val != null)
                        {
                            this.InstalledPackageFromDictionary(parent, pair.Key, mypath, val);
                        }
                    }
                }
                else
                {
                    installed.HasDependencies = false;
                }
            }
        }
コード例 #5
0
ファイル: MockTestData.cs プロジェクト: ashlabs/npm.net
 /// <summary>
 /// Expected output from install
 /// </summary>
 /// <returns>Expected result for install test</returns>
 public static List<NpmInstalledPackage> Install1Expected()
 {
     List<NpmInstalledPackage> expected = new List<NpmInstalledPackage>();
     NpmInstalledPackage package = new NpmInstalledPackage();
     package.Name = "underscore";
     package.Version = "1.3.3";
     package.DependentPath = string.Empty;
     expected.Add(package);
     return expected;
 }
コード例 #6
0
ファイル: MockTestData.cs プロジェクト: ashlabs/npm.net
 /// <summary>
 /// Expected output from list
 /// </summary>
 /// <returns>Expected result for list test</returns>
 public static List<NpmInstalledPackage> ListProblem1Expected()
 {
     List<NpmInstalledPackage> expected = new List<NpmInstalledPackage>();
     NpmInstalledPackage package;
     package = new NpmInstalledPackage();
     package.Name = "azure";
     package.Version = "0.5.2";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.DependentPath = string.Empty;
     package.HasDependencies = true;
     expected.Add(package);
     package = new NpmInstalledPackage();
     package.Name = "xml2js";
     package.Version = "0.1.13";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.DependentPath = "azure";
     package.HasDependencies = false;
     expected.Add(package);
     package = new NpmInstalledPackage();
     package.Name = "mime";
     package.IsMissing = true;
     package.IsOutdated = false;
     package.DependentPath = "azure";
     package.HasDependencies = false;
     expected.Add(package);
     package = new NpmInstalledPackage();
     package.Name = "underscore";
     package.Version = "1.3.0";
     package.IsMissing = false;
     package.IsOutdated = true;
     package.DependentPath = "azure";
     package.HasDependencies = false;
     expected.Add(package);
     return expected;
 }
コード例 #7
0
ファイル: MockTestData.cs プロジェクト: ashlabs/npm.net
 /// <summary>
 /// Expected result for IsInstalled
 /// </summary>
 /// <returns>Expected result for IsInstalled test</returns>
 public static NpmInstalledPackage List1MatchInstalledExpected()
 {
     NpmInstalledPackage package;
     package = new NpmInstalledPackage();
     package.Name = "xml2js";
     package.Version = "0.1.13";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.DependentPath = "azure";
     return package;
 }
コード例 #8
0
ファイル: MockTestData.cs プロジェクト: ashlabs/npm.net
 /// <summary>
 /// Expected output from list
 /// </summary>
 /// <returns>Expected result for list test</returns>
 public static List<NpmInstalledPackage> List2ChildrenExpected()
 {
     List<NpmInstalledPackage> expected = new List<NpmInstalledPackage>();
     NpmInstalledPackage package;
     package = new NpmInstalledPackage();
     package.Name = "azure";
     package.Version = "0.5.2";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.HasDependencies = true;
     package.DependentPath = ".";
     expected.Add(package);
     return expected;
 }
コード例 #9
0
ファイル: MockTestData.cs プロジェクト: ashlabs/npm.net
 /// <summary>
 /// Expected output from list
 /// </summary>
 /// <returns>Expected result for list test</returns>
 public static List<NpmInstalledPackage> List1ChildrenExpected()
 {
     List<NpmInstalledPackage> expected = new List<NpmInstalledPackage>();
     NpmInstalledPackage package;
     package = new NpmInstalledPackage();
     package.Name = "xml2js";
     package.Version = "0.1.13";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.HasDependencies = false;
     package.DependentPath = "azure";
     expected.Add(package);
     package = new NpmInstalledPackage();
     package.Name = "sax";
     package.Version = "0.4.0";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.HasDependencies = false;
     package.DependentPath = "azure";
     expected.Add(package);
     package = new NpmInstalledPackage();
     package.Name = "jshint";
     package.Version = "0.5.9";
     package.IsMissing = false;
     package.IsOutdated = false;
     package.HasDependencies = true;
     package.DependentPath = "azure";
     expected.Add(package);
     return expected;
 }