Build errors in custom plugin after upgrade to 3.1

Posts   
 
    
K10
User
Posts: 7
Joined: 26-Apr-2011
# Posted on: 12-May-2011 16:12:57   

Hi,

I'm currently using the 2.6 version of LLBLGen and decided to upgrade into 3.1. I'm having problems with my custom plugin solution though. My plugin inherits from SD.LLBLGen.Pro.ApplicationCore.Extensibility.PluginBase. There are 3 problems:

  1. In the code I use a loop to go through all EntityDefinition in base.Entities. I need an access to all additional interfaces and remove also. That's why my code uses this property: e.AdditionalInterfaces. But that property is no longer existing. The only thing I found is e.GetAdditionalInterfaces(..) but it returns me an IEnumerable of strings. So I can't remove any relation. How in 3.1 should I get the interface to be able to remove if neccesery?

  2. I loop in code all relations using EntityDefinition.Relations property but again, it's no longer present in 3.1 version. How can I get access to relations of EntityDefinition?

  3. I was creating an sql connection in my code using this line:

SqlConnection conn = new SqlConnection(base.ProjectToTarget.ConnectionString);

but it gives me compile error as Project class has no longer the ConnectionString property.

What do you suggest to have that all working in 3.1 version?

Regards

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 12-May-2011 21:03:40   

Hi There

I've asked one of the dev team to respond to your message, so someone should be back to you shortly. In the mean time, please could you expand a bit on what your plugin is trying to acheive - this will enable us to point you towards the functionality that you need for 3.1

Thanks

Matt

K10
User
Posts: 7
Joined: 26-Apr-2011
# Posted on: 13-May-2011 09:36:11   

My plugin is adding an implementation of some interfaces to proper entities. It also connects to DB and generates some files we use further. This is how our Excecute method looks:


public override void Execute()
      {
         base.ProgressTaskStart("Processing entities");
         base.ProgressSubtaskInit(base.Entities.Count + 9);

         foreach (EntityDefinition e in base.Entities)
         {          
            base.ProgressSubtaskStart("Processing entity: " + e.Name);

            ////////////////// --- The AdditionalInterfaces no longer exists  ---- /////////////////////            
            if (e.AdditionalInterfaces.Contains("ISupportsDescriptionTranslation"))
               e.AdditionalInterfaces.Remove("ISupportsDescriptionTranslation");

            if (e.AdditionalInterfaces.Contains("IDataProfileLink"))
               e.AdditionalInterfaces.Remove("IDataProfileLink");

            if (e.AdditionalInterfaces.Contains("ISupportsDataProfileBase"))
               e.AdditionalInterfaces.Remove("ISupportsDataProfileBase");

            if (e.AdditionalInterfaces.Contains("ISupportsDataProfile"))
               e.AdditionalInterfaces.Remove("ISupportsDataProfile");

            ////////////////// --- Realtions property no longer exists  ---- /////////////////////          
            foreach (EntityRelation er in e.Relations)
            {
               #region Support Translation
               if (Control.SupportTranslation)
               {
                  if (er.RelationEndPoint.Target.Name.ToUpper() == "Descriptions".ToUpper() && er.RelationStartPoint.Target.Name != "DescriptionValues")                    
                     if (er.FkFields != null && er.FkFields.Count > 0 && er.FkFields[0].FieldName.ToUpper() == "DescriptionId".ToUpper())
                     {
                        e.AdditionalInterfaces.Add("ISupportsDescriptionTranslation");
                        base.LogLineToApplicationOutput(string.Format("Added ISupportsDescriptionTranslation Interface to '{0}'", e.Name), "ISupportsDescriptionTranslation", true, true);
                     }
               }
               #endregion

               #region DataProfileLink
               if (er.RelationEndPoint.TargetName.ToUpper() == "DataProfiles".ToUpper() && er.RelationType == EntityRelationType.ManyToOne)
               {
                  e.AdditionalInterfaces.Add("IDataProfileLink");
                  base.LogLineToApplicationOutput(string.Format("Added IDataProfileLink Interface to '{0}'", e.Name), "IDataProfileLink", true, true);
               }
               #endregion

               #region SupportsDataProfileBase en SupportsDataProfile
               if (er.RelationType == EntityRelationType.OneToMany)
               {
                  foreach (EntityRelation subEr in er.RelationEndPoint.Relations)
                  {
                     //Only add these interfaces once! (For Login it would be added twice!)
                     if (e.AdditionalInterfaces.Contains("ISupportsDataProfile"))
                        continue;

                     if (subEr.RelationType == EntityRelationType.ManyToOne && subEr.RelationEndPoint.TargetName.ToUpper() == "DataProfiles".ToUpper() && subEr.RelationEndPoint.Name != e.Name)
                     {
                        e.AdditionalInterfaces.Add("ISupportsDataProfileBase");
                        e.AdditionalInterfaces.Add("ISupportsDataProfile");
                        base.LogLineToApplicationOutput(string.Format("Added ISupportsDataProfile and ISupportsDataProfileBase interfaces to '{0}'", e.Name), "ISupportsDataProfile", true, true);
                     }
                  }
               }
               #endregion
            }

            #region ID and Version
            if (Control.IdAndVersion)
            {
               if (!e.AdditionalInterfaces.Contains("IIdAndVersion"))
               {
                  e.AdditionalInterfaces.Add("IIdAndVersion");
                  base.LogLineToApplicationOutput(string.Format("Added IIdAndVersion Interface to '{0}'", e.Name), "IDInterfacePlugin", true, true);
               }
            }
            #endregion

            #region ISupportsAuditing
            if (Control.SupportsAuditing)
            {
               if (!e.AdditionalInterfaces.Contains("ISupportsAuditing"))
               {
                  e.AdditionalInterfaces.Add("ISupportsAuditing");
                  base.LogLineToApplicationOutput(string.Format("Added ISupportsAuditing Interface to '{0}'", e.Name), "IDInterfacePlugin", true, true);
               }
            }
            #endregion

            base.ProgressSubtaskComplete();
         }

         ////////////////// --- ConnectionString property no longer exists  ---- /////////////////////
         SqlConnection conn = new SqlConnection(base.ProjectToTarget.ConnectionString);

         #region Generate ExceptionKeys
         if (Control.ExceptionKeys)
         {
            base.ProgressSubtaskStart("Generating Exception keys");

            SqlDataAdapter da = new SqlDataAdapter("select SUBSTRING(T.TranslationKey, 3, LEN(T.TranslationKey) - 2), T.TranslationKey from core.Errors E, core.Translations T where E.TranslationID = T.TranslationID order by T.TranslationKey", conn);
            WriteCodeFile(da, CodeFile.ExceptionKeys);

            base.ProgressSubtaskComplete();
         }
         #endregion

         #region Generate TranslationKeys
         if (Control.TranslationKeys)
         {
            base.ProgressSubtaskStart("Generating Translation keys");

            SqlDataAdapter da = new SqlDataAdapter("select TranslationKey, TranslationKey from core.Translations", conn);
            WriteCodeFile(da, CodeFile.TranslationKeys);

            base.ProgressSubtaskComplete();
         }
         #endregion

         #region Generate Messages (DeviceMessage, ProcessMessages, TimeCalculationMessages ...)
         if (Control.Messages)
         {
            #region DeviceMessages
            base.ProgressSubtaskStart("Generating Device Messages");

            SqlDataAdapter da = new SqlDataAdapter("SELECT Code, Code as Description FROM core.Messages WHERE discriminator = 'DeviceMessage' ORDER BY Code", conn);
            WriteCodeFile(da, CodeFile.DeviceMessages);

            base.ProgressSubtaskComplete();
            #endregion

            #region DeviceMessageCodes
            base.ProgressSubtaskStart("Generating Device Messages Codes");

            da = new SqlDataAdapter("SELECT Code, Code as Description, BitNumber FROM core.Messages WHERE discriminator = 'DeviceMessage' AND BitNumber > 0 ORDER BY BitNumber", conn);
            WriteCodeFile(da, CodeFile.DeviceMessageCodes);

            base.ProgressSubtaskComplete();
            #endregion

            #region Process Messages
            base.ProgressSubtaskStart("Generating ProcessMessages");

            da = new SqlDataAdapter("SELECT Code, Code as Description FROM core.Messages WHERE discriminator = 'ProcessMessage' ORDER BY Code", conn);
            WriteCodeFile(da, CodeFile.ProcessMessages);

            base.ProgressSubtaskComplete();
            #endregion

            #region TimeCalculationMessages
            base.ProgressSubtaskStart("Generating TimeCalculationMessages");

            da = new SqlDataAdapter("SELECT Code, Code as Description FROM core.Messages WHERE discriminator = 'TimeCalculationMessage' ORDER BY Code", conn);
            WriteCodeFile(da, CodeFile.TimeCalculationMessages);

            base.ProgressSubtaskComplete();
            #endregion
         }
         #endregion

         #region Generate Trace Switches
         if (Control.TraceSwitches)
         {
            base.ProgressSubtaskStart("Generating Trace Switches");

            SqlDataAdapter da = new SqlDataAdapter("select ts.Name, ts.Description, ts.Framework from core.TraceSwitches ts order by ts.Name", conn);
            WriteTraceSwitches(da, CodeFile.TraceSwitches);

            base.ProgressSubtaskComplete();
         }
         #endregion

         #region Generate Features
         if (Control.GenerateFeatures)
         {
            base.ProgressSubtaskStart("Genereating Features Code file");

            SqlDataAdapter da = new SqlDataAdapter("select f.featureKey, tv.value from core.features f left outer join core.translations t on f.descriptionid = t.translationid left outer join core.translationvalues tv on t.translationId = tv.TranslationID left outer join core.languages l on l.languageId = tv.languageId where l.name = 'en' order by f.featureKey", conn);
            WriteCodeFile(da, CodeFile.Features);

            base.ProgressSubtaskComplete();
         }
         #endregion

         #region Generate Roles
         if (Control.GenerateRoles)
         {
            base.ProgressSubtaskStart("Genereating Roles Code file");

            SqlDataAdapter da = new SqlDataAdapter("select r.rolekey, tv.value from core.roles r left outer join core.translations t on r.descriptionid = t.translationid left outer join core.translationvalues tv on t.translationid = tv.translationid left outer join core.languages l on l.languageid = tv.languageid where l.name = 'en' order by r.rolekey", conn);
            WriteCodeFile(da, CodeFile.Roles);

            base.ProgressSubtaskComplete();
         }
         #endregion

         base.ProgressTaskComplete();
      }

If some other details are needed please let me know.

Regards

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 13-May-2011 11:41:24   

For details on all answers, see as well the reference manual for the designer assemblies.

K10 wrote:

Hi, I'm currently using the 2.6 version of LLBLGen and decided to upgrade into 3.1. I'm having problems with my custom plugin solution though. My plugin inherits from SD.LLBLGen.Pro.ApplicationCore.Extensibility.PluginBase. There are 3 problems:

  1. In the code I use a loop to go through all EntityDefinition in base.Entities. I need an access to all additional interfaces and remove also. That's why my code uses this property: e.AdditionalInterfaces. But that property is no longer existing. The only thing I found is e.GetAdditionalInterfaces(..) but it returns me an IEnumerable of strings. So I can't remove any relation. How in 3.1 should I get the interface to be able to remove if neccesery?

Every 'GroupableModelElement' (entity, valuetype, typedview) has a property called OutputSettingValues, which is an OutputSettingValuesContainer (see Ref manual of designer assemblies). In there, you'll find additional interfaces, attributes and the like for the entity. However, at the project level, users can also define additional interfaces, namespaces and attributes for the 'entity' type, which are then inherited by all entities. So from the looks of it, you want to remove interfaces from the entity objects, not the ones inherited by all. You can do so directly on the OutputSettingValues.

  1. I loop in code all relations using EntityDefinition.Relations property but again, it's no longer present in 3.1 version. How can I get access to relations of EntityDefinition?

Relationships are 'edges' in the graph returned my project.EntityModel. The easiest way to get relationships for entity X is to ask the project, using project.GetAllRelationshipsForEntity(entity, bool).

  1. I was creating an sql connection in my code using this line: SqlConnection conn = new SqlConnection(base.ProjectToTarget.ConnectionString);

but it gives me compile error as Project class has no longer the ConnectionString property.

What do you suggest to have that all working in 3.1 version? Regards

Connection strings aren't stored in the project, they're created on the fly: oroject.CreateConnectionStringForDatabase(driverID). The DriverID is the ID for the database driver for the database, e.g. the driverid for the sqlserver driver is "2D18D138-1DD2-467E-86CC-4838250611AE" (string value). You can find the driver id's in the driver.config files .

Frans Bouma | Lead developer LLBLGen Pro