You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
@ -0,0 +1,396 @@
|
||||
//-------------------------------------------------------------
|
||||
// <copyright company=<3D>Microsoft Corporation<6F>>
|
||||
// Copyright <20> Microsoft Corporation. All Rights Reserved.
|
||||
// </copyright>
|
||||
//-------------------------------------------------------------
|
||||
// @owner=alexgor, deliant
|
||||
//=================================================================
|
||||
// File: ColorPalette.cs
|
||||
//
|
||||
// Namespace: System.Web.UI.WebControls[Windows.Forms].Charting
|
||||
// System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
|
||||
//
|
||||
// Classes: ChartPaletteColors
|
||||
//
|
||||
// Purpose: A utility class which defines chart palette colors.
|
||||
// These palettes are used to assign unique colors to
|
||||
// different chart series. For some chart types, like
|
||||
// Pie, different colors are applied on the data point
|
||||
// level.
|
||||
//
|
||||
// Selected chart series/points palette is exposed
|
||||
// through Chart.Palette property. Series.Palette
|
||||
// property should be used to set different palette
|
||||
// color for each point of the series.
|
||||
//
|
||||
// Reviewed: AG - August 7, 2002
|
||||
// AG - Microsoft 5, 2007
|
||||
//
|
||||
//===================================================================
|
||||
|
||||
#region Used Namespaces
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
using System.Windows.Forms.DataVisualization.Charting;
|
||||
#else
|
||||
using System.Web.UI.DataVisualization.Charting;
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
namespace System.Windows.Forms.DataVisualization.Charting
|
||||
#else
|
||||
namespace System.Web.UI.DataVisualization.Charting
|
||||
|
||||
#endif
|
||||
{
|
||||
#region Color palettes enumeration
|
||||
|
||||
/// <summary>
|
||||
/// Chart color palettes enumeration
|
||||
/// </summary>
|
||||
public enum ChartColorPalette
|
||||
{
|
||||
/// <summary>
|
||||
/// Palette not set.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Bright palette.
|
||||
/// </summary>
|
||||
Bright,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with gray scale colors.
|
||||
/// </summary>
|
||||
Grayscale,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with Excel style colors.
|
||||
/// </summary>
|
||||
Excel,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with LightStyle style colors.
|
||||
/// </summary>
|
||||
Light,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with Pastel style colors.
|
||||
/// </summary>
|
||||
Pastel,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with Earth Tones style colors.
|
||||
/// </summary>
|
||||
EarthTones,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with SemiTransparent style colors.
|
||||
/// </summary>
|
||||
SemiTransparent,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with Berry style colors.
|
||||
/// </summary>
|
||||
Berry,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with Chocolate style colors.
|
||||
/// </summary>
|
||||
Chocolate,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with Fire style colors.
|
||||
/// </summary>
|
||||
Fire,
|
||||
|
||||
/// <summary>
|
||||
/// Palette with SeaGreen style colors.
|
||||
/// </summary>
|
||||
SeaGreen,
|
||||
|
||||
/// <summary>
|
||||
/// Bright pastel palette.
|
||||
/// </summary>
|
||||
BrightPastel
|
||||
};
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
namespace System.Windows.Forms.DataVisualization.Charting.Utilities
|
||||
#else
|
||||
namespace System.Web.UI.DataVisualization.Charting.Utilities
|
||||
#endif
|
||||
{
|
||||
/// <summary>
|
||||
/// ChartPaletteColors is a utility class which provides access
|
||||
/// to the predefined chart color palettes. These palettes are
|
||||
/// used to assign unique colors to different chart series.
|
||||
/// For some chart types, like Pie, different colors are applied
|
||||
/// on the data point level.
|
||||
///
|
||||
/// GetPaletteColors method takes a ChartColorPalette enumeration
|
||||
/// as a parameter and returns back an array of Colors. Each
|
||||
/// palette contains different number of colors but it is a
|
||||
/// good practice to keep this number around 15.
|
||||
/// </summary>
|
||||
internal static class ChartPaletteColors
|
||||
{
|
||||
#region Fields
|
||||
|
||||
// Fields which store the palette color values
|
||||
private static Color[] _colorsGrayScale = InitializeGrayScaleColors();
|
||||
private static Color[] _colorsDefault = {
|
||||
Color.Green,
|
||||
Color.Blue,
|
||||
Color.Purple,
|
||||
Color.Lime,
|
||||
Color.Fuchsia,
|
||||
Color.Teal,
|
||||
Color.Yellow,
|
||||
Color.Gray,
|
||||
Color.Aqua,
|
||||
Color.Navy,
|
||||
Color.Maroon,
|
||||
Color.Red,
|
||||
Color.Olive,
|
||||
Color.Silver,
|
||||
Color.Tomato,
|
||||
Color.Moccasin
|
||||
};
|
||||
|
||||
private static Color[] _colorsPastel = {
|
||||
Color.SkyBlue,
|
||||
Color.LimeGreen,
|
||||
Color.MediumOrchid,
|
||||
Color.LightCoral,
|
||||
Color.SteelBlue,
|
||||
Color.YellowGreen,
|
||||
Color.Turquoise,
|
||||
Color.HotPink,
|
||||
Color.Khaki,
|
||||
Color.Tan,
|
||||
Color.DarkSeaGreen,
|
||||
Color.CornflowerBlue,
|
||||
Color.Plum,
|
||||
Color.CadetBlue,
|
||||
Color.PeachPuff,
|
||||
Color.LightSalmon
|
||||
};
|
||||
|
||||
private static Color[] _colorsEarth = {
|
||||
Color.FromArgb(255, 128, 0),
|
||||
Color.DarkGoldenrod,
|
||||
Color.FromArgb(192, 64, 0),
|
||||
Color.OliveDrab,
|
||||
Color.Peru,
|
||||
Color.FromArgb(192, 192, 0),
|
||||
Color.ForestGreen,
|
||||
Color.Chocolate,
|
||||
Color.Olive,
|
||||
Color.LightSeaGreen,
|
||||
Color.SandyBrown,
|
||||
Color.FromArgb(0, 192, 0),
|
||||
Color.DarkSeaGreen,
|
||||
Color.Firebrick,
|
||||
Color.SaddleBrown,
|
||||
Color.FromArgb(192, 0, 0)
|
||||
};
|
||||
|
||||
private static Color[] _colorsSemiTransparent = {
|
||||
Color.FromArgb(150, 255, 0, 0),
|
||||
Color.FromArgb(150, 0, 255, 0),
|
||||
Color.FromArgb(150, 0, 0, 255),
|
||||
Color.FromArgb(150, 255, 255, 0),
|
||||
Color.FromArgb(150, 0, 255, 255),
|
||||
Color.FromArgb(150, 255, 0, 255),
|
||||
Color.FromArgb(150, 170, 120, 20),
|
||||
Color.FromArgb(80, 255, 0, 0),
|
||||
Color.FromArgb(80, 0, 255, 0),
|
||||
Color.FromArgb(80, 0, 0, 255),
|
||||
Color.FromArgb(80, 255, 255, 0),
|
||||
Color.FromArgb(80, 0, 255, 255),
|
||||
Color.FromArgb(80, 255, 0, 255),
|
||||
Color.FromArgb(80, 170, 120, 20),
|
||||
Color.FromArgb(150, 100, 120, 50),
|
||||
Color.FromArgb(150, 40, 90, 150)
|
||||
};
|
||||
|
||||
private static Color[] _colorsLight = {
|
||||
Color.Lavender,
|
||||
Color.LavenderBlush,
|
||||
Color.PeachPuff,
|
||||
Color.LemonChiffon,
|
||||
Color.MistyRose,
|
||||
Color.Honeydew,
|
||||
Color.AliceBlue,
|
||||
Color.WhiteSmoke,
|
||||
Color.AntiqueWhite,
|
||||
Color.LightCyan
|
||||
};
|
||||
|
||||
private static Color[] _colorsExcel = {
|
||||
Color.FromArgb(153,153,255),
|
||||
Color.FromArgb(153,51,102),
|
||||
Color.FromArgb(255,255,204),
|
||||
Color.FromArgb(204,255,255),
|
||||
Color.FromArgb(102,0,102),
|
||||
Color.FromArgb(255,128,128),
|
||||
Color.FromArgb(0,102,204),
|
||||
Color.FromArgb(204,204,255),
|
||||
Color.FromArgb(0,0,128),
|
||||
Color.FromArgb(255,0,255),
|
||||
Color.FromArgb(255,255,0),
|
||||
Color.FromArgb(0,255,255),
|
||||
Color.FromArgb(128,0,128),
|
||||
Color.FromArgb(128,0,0),
|
||||
Color.FromArgb(0,128,128),
|
||||
Color.FromArgb(0,0,255)};
|
||||
|
||||
private static Color[] _colorsBerry = {
|
||||
Color.BlueViolet,
|
||||
Color.MediumOrchid,
|
||||
Color.RoyalBlue,
|
||||
Color.MediumVioletRed,
|
||||
Color.Blue,
|
||||
Color.BlueViolet,
|
||||
Color.Orchid,
|
||||
Color.MediumSlateBlue,
|
||||
Color.FromArgb(192, 0, 192),
|
||||
Color.MediumBlue,
|
||||
Color.Purple
|
||||
};
|
||||
|
||||
private static Color[] _colorsChocolate = {
|
||||
Color.Sienna,
|
||||
Color.Chocolate,
|
||||
Color.DarkRed,
|
||||
Color.Peru,
|
||||
Color.Brown,
|
||||
Color.SandyBrown,
|
||||
Color.SaddleBrown,
|
||||
Color.FromArgb(192, 64, 0),
|
||||
Color.Firebrick,
|
||||
Color.FromArgb(182, 92, 58)
|
||||
};
|
||||
|
||||
private static Color[] _colorsFire = {
|
||||
Color.Gold,
|
||||
Color.Red,
|
||||
Color.DeepPink,
|
||||
Color.Crimson,
|
||||
Color.DarkOrange,
|
||||
Color.Magenta,
|
||||
Color.Yellow,
|
||||
Color.OrangeRed,
|
||||
Color.MediumVioletRed,
|
||||
Color.FromArgb(221, 226, 33)
|
||||
};
|
||||
|
||||
private static Color[] _colorsSeaGreen = {
|
||||
Color.SeaGreen,
|
||||
Color.MediumAquamarine,
|
||||
Color.SteelBlue,
|
||||
Color.DarkCyan,
|
||||
Color.CadetBlue,
|
||||
Color.MediumSeaGreen,
|
||||
Color.MediumTurquoise,
|
||||
Color.LightSteelBlue,
|
||||
Color.DarkSeaGreen,
|
||||
Color.SkyBlue
|
||||
};
|
||||
|
||||
private static Color[] _colorsBrightPastel = {
|
||||
Color.FromArgb(65, 140, 240),
|
||||
Color.FromArgb(252, 180, 65),
|
||||
Color.FromArgb(224, 64, 10),
|
||||
Color.FromArgb(5, 100, 146),
|
||||
Color.FromArgb(191, 191, 191),
|
||||
Color.FromArgb(26, 59, 105),
|
||||
Color.FromArgb(255, 227, 130),
|
||||
Color.FromArgb(18, 156, 221),
|
||||
Color.FromArgb(202, 107, 75),
|
||||
Color.FromArgb(0, 92, 219),
|
||||
Color.FromArgb(243, 210, 136),
|
||||
Color.FromArgb(80, 99, 129),
|
||||
Color.FromArgb(241, 185, 168),
|
||||
Color.FromArgb(224, 131, 10),
|
||||
Color.FromArgb(120, 147, 190)
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the GrayScale color array
|
||||
/// </summary>
|
||||
private static Color[] InitializeGrayScaleColors()
|
||||
{
|
||||
// Define gray scale colors
|
||||
Color[] grayScale = new Color[16];
|
||||
for(int i = 0; i < grayScale.Length; i++)
|
||||
{
|
||||
int colorValue = 200 - i * (180/16);
|
||||
grayScale[i] = Color.FromArgb(colorValue, colorValue, colorValue);
|
||||
}
|
||||
|
||||
return grayScale;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Return array of colors for the specified palette. Number of
|
||||
/// colors returned varies depending on the palette selected.
|
||||
/// </summary>
|
||||
/// <param name="palette">Palette to get the colors for.</param>
|
||||
/// <returns>Array of colors.</returns>
|
||||
public static Color[] GetPaletteColors(ChartColorPalette palette)
|
||||
{
|
||||
switch(palette)
|
||||
{
|
||||
case(ChartColorPalette.None):
|
||||
{
|
||||
throw (new ArgumentException(SR.ExceptionPaletteIsEmpty));
|
||||
}
|
||||
case(ChartColorPalette.Bright):
|
||||
return _colorsDefault;
|
||||
case(ChartColorPalette.Grayscale):
|
||||
return _colorsGrayScale;
|
||||
case(ChartColorPalette.Excel):
|
||||
return _colorsExcel;
|
||||
case(ChartColorPalette.Pastel):
|
||||
return _colorsPastel;
|
||||
case(ChartColorPalette.Light):
|
||||
return _colorsLight;
|
||||
case(ChartColorPalette.EarthTones):
|
||||
return _colorsEarth;
|
||||
case(ChartColorPalette.SemiTransparent):
|
||||
return _colorsSemiTransparent;
|
||||
case(ChartColorPalette.Berry):
|
||||
return _colorsBerry;
|
||||
case(ChartColorPalette.Chocolate):
|
||||
return _colorsChocolate;
|
||||
case(ChartColorPalette.Fire):
|
||||
return _colorsFire;
|
||||
case(ChartColorPalette.SeaGreen):
|
||||
return _colorsSeaGreen;
|
||||
case(ChartColorPalette.BrightPastel):
|
||||
return _colorsBrightPastel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,421 @@
|
||||
//-------------------------------------------------------------
|
||||
// <copyright company=<3D>Microsoft Corporation<6F>>
|
||||
// Copyright <20> Microsoft Corporation. All Rights Reserved.
|
||||
// </copyright>
|
||||
//-------------------------------------------------------------
|
||||
// @owner=alexgor, deliant
|
||||
//=================================================================
|
||||
// File: ImageLoader.cs
|
||||
//
|
||||
// Namespace: System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
|
||||
//
|
||||
// Classes: ImageLoader
|
||||
//
|
||||
// Purpose: ImageLoader utility class loads specified image and
|
||||
// caches it in the memory for the future use.
|
||||
//
|
||||
// Images can be loaded from different places including
|
||||
// Files, URIs, WebRequests and Control Resources.
|
||||
//
|
||||
// Reviewed: AG - August 7, 2002
|
||||
// AG - Microsoft 5, 2007
|
||||
//
|
||||
//===================================================================
|
||||
|
||||
|
||||
#region Used Namespaces
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Resources;
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
using System.Windows.Forms.DataVisualization.Charting;
|
||||
#else
|
||||
using System.Web;
|
||||
using System.Web.UI.DataVisualization.Charting;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
namespace System.Windows.Forms.DataVisualization.Charting.Utilities
|
||||
#else
|
||||
namespace System.Web.UI.DataVisualization.Charting.Utilities
|
||||
#endif
|
||||
{
|
||||
/// <summary>
|
||||
/// ImageLoader utility class loads and returns specified image
|
||||
/// form the File, URI, Web Request or Chart Resources.
|
||||
/// Loaded images are stored in the internal hashtable which
|
||||
/// allows to improve performance if image need to be used
|
||||
/// several times.
|
||||
/// </summary>
|
||||
internal class ImageLoader : IDisposable, IServiceProvider
|
||||
{
|
||||
#region Fields
|
||||
|
||||
// Image storage
|
||||
private Hashtable _imageData = null;
|
||||
|
||||
// Reference to the service container
|
||||
private IServiceContainer _serviceContainer = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors and Initialization
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor is not accessible.
|
||||
/// </summary>
|
||||
private ImageLoader()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default public constructor.
|
||||
/// </summary>
|
||||
/// <param name="container">Service container.</param>
|
||||
public ImageLoader(IServiceContainer container)
|
||||
{
|
||||
if(container == null)
|
||||
{
|
||||
throw(new ArgumentNullException(SR.ExceptionImageLoaderInvalidServiceContainer));
|
||||
}
|
||||
_serviceContainer = container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Image Loader service object
|
||||
/// </summary>
|
||||
/// <param name="serviceType">Requested service type.</param>
|
||||
/// <returns>Image Loader service object.</returns>
|
||||
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
|
||||
object IServiceProvider.GetService(Type serviceType)
|
||||
{
|
||||
if(serviceType == typeof(ImageLoader))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
throw (new ArgumentException( SR.ExceptionImageLoaderUnsupportedType( serviceType.ToString())));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose images in the hashtable
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_imageData != null)
|
||||
{
|
||||
foreach (DictionaryEntry entry in _imageData)
|
||||
{
|
||||
if (entry.Value is IDisposable)
|
||||
{
|
||||
((IDisposable)entry.Value).Dispose();
|
||||
}
|
||||
}
|
||||
_imageData = null;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Loads image from URL. Checks if image already loaded (cached).
|
||||
/// </summary>
|
||||
/// <param name="imageURL">Image name (FileName, URL, Resource).</param>
|
||||
/// <returns>Image object.</returns>
|
||||
public System.Drawing.Image LoadImage(string imageURL)
|
||||
{
|
||||
return LoadImage(imageURL, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads image from URL. Checks if image already loaded (cached).
|
||||
/// </summary>
|
||||
/// <param name="imageURL">Image name (FileName, URL, Resource).</param>
|
||||
/// <param name="saveImage">True if loaded image should be saved in cache.</param>
|
||||
/// <returns>Image object</returns>
|
||||
public System.Drawing.Image LoadImage(string imageURL, bool saveImage)
|
||||
{
|
||||
System.Drawing.Image image = null;
|
||||
|
||||
// Check if image is defined in the chart image collection
|
||||
if (_serviceContainer != null)
|
||||
{
|
||||
Chart chart = (Chart)_serviceContainer.GetService(typeof(Chart));
|
||||
if(chart != null)
|
||||
{
|
||||
foreach(NamedImage namedImage in chart.Images)
|
||||
{
|
||||
if(namedImage.Name == imageURL)
|
||||
{
|
||||
return namedImage.Image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create new hashtable
|
||||
if (_imageData == null)
|
||||
{
|
||||
_imageData = new Hashtable(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// First check if image with this name already loaded
|
||||
if (_imageData.Contains(imageURL))
|
||||
{
|
||||
image = (System.Drawing.Image)_imageData[imageURL];
|
||||
}
|
||||
|
||||
#if ! Microsoft_CONTROL
|
||||
|
||||
// Try to load as relative URL using the Control object
|
||||
if(image == null)
|
||||
{
|
||||
Chart control = (Chart)_serviceContainer.GetService(typeof(Chart));
|
||||
if (control != null && control.Page != null)
|
||||
{
|
||||
if (!control.IsDesignMode())
|
||||
{
|
||||
image = LoadFromFile(control.Page.MapPath(imageURL));
|
||||
}
|
||||
else if (control.IsDesignMode() && !String.IsNullOrEmpty(control.webFormDocumentURL))
|
||||
{
|
||||
// Find current web page path and fileName
|
||||
Uri pageUri = new Uri(control.webFormDocumentURL);
|
||||
string path = pageUri.LocalPath;
|
||||
string pageFile = pageUri.Segments[pageUri.Segments.Length-1];
|
||||
|
||||
// Find full image fileName
|
||||
string imageFileRelative = control.ResolveClientUrl(imageURL);
|
||||
string imageFile = path.Replace(pageFile, imageFileRelative);
|
||||
|
||||
// Load image
|
||||
image = LoadFromFile(imageFile);
|
||||
}
|
||||
}
|
||||
|
||||
else if ( HttpContext.Current != null )
|
||||
{
|
||||
image = LoadFromFile(HttpContext.Current.Request.MapPath(imageURL));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Try to load image from resource
|
||||
if(image == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// Check if resource class type was specified
|
||||
int columnIndex = imageURL.IndexOf("::", StringComparison.Ordinal);
|
||||
if (columnIndex > 0)
|
||||
{
|
||||
string resourceRootName = imageURL.Substring(0, columnIndex);
|
||||
string resourceName = imageURL.Substring(columnIndex + 2);
|
||||
System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager(resourceRootName, Assembly.GetExecutingAssembly());
|
||||
image = (System.Drawing.Image)(resourceManager.GetObject(resourceName));
|
||||
}
|
||||
#if Microsoft_CONTROL
|
||||
else if (Assembly.GetEntryAssembly() != null)
|
||||
{
|
||||
// Check if resource class type was specified
|
||||
columnIndex = imageURL.IndexOf(':');
|
||||
if (columnIndex > 0)
|
||||
{
|
||||
string resourceRootName = imageURL.Substring(0, columnIndex);
|
||||
string resourceName = imageURL.Substring(columnIndex + 1);
|
||||
System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager(resourceRootName, Assembly.GetEntryAssembly());
|
||||
image = (Image)(resourceManager.GetObject(resourceName));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to load resource from every type defined in entry assembly
|
||||
Assembly entryAssembly = Assembly.GetEntryAssembly();
|
||||
if (entryAssembly != null)
|
||||
{
|
||||
foreach (Type type in entryAssembly.GetTypes())
|
||||
{
|
||||
System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager(type);
|
||||
try
|
||||
{
|
||||
image = (Image)(resourceManager.GetObject(imageURL));
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
}
|
||||
catch (MissingManifestResourceException)
|
||||
{
|
||||
}
|
||||
|
||||
// Check if image was loaded
|
||||
if (image != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (MissingManifestResourceException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Try to load image using the Web Request
|
||||
if(image == null)
|
||||
{
|
||||
Uri imageUri = null;
|
||||
try
|
||||
{
|
||||
// Try to create URI directly from image URL (will work in case of absolute URL)
|
||||
imageUri = new Uri(imageURL);
|
||||
}
|
||||
catch(UriFormatException)
|
||||
{}
|
||||
|
||||
|
||||
// Load image from file or web resource
|
||||
if(imageUri != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
WebRequest request = WebRequest.Create(imageUri);
|
||||
image = System.Drawing.Image.FromStream(request.GetResponse().GetResponseStream());
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
}
|
||||
catch (SecurityException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#if Microsoft_CONTROL
|
||||
// absolute uri(without Server.MapPath)in web is not allowed. Loading from replative uri Server[Page].MapPath is done above.
|
||||
// Try to load as file
|
||||
if(image == null)
|
||||
{
|
||||
|
||||
image = LoadFromFile(imageURL);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Error loading image
|
||||
if(image == null)
|
||||
{
|
||||
#if ! Microsoft_CONTROL
|
||||
throw(new ArgumentException( SR.ExceptionImageLoaderIncorrectImageUrl( imageURL ) ) );
|
||||
#else
|
||||
throw(new ArgumentException( SR.ExceptionImageLoaderIncorrectImageLocation( imageURL ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
// Save new image in cache
|
||||
if(saveImage)
|
||||
{
|
||||
_imageData[imageURL] = image;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper function which loads image from file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">File name.</param>
|
||||
/// <returns>Loaded image or null.</returns>
|
||||
private System.Drawing.Image LoadFromFile(string fileName)
|
||||
{
|
||||
// Try to load image from file
|
||||
try
|
||||
{
|
||||
return System.Drawing.Image.FromFile(fileName);
|
||||
}
|
||||
catch(FileNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the image size taking the image DPI into consideration.
|
||||
/// </summary>
|
||||
/// <param name="name">Image name (FileName, URL, Resource).</param>
|
||||
/// <param name="graphics">Graphics used to calculate the image size.</param>
|
||||
/// <param name="size">Calculated size.</param>
|
||||
/// <returns>false if it fails to calculate the size, otherwise true.</returns>
|
||||
internal bool GetAdjustedImageSize(string name, Graphics graphics, ref SizeF size)
|
||||
{
|
||||
Image image = LoadImage(name);
|
||||
|
||||
if (image == null)
|
||||
return false;
|
||||
|
||||
GetAdjustedImageSize(image, graphics, ref size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the image size taking the image DPI into consideration.
|
||||
/// </summary>
|
||||
/// <param name="image">Image for whcih to calculate the size.</param>
|
||||
/// <param name="graphics">Graphics used to calculate the image size.</param>
|
||||
/// <param name="size">Calculated size.</param>
|
||||
internal static void GetAdjustedImageSize(Image image, Graphics graphics, ref SizeF size)
|
||||
{
|
||||
if (graphics != null)
|
||||
{
|
||||
//this will work in case the image DPI is specified, otherwise the image DPI will be assumed to be same as the screen DPI
|
||||
size.Width = image.Width * graphics.DpiX / image.HorizontalResolution;
|
||||
size.Height = image.Height * graphics.DpiY / image.VerticalResolution;
|
||||
}
|
||||
else
|
||||
{
|
||||
size.Width = image.Width;
|
||||
size.Height = image.Height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the image has the same DPI as the graphics object.
|
||||
/// </summary>
|
||||
/// <param name="image">Image to be checked.</param>
|
||||
/// <param name="graphics">Graphics object to be used.</param>
|
||||
/// <returns>true if they match, otherwise false.</returns>
|
||||
internal static bool DoDpisMatch(Image image, Graphics graphics)
|
||||
{
|
||||
return graphics.DpiX == image.HorizontalResolution && graphics.DpiY == image.VerticalResolution;
|
||||
}
|
||||
|
||||
internal static Image GetScaledImage(Image image, Graphics graphics)
|
||||
{
|
||||
Bitmap scaledImage = new Bitmap(image, new Size((int)(image.Width * graphics.DpiX / image.HorizontalResolution),
|
||||
(int)(image.Height * graphics.DpiY / image.VerticalResolution)));
|
||||
|
||||
return scaledImage;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,495 @@
|
||||
//-------------------------------------------------------------
|
||||
// <copyright company=<3D>Microsoft Corporation<6F>>
|
||||
// Copyright <20> Microsoft Corporation. All Rights Reserved.
|
||||
// </copyright>
|
||||
//-------------------------------------------------------------
|
||||
// @owner=alexgor, deliant
|
||||
//=================================================================
|
||||
// File: KeywordsRegistry.cs
|
||||
//
|
||||
// Namespace: System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
|
||||
//
|
||||
// Classes: KeywordsRegistry, KeywordInfo
|
||||
//
|
||||
// Purpose: A registry that keeps track of all available
|
||||
// keywords and name of the objects and properties
|
||||
// where they can be used.
|
||||
//
|
||||
// Formatting Keywords Overview:
|
||||
// -----------------------------
|
||||
// A Formatting Keyword is a specially formatted character sequence
|
||||
// that gets replaced by an associated Chart Series value, or
|
||||
// calculated value. Keywords can be used with most string properties
|
||||
// of Series and DataPoint objects.
|
||||
//
|
||||
// Here is an example of setting series labels so that the first
|
||||
// line will display the Y value and the second line displays
|
||||
// the X value.
|
||||
//
|
||||
// Chart1.Series["Series1"].Label = "Y = #VALY\nX = #VALX";
|
||||
//
|
||||
// Series label in this case will look like this:
|
||||
//
|
||||
// Y = 45.78
|
||||
// X = 456
|
||||
//
|
||||
// An optional format string can be added after the keyword.
|
||||
// For example, when you set the Format option to Percent for
|
||||
// the first Y value, the resulting keyword produced is "#VALY{P}".
|
||||
// You can also apply format strings in code-behind using the same
|
||||
// nomenclature; you do this by following the keyword with a format
|
||||
// specifier enclosed in braces. For information concerning the
|
||||
// types of formatting that can be used, see the Formatting Types
|
||||
// topic in the MSDN library.
|
||||
//
|
||||
// Reviewed: AG - Microsoft 5, 2007
|
||||
//
|
||||
//===================================================================
|
||||
|
||||
|
||||
#region Used Namespaces
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
using System.Windows.Forms.DataVisualization.Charting;
|
||||
using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
|
||||
#else
|
||||
using System.Web.UI.DataVisualization.Charting;
|
||||
using System.Web.UI.DataVisualization.Charting.ChartTypes;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
namespace System.Windows.Forms.DataVisualization.Charting.Utilities
|
||||
#else // Microsoft_CONTROL
|
||||
namespace System.Web.UI.DataVisualization.Charting.Utilities
|
||||
#endif // Microsoft_CONTROL
|
||||
{
|
||||
/// <summary>
|
||||
/// KeywordName class contains constant strings defining
|
||||
/// names of all keywords used in the data point and series classes.
|
||||
/// </summary>
|
||||
internal static class KeywordName
|
||||
{
|
||||
#region Keyword Names
|
||||
|
||||
internal const string Index = "#INDEX";
|
||||
internal const string ValX = "#VALX";
|
||||
internal const string ValY = "#VALY";
|
||||
internal const string Val = "#VAL";
|
||||
internal const string Total = "#TOTAL";
|
||||
internal const string Percent = "#PERCENT";
|
||||
internal const string Label = "#LABEL";
|
||||
internal const string AxisLabel = "#AXISLABEL";
|
||||
internal const string LegendText = "#LEGENDTEXT";
|
||||
internal const string SeriesName = "#SERIESNAME";
|
||||
internal const string Ser = "#SER";
|
||||
internal const string Avg = "#AVG";
|
||||
internal const string Max = "#MAX";
|
||||
internal const string Min = "#MIN";
|
||||
internal const string Last = "#LAST";
|
||||
internal const string First = "#FIRST";
|
||||
internal const string CustomProperty = "#CUSTOMPROPERTY";
|
||||
|
||||
#endregion // Keyword Names
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// KeywordRegistry class stores information about all
|
||||
/// chart formatting keywords. It automatically registers
|
||||
/// all known keywords when object is constructed. This
|
||||
/// data is exposed as ArrayList through the <20>registeredKeywords<64>
|
||||
/// field. Each item in this ArrayList is a KeywordInfo
|
||||
/// object which describes a single formatting keyword.
|
||||
/// </summary>
|
||||
internal class KeywordsRegistry : IServiceProvider
|
||||
{
|
||||
#region Fields
|
||||
|
||||
// List of registered keywords
|
||||
internal ArrayList registeredKeywords = new ArrayList();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor and Services
|
||||
|
||||
/// <summary>
|
||||
/// Keywords registry public constructor.
|
||||
/// </summary>
|
||||
public KeywordsRegistry()
|
||||
{
|
||||
// Register Keywords used in the chart
|
||||
RegisterKeywords();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Keywords registry service object.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">Service type to get.</param>
|
||||
/// <returns>Custom properties registry service.</returns>
|
||||
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
|
||||
object IServiceProvider.GetService(Type serviceType)
|
||||
{
|
||||
if(serviceType == typeof(KeywordsRegistry))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
throw (new ArgumentException( SR.ExceptionKeywordsRegistryUnsupportedType(serviceType.ToString())));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keywords Registering methods
|
||||
|
||||
/// <summary>
|
||||
/// Registers all chart formatting keywords.
|
||||
/// </summary>
|
||||
private void RegisterKeywords()
|
||||
{
|
||||
string seriesPointSupportedProperties = "Text,Label,LabelMapAreaAttributes,ToolTip,Url,LabelToolTip,MapAreaAttributes,AxisLabel,LegendToolTip,LegendMapAreaAttributes,LegendUrl,LegendText";
|
||||
|
||||
// #INDEX keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameIndexDataPoint,
|
||||
KeywordName.Index,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordIndexDataPoint2,
|
||||
"DataPoint",
|
||||
seriesPointSupportedProperties,
|
||||
false,
|
||||
false);
|
||||
|
||||
// #VALX keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameXValue,
|
||||
KeywordName.ValX,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordXValue,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
false);
|
||||
|
||||
// #VALY keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameYValue,
|
||||
KeywordName.Val,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordYValue,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
|
||||
// #TOTAL keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameTotalYValues,
|
||||
KeywordName.Total,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordTotalYValues,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
false);
|
||||
|
||||
// #PERCENT keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameYValuePercentTotal,
|
||||
KeywordName.Percent,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordYValuePercentTotal,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
|
||||
// #INDEX keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameIndexTheDataPoint,
|
||||
KeywordName.Index,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordIndexDataPoint,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
false,
|
||||
false);
|
||||
|
||||
// #LABEL keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameLabelDataPoint,
|
||||
KeywordName.Label,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordLabelDataPoint,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
false,
|
||||
false);
|
||||
|
||||
// #AXISLABEL keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameAxisLabelDataPoint,
|
||||
KeywordName.AxisLabel,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordAxisLabelDataPoint,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
false,
|
||||
false);
|
||||
|
||||
// #LEGENDTEXT keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameLegendText,
|
||||
KeywordName.LegendText,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordLegendText,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
false,
|
||||
false);
|
||||
|
||||
// #SERIESNAME keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameSeriesName,
|
||||
KeywordName.SeriesName,
|
||||
KeywordName.Ser,
|
||||
SR.DescriptionKeyWordSeriesName,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
false,
|
||||
false);
|
||||
|
||||
// *************** NEW KEYWORDS in version 5.5 ***************
|
||||
|
||||
// #AVG keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameAverageYValues,
|
||||
KeywordName.Avg,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordAverageYValues,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
|
||||
// #MAX keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameMaximumYValues,
|
||||
KeywordName.Max,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordMaximumYValues,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
|
||||
// #MIN keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameMinimumYValues,
|
||||
KeywordName.Min,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordMinimumYValues,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
|
||||
// #LAST keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameLastPointYValue,
|
||||
KeywordName.Last,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordLastPointYValue,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
|
||||
// #FIRST keyword
|
||||
this.Register(
|
||||
SR.DescriptionKeyWordNameFirstPointYValue,
|
||||
KeywordName.First,
|
||||
string.Empty,
|
||||
SR.DescriptionKeyWordFirstPointYValue,
|
||||
"Series,DataPoint,Annotation,LegendCellColumn",
|
||||
seriesPointSupportedProperties,
|
||||
true,
|
||||
true);
|
||||
}
|
||||
|
||||
#endregion // Keywords Registering methods
|
||||
|
||||
#region Registry methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds keyword information into the registry.
|
||||
/// </summary>
|
||||
/// <param name="name">Keyword full name.</param>
|
||||
/// <param name="keyword">Keyword text.</param>
|
||||
/// <param name="keywordAliases">Keyword alternative text.</param>
|
||||
/// <param name="description">Keyword description.</param>
|
||||
/// <param name="appliesToTypes">Comma separated list of applicable classes</param>
|
||||
/// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
|
||||
/// <param name="supportsFormatting">True if formatting is supported.</param>
|
||||
/// <param name="supportsValueIndex">True if different point Y values are supported.</param>
|
||||
public void Register(
|
||||
string name,
|
||||
string keyword,
|
||||
string keywordAliases,
|
||||
string description,
|
||||
string appliesToTypes,
|
||||
string appliesToProperties,
|
||||
bool supportsFormatting,
|
||||
bool supportsValueIndex)
|
||||
{
|
||||
// Create new keyword information object
|
||||
KeywordInfo keywordInfo = new KeywordInfo(
|
||||
name,
|
||||
keyword,
|
||||
keywordAliases,
|
||||
description,
|
||||
appliesToTypes,
|
||||
appliesToProperties,
|
||||
supportsFormatting,
|
||||
supportsValueIndex);
|
||||
|
||||
// Add keyword information to the hash table
|
||||
registeredKeywords.Add(keywordInfo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// KeywordInfo class stores information about a single
|
||||
/// formatting keyword. This information includes Name,
|
||||
/// Description, list of data types and properties it
|
||||
/// applies to and other information.
|
||||
/// </summary>
|
||||
internal class KeywordInfo
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
/// <summary>
|
||||
/// Keyword full name.
|
||||
/// </summary>
|
||||
public string Name = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// String that represent this keyword in the property (keyword).
|
||||
/// </summary>
|
||||
public string Keyword = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Comma separated strings that may alternatively represent this
|
||||
/// keyword in the property.
|
||||
/// </summary>
|
||||
public string KeywordAliases = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Keyword description.
|
||||
/// </summary>
|
||||
public string Description = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Comma separated names of classes this keyword applies to.
|
||||
/// </summary>
|
||||
public string AppliesToTypes = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Comma separated names of properties this keyword applies to.
|
||||
/// </summary>
|
||||
public string AppliesToProperties = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// True if keyword value can be formatted.
|
||||
/// </summary>
|
||||
public bool SupportsFormatting = false;
|
||||
|
||||
/// <summary>
|
||||
/// True if keyword can be used with different point Y values.
|
||||
/// </summary>
|
||||
public bool SupportsValueIndex = false;
|
||||
|
||||
#endregion // Public Fields
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Keyword information object constructor
|
||||
/// </summary>
|
||||
/// <param name="name">Keyword full name.</param>
|
||||
/// <param name="keyword">Keyword text.</param>
|
||||
/// <param name="keywordAliases">Keyword alternative text.</param>
|
||||
/// <param name="description">Keyword description.</param>
|
||||
/// <param name="appliesToTypes">Comma separated list of applicable classes</param>
|
||||
/// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
|
||||
/// <param name="supportsFormatting">True if formatting is supported.</param>
|
||||
/// <param name="supportsValueIndex">True if different point Y values are supported.</param>
|
||||
public KeywordInfo(
|
||||
string name,
|
||||
string keyword,
|
||||
string keywordAliases,
|
||||
string description,
|
||||
string appliesToTypes,
|
||||
string appliesToProperties,
|
||||
bool supportsFormatting,
|
||||
bool supportsValueIndex)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Keyword = keyword;
|
||||
this.KeywordAliases = keywordAliases;
|
||||
this.Description = description;
|
||||
this.AppliesToTypes = appliesToTypes;
|
||||
this.AppliesToProperties = appliesToProperties;
|
||||
this.SupportsFormatting = supportsFormatting;
|
||||
this.SupportsValueIndex = supportsValueIndex;
|
||||
}
|
||||
|
||||
#endregion // Constructor
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns a String that represents the current keyword Information.
|
||||
/// </summary>
|
||||
/// <returns>Returns keyword name.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an array of keywords names including the aliases.
|
||||
/// </summary>
|
||||
/// <returns>A string array of keyword names that represent this keyword.</returns>
|
||||
public string[] GetKeywords()
|
||||
{
|
||||
// NOTE: Each keyword has a unique name. In addition the keyword may have an
|
||||
// alternative names (aliases).
|
||||
// Most common scenario for a keyword aliase is when keyword has a long and
|
||||
// short form. For example, KeywordName.Ser and "#SERIES".
|
||||
|
||||
// Fill array of possible names for that keyword
|
||||
if(this.KeywordAliases.Length > 0)
|
||||
{
|
||||
string[] keywordAliases = this.KeywordAliases.Split(',');
|
||||
string[] keywordNames = new string[keywordAliases.Length + 1];
|
||||
keywordNames[0] = this.Keyword;
|
||||
keywordAliases.CopyTo(keywordNames, 1);
|
||||
return keywordNames;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new string[] { this.Keyword };
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // Methods
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,194 @@
|
||||
//-------------------------------------------------------------
|
||||
// <copyright company=<3D>Microsoft Corporation<6F>>
|
||||
// Copyright <20> Microsoft Corporation. All Rights Reserved.
|
||||
// </copyright>
|
||||
//-------------------------------------------------------------
|
||||
// @owner=alexgor, deliant
|
||||
//=================================================================
|
||||
// File: ValueConverter.cs
|
||||
//
|
||||
// Namespace: System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
|
||||
//
|
||||
// Classes: ValueConverter
|
||||
//
|
||||
// Purpose: Helper class which converts DateTime or numeric
|
||||
// values to string. It used to display data point
|
||||
// values as labels, tooltips and axis labels.
|
||||
//
|
||||
// Reviewed: AG - August 7, 2002
|
||||
// AG - Microsoft 5, 2007
|
||||
//
|
||||
//===================================================================
|
||||
|
||||
|
||||
#region Used Namespaces
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
using System.Windows.Forms.DataVisualization.Charting;
|
||||
#else
|
||||
using System.Web.UI.DataVisualization.Charting;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#if Microsoft_CONTROL
|
||||
namespace System.Windows.Forms.DataVisualization.Charting.Utilities
|
||||
#else
|
||||
namespace System.Web.UI.DataVisualization.Charting.Utilities
|
||||
#endif
|
||||
{
|
||||
/// <summary>
|
||||
/// ValueConverter class is used when numeric or DateTime
|
||||
/// value needs to be converted to a string using specified format.
|
||||
/// </summary>
|
||||
internal static class ValueConverter
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Converts value to string using specified format.
|
||||
/// </summary>
|
||||
/// <param name="chart">Reference to the chart object.</param>
|
||||
/// <param name="obj">Reference to the object being formatted.</param>
|
||||
/// <param name="objTag">Additional object tag.</param>
|
||||
/// <param name="value">Value converted to string.</param>
|
||||
/// <param name="format">Format string.</param>
|
||||
/// <param name="valueType">Value type.</param>
|
||||
/// <param name="elementType">Chart element type being formatted.</param>
|
||||
public static string FormatValue(
|
||||
Chart chart,
|
||||
object obj,
|
||||
object objTag,
|
||||
double value,
|
||||
string format,
|
||||
ChartValueType valueType,
|
||||
ChartElementType elementType)
|
||||
{
|
||||
format = format ?? String.Empty;
|
||||
string convertionFormat = format;
|
||||
string result = "";
|
||||
|
||||
// Make sure value index is part of the format
|
||||
if(convertionFormat != null && convertionFormat.Length > 0)
|
||||
{
|
||||
int bracketIndex = convertionFormat.IndexOf('{', 0);
|
||||
if(bracketIndex >= 0)
|
||||
{
|
||||
while(bracketIndex >= 0)
|
||||
{
|
||||
// If format is not followed by the value index
|
||||
if(!convertionFormat.Substring(bracketIndex).StartsWith("{0:", StringComparison.Ordinal))
|
||||
{
|
||||
// Check charcter prior to the bracket
|
||||
if(bracketIndex >= 1 && convertionFormat.Substring(bracketIndex - 1, 1) == "{")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Insert value index in format
|
||||
convertionFormat = convertionFormat.Insert(bracketIndex + 1, "0:");
|
||||
}
|
||||
}
|
||||
|
||||
bracketIndex = convertionFormat.IndexOf('{', bracketIndex + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
convertionFormat = "{0:" + convertionFormat + "}";
|
||||
}
|
||||
}
|
||||
|
||||
// Date/time formating
|
||||
if (valueType == ChartValueType.DateTime ||
|
||||
valueType == ChartValueType.DateTimeOffset ||
|
||||
valueType == ChartValueType.Date)
|
||||
{
|
||||
// Set default format
|
||||
if(convertionFormat.Length == 0)
|
||||
{
|
||||
convertionFormat = "{0:d}";
|
||||
if (valueType == ChartValueType.DateTimeOffset)
|
||||
convertionFormat += " +0";
|
||||
}
|
||||
|
||||
// Convert date to string
|
||||
result = String.Format(CultureInfo.CurrentCulture, convertionFormat, DateTime.FromOADate(value));
|
||||
}
|
||||
else if(valueType == ChartValueType.Time)
|
||||
{
|
||||
// Set default format
|
||||
if(convertionFormat.Length == 0)
|
||||
{
|
||||
convertionFormat = "{0:t}";
|
||||
}
|
||||
|
||||
// Convert date to string
|
||||
result = String.Format(CultureInfo.CurrentCulture, convertionFormat, DateTime.FromOADate(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool failedFlag = false;
|
||||
|
||||
// Set default format
|
||||
if(convertionFormat.Length == 0)
|
||||
{
|
||||
convertionFormat = "{0:G}";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Numeric value formatting
|
||||
result = String.Format(CultureInfo.CurrentCulture,convertionFormat, value);
|
||||
}
|
||||
catch(FormatException)
|
||||
{
|
||||
failedFlag = true;
|
||||
}
|
||||
|
||||
// If numeric formatting failed try to format using decimal number
|
||||
if(failedFlag)
|
||||
{
|
||||
failedFlag = false;
|
||||
try
|
||||
{
|
||||
// Decimal value formatting
|
||||
result = String.Format(CultureInfo.CurrentCulture, convertionFormat, (long)value);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
failedFlag = true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
failedFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Return format string as result (literal) if all formatting methods failed
|
||||
if(failedFlag)
|
||||
{
|
||||
result = format;
|
||||
}
|
||||
}
|
||||
|
||||
// For the Reporting Services chart a special number formatting
|
||||
// handler may be set and used for all formatting needs.
|
||||
if (chart != null)
|
||||
{
|
||||
// Call number formatter
|
||||
FormatNumberEventArgs eventArguments = new FormatNumberEventArgs(value, format, valueType, result, objTag, elementType);
|
||||
chart.CallOnFormatNumber(obj, eventArguments);
|
||||
result = eventArguments.LocalizedValue;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
000f56f2d67602c86546d8ead49dfe3f2d0009c1
|
Reference in New Issue
Block a user