//
// (C) Copyright 2003-2009 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Reflection;
using System.Globalization;
using Autodesk.Revit;
namespace Revit.SDK.Samples.RDBLink.CS
{
///
/// Provides static functions to get resource string from resource file
///
public static class RDBResource
{
#region Fields
///
/// ResourceManager
///
static ResourceManager resource;
///
/// Prefix of a table resource id
///
public const string TableKeyPrefix = "TabN_";
///
/// Suffix of a table resource id which contains instances
///
public const string TableKeyInstanceSuffix = "_INSTANCE";
///
/// Suffix of a table resource id which contains instances
///
public const string TableKeySymbolSuffix = "_SYMBOL";
#endregion
#region Constructors
///
/// Create ResourceManager
///
static RDBResource()
{
resource = new ResourceManager(
"Revit.SDK.Samples.RDBLink.CS.RDBLinkData",
Assembly.GetExecutingAssembly());
}
#endregion
#region Methods
///
/// Get the localized resource value
///
/// Resource id
/// Resource value
public static string GetString(string key)
{
return resource.GetString(key);
}
///
/// Get database column name from resource and remove some invalid characters
///
/// Resource id
/// database column name
public static string GetColumnName(string key)
{
string value = GetString(key);
foreach (char ch in DatabaseConfig.Instance().InvalidCharacters)
{
value = value.Replace(ch.ToString(), "");
}
return value;
}
///
/// Get database table name from resource and remove some invalid characters
///
/// Resource id
/// database table name
public static string GetTableName(string key)
{
if (key == null) return null;
string value = GetString(key);
if (value == null)
return null;
string mapValue = null;
DatabaseConfig.Instance().KeyWordsMap.TryGetValue(value, out mapValue);
return mapValue == null ? value : mapValue;
}
///
/// Get table resource id from a category and its type (element or symbol)
///
/// category
/// true if the table contains symbols, false if instances
/// table resource id
public static string GetTableKey(Autodesk.Revit.Category category, bool isSymbol)
{
if (category == null) return null;
BuiltInCategory buInCat = (BuiltInCategory)category.Id.Value;
string tableKeySuffix = isSymbol ? TableKeySymbolSuffix : TableKeyInstanceSuffix;
return TableKeyPrefix + buInCat.ToString() + tableKeySuffix;
}
#endregion
}
}