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

Forums / Developing with Sitefinity / Libraries, access to base from derived class

Libraries, access to base from derived class

3 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    17 Feb 2010
    Link to this post
    Hi,

    I build one extension for Libraries. I use base class DefaultProvider as base to CustomDefaultProvider and override some methods like SaveContent. This is working perfect in App_Code but in external projects i can't cast the base.SaveContent. Exist some way to cast the base from derived class or instantiate the Default provider. 

    public class CustomDefaultProvider : Telerik.Libraries.Data.DefaultProvider 
    {
         public override void SaveContent(IContent content, bool fireEvents) 
        { 
        CmsContentBase contentBase = null; 
        if (content is CmsContentBase) 
        { 
            contentBase = (CmsContentBase)content; 
        } 
        else 
        {   
            contentBase = this.SetContentBase(content); 
        }     ......
        base.SaveContent(contentBase as IContent, fireEvents); //<--NO CAST base
    }

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Feb 2010
    Link to this post
    Hello Pierre,

    You do not have to use the CmsContentBase and then cast it to content object contentBase = (CmsContentBase)content;  , because you already have the IContent item as a parameter.

    Since you inheriting from the default provider I do not see why you are overriding SaveContent from the base and then calling the same method. Generally you should do this when you want to persist some other parameters to the object or alter the transaction

    sample

    public override void SaveContent(IContent content, bool fireEvents)
          {
              if (content == null)
                  throw new ArgumentNullException("content");
     
              lock (this)
              {
               
                  cntBase = (CmsContentBase)content;
     
                  IOdbClass odb = (IOdbClass)cntBase;
                  if (odb.Provider != this.odbProvider)
                      throw new InvalidOperationException("ItemBelongsToOtherProvider");
     
                  Transaction tran = odb.CurrentTransaction;
                  if (tran == null)
                  {
                      tran = new Transaction();
                      if (odb.CurrentState == OdbObjectStates.Uninitialized)
                          tran.Create(odb, this.odbProvider);
                      else
                          tran.Join(odb);
                  }
                  if (fireEvents)
                  {
                      EventExecuteController eec = new EventExecuteController(this, odb, content.ID, typeof(IContent), "Content");
                  }
                  else
                  {
                      cntBase.ContentVersion.isSilentChange = true;
                  }
     
                  if (cntBase.NeedToUpdateAllVersions)
                  {
                      cntBase.ContentVersions.ForEach(delegate(ContentVersion cv) { tran.Join(cv); });
                  }
                   
                  tran.Commit();
              }
          }



    Greetings,
    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. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    18 Feb 2010
    Link to this post
    Hi Ivan,

    Many times in place of override the complete class i prefer instate the initial steps and joint the base for the end of job make by you, or but my custom code later the base class to make one complementary save for some data. This is working is app_codes but is more complex in applications where call the base class from one derived is more difficult.

    inheriting : DefaultProvider
    protected override ClassName(params)
    {
         Customcode
         base.ClassName(params) //base is DefaultProvider in this case
    }

    Some way to call base from one derived class?, if you use THIS is ok for compil but after add this dll in the sf solution THIS not have the correct signification and only call the derived class and not the base.
    regards, Romi.
Register for webinar
3 posts, 0 answered