/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Everest.Library.ExtensionMethod;
namespace Everest.CmsServices.Models{
public class Component
{
const string ValuePattern = "{0}:{1}";
public ComponentType ComponentType { get; set; }
public string ComponentValue { get; set; }
public string ComponentName { get; set; }
public string Image
{
get
{
switch (this.ComponentType)
{
case ComponentType.ContentTemplate:
return "~/Styles/Images/ContentTemplate.gif";
case ComponentType.Module:
return "~/Styles/Images/Module.png";
case ComponentType.WebForm:
return "~/Styles/Images/webform.png";
default:
return "~/Styles/Images/ContentTemplate.gif";
}
}
}
public string ToValue()
{
return ToValue(this.ComponentValue, this.ComponentType);
}
/// <summary>
/// Toes the value.
/// </summary>
/// <param name="componentValue">The component value.</param>
/// <param name="componentType">Type of the component.</param>
/// <returns></returns>
public static string ToValue(string componentValue, ComponentType componentType)
{
return string.Format(ValuePattern, (int)componentType, componentValue);
}
/// <summary>
/// Parses the value.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="componentValue">The component value.</param>
/// <param name="componentType">Type of the component.</param>
public static void ParseValue(string value, out string componentValue, out ComponentType componentType)
{
if (StringExtensions.IsNullOrEmptyTrim(value))
{
throw new Exception("Invalide component value..");
}
int indexOf = value.IndexOf(':');
componentType = (ComponentType)int.Parse(value.Substring(0, indexOf));
componentValue = value.Substring(indexOf + 1);
}
}
}
|