/// <summary> /// Handles the Click event of the SaveButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveButton_Click(object sender, System.EventArgs e) { // Validate form if (!this.Page.IsValid) { ((Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs)e).RunScript = false; return; } string name = Name.Text; string friendlyName = FriendlyName.Text; string description = Description.Text; int parentId = int.Parse(DdlObjectType.SelectedValue); MetaClass mcParent = MetaClass.Load(MDContext, parentId); if (mcParent != null) { MetaClass mc = MetaClass.Create(MDContext, Namespace + ".User", name, friendlyName, String.Format("{0}{1}{2}", mcParent.Name, "Ex_", name), parentId, false, description); } else { // throw some exception here } }
public virtual void TestBasic() { //--Basics //(succeed) MetaClass.Create("java.lang.String"); NUnit.Framework.Assert.AreEqual(MetaClass.Create("java.lang.String").CreateInstance("hello"), "hello"); //(fail) try { MetaClass.Create(Class + "$SomethingWrapper").CreateInstance("hello"); } catch (MetaClass.ClassCreationException) { NUnit.Framework.Assert.IsTrue(true, "Should not instantiate Super with String"); } //--Argument Length MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.Something(), new MetaClassTest.Something(), new MetaClassTest.Something()); NUnit.Framework.Assert.AreEqual(((MetaClassTest.ManyConstructors)MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.Something())).ConstructorInvoked(), new MetaClassTest.ManyConstructors(new MetaClassTest.Something ()).ConstructorInvoked()); NUnit.Framework.Assert.AreEqual(((MetaClassTest.ManyConstructors)MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.Something(), new MetaClassTest.Something())).ConstructorInvoked(), new MetaClassTest.ManyConstructors (new MetaClassTest.Something(), new MetaClassTest.Something()).ConstructorInvoked()); NUnit.Framework.Assert.AreEqual(((MetaClassTest.ManyConstructors)MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.Something(), new MetaClassTest.Something(), new MetaClassTest.Something())).ConstructorInvoked(), new MetaClassTest.ManyConstructors(new MetaClassTest.Something(), new MetaClassTest.Something(), new MetaClassTest.Something()).ConstructorInvoked()); NUnit.Framework.Assert.AreEqual(new MetaClassTest.ManyConstructors(new string("hi")), MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new string("hi"))); NUnit.Framework.Assert.AreEqual(new MetaClassTest.ManyConstructors(new MetaClassTest.Something()), MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.Something())); NUnit.Framework.Assert.AreEqual(new MetaClassTest.ManyConstructors(new MetaClassTest.SSomething()), MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.SSomething())); NUnit.Framework.Assert.AreEqual(new MetaClassTest.ManyConstructors(new MetaClassTest.SubSSomething()), MetaClass.Create(Class + "$ManyConstructors").CreateInstance(new MetaClassTest.SubSSomething())); }
private static MetaClass LoadMetaClassVersion10(XmlNode xmlMetaClass, MetaClass parent) { string Name = xmlMetaClass.SelectSingleNode("Name").InnerXml; MetaClass mc = MetaClass.Load(Name); if (mc == null) { mc = MetaClass.Create(xmlMetaClass.SelectSingleNode("Namespace").InnerXml, Name, xmlMetaClass.SelectSingleNode("FriendlyName").InnerXml, xmlMetaClass.SelectSingleNode("TableName").InnerXml, parent, (MetaClassType)Enum.Parse(typeof(MetaClassType), xmlMetaClass.SelectSingleNode("MetaClassType").InnerXml), xmlMetaClass.SelectSingleNode("Description").InnerXml); } else { if (mc.FriendlyName != xmlMetaClass.SelectSingleNode("FriendlyName").InnerXml) { mc.FriendlyName = xmlMetaClass.SelectSingleNode("FriendlyName").InnerXml; } if (mc.Description != xmlMetaClass.SelectSingleNode("Description").InnerXml) { mc.Description = xmlMetaClass.SelectSingleNode("Description").InnerXml; } } string FieldListChangedSqlScript = xmlMetaClass.SelectSingleNode("FieldListChangedSqlScript").InnerXml; if (!string.IsNullOrEmpty(FieldListChangedSqlScript) && mc.FieldListChangedSqlScript != FieldListChangedSqlScript) { mc.FieldListChangedSqlScript = FieldListChangedSqlScript; } else { if (mc.FieldListChangedSqlScript != null) { mc.FieldListChangedSqlScript = null; } } string strTag = xmlMetaClass.SelectSingleNode("Tag").InnerXml; if (!string.IsNullOrEmpty(strTag)) { mc.Tag = Convert.FromBase64String(strTag); } else { if (mc.Tag != null) { mc.Tag = null; } } return(mc); }
/// <summary> /// Creates the classes. /// </summary> private static void CreateClasses() { // Create main class MetaClass metaClass = MetaClass.Load(OrderContext.MetaDataContext, "OrderGroup"); if (metaClass == null) { metaClass = MetaClass.Create(OrderContext.MetaDataContext, "OrderGroup", "Order Group", "OrderGroup", 0, true, "OrderGroup Class"); } // create purchase order class MetaClass purchaseOrderClass = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.PurchaseOrderClass.Name); if (purchaseOrderClass == null) { purchaseOrderClass = MetaClass.Create(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.PurchaseOrderClass.Name, "Purchase Order Class", "OrderGroup_PurchaseOrder", metaClass, MetaClassType.User, "Purchase Order Class"); } MetaField field = MetaField.Load(OrderContext.MetaDataContext, "TrackingNumber"); if (field == null) { field = MetaField.Create(OrderContext.MetaDataContext, "Mediachase.Commerce.Orders", "TrackingNumber", "Tracking Number", "Allows one to specify tracking number for the order", MetaDataType.ShortString, 50, true, false, false, true, false); } if (!purchaseOrderClass.UserMetaFields.Contains(field)) { purchaseOrderClass.AddField(field); } // create cart class MetaClass cartOrderClass = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.ShoppingCartClass.Name); if (cartOrderClass == null) { cartOrderClass = MetaClass.Create(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.ShoppingCartClass.Name, "Cart Order Class", "OrderGroup_ShoppingCart", metaClass, MetaClassType.User, "Cart Order Class"); } // Create System Order Info class MetaClass orderFormClass = MetaClass.Load(OrderContext.MetaDataContext, "OrderForm"); if (orderFormClass == null) { orderFormClass = MetaClass.Create(OrderContext.MetaDataContext, "OrderForm", "Order Form", "OrderForm", 0, true, "OrderForm Class"); } // create purchase order class MetaClass orderFormExClass = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.OrderFormClass.Name); if (orderFormExClass == null) { purchaseOrderClass = MetaClass.Create(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.OrderFormClass.Name, "Order Form Ex Class", "OrderFormEx", orderFormClass, MetaClassType.User, "Order Form Ex Class"); } BackupMetaData(); }
private void CreateMetaClass(MetaDataContext mdContext, string parentName, string metaDataNamespace, string name, string tableName, string description) { MetaClass parentClass = MetaClass.Load(mdContext, parentName); if (MetaClass.Load(mdContext, name) == null) { MetaClass.Create(mdContext, metaDataNamespace, name, name, tableName, parentClass, false, description); } }
private MetaClass GetOrCreateMetaClass(MetaDataContext mdContext, string metaNamespace, string className, string friendlyName, string tableName, string parentClass) { var mc = MetaClass.Load(mdContext, className); if (mc == null) { Logger.Debug(string.Format("Creating MetaClass '{0}' for Paypal payment integration.", className)); var parent = MetaClass.Load(mdContext, parentClass); mc = MetaClass.Create(mdContext, metaNamespace, className, friendlyName, tableName, parent, false, string.Empty); } return(mc); }
public virtual void TestInheritance() { //--Implementing Class try { object o = MetaClass.Create(Class + "$SomethingWrapper").CreateInstance(new MetaClassTest.Something()); NUnit.Framework.Assert.IsTrue(o is MetaClassTest.SomethingWrapper, "Returned class should be a SomethingWrapper"); NUnit.Framework.Assert.AreEqual(((MetaClassTest.SomethingWrapper)o).Display(), "something"); } catch (MetaClass.ClassCreationException e) { Sharpen.Runtime.PrintStackTrace(e); NUnit.Framework.Assert.IsFalse(true, "Should not exception on this call"); } //--Implementing super class try { object o = MetaClass.Create(Class + "$SomethingWrapper").CreateInstance(new MetaClassTest.SInstSomething()); NUnit.Framework.Assert.IsTrue(o is MetaClassTest.SomethingWrapper, "Returned class should be a SomethingWrapper"); NUnit.Framework.Assert.AreEqual(((MetaClassTest.SomethingWrapper)o).DisplayS(), "Ssomething"); } catch (MetaClass.ClassCreationException e) { Sharpen.Runtime.PrintStackTrace(e); NUnit.Framework.Assert.IsFalse(true, "Should not exception on this call"); } //--Implementing abstract classes try { object o = MetaClass.Create(Class + "$SomethingWrapper").CreateInstance(new MetaClassTest.AInstSomething()); NUnit.Framework.Assert.IsTrue(o is MetaClassTest.SomethingWrapper, "Returned class should be a SomethingWrapper"); NUnit.Framework.Assert.AreEqual(((MetaClassTest.SomethingWrapper)o).DisplayA(), "Asomething"); } catch (MetaClass.ClassCreationException e) { Sharpen.Runtime.PrintStackTrace(e); NUnit.Framework.Assert.IsFalse(true, "Should not exception on this call"); } //--Implementing interfaces try { object o = MetaClass.Create(Class + "$SomethingWrapper").CreateInstance(new MetaClassTest.IInstSomething()); NUnit.Framework.Assert.IsTrue(o is MetaClassTest.SomethingWrapper, "Returned class should be a SomethingWrapper"); NUnit.Framework.Assert.AreEqual(((MetaClassTest.SomethingWrapper)o).DisplayI(), "Isomething"); } catch (MetaClass.ClassCreationException e) { Sharpen.Runtime.PrintStackTrace(e); NUnit.Framework.Assert.IsFalse(true, "Should not exception on this call"); } }
private static void AddProjectType(string ProjectTypeName) { using (DbTransaction tran = DbTransaction.Begin()) { int ProjectTypeId = DBProject.AddProjectType(ProjectTypeName); string MetaClassName = String.Format("ProjectsEx_{0}", ProjectTypeId); MetaClass metaProjectTypeEx = MetaClass.Create(MetaClassName, ProjectTypeName, MetaClassName, MetaClass.Load("Projects"), false, "Project Type Extension"); RebuildProjectsSearch(metaProjectTypeEx); tran.Commit(); } }
/// <summary>Run Redwood with SLF4J if available, otherwise with stderr logging at the error only level.</summary> /// <returns> /// A redwood configuration. Remember to call /// <see cref="Apply()"/> /// . /// </returns> public static RedwoodConfiguration ErrorLevel() { RedwoodConfiguration config; try { MetaClass.Create("org.slf4j.LoggerFactory").CreateInstance(); config = new RedwoodConfiguration().Clear().Handlers(RedwoodConfiguration.Handlers.Chain(RedwoodConfiguration.Handlers.showOnlyError, RedwoodConfiguration.Handlers.slf4j)); } catch (Exception) { config = new RedwoodConfiguration().Clear().Handlers(RedwoodConfiguration.Handlers.Chain(RedwoodConfiguration.Handlers.showOnlyError, RedwoodConfiguration.Handlers.stderr)); } return(config); }
public virtual void TestPrimitives() { // pass a value as a class MetaClass.Create(Class + "$Primitive").CreateInstance(7); MetaClass.Create(Class + "$Primitive").CreateInstance(System.Convert.ToDouble(7)); // pass a value as a primitive MetaClass.Create(Class + "$Primitive").CreateInstance(7); MetaClass.Create(Class + "$Primitive").CreateInstance(2.8); //(fail) try { MetaClass.Create(Class + "$Primitive").CreateInstance(7L); } catch (MetaClass.ClassCreationException) { NUnit.Framework.Assert.IsTrue(true, "Should not be able to case Long int Primitive()"); } }
private MetaClass CreatePaymentMetaClass(MetaDataContext mdContext, string metaClassNameSpace, string name) { string text1 = name; string text2 = name; string text3 = "Imported"; MetaClass parentMetaClass = MetaClass.Load(mdContext, "OrderFormPayment"); MetaClass metaClass = MetaClass.Load(mdContext, name); if (metaClass == null) { metaClass = MetaClass.Create(mdContext, metaClassNameSpace + ".User", text1, text2, string.Format("{0}{1}{2}", (object)name, (object)"Ex_", (object)text1), parentMetaClass, false, text3); } return(metaClass); }
public virtual void TestConsistencyWithJava() { object[] options = new object[] { new string("hi"), new MetaClassTest.Something(), new MetaClassTest.SSomething(), new MetaClassTest.SubSSomething() }; /* * Single Term */ //--Cast everything as an object foreach (object option in options) { MetaClassTest.ManyConstructors @ref = new MetaClassTest.ManyConstructors(option); MetaClassTest.ManyConstructors test = (MetaClassTest.ManyConstructors)MetaClass.Create(Class + "$ManyConstructors").CreateFactory(typeof(object)).CreateInstance(option); NUnit.Framework.Assert.AreEqual(@ref.ConstructorInvoked(), test.ConstructorInvoked()); } //--Use native types for (int i = 0; i < options.Length; i++) { MetaClassTest.ManyConstructors @ref = MakeRef(i); MetaClassTest.ManyConstructors test = (MetaClassTest.ManyConstructors)MetaClass.Create(Class + "$ManyConstructors").CreateInstance(options[i]); NUnit.Framework.Assert.AreEqual(@ref, test); } /* * Multi Term */ //--Use native types for (int i_1 = 0; i_1 < options.Length; i_1++) { for (int j = 0; j < options.Length; j++) { MetaClassTest.ManyConstructors @ref = MakeRef(i_1, j); MetaClassTest.ManyConstructors test = (MetaClassTest.ManyConstructors)MetaClass.Create(Class + "$ManyConstructors").CreateInstance(options[i_1], options[j]); NUnit.Framework.Assert.AreEqual(@ref, test); } } }