Browse Source

Secured BuildOurOwnBabylonJSController actions
Call BuildOurOwnBabylonJS.exe once BuildOurOwnBabylonJSWinJSApp has been built

Note: whereas ourOwnBabylon.js is regenerated when F5 is pressed for BuildOurOwnBabylonJSServer, it's not when F5 is pressed for BuildOurOwnBabylonJSWinJSApp (you have to first build the app)

Gwenaël Hagenmuller 11 years ago
parent
commit
1e2fc4fe93

+ 57 - 47
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJSServer/Controllers/BuildOurOwnBabylonJSController.cs

@@ -15,44 +15,44 @@ namespace BuildOurOwnBabylonJSServer.Controllers
         [ActionName(BuildOurOwnBabylonJSController.GetFileContentActionName)]
         public ActionResult GetFileContent(string rootPath, string relPath)
         {
-            var babylonJSPath = Path.Combine(Server.MapPath("~"), rootPath);
+            try
+            {
+                var babylonJSPath = Path.Combine(Server.MapPath("~"), rootPath);
 
-            var absPath = Path.Combine(babylonJSPath, relPath);
+                var absPath = Path.Combine(babylonJSPath, relPath);
 
-            var type = "";
-            var extension = "";
+                var type = "";
+                var extension = "";
 
-            if (!String.IsNullOrEmpty(relPath))
-                extension = Path.GetExtension(relPath).ToLower();
+                if (!String.IsNullOrEmpty(relPath))
+                    extension = Path.GetExtension(relPath).ToLower();
 
-            switch (extension)
-            {
-                case ".js":
-                case ".babylon":
-                case ".manifest":
-                    type = "text/javascript";
-                    break;
+                switch (extension)
+                {
+                    case ".js":
+                    case ".babylon":
+                    case ".manifest":
+                        type = "text/javascript";
+                        break;
 
-                case ".png":
-                    type = "image/png";
-                    break;
+                    case ".png":
+                        type = "image/png";
+                        break;
 
-                case ".jpeg":
-                case ".jpg":
-                    type = "image/jpeg";
-                    break;
+                    case ".jpeg":
+                    case ".jpg":
+                        type = "image/jpeg";
+                        break;
 
-                case ".bmp":
-                    type = "image/bmp";
-                    break;
-
-                default:
-                    type = "text/plain";
-                    break;
-            }
+                    case ".bmp":
+                        type = "image/bmp";
+                        break;
 
-            try
-            {
+                    default:
+                        type = "text/plain";
+                        break;
+                }
+            
                 return File(new FileStream(absPath, FileMode.Open), type);
             }
             catch
@@ -64,27 +64,37 @@ namespace BuildOurOwnBabylonJSServer.Controllers
         [ActionName(BuildOurOwnBabylonJSController.GetBabylonScenesActionName)]
         public string GetBabylonScenes(string rootPath)
         {
-            var dir = new DirectoryInfo(rootPath);
-            var subDirs = dir.GetDirectories();
-            var files = new List<JObject>();
+            try
+            {
+                var dir = new DirectoryInfo(rootPath);
+                var subDirs = dir.GetDirectories();
+                var files = new List<JObject>();
 
-            foreach (var directory in subDirs) {
-                var babylonFiles = directory.GetFiles("*.babylon");
-                if (babylonFiles.Length == 0) {
-                    continue;
-                }
+                foreach (var directory in subDirs)
+                {
+                    var babylonFiles = directory.GetFiles("*.babylon");
 
-                foreach (var file in babylonFiles) {
-                    var linkName = directory.Name + (file.Name.Contains(".incremental.babylon") ? " - Incremental" : "");
-                    files.Add(new JObject(
-                        new JProperty("url", Url.Action("Index", "BabylonJSDemo", new { demoFolderName = directory.Name, demoFile = file.Name })),
-                        new JProperty("linkName", linkName)
-                    ));
+                    if (babylonFiles.Length == 0)
+                        continue;
+
+                    foreach (var file in babylonFiles)
+                    {
+                        var linkName = directory.Name + (file.Name.Contains(".incremental.babylon") ? " - Incremental" : "");
+                        files.Add(new JObject(
+                            new JProperty("url", Url.Action("Index", "BabylonJSDemo", new { demoFolderName = directory.Name, demoFile = file.Name })),
+                            new JProperty("linkName", linkName)
+                        ));
+                    }
                 }
-            }
 
-            var json = new JObject(new JProperty("files", files));
-            return json.ToString(Newtonsoft.Json.Formatting.None);
+                var json = new JObject(new JProperty("files", files));
+                return json.ToString(Newtonsoft.Json.Formatting.None);
+            }
+            catch
+            {
+                var json = new JObject(new JProperty("files", ""));
+                return json.ToString(Newtonsoft.Json.Formatting.None);
+            }
         }
     }
 }

+ 7 - 2
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJSWinJSApp/BuildOurOwnBabylonJSWinJSApp.jsproj

@@ -91,13 +91,18 @@
   </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).targets" />
   <Import Project="packageExtraFiles.targets" />
+  <Target Name="AfterBuild">
+    <PropertyGroup>
+      <!--ConfigurationName should be the one set by the Solution but it doesn't really matter here, doesn't it?-->
+      <_BuildOurOwnBabylonJSExeFolder>$(SolutionDir)BuildOurOwnBabylonJS\bin\$(ConfigurationName)\</_BuildOurOwnBabylonJSExeFolder>
+    </PropertyGroup>
+    <Exec Command="&quot;$(_BuildOurOwnBabylonJSExeFolder)BuildOurOwnBabylonJS.exe&quot; /w:&quot;$(SolutionDir)..\..&quot; /i:&quot;$(SolutionDir)BuildOurOwnBabylonJS\ourOwnBabylonJS.xml&quot; /s:&quot;Babylon\Shaders&quot; /o:&quot;$(SolutionDir)BuildOurOwnBabylonJS&quot; /k:&quot;$(_BuildOurOwnBabylonJSExeFolder)executables&quot;" />
+  </Target>
   <!-- To modify your build process, add your task inside one of the targets below then uncomment
        that target and the DisableFastUpToDateCheck PropertyGroup. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
   </Target>
-  <Target Name="AfterBuild">
-  </Target>
   <PropertyGroup>
     <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
   </PropertyGroup>