V2 plugin for unchecking nullable type checkbox in the works

Posts   
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Jul-2006 17:19:46   

As a lot of people have problems with migrating a v1.0 project to v2.0 when it comes to nullable types (which are enabled by default and cumbersome to switch off), we'll be releasing a plugin which will make this very simple. The plugin will toggle the generate as nullable type flag for all entity fields which are a value type and nullable. By default, when you migrate an v1.0 project to v2.0, this flag is automatically set to true, which can be cumbersome to undo as you then have to uncheck the checkbox for all fields manually.

This plugin will be added to the normal set of plugins in the next build of the designer and to the SDK sourcecode. We hope to have the plugin ready tomorrow. (thursday)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Jul-2006 18:05:44   

Ok, plugin is done. Turned out to be very simple. The code will be rolled into the installer and SDK in the next build, which is likely tomorrow.

For the impatient people among us (ain't we all?) the code is posted below.

BulkSetGenerateAsNullableTypeFlagsControl.designer.cs


namespace SD.LLBLGen.Pro.Plugins
{
    partial class BulkSetGenerateAsNullableTypeFlagsControl
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if(disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this._actionComboBox = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(13, 11);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(87, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Action to perform";
            // 
            // _actionComboBox
            // 
            this._actionComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this._actionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this._actionComboBox.FormattingEnabled = true;
            this._actionComboBox.Items.AddRange(new object[] {
            "Set all \'Generate as Nullable Type\' flags to false",
            "Set all \'Generate as Nullable Type\' flags to true",
            "Toggle all \'Generate as Nullable Type\' flags"});
            this._actionComboBox.Location = new System.Drawing.Point(106, 8);
            this._actionComboBox.Name = "_actionComboBox";
            this._actionComboBox.Size = new System.Drawing.Size(308, 21);
            this._actionComboBox.TabIndex = 1;
            this._actionComboBox.SelectedIndexChanged += new System.EventHandler(this._actionComboBox_SelectedIndexChanged);
            // 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label2.Location = new System.Drawing.Point(13, 48);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(401, 33);
            this.label2.TabIndex = 0;
            this.label2.Text = "Note: non-value typed entity fields are not affected as these aren\'t generated as" +
                " a Nullable type anyway.";
            // 
            // BulkSetGenerateAsNullableTypeFlagsControl
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this._actionComboBox);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Name = "BulkSetGenerateAsNullableTypeFlagsControl";
            this.Size = new System.Drawing.Size(429, 230);
            this.Load += new System.EventHandler(this.BulkSetGenerateAsNullableTypeFlagsControl_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.ComboBox _actionComboBox;
        private System.Windows.Forms.Label label2;
    }
}

BulkSetGenerateAsNullableTypeFlagsControl.resx


<?xml version="1.0" encoding="utf-8"?>
<root>
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="metadata">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
              </xsd:sequence>
              <xsd:attribute name="name" use="required" type="xsd:string" />
              <xsd:attribute name="type" type="xsd:string" />
              <xsd:attribute name="mimetype" type="xsd:string" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="assembly">
            <xsd:complexType>
              <xsd:attribute name="alias" type="xsd:string" />
              <xsd:attribute name="name" type="xsd:string" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
</root>

BulkSetGenerateAsNullableTypeFlagsControl.cs


//////////////////////////////////////////////////////////////////////
// Public Class definitions for the Plugins assembly of LLBLGen Pro.
// (c) 2002-2006 Solutions Design, all rights reserved.
// http://www.llblgen.com/
//////////////////////////////////////////////////////////////////////
// The sourcecode for this plug-in is released as BSD2 licensed open source, so licensees and others can
// modify, update, extend or use it to write other plug-ins. 
//////////////////////////////////////////////////////////////////////
// COPYRIGHTS:
// Copyright (c)2002-2006 Solutions Design. All rights reserved.
// 
// This LLBLGen Pro Plug-in is released under the following license: (BSD2)
// -------------------------------------------------------------------------
// Redistribution and use in source and binary forms, with or without modification, 
// are permitted provided that the following conditions are met: 
//
// 1) Redistributions of source code must retain the above copyright notice, this list of 
//  conditions and the following disclaimer. 
// 2) Redistributions in binary form must reproduce the above copyright notice, this list of 
//  conditions and the following disclaimer in the documentation and/or other materials 
//  provided with the distribution. 
// 
// THIS SOFTWARE IS PROVIDED BY SOLUTIONS DESIGN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOLUTIONS DESIGN OR CONTRIBUTORS BE LIABLE FOR 
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
//
// The views and conclusions contained in the software and documentation are those of the authors 
// and should not be interpreted as representing official policies, either expressed or implied, 
// of Solutions Design. 
//
//////////////////////////////////////////////////////////////////////
// Contributers to the code:
//      - Frans Bouma [FB]
//////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SD.LLBLGen.Pro.ApplicationCore;

namespace SD.LLBLGen.Pro.Plugins
{
    /// <summary>
    /// Configuration control for the BulkSetGenerateAsNullableTypeFlags plug-in
    /// </summary>
    public partial class BulkSetGenerateAsNullableTypeFlagsControl : UserControl, IPluginConfigurationControl
    {
        #region Events
        public event EventHandler DataIsValid;
        public event EventHandler DataIsInvalid;
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="BulkSetGenerateAsNullableTypeFlagsControl"/> class.
        /// </summary>
        public BulkSetGenerateAsNullableTypeFlagsControl()
        {
            InitializeComponent();
        }

        private void _actionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(_actionComboBox.SelectedIndex >= 0)
            {
                if(DataIsValid != null)
                {
                    DataIsValid(this, new EventArgs());
                }
            }
            else
            {
                if(DataIsInvalid != null)
                {
                    DataIsInvalid(this, new EventArgs());
                }
            }
        }


        private void BulkSetGenerateAsNullableTypeFlagsControl_Load(object sender, EventArgs e)
        {
            _actionComboBox.SelectedIndex = 0;
        }
        

        #region Class Property Declarations
        /// <summary>
        /// Gets the selected action.
        /// </summary>
        /// <value>The selected action.</value>
        public int SelectedAction
        {
            get { return _actionComboBox.SelectedIndex; }
        }
        #endregion

    }
}

BulkSetGenerateAsNullableTypeFlagsPlugin.cs


//////////////////////////////////////////////////////////////////////
// Public Class definitions for the Plugins assembly of LLBLGen Pro.
// (c) 2002-2006 Solutions Design, all rights reserved.
// http://www.llblgen.com/
//////////////////////////////////////////////////////////////////////
// The sourcecode for this plug-in is released as BSD2 licensed open source, so licensees and others can
// modify, update, extend or use it to write other plug-ins. 
//////////////////////////////////////////////////////////////////////
// COPYRIGHTS:
// Copyright (c)2002-2006 Solutions Design. All rights reserved.
// 
// This LLBLGen Pro Plug-in is released under the following license: (BSD2)
// -------------------------------------------------------------------------
// Redistribution and use in source and binary forms, with or without modification, 
// are permitted provided that the following conditions are met: 
//
// 1) Redistributions of source code must retain the above copyright notice, this list of 
//  conditions and the following disclaimer. 
// 2) Redistributions in binary form must reproduce the above copyright notice, this list of 
//  conditions and the following disclaimer in the documentation and/or other materials 
//  provided with the distribution. 
// 
// THIS SOFTWARE IS PROVIDED BY SOLUTIONS DESIGN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOLUTIONS DESIGN OR CONTRIBUTORS BE LIABLE FOR 
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
//
// The views and conclusions contained in the software and documentation are those of the authors 
// and should not be interpreted as representing official policies, either expressed or implied, 
// of Solutions Design. 
//
//////////////////////////////////////////////////////////////////////
// Contributers to the code:
//      - Frans Bouma [FB]
//////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.Windows.Forms;

using SD.LLBLGen.Pro.ApplicationCore;
using SD.LLBLGen.Pro.ApplicationCore.Entities;
using SD.LLBLGen.Pro.ApplicationCore.StoredProcedures;
using SD.LLBLGen.Pro.ApplicationCore.TypedLists;
using SD.LLBLGen.Pro.ApplicationCore.TypedViews;

namespace SD.LLBLGen.Pro.Plugins
{
    /// <summary>
    /// ToggleGenerateAsNullableTypeFlagsPlugin implementation. Sets the GenerateAsNullableOfT flag for all fields in the selected entities to the value specified.
    /// </summary>
    public class BulkSetGenerateAsNullableTypeFlagsPlugin : PluginBase
    {
        #region Enums
        /// <summary>
        /// action enum for the execute method, which contains values which correspond with the indexes in the combobox of the configure control.
        /// </summary>
        internal enum BulkSetAction
        {
            DisableAllFlags,
            EnableAllFlags,
            ToggleFlags
        }
        #endregion
        #region Constants
        private const string    _version = "2.0.0.0";
        private const string    _build = "07122006";
        #endregion

        #region Class Member Declarations
        private BulkSetGenerateAsNullableTypeFlagsControl _control;
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="ToggleHideFlagsMNRelationsPlugin"/> class.
        /// </summary>
        public BulkSetGenerateAsNullableTypeFlagsPlugin()
        {
        }


        /// <summary>
        /// Gets the configuration control.
        /// </summary>
        /// <returns></returns>
        public override Control GetConfigurationControl()
        {
            _control = new BulkSetGenerateAsNullableTypeFlagsControl();
            return _control;
        }


        /// <summary>
        /// Describes this plugin.
        /// </summary>
        /// <returns></returns>
        public override PluginDescription Describe()
        {
            PluginDescription toReturn = base.Describe();

            toReturn.Build = _build;
            toReturn.Description = "General plug-in to bulk-set the Generate as nullable type flag on all entity fields in the selected entities of an LLBLGen Pro project.";
            toReturn.Id = new Guid("{1CCEEDD1-AD19-49c9-B711-AB2087D0F94A}");
            toReturn.Name = "Sets GenerateAsNullableOfT Flags Of Entity Fields Plug-in";
            toReturn.ShowProgressViewerDuringExecution=true;
            toReturn.TargetType = PluginTargetType.Entity;
            toReturn.TypeOfPlugin = PluginType.SingleAndMultiElementPlugin;
            toReturn.Vendor = "Solutions Design";
            toReturn.Version = _version;
            toReturn.SurpressProjectExplorerRedraw = true;
            return toReturn;
        }


        /// <summary>
        /// Executes this plugin
        /// </summary>
        public override void Execute()
        {
            BulkSetAction actionToTake = (BulkSetAction)_control.SelectedAction;

            // 1 main task: entity
            base.ProgressTaskInit(1);

            base.ProgressTaskStart("Processing entities");
            base.ProgressSubtaskInit(base.Entities.Count);
            foreach(EntityDefinition entity  in base.Entities)
            {
                bool entityChanged = false;
                base.ProgressSubtaskStart("Processing entity: " + entity.Name);

                // process all fields in the entity.
                foreach(EntityFieldDefinition field in entity.Fields)
                {
                    if(!field.DotNetType.IsValueType)
                    {
                        // not a valuetype, ignore
                        continue;
                    }
                    switch(actionToTake)
                    {
                        case BulkSetAction.DisableAllFlags:
                            field.GenerateAsNullableOfT = false;
                            break;
                        case BulkSetAction.EnableAllFlags:
                            field.GenerateAsNullableOfT = true;
                            break;
                        case BulkSetAction.ToggleFlags:
                            field.GenerateAsNullableOfT = !field.GenerateAsNullableOfT;
                            break;
                    }
                    entityChanged = true;
                }
                base.ProgressSubtaskComplete();
                if(entityChanged)
                {
                    entity.MarkEntityDefinitionAsChanged(ObjectChangeType.EntityFields);
                    entity.MarkEntityDefinitionRequiresRedraw(ObjectChangeType.EntityFields);
                }
            }
            base.ProgressTaskComplete();
        }
    }
}

Frans Bouma | Lead developer LLBLGen Pro
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 12-Jul-2006 23:45:38   

Otis wrote:


//////////////////////////////////////////////////////////////////////
// COPYRIGHTS:
// Copyright (c)2002-2006 Solutions Design. All rights reserved.
// 
// This LLBLGen Pro Plug-in is released under the following license: (BSD2)
// -------------------------------------------------------------------------
// Redistribution and use in source and binary forms, with or without modification, 
// are permitted provided that the following conditions are met: 
//
// 1) Redistributions of source code must retain the above copyright notice, this list of 
//  conditions and the following disclaimer. 
// 2) Redistributions in binary form must reproduce the above copyright notice, this list of 
//  conditions and the following disclaimer in the documentation and/or other materials 
//  provided with the distribution. 
// 

What is the BSD2 license? Why is this released under a different license than LLBLGen is?

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Jul-2006 00:09:21   

All plug-in sourcecode, runtime sourcecode is released under the BSD2 license so you can change / update / re-use it without having to worry about licenses, you just have to obey the 2 clauses stated there if you for example re-use a plugin's sourcecode and want to distribute it yourself.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 14-Jul-2006 12:26:12   

Now available through the latest installer / SDK.

Frans Bouma | Lead developer LLBLGen Pro