Developer forum

Forum » Integration » Make it easier to work with base classes like DynamicwebProvider

Make it easier to work with base classes like DynamicwebProvider

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I think this should go into the Feature Requests forum, but I wanted to discuss it here first. We have some custom code that inherits DynamicwebProvider. The use case is fairly simple: execute a stored procedure before and after the job runs. It's fairly simple to implement, but requires a lot of code duplication. For example, saving settings looks like this:

 public override void SaveAsXml(XmlTextWriter xmlTextWriter)
{
    // Ideally we wouldn't need to duplicate all of these here..  But the way it's written I don't see how.
    xmlTextWriter.WriteElementString("RemoveMissingAfterImport", RemoveMissingAfterImport.ToString(CultureInfo.CurrentCulture));
    xmlTextWriter.WriteElementString("DeactivateMissingProducts", DeactivateMissingProducts.ToString(CultureInfo.CurrentCulture));
    xmlTextWriter.WriteElementString("DeleteIncomingItems", DeleteIncomingItems.ToString(CultureInfo.CurrentCulture));

    xmlTextWriter.WriteElementString("SqlConnectionString", SqlConnectionString);
    xmlTextWriter.WriteElementString("Shop", Shop);
    xmlTextWriter.WriteElementString("UpdateSearchIndexAfterImport", IsFullProductIndexUpdate.ToString(CultureInfo.CurrentCulture));
    xmlTextWriter.WriteElementString("ProductIndexUpdate", ProductIndexUpdate);
    xmlTextWriter.WriteElementString("DeleteProductsAndGroupForSpecificLanguage", DeleteProductsAndGroupForSpecificLanguage.ToString(CultureInfo.CurrentCulture));
    xmlTextWriter.WriteElementString("DefaultLanguage", DefaultLanguage);
    xmlTextWriter.WriteElementString("RepositoriesIndexUpdate", RepositoriesIndexUpdate);

    xmlTextWriter.WriteElementString("StoredProcBefore", StoredProcBefore);
    xmlTextWriter.WriteElementString("StoredProcAfter", StoredProcAfter);


    GetSchema().SaveAsXml(xmlTextWriter);
}

I really just care about the two lines that set the stored procedure names. All the other stuff is ideally hidden in the base class. Same goes for methods like Serialize and RunJob. I need to implement / duplicate quote a lot of stuff from the base class to make this all work.

Can we make this a bit more extensible and provide just a few hooks (LoadSettings, SaveSettings, OnBeforeRun, OnAfterRon or so) that I could tap into and leave everything else up to the base class?

Thanks!

Imar


Replies

 
Jonas Krarup Dam
Reply

Hi Imar,

I think it's possible to do your "extra" lines, and then call the base method. basically just do:

 public override void SaveAsXml(XmlTextWriter xmlTextWriter)
{

    xmlTextWriter.WriteElementString("StoredProcBefore", StoredProcBefore);
    xmlTextWriter.WriteElementString("StoredProcAfter", StoredProcAfter);


 base.SaveAsXml(xmlTextWriter);
}

Have you tried this?

Regards, Jonas

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I haven't, but it sounds good. Will give it a try. What about the other methods like Serialze? Those seem to still require more knowledge than needed to build your own provider.

Thanks,

Imar

 
Jonas Krarup Dam
Reply

I agree that they make custom provider development, but they are required in order for the configurableAddin functionality to work - without them, the GUI for configuring source/destination settings will not work.

I like your idea for addin some hooks that would be called if implemented, to simplify tasks like this, but I don't think it's a priority right now.

I'll add it to the backlog for later :-)

Regards, Jonas

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Great, thank you!

 

You must be logged in to post in the forum