/// <summary>
        ///     Creates scalar property with a default, unique name and passed type
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="parentComplexType">parent for new property</param>
        /// <param name="type">type for new property</param>
        /// <returns></returns>
        internal static Property CreateDefaultProperty(CommandProcessorContext cpc, ComplexType parentComplexType, string type)
        {
            var name = ModelHelper.GetUniqueName(typeof(ConceptualProperty), parentComplexType, Property.DefaultPropertyName);
            var cmd  = new CreateComplexTypePropertyCommand(name, parentComplexType, type, false);

            var cp = new CommandProcessor(cpc, cmd);

            cp.Invoke();

            return(cmd.Property);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Sets facets on the property being created by the passed in command.
        /// </summary>
        /// <param name="prereq">Must be non-null command creating the storage property</param>
        /// <param name="theDefault">Optional facet</param>
        /// <param name="maxLength">Optional facet</param>
        /// <param name="fixedLength">Optional facet</param>
        /// <param name="precision">Optional facet</param>
        /// <param name="scale">Optional facet</param>
        /// <param name="unicode">Optional facet</param>
        /// <param name="collation">Optional facet</param>
        /// <param name="concurrencyMode">Optional facet</param>
        internal SetPropertyFacetsCommand(
            CreateComplexTypePropertyCommand prereq, StringOrNone theDefault,
            StringOrPrimitive <UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive <UInt32> precision,
            StringOrPrimitive <UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode)
        {
            ValidatePrereqCommand(prereq);

            _theDefault      = theDefault;
            _maxLength       = maxLength;
            _fixedLength     = fixedLength;
            _precision       = precision;
            _scale           = scale;
            _unicode         = unicode;
            _collation       = collation;
            _concurrencyMode = concurrencyMode;

            AddPreReqCommand(prereq);
        }
Exemplo n.º 3
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // get unique name for the property
            var propertyName = ModelHelper.GetUniqueName(typeof(ConceptualProperty), _parentComplexType, _clipboardProperty.PropertyName);

            if (!_clipboardProperty.IsComplexProperty)
            {
                // scalar property case
                var cmd = new CreateComplexTypePropertyCommand(
                    propertyName, _parentComplexType, _clipboardProperty.PropertyType, _clipboardProperty.IsNullable);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                _createdProperty = cmd.Property;
            }
            else
            {
                // complex property case
                // first try to find ComplexType by it's name
                var complexTypeNormalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(
                    _parentComplexType, _clipboardProperty.PropertyType);
                var         items       = _parentComplexType.Artifact.ArtifactSet.GetSymbolList(complexTypeNormalizedName.Symbol);
                ComplexType complexType = null;
                foreach (var efElement in items)
                {
                    // the GetSymbolList() method might return more than one element so choose the first ComplexType
                    complexType = efElement as ComplexType;
                    if (complexType != null)
                    {
                        break;
                    }
                }
                if (complexType != null)
                {
                    // if the ComplexType is found, simply use the create command
                    var cmd = new CreateComplexTypePropertyCommand(propertyName, _parentComplexType, complexType, false);
                    CommandProcessor.InvokeSingleCommand(cpc, cmd);
                    _createdProperty = cmd.Property;
                }
                else
                {
                    // in this case we're going to create ComplexProperty with unresolved type
                    var complexProperty = new ComplexConceptualProperty(_parentComplexType, null);
                    complexProperty.ComplexType.SetXAttributeValue(_clipboardProperty.PropertyType);
                    // set the name and add to the parent entity
                    complexProperty.LocalName.Value = propertyName;
                    _parentComplexType.AddProperty(complexProperty);

                    // set other attributes of the property
                    complexProperty.Nullable.Value = BoolOrNone.FalseValue;

                    XmlModelHelper.NormalizeAndResolve(complexProperty);
                    Debug.Assert(
                        complexProperty.ComplexType.Status != BindingStatus.Known,
                        "Why didn't we find the ComplexType in the ArtifactSet previously?");
                    _createdProperty = complexProperty;
                }
            }

            // safety check
            Debug.Assert(_createdProperty != null, "We didn't get good Property out of the command");
            if (_createdProperty != null)
            {
                // set Property attributes
                var cmd2 = new SetConceptualPropertyFacetsCommand(
                    _createdProperty, _clipboardProperty.Default,
                    _clipboardProperty.ConcurrencyMode, _clipboardProperty.GetterAccessModifier, _clipboardProperty.SetterAccessModifier,
                    _clipboardProperty.MaxLength,
                    DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.FixedLength), _clipboardProperty.Precision,
                    _clipboardProperty.Scale,
                    DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.Unicode), _clipboardProperty.Collation);
                CommandProcessor.InvokeSingleCommand(cpc, cmd2);
            }
        }
        /// <summary>
        ///     Sets facets on the property being created by the passed in command.
        /// </summary>
        /// <param name="prereq">Must be non-null command creating the storage property</param>
        /// <param name="theDefault">Optional facet</param>
        /// <param name="maxLength">Optional facet</param>
        /// <param name="fixedLength">Optional facet</param>
        /// <param name="precision">Optional facet</param>
        /// <param name="scale">Optional facet</param>
        /// <param name="unicode">Optional facet</param>
        /// <param name="collation">Optional facet</param>
        /// <param name="concurrencyMode">Optional facet</param>
        internal SetPropertyFacetsCommand(
            CreateComplexTypePropertyCommand prereq, StringOrNone theDefault,
            StringOrPrimitive<UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive<UInt32> precision,
            StringOrPrimitive<UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode)
        {
            ValidatePrereqCommand(prereq);

            _theDefault = theDefault;
            _maxLength = maxLength;
            _fixedLength = fixedLength;
            _precision = precision;
            _scale = scale;
            _unicode = unicode;
            _collation = collation;
            _concurrencyMode = concurrencyMode;

            AddPreReqCommand(prereq);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Add commands to create and set the facets for a new complex type property to match the column.
        /// </summary>
        internal static void AddCreateComplexTypePropertyCommands(
            StorageEntityModel storageModel, IRawDataSchemaColumn column, CreateComplexTypeCommand cmdNewComplexType,
            ComplexType complexType, IList <Command> commands)
        {
            // Assert if both cmdNewComplexType and complexType are null or if both are not null.
            Debug.Assert(
                ((cmdNewComplexType != null && complexType == null) || (cmdNewComplexType == null && complexType != null)),
                "Both cmdNewComplexType and complexType are null or both are not null. cmdNewComplexType is null : "
                + (cmdNewComplexType == null).ToString() + ", complexType is null : " + (complexType == null).ToString());

            if ((cmdNewComplexType != null && complexType == null) ||
                (cmdNewComplexType == null && complexType != null))
            {
                // Skip creating the complex type property for a column if the column type is unknown or not supported ( providerDataType == -1 ).
                if (column.ProviderDataType != -1)
                {
                    var primitiveType = ModelHelper.GetPrimitiveType(storageModel, column.NativeDataType, column.ProviderDataType);
                    // We only create complex type property if primitive type is known.
                    if (primitiveType != null)
                    {
                        CreateComplexTypePropertyCommand cmdNewComplexTypeProperty = null;
                        // if complex type is not created yet.
                        if (cmdNewComplexType != null)
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character.
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                cmdNewComplexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }
                        else
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character.
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                complexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }

                        // We only update the facets that are displayed in Function Import dialog return type view list:
                        // - Nullable.
                        // - Max Size.
                        // - Precision.
                        // - Scale.
                        var cmdSetPropertyFacets = new SetPropertyFacetsCommand(
                            cmdNewComplexTypeProperty
                            , null // Default value
                            , ModelHelper.GetMaxLengthFacetValue(column.Size)
                            , null // Fixed Length
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Precision)
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Scale)
                            , null // unicode
                            , null // collation
                            , null // concurrency mode
                            );
                        commands.Add(cmdSetPropertyFacets);
                    }
                }
            }
        }
        /// <summary>
        ///     Creates complex property with a default,unique name and passed complex type
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="parentComplexType">parent for new property</param>
        /// <param name="type">type for new property</param>
        /// <returns></returns>
        internal static Property CreateDefaultProperty(CommandProcessorContext cpc, ComplexType parentComplexType, ComplexType type)
        {
            var name = ModelHelper.GetUniqueName(
                typeof(ConceptualProperty), parentComplexType, ComplexConceptualProperty.DefaultComplexPropertyName);
            var cmd = new CreateComplexTypePropertyCommand(name, parentComplexType, type, false);

            var cp = new CommandProcessor(cpc, cmd);
            cp.Invoke();

            return cmd.Property;
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // get unique name for the property
            var propertyName = ModelHelper.GetUniqueName(typeof(ConceptualProperty), _parentComplexType, _clipboardProperty.PropertyName);

            if (!_clipboardProperty.IsComplexProperty)
            {
                // scalar property case
                var cmd = new CreateComplexTypePropertyCommand(
                    propertyName, _parentComplexType, _clipboardProperty.PropertyType, _clipboardProperty.IsNullable);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                _createdProperty = cmd.Property;
            }
            else
            {
                // complex property case
                // first try to find ComplexType by it's name
                var complexTypeNormalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(
                    _parentComplexType, _clipboardProperty.PropertyType);
                var items = _parentComplexType.Artifact.ArtifactSet.GetSymbolList(complexTypeNormalizedName.Symbol);
                ComplexType complexType = null;
                foreach (var efElement in items)
                {
                    // the GetSymbolList() method might return more than one element so choose the first ComplexType
                    complexType = efElement as ComplexType;
                    if (complexType != null)
                    {
                        break;
                    }
                }
                if (complexType != null)
                {
                    // if the ComplexType is found, simply use the create command
                    var cmd = new CreateComplexTypePropertyCommand(propertyName, _parentComplexType, complexType, false);
                    CommandProcessor.InvokeSingleCommand(cpc, cmd);
                    _createdProperty = cmd.Property;
                }
                else
                {
                    // in this case we're going to create ComplexProperty with unresolved type
                    var complexProperty = new ComplexConceptualProperty(_parentComplexType, null);
                    complexProperty.ComplexType.SetXAttributeValue(_clipboardProperty.PropertyType);
                    // set the name and add to the parent entity
                    complexProperty.LocalName.Value = propertyName;
                    _parentComplexType.AddProperty(complexProperty);

                    // set other attributes of the property
                    complexProperty.Nullable.Value = BoolOrNone.FalseValue;

                    XmlModelHelper.NormalizeAndResolve(complexProperty);
                    Debug.Assert(
                        complexProperty.ComplexType.Status != BindingStatus.Known,
                        "Why didn't we find the ComplexType in the ArtifactSet previously?");
                    _createdProperty = complexProperty;
                }
            }

            // safety check
            Debug.Assert(_createdProperty != null, "We didn't get good Property out of the command");
            if (_createdProperty != null)
            {
                // set Property attributes
                var cmd2 = new SetConceptualPropertyFacetsCommand(
                    _createdProperty, _clipboardProperty.Default,
                    _clipboardProperty.ConcurrencyMode, _clipboardProperty.GetterAccessModifier, _clipboardProperty.SetterAccessModifier,
                    _clipboardProperty.MaxLength,
                    DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.FixedLength), _clipboardProperty.Precision,
                    _clipboardProperty.Scale,
                    DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.Unicode), _clipboardProperty.Collation);
                CommandProcessor.InvokeSingleCommand(cpc, cmd2);
            }
        }
        /// <summary>
        ///     Add commands to create and set the facets for a new complex type property to match the column.
        /// </summary>
        internal static void AddCreateComplexTypePropertyCommands(
            StorageEntityModel storageModel, IRawDataSchemaColumn column, CreateComplexTypeCommand cmdNewComplexType,
            ComplexType complexType, IList<Command> commands)
        {
            // Assert if both cmdNewComplexType and complexType are null or if both are not null.
            Debug.Assert(
                ((cmdNewComplexType != null && complexType == null) || (cmdNewComplexType == null && complexType != null)),
                "Both cmdNewComplexType and complexType are null or both are not null. cmdNewComplexType is null : "
                + (cmdNewComplexType == null).ToString() + ", complexType is null : " + (complexType == null).ToString());

            if ((cmdNewComplexType != null && complexType == null)
                || (cmdNewComplexType == null && complexType != null))
            {
                // Skip creating the complex type property for a column if the column type is unknown or not supported ( providerDataType == -1 ).
                if (column.ProviderDataType != -1)
                {
                    var primitiveType = ModelHelper.GetPrimitiveType(storageModel, column.NativeDataType, column.ProviderDataType);
                    // We only create complex type property if primitive type is known.
                    if (primitiveType != null)
                    {
                        CreateComplexTypePropertyCommand cmdNewComplexTypeProperty = null;
                        // if complex type is not created yet.
                        if (cmdNewComplexType != null)
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character. 
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                cmdNewComplexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }
                        else
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character. 
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                complexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }

                        // We only update the facets that are displayed in Function Import dialog return type view list:
                        // - Nullable.
                        // - Max Size.
                        // - Precision.
                        // - Scale.
                        var cmdSetPropertyFacets = new SetPropertyFacetsCommand(
                            cmdNewComplexTypeProperty
                            , null // Default value
                            , ModelHelper.GetMaxLengthFacetValue(column.Size)
                            , null // Fixed Length
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Precision)
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Scale)
                            , null // unicode
                            , null // collation
                            , null // concurrency mode 
                            );
                        commands.Add(cmdSetPropertyFacets);
                    }
                }
            }
        }