using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.IO.Compression;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;

namespace Super2d3dGraphLibrary;

public class SettingsFactory
{
	private Super2d3dGraph _chart;

	private string code;

	private CODE_LANGUAGE lang;

	private string term;

	private string newKW;

	private string s;

	public SettingsFactory(Super2d3dGraph chart)
	{
		_chart = chart;
	}

	private string m_WriteDateTime(DateTime d)
	{
		return "#" + Conversions.ToString(d.Month) + "/" + Conversions.ToString(d.Day) + "/" + Conversions.ToString(d.Year) + "#";
	}

	private string m_WriteNumber(object s)
	{
		return m_WriteNumber(s.ToString());
	}

	private string m_WriteNumber(double s)
	{
		return m_WriteNumber(s.ToString());
	}

	private string m_WriteNumber(string s)
	{
		return s.Replace(",", ".");
	}

	private void m_SaveSetting(string name, Type type, object obj, string arrayPropName)
	{
		if (obj == null)
		{
			s += "  <item type=\"Nothing\" />";
			code = Conversions.ToString(Operators.ConcatenateObject(code, Interaction.IIf(lang == CODE_LANGUAGE.VBNET, "Nothing", "null")));
			return;
		}
		if ((Operators.CompareString(name, "", TextCompare: false) == 0) & Information.IsArray(RuntimeHelpers.GetObjectValue(obj)))
		{
			name = "array";
		}
		if (Operators.CompareString(name, "", TextCompare: false) != 0)
		{
			s = s + "<" + name;
			code = Conversions.ToString(Operators.ConcatenateObject(code, Interaction.IIf(lang == CODE_LANGUAGE.VBNET, "  ." + name + " =", "chart." + name + " =")));
		}
		checked
		{
			if (Information.IsArray(RuntimeHelpers.GetObjectValue(obj)))
			{
				int length = ((Array)obj).Length;
				s = s + " type=\"" + type.Name + "\" count=\"" + Conversions.ToString(length) + "\">\r\n";
				if (lang == CODE_LANGUAGE.VBNET)
				{
					code = code + " " + newKW + " " + type.Name.Replace("[]", "()");
				}
				else
				{
					code = code + " " + newKW + " " + type.Name;
				}
				code += " {";
				if (Operators.CompareString(type.Name, "ArrayList[]", TextCompare: false) == 0)
				{
					int num = length;
					for (int i = 1; i <= num; i++)
					{
						if (i > 1)
						{
							code += ", ";
						}
						if (lang == CODE_LANGUAGE.VBNET)
						{
							code = code + "" + newKW + " ArrayList()";
						}
						else
						{
							code = code + "" + newKW + " ArrayList[]";
						}
					}
				}
				else
				{
					int num2 = length;
					for (int j = 1; j <= num2; j++)
					{
						object objectValue = RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(obj, new object[1] { j - 1 }, null));
						if (j > 1)
						{
							code += ", ";
						}
						if (objectValue == null)
						{
							m_SaveSetting("", null, null, name);
							continue;
						}
						m_SaveSetting("", objectValue.GetType(), RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(obj, new object[1] { j - 1 }, null)), name);
					}
				}
				code = code + "}" + term + "\r\n";
				if (Operators.CompareString(type.Name, "ArrayList[]", TextCompare: false) == 0)
				{
					int num3 = length;
					for (int k = 1; k <= num3; k++)
					{
						object objectValue2 = RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(obj, new object[1] { k - 1 }, null));
						if (lang == CODE_LANGUAGE.VBNET)
						{
							code = code + "  ." + name + "(" + Conversions.ToString(k - 1) + ") = " + newKW + " ArrayList()" + term + "\r\n";
						}
						else
						{
							code = code + "chart." + name + "[" + Conversions.ToString(k - 1) + "] = " + newKW + " ArrayList[]" + term + "\r\n";
						}
						if (objectValue2 == null)
						{
							m_SaveSetting("", null, null, name);
							continue;
						}
						m_SaveSetting("", objectValue2.GetType(), RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(obj, new object[1] { k - 1 }, null)), name + "(" + Conversions.ToString(k - 1) + ")");
					}
				}
				if (Operators.CompareString(name, "", TextCompare: false) != 0)
				{
					s = s + "</" + name + ">\r\n";
				}
				return;
			}
			if (Operators.CompareString(type.Name, "ArrayList", TextCompare: false) == 0)
			{
				int count = ((ArrayList)obj).Count;
				s = s + "<array type=\"ArrayList\" count=\"" + Conversions.ToString(count) + "\">\r\n";
				int num4 = count;
				for (int l = 1; l <= num4; l++)
				{
					code = Conversions.ToString(Operators.ConcatenateObject(code, Interaction.IIf(lang == CODE_LANGUAGE.VBNET, "  ." + arrayPropName + ".Add(", "chart." + arrayPropName + ".Add(")));
					object objectValue3 = RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(obj, new object[1] { l - 1 }, null));
					if (objectValue3 == null)
					{
						m_SaveSetting("", null, null, arrayPropName);
					}
					else
					{
						m_SaveSetting("", objectValue3.GetType(), RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(obj, new object[1] { l - 1 }, null)), arrayPropName);
					}
					code = code + ")" + term + "\r\n";
				}
				s += "</array>\r\n";
				return;
			}
			if (Operators.CompareString(name, "", TextCompare: false) == 0)
			{
				s += "  <item";
			}
			switch (type.Name)
			{
			case "Pen":
				s = s + " type=\"" + type.Name + "\" color=\"" + Conversions.ToString(((Pen)obj).Color.ToArgb()) + "\" width=\"" + Conversions.ToString(((Pen)obj).Width) + "\"";
				code = code + "" + newKW + " Pen(Color.FromArgb(" + Conversions.ToString(((Pen)obj).Color.ToArgb()) + "), " + Conversions.ToString(((Pen)obj).Width) + ")";
				break;
			case "Font":
			{
				Font font = (Font)obj;
				s = s + " type=\"" + type.Name + "\" family=\"" + font.FontFamily.ToString() + "\" size=\"" + m_WriteNumber(font.Size) + "\"";
				code = code + "" + newKW + " Font(\"" + font.FontFamily.ToString() + "\", " + m_WriteNumber(font.Size) + ")";
				break;
			}
			case "String":
				s = s + " type=\"" + type.Name + "\" value=\"" + obj.ToString() + "\"";
				code = code + "\"" + obj.ToString() + "\"";
				break;
			case "Integer":
			case "Long":
			case "Int32":
			case "Int64":
				s = s + " type=\"" + type.Name + "\" value=\"" + obj.ToString() + "\"";
				code += obj.ToString();
				break;
			case "Single":
			case "Double":
				s = s + " type=\"" + type.Name + "\" value=\"" + obj.ToString().Replace(",", ".") + "\"";
				code += m_WriteNumber(obj.ToString());
				break;
			case "Boolean":
				s = s + " type=\"" + type.Name + "\"";
				if (Conversions.ToBoolean(obj))
				{
					s += " value=\"-1\"";
					code += "True";
				}
				else
				{
					s += " value=\"0\"";
					code += "False";
				}
				break;
			case "Size":
			{
				Size size = default(Size);
				Size size2 = ((obj != null) ? ((Size)obj) : size);
				s = s + " type=\"" + type.Name + "\" width=\"" + Conversions.ToString(size2.Width) + "\" height=\"" + Conversions.ToString(size2.Height) + "\"";
				code = code + "" + newKW + " Size(" + m_WriteNumber(size2.Width) + "," + m_WriteNumber(size2.Height);
				break;
			}
			case "Rectangle":
			{
				Rectangle rectangle = default(Rectangle);
				Rectangle rectangle2 = ((obj != null) ? ((Rectangle)obj) : rectangle);
				s = s + " type=\"" + type.Name + "\" left=\"" + Conversions.ToString(rectangle2.Left) + "\" top=\"" + Conversions.ToString(rectangle2.Top) + "\" width=\"" + Conversions.ToString(rectangle2.Width) + "\" height=\"" + Conversions.ToString(rectangle2.Height) + "\"";
				code = code + "" + newKW + " Rectangle(" + m_WriteNumber(rectangle2.Left) + "," + m_WriteNumber(rectangle2.Top) + "," + m_WriteNumber(rectangle2.Width) + "," + m_WriteNumber(rectangle2.Height) + ")";
				break;
			}
			case "Bitmap":
			{
				MemoryStream memoryStream = new MemoryStream();
				((Bitmap)obj).Save(memoryStream, ImageFormat.Png);
				s = s + " type=\"" + type.Name + "\" src=\"" + Convert.ToBase64String(memoryStream.GetBuffer(), Base64FormattingOptions.None) + "\"";
				code = code + "" + newKW + " Bitmap() ' TODO: add code to load bitmap content";
				break;
			}
			case "DateTime":
			{
				DateTime d = Conversions.ToDate(obj);
				s = s + " type=\"" + type.Name + "\" value=\"" + d.ToString("yyMMddHHmmss") + "\"";
				code += m_WriteDateTime(d);
				break;
			}
			case "SolidBrush":
				s = s + " type=\"" + type.Name + "\" color=\"" + Conversions.ToString(((SolidBrush)obj).Color.ToArgb()) + "\"";
				code = code + "" + newKW + " SolidBrush(Color.FromArgb(" + Conversions.ToString(((SolidBrush)obj).Color.ToArgb()) + "))";
				break;
			case "Color":
			{
				string[] array = new string[6] { s, " type=\"", type.Name, "\" color=\"", null, null };
				Color color = default(Color);
				array[4] = Conversions.ToString(((obj != null) ? ((Color)obj) : color).ToArgb());
				array[5] = "\"";
				s = string.Concat(array);
				code = code + "Color.FromArgb(" + Conversions.ToString(((obj != null) ? ((Color)obj) : color).ToArgb()) + ")";
				break;
			}
			default:
				if (obj != null && ((Operators.CompareString(Strings.Left(obj.GetType().ToString(), 14), "Super2d3dGraph", TextCompare: false) == 0) | (Operators.CompareString(Strings.Left(obj.GetType().ToString(), 6), "System", TextCompare: false) == 0)))
				{
					s = s + " type=\"Integer\" value=\"" + Conversions.ToString(int.Parse(Conversions.ToString(obj))) + "\"";
					code = code + obj.GetType().Name + "." + obj.ToString();
				}
				break;
			}
			s += " />\r\n";
			if (Operators.CompareString(name, "", TextCompare: false) != 0)
			{
				code = code + term + "\r\n";
			}
		}
	}

	private void m_Collect(bool discardData)
	{
		Super2d3dGraph component = new Super2d3dGraph();
		PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(_chart);
		PropertyDescriptorCollection properties2 = TypeDescriptor.GetProperties(component);
		properties = properties.Sort();
		s = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<settings>\r\n";
		code = "";
		ArrayList arrayList = new ArrayList();
		arrayList.Add("Settings");
		arrayList.Add("Image");
		if (discardData)
		{
			arrayList.Add("Series");
		}
		arrayList.Add("Width");
		arrayList.Add("Height");
		arrayList.Add("Top");
		arrayList.Add("Left");
		arrayList.Add("AutoRefresh");
		arrayList.Add("ChartInnerRectangle");
		checked
		{
			foreach (PropertyDescriptor item in properties)
			{
				if (!(!item.IsReadOnly & item.PropertyType.IsSerializable & (Operators.CompareString(item.ComponentType.Name, "Super2d3dGraph", TextCompare: false) == 0) & !arrayList.Contains(item.Name)))
				{
					continue;
				}
				object objectValue = RuntimeHelpers.GetObjectValue(item.GetValue(_chart));
				bool flag = objectValue != null;
				if (flag)
				{
					flag = Operators.CompareString(item.Name, "SeriesBorderStyle", TextCompare: false) != 0;
				}
				if (flag && _chart.Style != STYLE2D3D.STYLE2D_PICTURES)
				{
					flag = Operators.CompareString(item.Name, "SeriesPictures", TextCompare: false) != 0;
				}
				if (flag && _chart.Style != STYLE2D3D.STYLE2D_GANTT)
				{
					flag = Operators.CompareString(item.Name.Substring(0, 5), "Gantt", TextCompare: false) != 0;
				}
				if (flag && _chart.Style != STYLE2D3D.STYLE2D_GAUGE)
				{
					flag = Operators.CompareString(item.Name.Substring(0, 5), "Gauge", TextCompare: false) != 0;
				}
				if (flag && !_chart.IsPie)
				{
					flag = Operators.CompareString(item.Name, "ItemsHighlight", TextCompare: false) != 0;
				}
				if (flag && Operators.CompareString(item.Name, "HotSpotTooltips", TextCompare: false) == 0)
				{
					flag = false;
					ArrayList[] array = (ArrayList[])item.GetValue(_chart);
					int num = array.Length - 1;
					for (int i = 1; i <= num; i++)
					{
						int count = array[i].Count;
						for (int j = 1; j <= count; j++)
						{
							if (Operators.ConditionalCompareObjectNotEqual(array[i - 1][j - 1], "$$", TextCompare: false))
							{
								flag = true;
								break;
							}
						}
					}
				}
				if (!flag)
				{
					continue;
				}
				foreach (PropertyDescriptor item2 in properties2)
				{
					if (Operators.CompareString(item2.Name, item.Name, TextCompare: false) == 0)
					{
						object objectValue2 = RuntimeHelpers.GetObjectValue(item2.GetValue(component));
						if (objectValue2 == null)
						{
							break;
						}
						if (objectValue2.Equals(RuntimeHelpers.GetObjectValue(objectValue)))
						{
							flag = false;
							break;
						}
					}
				}
				if (flag)
				{
					m_SaveSetting(item.Name, item.GetValue(_chart).GetType(), RuntimeHelpers.GetObjectValue(objectValue), "");
				}
			}
			s += "</settings>";
		}
	}

	private object m_ReadObject(XmlTextReader xr)
	{
		string attribute = xr.GetAttribute("type");
		checked
		{
			if (attribute != null)
			{
				object obj = null;
				string familyName = "Arial";
				object obj2 = null;
				byte[] buffer = null;
				obj = xr.GetAttribute("family");
				if (obj != null)
				{
					familyName = Conversions.ToString(obj);
				}
				obj = xr.GetAttribute("size");
				float emSize = default(float);
				if (obj != null)
				{
					emSize = Conversions.ToSingle(obj);
				}
				obj = xr.GetAttribute("color");
				Color color = default(Color);
				if (obj != null)
				{
					color = Color.FromArgb(Conversions.ToInteger(obj));
				}
				obj = xr.GetAttribute("width");
				float num = default(float);
				if (obj != null)
				{
					num = Conversions.ToSingle(obj);
				}
				obj = xr.GetAttribute("height");
				float num2 = default(float);
				if (obj != null)
				{
					num2 = Conversions.ToSingle(obj);
				}
				obj = xr.GetAttribute("top");
				float num3 = default(float);
				if (obj != null)
				{
					num3 = Conversions.ToSingle(obj);
				}
				obj = xr.GetAttribute("left");
				float num4 = default(float);
				if (obj != null)
				{
					num4 = Conversions.ToSingle(obj);
				}
				obj = xr.GetAttribute("value");
				if (obj != null)
				{
					obj2 = RuntimeHelpers.GetObjectValue(obj);
				}
				obj = xr.GetAttribute("src");
				if (obj != null)
				{
					buffer = Convert.FromBase64String(Conversions.ToString(obj));
				}
				switch (attribute)
				{
				case "Pen":
				{
					Pen pen = new Pen(color);
					pen.Width = num;
					return pen;
				}
				case "Double":
					return Conversion.Val(RuntimeHelpers.GetObjectValue(obj2));
				case "Single":
					return Convert.ToSingle(Conversion.Val(RuntimeHelpers.GetObjectValue(obj2)));
				case "Int32":
				case "Integer":
					return Convert.ToInt32(Conversion.Val(RuntimeHelpers.GetObjectValue(obj2)));
				case "Int64":
				case "Long":
					return Convert.ToInt64(Conversion.Val(RuntimeHelpers.GetObjectValue(obj2)));
				case "Bitmap":
				{
					MemoryStream stream = new MemoryStream(buffer);
					return new Bitmap(stream);
				}
				case "ArrayList":
				{
					ArrayList arrayList = new ArrayList();
					int num6 = int.Parse(xr.GetAttribute("count"));
					object[] array3 = new object[num6 - 1 + 1];
					object array2 = array3;
					m_ReadArray("array", xr, ref array2);
					array3 = (object[])array2;
					int num7 = num6;
					for (int i = 1; i <= num7; i++)
					{
						arrayList.Add(RuntimeHelpers.GetObjectValue(array3[i - 1]));
					}
					return arrayList;
				}
				case "Object[]":
				{
					int num5 = int.Parse(xr.GetAttribute("count"));
					object[] array = new object[num5 - 1 + 1];
					object array2 = array;
					m_ReadArray("array", xr, ref array2);
					return (object[])array2;
				}
				case "SolidBrush":
					return new SolidBrush(color);
				case "Color":
					return color;
				case "Boolean":
					return Operators.CompareObjectEqual(obj2, "-1", TextCompare: false);
				case "DateTime":
				{
					string text = obj2.ToString();
					int year = Convert.ToInt32(text.Substring(0, 2));
					int month = Convert.ToInt32(text.Substring(2, 2));
					int day = Convert.ToInt32(text.Substring(4, 2));
					int hour = Convert.ToInt32(text.Substring(6, 2));
					int minute = Convert.ToInt32(text.Substring(8, 2));
					int second = Convert.ToInt32(text.Substring(10, 2));
					DateTime dateTime = new DateTime(year, month, day, hour, minute, second);
					return dateTime;
				}
				case "Rectangle":
				{
					Rectangle rectangle = new Rectangle((int)Math.Round(num4), (int)Math.Round(num3), (int)Math.Round(num), (int)Math.Round(num2));
					return rectangle;
				}
				case "Font":
					return new Font(familyName, emSize);
				default:
					return obj2;
				}
			}
			return null;
		}
	}

	private void m_ReadArray(string propName, XmlTextReader xr, ref object array)
	{
		int num = 0;
		while (xr.Read() && !((xr.NodeType == XmlNodeType.EndElement) & (Operators.CompareString(xr.Name, propName, TextCompare: false) == 0)))
		{
			if (xr.NodeType == XmlNodeType.Element)
			{
				NewLateBinding.LateIndexSet(array, new object[2]
				{
					num,
					RuntimeHelpers.GetObjectValue(m_ReadObject(xr))
				}, null);
				num = checked(num + 1);
			}
		}
	}

	private byte[] CompressByte(byte[] byteSource)
	{
		MemoryStream memoryStream = new MemoryStream();
		GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Compress, leaveOpen: true);
		gZipStream.Write(byteSource, 0, byteSource.Length);
		gZipStream.Dispose();
		memoryStream.Position = 0L;
		byte[] array = new byte[checked((int)memoryStream.Length + 1)];
		memoryStream.Read(array, 0, array.Length);
		memoryStream.Dispose();
		return array;
	}

	private byte[] DecompressByte(byte[] byteCompressed)
	{
		checked
		{
			byte[] result;
			try
			{
				MemoryStream memoryStream = new MemoryStream(byteCompressed);
				GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress);
				byte[] array = new byte[4];
				memoryStream.Position = memoryStream.Length - 5;
				memoryStream.Read(array, 0, 4);
				int num = BitConverter.ToInt32(array, 0);
				memoryStream.Position = 0L;
				byte[] array2 = new byte[num - 1 + 1];
				gZipStream.Read(array2, 0, num);
				gZipStream.Dispose();
				memoryStream.Dispose();
				result = array2;
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				result = null;
				ProjectData.ClearProjectError();
			}
			return result;
		}
	}

	public void Apply(string settings, bool discardData = true)
	{
		byte[] byteCompressed = Convert.FromBase64String(settings);
		ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
		_chart.Reset(discardData);
		m_Apply(aSCIIEncoding.GetString(DecompressByte(byteCompressed)), discardData);
	}

	private void m_Apply(string s, bool discardData)
	{
		bool autoRefresh = _chart.AutoRefresh;
		_chart.AutoRefresh = false;
		StringReader stringReader = new StringReader(s);
		XmlTextReader xmlTextReader = new XmlTextReader(stringReader);
		while (xmlTextReader.Read())
		{
			if (xmlTextReader.NodeType != XmlNodeType.Element)
			{
				continue;
			}
			string attribute = xmlTextReader.GetAttribute("type");
			if (attribute == null)
			{
				continue;
			}
			string name = xmlTextReader.Name;
			if (!((Operators.CompareString(name, "Series", TextCompare: false) != 0) | (Operators.CompareString(name, "Series", TextCompare: false) == 0 && !discardData)))
			{
				continue;
			}
			object obj = null;
			checked
			{
				if (attribute.EndsWith("[]"))
				{
					int num = (int)Math.Round(Conversions.ToDouble(xmlTextReader.GetAttribute("count")) - 1.0);
					switch (attribute.Substring(0, attribute.Length - 2))
					{
					case "Pen":
					{
						Pen[] array9 = new Pen[num + 1];
						object array2 = array9;
						m_ReadArray(name, xmlTextReader, ref array2);
						array9 = (Pen[])array2;
						obj = array9;
						break;
					}
					case "Single":
					{
						float[] array8 = new float[num + 1];
						object array2 = array8;
						m_ReadArray(name, xmlTextReader, ref array2);
						array8 = (float[])array2;
						obj = array8;
						break;
					}
					case "Image":
					{
						Bitmap[] array7 = new Bitmap[num + 1];
						object array2 = array7;
						m_ReadArray(name, xmlTextReader, ref array2);
						array7 = (Bitmap[])array2;
						break;
					}
					case "String":
					{
						string[] array6 = new string[num + 1];
						object array2 = array6;
						m_ReadArray(name, xmlTextReader, ref array2);
						array6 = (string[])array2;
						obj = array6;
						break;
					}
					case "ArrayList":
					{
						ArrayList[] array5 = new ArrayList[num + 1];
						object array2 = array5;
						m_ReadArray(name, xmlTextReader, ref array2);
						array5 = (ArrayList[])array2;
						obj = array5;
						break;
					}
					case "Brush":
					{
						Brush[] array4 = new Brush[num + 1];
						object array2 = array4;
						m_ReadArray(name, xmlTextReader, ref array2);
						array4 = (Brush[])array2;
						obj = array4;
						break;
					}
					case "SolidBrush":
					{
						SolidBrush[] array3 = new SolidBrush[num + 1];
						object array2 = array3;
						m_ReadArray(name, xmlTextReader, ref array2);
						array3 = (SolidBrush[])array2;
						obj = array3;
						break;
					}
					case "Color":
					{
						Color[] array = new Color[num + 1];
						object array2 = array;
						m_ReadArray(name, xmlTextReader, ref array2);
						array = (Color[])array2;
						obj = array;
						break;
					}
					}
				}
				else
				{
					obj = RuntimeHelpers.GetObjectValue(m_ReadObject(xmlTextReader));
				}
				PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(_chart);
				foreach (PropertyDescriptor item in properties)
				{
					if (Operators.CompareString(item.Name, name, TextCompare: false) == 0)
					{
						item.SetValue(_chart, RuntimeHelpers.GetObjectValue(obj));
						break;
					}
				}
			}
		}
		xmlTextReader.Close();
		stringReader.Close();
		_chart.AutoRefresh = autoRefresh;
		if (!autoRefresh)
		{
			_chart.RefreshChart();
		}
	}

	public string GetSettings(bool discardData = true)
	{
		m_Collect(discardData);
		ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
		byte[] bytes = aSCIIEncoding.GetBytes(s);
		return Convert.ToBase64String(CompressByte(bytes));
	}

	public string GetCode(CODE_LANGUAGE language)
	{
		lang = language;
		if (language == CODE_LANGUAGE.CSHARP)
		{
			term = ";";
			newKW = "new";
		}
		else
		{
			term = "";
			newKW = "New";
		}
		m_Collect(discardData: true);
		string text;
		if (language == CODE_LANGUAGE.VBNET)
		{
			text = "With Super2d3dGraph1   ' TODO: change \"Super2d3dGraph1\" name if neccesary\r\n  .AutoRefresh = False\r\n" + code + "\r\n  ' Chart data\r\n";
			text += "  Dim sf as New SeriesFactory\r\n";
		}
		else
		{
			text = "// TODO: change \"chart\" name if neccesary\r\nchart.AutoRefresh = false;\r\n" + code + "\r\n// Chart data\r\n";
			text += "SeriesFactory sf = new SeriesFactory();\r\n";
		}
		SeriesFactory seriesFactory = new SeriesFactory();
		int num = _chart.Series.Length;
		checked
		{
			for (int i = 1; i <= num; i++)
			{
				if (i > 1)
				{
					text = text + "  sf.NewSerie()" + term + "\r\n";
				}
				int count = _chart.Series[i - 1].Count;
				for (int j = 1; j <= count; j++)
				{
					switch (_chart.Style)
					{
					case STYLE2D3D.STYLE2D_BUBBLE:
						text = text + "  sf.AddBubble(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 2 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_CANDLESTICK:
						text = text + "  sf.AddHighLowOpenClose(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 2 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 3 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_GANTT:
						text = text + "  sf.AddTask(" + m_WriteDateTime(Conversions.ToDate(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteDateTime(Conversions.ToDate(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 2 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_HIGHLOWCLOSE:
						text = text + "  sf.AddHighLowClose(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 2 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_HIGHLOW:
						text = text + "  sf.AddHighLow(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_XY_DATETIME:
					case STYLE2D3D.STYLE2D_XY_LINE_DATETIME:
						text = text + "  sf.AddDateTimeValue(" + m_WriteDateTime(Conversions.ToDate(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_XY:
					case STYLE2D3D.STYLE2D_XY_SPLINE:
						text = text + "  sf.AddPoint(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ")";
						break;
					case STYLE2D3D.STYLE2D_XY_SPLINE_DEV:
						text = text + "  sf.AddPoint(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 0 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ", " + m_WriteNumber(RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(_chart.Series[i - 1][j - 1], new object[1] { 1 }, null))) + ")";
						break;
					default:
						text = text + "  sf.AddValue(" + m_WriteNumber(RuntimeHelpers.GetObjectValue(_chart.Series[i - 1][j - 1])) + ")";
						break;
					}
					text += ";\r\n";
				}
			}
			if (language == CODE_LANGUAGE.VBNET)
			{
				text += "  sf.ApplyTo(Super2d3dGraph1)\r\n";
				return text + "End With\r\n";
			}
			return text + "  sf.ApplyTo(chart);\r\n";
		}
	}
}
