Browse Source

Merge pull request #1496 from LadyMozzarella/lgratrix-fix-servicestack2

Update Fix ServiceStack
Brittany Mazza 10 years ago
parent
commit
9b03c00224

+ 0 - 8
frameworks/CSharp/servicestack/bash_profile.sh

@@ -1,8 +0,0 @@
-#!/bin/bash
-
-export MONO_ROOT=${IROOT}/mono-3.6.0-install
-
-export PATH="$MONO_ROOT/bin:$PATH"
-
-# Needed to find Mono's shared libraries
-export LD_LIBRARY_PATH="$MONO_ROOT/lib"

+ 30 - 0
frameworks/CSharp/servicestack/setup_nginx.sh

@@ -0,0 +1,30 @@
+#!/bin/bash
+
+export NGINX_HOME=${IROOT}/nginx
+
+set -e
+# mono environment variables
+. ${IROOT}/mono.installed
+sed -i 's|localhost|'"$DBHOST"'|g' src/Web.config
+sed -i 's|/usr/local/nginx/|'"${IROOT}"'/nginx/|g' nginx.conf
+
+# extra cleaning
+rm -rf src/bin src/obj
+xbuild src/ServiceStackBenchmark.csproj /t:Clean
+xbuild src/ServiceStackBenchmark.csproj /t:Build
+# one fastcgi instance for each thread
+# load balanced by nginx
+port_start=9001
+port_end=$(($port_start+$MAX_THREADS))
+# nginx
+conf="upstream mono {\n"
+for port in $(seq $port_start $port_end); do
+conf+="\tserver 127.0.0.1:${port};\n"
+done
+conf+="}"
+echo -e $conf > $TROOT/nginx.upstream.conf
+$NGINX_HOME/sbin/nginx -c $TROOT/nginx.conf -g "worker_processes ${MAX_THREADS};"
+# To debug, use --printlog --verbose --loglevels=All
+for port in $(seq $port_start $port_end); do
+	MONO_OPTIONS=--gc=sgen fastcgi-mono-server4 --applications=/:${TROOT}/src --socket=tcp:127.0.0.1:$port &
+done

+ 14 - 0
frameworks/CSharp/servicestack/setup_xsp.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+
+export NGINX_HOME=${IROOT}/nginx
+
+set -e
+# mono environment variables
+. ${IROOT}/mono.installed
+sed -i 's|localhost|'"$DBHOST"'|g' src/Web.config
+# extra cleaning
+rm -rf src/bin src/obj
+xbuild src/ServiceStackBenchmark.csproj /t:Clean
+xbuild src/ServiceStackBenchmark.csproj /p:Configuration=Release
+# xsp
+MONO_OPTIONS=--gc=sgen xsp4 --port 8080 -nonstop &

+ 12 - 0
frameworks/CSharp/servicestack/src/AppHostConfigHelper.cs

@@ -4,6 +4,8 @@ using System.Configuration;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading;
 
 
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization;
 using MongoDB.Driver;
 using MongoDB.Driver;
 
 
 using ServiceStack.ServiceHost;
 using ServiceStack.ServiceHost;
@@ -24,6 +26,16 @@ namespace ServiceStackBenchmark
                 var database = server.GetDatabase("hello_world");
                 var database = server.GetDatabase("hello_world");
                 container.Register<MongoDatabase>(c => database);
                 container.Register<MongoDatabase>(c => database);
 
 
+                BsonClassMap.RegisterClassMap<World>(cm => {
+                    cm.MapProperty(c => c.id);
+                    cm.MapProperty(c => c.randomNumber);
+                });
+
+                BsonClassMap.RegisterClassMap<Fortune>(cm => {
+                    cm.MapProperty(c => c.id);
+                    cm.MapProperty(c => c.message);
+                });
+
                 // Create needed tables in MySql Server if they do not exist
                 // Create needed tables in MySql Server if they do not exist
                 return database.CreateWorldTable() && database.CreateFortuneTable();
                 return database.CreateWorldTable() && database.CreateFortuneTable();
             }
             }

+ 18 - 1
frameworks/CSharp/servicestack/src/DbFactories/PostgreSqlOrmLiteConnectionFactory.cs

@@ -7,6 +7,23 @@ namespace ServiceStackBenchmark
 {
 {
     public class PostgreSqlOrmLiteConnectionFactory : OrmLiteConnectionFactory, IPostgreSqlOrmLiteConnectionFactory
     public class PostgreSqlOrmLiteConnectionFactory : OrmLiteConnectionFactory, IPostgreSqlOrmLiteConnectionFactory
     {
     {
-        public PostgreSqlOrmLiteConnectionFactory(string s) : base(s, PostgreSQLDialectProvider.Instance) { }
+        public PostgreSqlOrmLiteConnectionFactory(string s) : base(s, PostgreSQLDialectProvider.Instance) {
+            this.DialectProvider.NamingStrategy = new LowercaseNamingStrategy();
+        }
     }
     }
+
+    public class LowercaseNamingStrategy : OrmLiteNamingStrategyBase
+    {
+        public override string GetTableName(string name)
+        {
+            return name.ToLower();
+        }
+
+        public override string GetColumnName(string name)
+        {
+            return name.ToLower();
+        }
+
+    }
+
 }
 }

+ 3 - 1
frameworks/CSharp/servicestack/src/Model/Fortune.cs

@@ -8,6 +8,7 @@ using MongoDB.Driver;
 using MongoDB.Driver.Builders;
 using MongoDB.Driver.Builders;
 
 
 using ServiceStack.DataAnnotations;
 using ServiceStack.DataAnnotations;
+using ServiceStack.Html;
 using ServiceStack.OrmLite;
 using ServiceStack.OrmLite;
 using ServiceStack.Text;
 using ServiceStack.Text;
 
 
@@ -103,7 +104,8 @@ namespace ServiceStackBenchmark.Model
         public static string ToHtml(List<Fortune> fortunes)
         public static string ToHtml(List<Fortune> fortunes)
         {
         {
             string page = @"<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
             string page = @"<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
-            fortunes.ForEach(f => page += @"<tr><td>{0}</td><td>{1}</td></tr>".Fmt(f.id, f.message));
+            HtmlHelper htmlHelper = new HtmlHelper();
+            fortunes.ForEach(f => page += @"<tr><td>{0}</td><td>{1}</td></tr>".Fmt(f.id, htmlHelper.Encode(f.message)));
             page += @"</table></body></html>";
             page += @"</table></body></html>";
             return page;
             return page;
         }
         }

+ 1 - 1
frameworks/CSharp/servicestack/src/ServiceStackBenchmark.csproj

@@ -14,7 +14,7 @@
     <FileAlignment>512</FileAlignment>
     <FileAlignment>512</FileAlignment>
     <TargetFrameworkProfile />
     <TargetFrameworkProfile />
     <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
     <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
-    <RestorePackages>true</RestorePackages>
+    <RestorePackages>false</RestorePackages>
   </PropertyGroup>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
     <PlatformTarget>AnyCPU</PlatformTarget>