+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Using a Manager (: ManagerBase<ContentProviderBase>) class outside of a web context

Using a Manager (: ManagerBase&lt;ContentProviderBase&gt;) class outside of a web context

8 posts, 1 answered
  1. Jon
    Jon avatar
    4 posts
    Registered:
    21 Oct 2010
    25 Oct 2010
    Link to this post
    We have a requirement to access implementations of ManagerBase<ContentProviderBase> outside of a running web-context. This is part of a proposed deployment process where we would want to script all updates to the database via a class prior to upgrading the code base deployed to a server. That is how it is, and is typical for large enterprise deployments that are built in house.

    I have attempted to do this by building a console application and using an implementation of the ManagerBase<ContentProviderBase> based on a the Product example. We are using that example as a basis for a Employees module (just as an example for us to build a case study around).

    I have pulled in the application's web.config into the console application's app.config yet we get the following ConfigurationErrorsException:
    "Provider with name 'Employees' has not been set"

       at Telerik.ManagerBase`1.SetProvider(String providerName)
       at Telerik.ManagerBase`1..ctor(String providerName)
       at XXX.Ww.XXX.Modules.Employees.EmployeeManager..ctor(String providerName) in C:\Projects\XXX-sitefinity-branch\src\XXX.Ww.XXX.Modules.Employees\EmployeeManager.cs:line 27
       at XXX.Ww.XXX.Modules.Employees.EmployeeManager..ctor() in C:\Projects\XXX-sitefinity-branch\src\XXX.Ww.XXX.Modules.Employees\EmployeeManager.cs:line 17
       at XXX.Ww.XXX.Tools.EmployeeExporter.Program.Main(String[] args) in C:\Projects\XXX-sitefinity-branch\src\XXX.Ww.XXX.Tools.EmployeeExporter\Program.cs:line 11
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

    This appears to be due to ConfigHelper.Handler having 0 items in it's Providers property.
    Is this a limitation on the example? Certainly the configuration mentions no specific "provider" named Employees but a "genericContentProvider(s)":

        <employees defaultGenericProvider="Employees">
          <genericContentProviders>
            <add providerName="Employees" urlRewriteFormat="[Name].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_"/>
          </genericContentProviders>
        </employees>

    This is how the Products example laid out it's stall, so to speak, but specifying a genericContentProviders.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Oct 2010
    Link to this post
    Hello Jon,

    Could you check whether you have defined a section for your provider inside <sectionGroup name="telerik"> and your provider is also declared inside <cmsEngine defaultProvider="Generic_Content"> section.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jon
    Jon avatar
    4 posts
    Registered:
    21 Oct 2010
    25 Oct 2010
    Link to this post
    Hi Ivan

    thank you for your quick response; do you know if this is possible at all as I don't really have much time to play with this issue this morning and in fact I really need to come out of this morning with an absolute response to whether we can work with Manager classes outside of the webcontext to update the database to perform data migrations.

    To answer your questons; given we're working against an example code pattern we have added the configuration as specified in the example; thus we have the following configuration in the locations you mention (namely we have renamed Product to Employee):
        <sectionGroup name="telerik">
          .......
          <section name="employees" type="XXX.Ww.XXX.Modules.Employees.Configuration.SectionHandler, XXX.Ww.XXX.Modules.Employees" requirePermission="false"/>
        </sectionGroup>
    .....

        <cmsEngine defaultProvider="Generic_Content">
          <providers>
            <clear/>
            ........
            <add name="Employees" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" securityProviderName="" allowVersioning="False" applicationName="/Employees" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data"/>
          </providers>


    Regards

    Jon
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Oct 2010
    Link to this post
    Hello Jon,

    The problem is that you are using a console application. You should call a web service through the console application that will make changes you want to apply. It would not be possible to use Sitefinity's API in a console application - there are many dependencies here.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Jon
    Jon avatar
    4 posts
    Registered:
    21 Oct 2010
    25 Oct 2010
    Link to this post
    Hi Ivan
    thank you again for responding; we are working with a limited timespan.

    We have an issue with requiring a webservice to perform this task. We perform data-migrations as part of our deployment. This is an enterprise requirement. Thus your suggestion regarding having a webservice introduces a chicken-and-egg problem requiring us to change our deployment process which given it's at an enterprise level just isn't going to happen.

    If we are to roll out a new data provider, we would require a webservice to be deployed, and once deployed, (and the site down as the data isn't registered yet) we would perform a 2nd deployment to push the code. I have provided this example to highlight the obvious issue. I must stress that changing our deployment process is not in the scope of this discussion.

    You mention "there are many dependencies" but you have not mentioned it is impossible. Is there something sealed within Sitefinitiy's code that makes working with Managers and Data Providers dependent on a running web-context?

    Kind regards

    Jon
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Oct 2010
    Link to this post
    Hi Jon,

    Sitefinity is a web project and its API is not designed to be used in a console application. There is no place where we have suggested this as a practice or as a possible solution.
    For the content items we check whether System.Web.Hosting.ApplicationManager is an object , otherwise we return false/null. Generally the API is supposed to work only for web applications. There are also license checks which will result in a trial message for the hosted application.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Jon
    Jon avatar
    4 posts
    Registered:
    21 Oct 2010
    25 Oct 2010
    Link to this post
    Hi Ivan

    thank you for your response; I really do appreciate the time you are taking out to respond to us. It is remarkable indeed :).

    So we can now discount using the API to prepare data migrations prior to the website deployment.

    Our main problem is that we really need to script, or declarative write, the loading of pages into the CMS as part of our deployment. Consider an empty environment with IIS loaded with a SQL Server somewhere. We need the ability to load up from a deployment script the code into a Website hosted on that IIS with predefined pages to be added to the initial Sitefinitiy installation without any human interaction, rather a purely scripted approach.

    So we need to be able to define pages, and structure and roles etc but not content.

    Sorry for the rush but I'm off to a meeting and will monitor this thread.

    Jon :)

  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Oct 2010
    Link to this post
    Hi Jon,

    You can create a local project with several pages and then export the project as a template by using the built-in Export tool located under Administration section. Then on each installation you can import this template or you can use database replication tool which will port all data from your predefined project.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
Register for webinar
8 posts, 1 answered