Import module builder export programmatically?
I am trying to import a module builder export programmatically, but the API in Sitefinity is marked as internal: Telerik.Sitefinity.DynamicModules.Builder.ExportImport.ModuleImporter. I can read the zip file from a location in the file system, but can't import it programmatically. Any idea on how to get around this?
Hello,
I'm in the same situation, did you find a solution?
kind regards,
bob
Unfortunately I have not and ticket support had none either.
The problem is the class/method needed to do this is marked as private in the SF source code (the same method used to "import a module" from the admin.
Hello,
I found a solution, it's not 100% because we have to indeed call internal stuff, but maybe it can help someone.
private
static
void
ImportDynamicModule()
Stream zipFileAsStream = ResourceHelper.ReadResourceFile(
typeof
(InstallCmCareModule),
"CmCare.zip"
);
using
(var moduleZipFile = ZipFile.Read(zipFileAsStream))
ReflectionUtilities.CallNonPublicStatic(
typeof
(App),
"Telerik.Sitefinity.DynamicModules.Builder.ExportImport.ModuleImporter"
,
"ImportModule"
, moduleZipFile);
private
static
void
ActivateModule()
PageManager.GetManager().Provider.SuppressSecurityChecks =
true
;
ConfigManager.GetManager().Provider.SuppressSecurityChecks =
true
;
string
providerName = DynamicModuleManager.GetDefaultProviderName();
ReflectionUtilities.CallMethodOnInternalClass(
"Telerik.Sitefinity.DynamicModules.Builder.Web.Services.ContentTypeService"
,
"ActivateModule"
, Constants.Guids.CmCareModuleId.ToString(), providerName);
ConfigManager.GetManager().Provider.SuppressSecurityChecks =
false
;
PageManager.GetManager().Provider.SuppressSecurityChecks =
false
;
public
static
object
CallNonPublicStatic(Type typeFromAssembly,
string
typeToResolve,
string
methodName,
params
object
[] paramaters)
if
(
string
.IsNullOrWhiteSpace(typeToResolve))
throw
new
ArgumentNullException(
"typeToResolve"
);
if
(
string
.IsNullOrWhiteSpace(methodName))
throw
new
ArgumentNullException(
"methodName"
);
var type = typeFromAssembly.Assembly.GetType(typeToResolve);
if
(type ==
null
)
throw
new
ArgumentException(
string
.Format(
"Type '0' not found."
, typeToResolve));
MethodInfo methodInfo = type.GetMethod(methodName);
if
(methodInfo ==
null
)
throw
new
ArgumentException(
string
.Format(
"Method '0' not found on type '1'."
, methodName, typeToResolve));
return
methodInfo.Invoke(
null
, paramaters);
public
static
object
CallMethodOnInternalClass(
string
fullQualifiedName,
string
methodName,
params
object
[] parameters)
if
(
string
.IsNullOrWhiteSpace(fullQualifiedName))
throw
new
ArgumentNullException(
"fullQualifiedName"
);
if
(
string
.IsNullOrWhiteSpace(methodName))
throw
new
ArgumentNullException(
"methodName"
);
Assembly assembly =
typeof
(App).Assembly;
Type internalClass = assembly.GetType(fullQualifiedName,
true
,
true
);
if
(internalClass ==
null
)
throw
new
ArgumentException(
string
.Format(
"Type '0' not found."
, fullQualifiedName));
var instance = Activator.CreateInstance(internalClass);
MethodInfo methodInfo = instance.GetType().GetMethod(methodName);
if
(methodInfo ==
null
)
throw
new
ArgumentException(
string
.Format(
"Method '0' not found on type '1'."
, methodName, fullQualifiedName));
return
methodInfo.Invoke(instance, parameters);