private static T CreateItem <T>(Type type, IPluginOption pluginOption, int prio, IServiceProvider serviceProvider, string key) where T : IPlugin { if (!(typeof(T).IsAssignableFrom(type))) { return(default(T)); } object plugin = null; try { plugin = ActivatorUtilities.CreateInstance(serviceProvider, type, new object[] { pluginOption }); } catch { plugin = ActivatorUtilities.CreateInstance(serviceProvider, type); } T item = (T)plugin; item.Priority = prio; item.Key = key; return(item); }
public void CopyItemCallback(IItem sourceItem, IItem destinationParentItem, IItem destinationItem) { if (_PluginOptions[0].Value == "False") { return; } if (_MethodInfos == null || (_MethodInfos != null && _MethodInfos.Count == 0)) { return; } string templateName = _PluginOptions[1].Value; string fieldName = _PluginOptions[2].Value; string[] templateNames = templateName.ToLower().Split(','); foreach (IItem sourceTemplate in sourceItem.Templates) { //If Item match our Template //if (!String.IsNullOrEmpty(templateName) && !String.IsNullOrEmpty(fieldName) && sourceItem.Template.Key == templateName.ToLower()) if (templateNames != null && templateNames.Length > 0 && !String.IsNullOrEmpty(fieldName) && templateNames.Contains <string>(sourceTemplate.Key)) { //Get Field that matches our FieldName. FieldName is assumed unique. IField foundField = null; try { foundField = sourceItem.Fields.Last <IField>(currentField => (currentField.Key.Equals(fieldName.ToLower()))); } catch { } if (foundField != null) { string inputFieldValue = foundField.Content; //Looking for FieldValue-Conversion Methods for (int i = 3; i < _PluginOptions.Length; i++) { IPluginOption pluginOption = _PluginOptions[i]; if (pluginOption.Type == PluginOptionTypes.CheckBox && !pluginOption.Value.Equals("False")) { //Get the MethodInfo MethodInfo currentMethod = _MethodInfos[pluginOption.Name]; if (currentMethod != null) { object[] arguments = new object[] { inputFieldValue }; string convertedFieldValue = currentMethod.Invoke(this, arguments).ToString(); //Using conversion method to convert field //Store the converted field into destination Field. FieldName is assumed unique. IField destinationField = destinationItem.Fields.Last <IField>(currentField => (currentField.Key.Equals(fieldName.ToLower()))); if (destinationField != null) { destinationField.Content = convertedFieldValue; } } } } } } } }
public void CopyItemCallback(IItem sourceItem, IItem destinationParentItem, IItem destinationItem) { if (_PluginOptions[0].Value == "False") { return; } if (_MethodInfos == null || (_MethodInfos != null && _MethodInfos.Count == 0)) { return; } //Looking for FieldValue-Conversion Methods for (int i = 1; i < _PluginOptions.Length; i++) { IPluginOption pluginOption = _PluginOptions[i]; if (pluginOption.Type == PluginOptionTypes.CheckBox && !pluginOption.Value.Equals("False")) { //Get the MethodInfo MethodInfo currentMethod = _MethodInfos[pluginOption.Name]; if (currentMethod != null) { object[] arguments = new object[] { sourceItem, destinationParentItem, destinationItem }; bool invoked = (bool)currentMethod.Invoke(this, arguments); //Calling Custom Converter Plugin } } } //If Item match our Template //if (!String.IsNullOrEmpty(templateName) && !String.IsNullOrEmpty(fieldName) && sourceItem.Template.Key == templateName.ToLower()) //if (templateNames != null && templateNames.Length > 0 && !String.IsNullOrEmpty(fieldName) && templateNames.Contains<string>(sourceItem.Template.Key)) //{ // //Get Field that matches our FieldName. FieldName is assumed unique. // IField foundField = null; // try // { // foundField = sourceItem.Fields.Last<IField>(currentField => (currentField.Key.Equals(fieldName.ToLower()))); // } // catch { } // if (foundField != null) // { // string inputFieldValue = foundField.Content; // //Looking for FieldValue-Conversion Methods // for (int i = 3; i < _PluginOptions.Length; i++) // { // IPluginOption pluginOption = _PluginOptions[i]; // if (pluginOption.Type == PluginOptionTypes.CheckBox && !pluginOption.Value.Equals("False")) // { // //Get the MethodInfo // MethodInfo currentMethod = _MethodInfos[pluginOption.Name]; // if (currentMethod != null) // { // object[] arguments = new object[] { inputFieldValue }; // string convertedFieldValue = currentMethod.Invoke(this, arguments).ToString(); //Using conversion method to convert field // //Store the converted field into destination Field. FieldName is assumed unique. // IField destinationField = destinationItem.Fields.Last<IField>(currentField => (currentField.Key.Equals(fieldName.ToLower()))); // if (destinationField != null) // destinationField.Content = convertedFieldValue; // } // } // } // } //} }