using EnVisage.Code.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace EnVisage.Code.Session
{
public static class AbsoluteUrl
{
private static bool initializedAlready = false;
private static Object initlock = new Object();
// AbsoluteUrl without parameters
public static string EDIT_SCENARIO_URL;
public static string NOTIFICATION_URL;
public static string EDIT_PROJECT_URL;
private static string SCENARIOID_MARKER = "SCENARIOID";
private static string PROJECTID_MARKER = "PROJECTID";
private static string NOTIFICATIONID_MARKER = "NOTIFICATIONID";
public static string EditScenarioUrl(Guid? id, EnVisageEntities ef)
{
if (id.HasValue)
{
if (string.IsNullOrEmpty(EDIT_SCENARIO_URL))
{
string root=(new SystemSettingsManager(ef)).GetSystemSettingsValue((int) SystemSettingType.SiteUrl);
if (string.IsNullOrEmpty(root))
return "";
char[] spl = { '/' };
if (root.EndsWith("/"))
root = root.Substring(0, root.Length - 1);
EDIT_SCENARIO_URL = root + "/Scenarios/Details/" + SCENARIOID_MARKER;
}
// "You must define a specific route for JavaScriptReplacableUrl to work", but it doesn't work for me. So I use this:
return EDIT_SCENARIO_URL.Replace(SCENARIOID_MARKER, id.Value.ToString());
}
return "";
}
public static string EditProjectUrl(Guid? id, EnVisageEntities ef)
{
if (id.HasValue)
{
if (string.IsNullOrEmpty(EDIT_PROJECT_URL))
{
string root = (new SystemSettingsManager(ef)).GetSystemSettingsValue((int) SystemSettingType.SiteUrl);
if (string.IsNullOrEmpty(root))
return "";
char[] spl = { '/' };
if (root.EndsWith("/"))
root = root.Substring(0, root.Length - 1);
EDIT_PROJECT_URL = root + "/Project/Edit/" + PROJECTID_MARKER;
}
// "You must define a specific route for JavaScriptReplacableUrl to work", but it doesn't work for me. So I use this:
return EDIT_PROJECT_URL.Replace(PROJECTID_MARKER, id.Value.ToString());
}
return "";
}
public static string NotificationPassthruUrl(Guid? id, EnVisageEntities ef)
{
if (id.HasValue)
{
if (string.IsNullOrEmpty(NOTIFICATION_URL))
{
string root = (new SystemSettingsManager(ef)).GetSystemSettingsValue((int) SystemSettingType.SiteUrl);
if (string.IsNullOrEmpty(root))
return "";
char[] spl = { '/' };
if (root.EndsWith("/"))
root = root.Substring(0, root.Length - 1);
NOTIFICATION_URL = root + "/Notification/PassThruLink/" + NOTIFICATIONID_MARKER;
}
// "You must define a specific route for JavaScriptReplacableUrl to work", but it doesn't work for me. So I use this:
return NOTIFICATION_URL.Replace(NOTIFICATIONID_MARKER, id.Value.ToString());
}
return "";
}
///
/// Initialize only on the first request
///
///
public static void Initialize(System.Web.HttpContext context)
{
if (initializedAlready)
{
return;
}
lock (initlock)
{
if (initializedAlready)
{
return;
}
var url = new UrlHelper(context.Request.RequestContext);
// var leftPart = context.Request.Url.GetLeftPart(UriPartial.Authority);
// AbsoluteUrl without parameters
EDIT_SCENARIO_URL = url.Action("Details", "Scenarios", new { Id = SCENARIOID_MARKER }, context.Request.Url.Scheme);
EDIT_PROJECT_URL = url.Action("Edit", "Project", new { Id = PROJECTID_MARKER }, context.Request.Url.Scheme);
NOTIFICATION_URL = url.Action("PassThruLink", "Notification", new { Id = NOTIFICATIONID_MARKER }, context.Request.Url.Scheme);
// AbsoluteUrl with parameters
initializedAlready = true;
}
}
//public static void Initialize(string projectUrl,string scenarioUrl)
//{
// if (initializedAlready)
// {
// return;
// }
// lock (initlock)
// {
// if (initializedAlready)
// {
// return;
// }
// // var leftPart = context.Request.Url.GetLeftPart(UriPartial.Authority);
// // AbsoluteUrl without parameters
// EDIT_SCENARIO_URL = scenarioUrl + SCENARIOID_MARKER;
// EDIT_PROJECT_URL = projectUrl+ PROJECTID_MARKER;
// // AbsoluteUrl with parameters
// initializedAlready = true;
// }
//}
}
}