From 5c61ba138c0a4b6199bba7d7b3b854ec4f819599 Mon Sep 17 00:00:00 2001
From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>
Date: Sun, 4 Jul 2010 16:31:31 +0000
Subject: [PATCH] QuickLinks implemented
---
Builder/IISMainHandler/build.txt | 2 +-
Builder/IISUploadHandler/build.txt | 2 +-
Common/Common.csproj | 1 +
Common/dataobjects/QuickLink.cs | 75 +++++++++++++++++++
IISMainHandler/IISMainHandler.csproj | 1 +
.../handlers/response/QuickLinkHandler.cs | 17 +++++
6 files changed, 96 insertions(+), 2 deletions(-)
create mode 100644 Common/dataobjects/QuickLink.cs
create mode 100644 IISMainHandler/handlers/response/QuickLinkHandler.cs
diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt
index dd35c6b..bccf25b 100644
--- a/Builder/IISMainHandler/build.txt
+++ b/Builder/IISMainHandler/build.txt
@@ -1 +1 @@
-548
\ No newline at end of file
+557
\ No newline at end of file
diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt
index 2989c6c..6eac4a6 100644
--- a/Builder/IISUploadHandler/build.txt
+++ b/Builder/IISUploadHandler/build.txt
@@ -1 +1 @@
-283
\ No newline at end of file
+292
\ No newline at end of file
diff --git a/Common/Common.csproj b/Common/Common.csproj
index dff83c5..c1bcce0 100644
--- a/Common/Common.csproj
+++ b/Common/Common.csproj
@@ -87,6 +87,7 @@
+
diff --git a/Common/dataobjects/QuickLink.cs b/Common/dataobjects/QuickLink.cs
new file mode 100644
index 0000000..4a1f500
--- /dev/null
+++ b/Common/dataobjects/QuickLink.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Xml.Linq;
+using FLocal.Core;
+using FLocal.Core.DB;
+using FLocal.Core.DB.conditions;
+
+namespace FLocal.Common.dataobjects {
+ public class QuickLink : SqlObject {
+
+ public class TableSpec : ISqlObjectTableSpec {
+ public const string TABLE = "QuickLinks";
+ public const string FIELD_ID = "Id";
+ public const string FIELD_NAME = "Name";
+ public const string FIELD_URL = "Url";
+ public static readonly TableSpec instance = new TableSpec();
+ public string name { get { return TABLE; } }
+ public string idName { get { return FIELD_ID; } }
+ public void refreshSqlObject(int id) { Refresh(id); }
+ }
+
+ protected override ISqlObjectTableSpec table { get { return TableSpec.instance; } }
+
+ private string _name;
+ public string name {
+ get {
+ this.LoadIfNotLoaded();
+ return this._name;
+ }
+ }
+
+ private string _url;
+ public string url {
+ get {
+ this.LoadIfNotLoaded();
+ return this._url;
+ }
+ }
+
+ private static Dictionary name2id = new Dictionary();
+ public static QuickLink LoadByName(string name) {
+ if(!name2id.ContainsKey(name)) {
+ lock(name2id) {
+ if(!name2id.ContainsKey(name)) {
+ List ids = Config.instance.mainConnection.LoadIdsByConditions(
+ TableSpec.instance,
+ new ComparisonCondition(
+ TableSpec.instance.getColumnSpec(TableSpec.FIELD_NAME),
+ ComparisonType.EQUAL,
+ name
+ ),
+ Diapasone.unlimited
+ );
+ if(ids.Count > 1) {
+ throw new CriticalException("not unique");
+ } else if(ids.Count == 1) {
+ name2id[name] = int.Parse(ids[0]);
+ } else {
+ throw new NotFoundInDBException();
+ }
+ }
+ }
+ }
+ return QuickLink.LoadById(name2id[name]);
+ }
+
+ protected override void doFromHash(Dictionary data) {
+ this._name = data[TableSpec.FIELD_NAME];
+ this._url = data[TableSpec.FIELD_URL];
+ }
+
+ }
+}
diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj
index fa2496d..27b8a4d 100644
--- a/IISMainHandler/IISMainHandler.csproj
+++ b/IISMainHandler/IISMainHandler.csproj
@@ -81,6 +81,7 @@
+
diff --git a/IISMainHandler/handlers/response/QuickLinkHandler.cs b/IISMainHandler/handlers/response/QuickLinkHandler.cs
new file mode 100644
index 0000000..edda726
--- /dev/null
+++ b/IISMainHandler/handlers/response/QuickLinkHandler.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FLocal.Core;
+using FLocal.Common;
+using FLocal.Common.dataobjects;
+
+namespace FLocal.IISHandler.handlers.response {
+ class QuickLinkHandler : RedirectGetHandler {
+
+ protected override string getRedirectUrl(WebContext context) {
+ return QuickLink.LoadByName(context.requestParts[1]).url;
+ }
+
+ }
+}