Commits

Cesar Lopez-Nataren committed 4285987

Initial import

Comments (0)

Files changed (8)

+bin/
+dist/
+*resharper.user
+[Dd]ebug/
+[Rr]elease/
+Signed Debug/
+Signed Release/
+obj/
+*.ncb
+*.suo
+_ReSharper.*/
+*.pdb
+*.snk
+*.user
+*.log
+App_Data/
+*.pidb
+*.test-cache
+*.userprefs
+*.resources
+*.cache
+*.pidb
+nunit-results.xml
+*.orig
+*.ReSharper
+*.tmp
+*.bak
+LocalSettings.php
+cache/
+attachments/
+.project
+devtools_firephp/
+.idea
+web/deki/javascript/out
+*.dotCover
+*.opensdf
+*.sdf
+web/lang.php
+test-results

HierarchyTopology.sln

+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HierarchyTopology", "HierarchyTopology\HierarchyTopology.csproj", "{95BFF356-395C-42E5-9506-392C6C235899}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{95BFF356-395C-42E5-9506-392C6C235899}.Debug|x86.ActiveCfg = Debug|x86
+		{95BFF356-395C-42E5-9506-392C6C235899}.Debug|x86.Build.0 = Debug|x86
+		{95BFF356-395C-42E5-9506-392C6C235899}.Release|x86.ActiveCfg = Release|x86
+		{95BFF356-395C-42E5-9506-392C6C235899}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

HierarchyTopology/HierarchyExplorer.cs

+using System;
+using System.Collections.Generic;
+using MindTouch.Dream;
+using MindTouch.Xml;
+
+namespace HierarchyTopology {
+    public class HierarchyExplorer {
+
+        //--- Fields ---
+        private readonly Plug _api;
+        private const string ARTICLE = "article:";
+
+        //--- Constructor ---
+        public HierarchyExplorer(Plug api) {
+            _api = api;
+        }
+
+        public IEnumerable<PageInfo> GetTopology(string pageroot) {
+            return GetPagesTopologyInformation(pageroot, 4);
+        }
+
+        private IEnumerable<PageInfo> GetPagesTopologyInformation(string p, int depth) {
+            return GetPagesTopologyInformationHelper(p, depth, 0, new List<PageInfo>());
+        }
+
+        private IEnumerable<PageInfo> GetPagesTopologyInformationHelper(string p, int depth, int counter, List<PageInfo> pageInfos) {
+             if(depth >= counter) {
+                 return pageInfos;
+             }
+            counter++;
+            var pageDoc = _api.At("@api", "deki", "pages", p).Get().ToDocument();
+            var articleType = GetArticleType(pageDoc);
+            var subpagesDoc = _api.At("@api", "deki", "pages", pageDoc["@id"].AsText, "subpages").Get().ToDocument();
+            var subpages = subpagesDoc[".//pageDoc.subpage"].ToList();
+            var pageId = pageDoc["@id"].AsText;
+            pageInfos.Add(new PageInfo(pageId, pageDoc[".//title"].AsText, subpages.Count, articleType, pageDoc));
+            return GetPagesTopologyInformationHelper(pageId, depth, counter, pageInfos);
+        }
+
+        private string GetArticleType(XDoc pageDoc) {
+            var tags = pageDoc[".//tags"];
+            var tagCount = tags["@count"].AsInt;
+            if(tagCount <= 0) {
+                return "";
+            }
+            foreach(var tag in tags[".//tag"]) {
+                var t = tag["@value"].AsText;
+                if(t.StartsWithInvariantIgnoreCase(ARTICLE)) {
+                    return t.Substring(ARTICLE.Length);
+                }
+            }
+            return "";
+        }
+    }
+}

HierarchyTopology/HierarchyTopology.csproj

+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95BFF356-395C-42E5-9506-392C6C235899}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HierarchyTopology</RootNamespace>
+    <AssemblyName>HierarchyTopology</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="mindtouch.dream">
+      <HintPath>..\..\..\Deki\src\redist\mindtouch.dream.dll</HintPath>
+    </Reference>
+    <Reference Include="Mono.Options">
+      <HintPath>..\..\..\Deki\src\redist\Mono.Options.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="HierarchyExplorer.cs" />
+    <Compile Include="PageInfo.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

HierarchyTopology/PageInfo.cs

+using MindTouch.Xml;
+
+namespace HierarchyTopology {
+    public class PageInfo {
+
+        //--- Fields ---
+        public readonly string ArticleType;
+        public readonly int SubpagesCount;
+        public readonly string Title;
+        public readonly string PageId;
+        public readonly XDoc Doc;
+
+        //--- Methods ---
+        public PageInfo(string pageId, string title, int subpagesCount, string articleType, XDoc doc) {
+            PageId = pageId;
+            Title = title;
+            ArticleType = articleType;
+            SubpagesCount = subpagesCount;
+            Doc = doc;
+        }
+    }
+}

HierarchyTopology/Program.cs

+using System;
+using MindTouch.Dream;
+using Mono.Options;
+
+namespace HierarchyTopology {
+    public class Program {
+        public static void Main(string[] args) {
+
+            // Validate the command line parameters
+            var hostname = "";
+            var startPage = "";
+            var optionSet = new OptionSet {
+                { "hostname=", "The {HOSTNAME} to use", v => hostname = v },
+                { "pageroot=", "The {PAGEID} of the root page we should start analyzing from", pageid => startPage = pageid }
+            };
+            var options = optionSet.Parse(args);
+            if(options == null || options.Count == 0 || string.IsNullOrEmpty(hostname) || string.IsNullOrEmpty(startPage)) {
+                Console.WriteLine(hostname);
+                Console.WriteLine(startPage);
+                ShowHelpBanner(optionSet);
+                return;
+            }
+
+            // Explore!
+            var hierarchyExplorer = new HierarchyExplorer(Plug.New(hostname));
+            var topology = hierarchyExplorer.GetTopology(startPage);
+            foreach(var page in topology) {
+                Console.WriteLine(string.Format("id = {0}, title = {1}, articletype = {2}, subpages = {3}", page.PageId, page.Title, page.ArticleType, page.SubpagesCount));
+            }
+        }
+
+        private static void ShowHelpBanner(OptionSet options) {
+            Console.WriteLine("MindTouch Topology Explorer v0.1");
+            Console.WriteLine("Options:");
+            options.WriteOptionDescriptions(Console.Out);
+        }
+    }
+}

HierarchyTopology/Properties/AssemblyInfo.cs

+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("HierarchyTopology")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HierarchyTopology")]
+[assembly: AssemblyCopyright("Copyright ©  2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("9ad1c3be-7b4a-442b-89fc-ad1fba805228")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

HierarchyTopology/app.config

+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>