private void ProcessDefinitionsPropertyNulableValidation(DefinitionBase def)
        {
            var nullableProps = def.GetType()
                                .GetProperties()
                                .Where(p => p.GetCustomAttributes(typeof(ExpectNullable), true).Count() > 0);


            TraceUtils.WithScope(trace =>
            {
                trace.WriteLine("");

                trace.WriteLine(string.Format("[INF]\tPROPERTY NULLABLE VALIDATION"));
                trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def));

                if (nullableProps.Count() == 0)
                {
                    trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping."));
                }
                else
                {
                    foreach (var prop in nullableProps)
                    {
                        trace.WriteLine(string.Format("[INF]\tSetting NULLABLE property: [" + prop.Name + "]"));
                        prop.SetValue(def, null);
                    }
                }
            });
        }
Esempio n. 2
0
        private static void CheckDefinition(ModelProvisionCompatibilityResult result,
                                            ModelNode rootNode,
                                            ModelNode modelNode,
                                            DefinitionBase def)
        {
            var defType = def.GetType();

            var defResult = new ModelProvisionCompatibilityResultValue();
            var attrs     = (SPObjectTypeAttribute[])defType
                            .GetCustomAttributes(typeof(SPObjectTypeAttribute), true);

            defResult.ModelNode  = modelNode;
            defResult.Definition = def;

            if (attrs.Length > 0)
            {
                defResult.IsCSOMCompatible = attrs.Any(a => a.ObjectModelType == SPObjectModelType.CSOM);
                defResult.IsSSOMCompatible = attrs.Any(a => a.ObjectModelType == SPObjectModelType.SSOM);
            }

            // temporary fix for SiteDefinition, it cannot be yet provisioned with SPMeta2 CSOM
            if (def.GetType() == typeof(SiteDefinition))
            {
                if (modelNode != null)
                {
                    if (modelNode.Options.RequireSelfProcessing)
                    {
                        // that's farm / web model or an attempt to provision a new site w/ SPMeta2
                        defResult.IsCSOMCompatible = false;
                    }
                    else
                    {
                        // SiteModel, all valid
                        defResult.IsCSOMCompatible = true;
                    }
                }
                else
                {
                    // that's definition validation call
                    // but still, we don't support it yet
                    defResult.IsCSOMCompatible = false;
                }
            }

            // fixing up root definitions
            // farm and web app model cannot be provisioned with SPMeta2 CSOM
            // handling call from model nodes & defs
            if ((modelNode == rootNode) || (modelNode == null && rootNode == null))
            {
                if (defType == typeof(FarmDefinition) ||
                    defType == typeof(WebApplicationDefinition))
                {
                    defResult.IsCSOMCompatible = false;
                }
            }

            result.Result.Add(defResult);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            //var aggregateException = new c();
            var exceptions = new List <SPMeta2ModelValidationException>();

            var props = ReflectionUtils.GetPropertiesWithCustomAttribute <ExpectRequired>(model, true);

            var requiredPropsGroups = props
                                      .GroupBy(g => (g.GetCustomAttributes(typeof(ExpectRequired), true).First() as ExpectRequired).GroupName);

            foreach (var group in requiredPropsGroups)
            {
                // all set is requred
                if (string.IsNullOrEmpty(group.Key))
                {
                    var isAllValid = AllOfThem(model, group.ToList());

                    if (isAllValid.Count > 0)
                    {
                        exceptions.AddRange(isAllValid);
                    }
                }
                else
                {
                    // skip 'Web part content' for typed web part definitions
                    //  a big todo

                    if (group.Key == "Web part content" && (model.GetType() != typeof(WebPartDefinition)))
                    {
                        continue;
                    }

                    var oneOfThem = OneOfThem(model, group.ToList());

                    if (!oneOfThem)
                    {
                        var ex = new SPMeta2ModelValidationException(
                            string.Format("One of the properties with [{0}] attribute should be set. Definition:[{1}]",
                                          group.Key, model))
                        {
                            Definition = model
                        };

                        exceptions.Add(ex);
                    }
                }
            }

            if (exceptions.Count > 0)
            {
                throw new SPMeta2AggregateException("Required properties validation error",
                                                    exceptions.OfType <Exception>());
            }
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var props = model.GetType()
                        .GetProperties()
                        .Where(p => p.GetCustomAttributes(typeof(ExpectRequired), true).Any());

            var requiredPropsGroups = props
                                      .GroupBy(g => (g.GetCustomAttributes(typeof(ExpectRequired), true).First() as ExpectRequired).GroupName);

            foreach (var group in requiredPropsGroups)
            {
                // all set is requred
                if (string.IsNullOrEmpty(group.Key))
                {
                    var isAllValid = AllOfThem(model, group.ToList());

                    if (!isAllValid)
                    {
                        throw new Exception("Not all of them");
                    }
                }
                else
                {
                    // skip 'Web part content' for typed web part definitions
                    //  a big todo

                    if (group.Key == "Web part content" && (model.GetType() != typeof(WebPartDefinition)))
                    {
                        continue;
                    }

                    var oneOfThem = OneOfThem(model, group.ToList());

                    if (!oneOfThem)
                    {
                        throw new Exception("Not one of them");
                    }
                }
            }
        }
Esempio n. 5
0
    public static void GridSplitterOpeningBounce(this DefinitionBase rowColDefinition, bool opening = false, int openToSize = 0, Action <bool> afterCompleted = null)
    {
        if (rowColDefinition == null)
        {
            return;                       //for when events fire before everything is initialized
        }
        var isRow = (rowColDefinition.GetType() == typeof(RowDefinition));

        Storyboard story;

        if (!GridSplitterPositions.TryGetValue(rowColDefinition, out story))
        {
            var animation = new GridLengthAnimation {
                To = new GridLength(openToSize), Duration = new TimeSpan(0, 0, 1)
            };

            Storyboard.SetTarget(animation, rowColDefinition);
            Storyboard.SetTargetProperty(animation, new PropertyPath(isRow ? "Height" : "Width"));

            GridSplitterPositions[rowColDefinition] = story = new Storyboard();
            story.Children.Add(animation);
            if (afterCompleted != null)
            {
                story.Completed += (s, e) => afterCompleted(opening);
            }
        }

        var currentPositionProperty = isRow ? RowDefinition.HeightProperty : ColumnDefinition.WidthProperty;

        if (opening)
        {
            //only bugger with popping open if not already opened by user
            if (((GridLength)rowColDefinition.GetValue(currentPositionProperty)).Value <= 0.0)
            {
                story.Begin();
            }
        }
        else
        {
            story.Stop();

            //save the current position in the animation's "To" property so it opens back to where it was before we closed it
            var current = (GridLength)rowColDefinition.GetValue(currentPositionProperty);
            if (current.GridUnitType != GridUnitType.Star && current.Value > 0)
            {
                ((GridLengthAnimation)story.Children[0]).To = current;
            }

            rowColDefinition.SetValue(currentPositionProperty, new GridLength(0, GridUnitType.Pixel));
        }
    }
        private void ProcessDefinitionsPropertyUpdateValidation(DefinitionBase def)
        {
            var updatableProps = def.GetType()
                                 .GetProperties()
                                 .Where(p => p.GetCustomAttributes(typeof(ExpectUpdate), true).Count() > 0);


            TraceUtils.WithScope(trace =>
            {
                trace.WriteLine("");

                trace.WriteLine(string.Format("[INF]\tPROPERTY UPDATE VALIDATION"));
                trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def));

                if (updatableProps.Count() == 0)
                {
                    trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping."));
                }
                else
                {
                    foreach (var prop in updatableProps)
                    {
                        object newValue      = null;
                        var expectUpdateAttr = prop.GetCustomAttributes(typeof(ExpectUpdate), true)
                                               .FirstOrDefault() as ExpectUpdate;


                        newValue = GetNewPropValue(expectUpdateAttr, def, prop);

                        trace.WriteLine(string.Format("[INF]\t\tChanging property [{0}] from [{1}] to [{2}]", prop.Name, prop.GetValue(def), newValue));
                        prop.SetValue(def, newValue);
                    }
                }

                trace.WriteLine("");
            });
        }
Esempio n. 7
0
        protected virtual bool IsSingletonIdentityDefinition(DefinitionBase definition)
        {
            var definitionType = definition.GetType();

            if (EnableCaching)
            {
                if (!_cache4SingletonIdentityTypes.ContainsKey(definitionType))
                {
                    var isInstanceIdentity = definitionType.GetCustomAttributes(typeof(SingletonIdentityAttribute), true).Any();

                    TraceService.VerboseFormat(0,
                                               "IsSingletonIdentityDefinition() - cold hit, adding value to cache:[{0}] -> [{1}]",
                                               new object[] { definitionType, isInstanceIdentity },
                                               null);

                    _cache4SingletonIdentityTypes.Add(definitionType, isInstanceIdentity);
                }
                else
                {
                    var isInstanceIdentity = _cache4SingletonIdentityTypes[definitionType];

                    TraceService.VerboseFormat(0,
                                               "IsSingletonIdentityDefinition() - hot hit, returning value from cache:[{0}] -> [{1}]",
                                               new object[] { definitionType, isInstanceIdentity },
                                               null);
                }

                return(_cache4SingletonIdentityTypes[definitionType]);
            }
            else
            {
                var isInstanceIdentity = definitionType.GetCustomAttributes(typeof(SingletonIdentityAttribute), true).Any();

                TraceService.VerboseFormat(0,
                                           "IsSingletonIdentityDefinition() - no caching. Returning value:[{0}] -> [{1}]",
                                           new object[] { definitionType, isInstanceIdentity },
                                           null);

                return(isInstanceIdentity);
            }
        }
Esempio n. 8
0
    public static void GridSplitterOpeningBounce(DefinitionBase RowColDefinition, int InitialSize, bool Opening)
    {
        if (RowColDefinition == null)
        {
            return;                       //for when events fire before everything is initialized
        }
        bool IsRow = (RowColDefinition.GetType() == typeof(RowDefinition));

        Storyboard story;

        if (!GridSplitterPositions.TryGetValue(RowColDefinition, out story))
        {
            GridLengthAnimation animation = new GridLengthAnimation();
            animation.To       = new GridLength(InitialSize);
            animation.Duration = new TimeSpan(0, 0, 1);

            Storyboard.SetTarget(animation, RowColDefinition);
            Storyboard.SetTargetProperty(animation, new PropertyPath(IsRow ? "Height" : "Width"));

            GridSplitterPositions[RowColDefinition] = story = new Storyboard();
            story.Children.Add(animation);
        }

        if (Opening)
        {
            story.Begin();
        }
        else
        {
            story.Stop();

            DependencyProperty CurrentPositionProperty = IsRow ? RowDefinition.HeightProperty : ColumnDefinition.WidthProperty;

            //save the current position in the animation's "To" property so it opens back to where it was before we closed it
            (story.Children[0] as GridLengthAnimation).To = (GridLength)RowColDefinition.GetValue(CurrentPositionProperty);

            RowColDefinition.SetValue(CurrentPositionProperty, new GridLength(0, GridUnitType.Pixel));
        }
    }
        private void ProcessDefinitionsPropertyUpdateValidation(DefinitionBase def)
        {
            var updatableProps = def.GetType()
                                 .GetProperties()
                                 .Where(p => p.GetCustomAttributes(typeof(ExpectUpdate), true).Count() > 0);


            TraceUtils.WithScope(trace =>
            {
                trace.WriteLine("");

                trace.WriteLine(string.Format("[INF]\tPROPERTY UPDATE VALIDATION"));
                trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def));

                if (updatableProps.Count() == 0)
                {
                    trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping."));
                }
                else
                {
                    foreach (var prop in updatableProps)
                    {
                        object newValue = null;

                        if (prop.PropertyType == typeof(string))
                        {
                            newValue = RegressionService.RndService.String();
                        }
                        else if (prop.PropertyType == typeof(bool))
                        {
                            newValue = RegressionService.RndService.Bool();
                        }
                        else if (prop.PropertyType == typeof(bool?))
                        {
                            newValue = RegressionService.RndService.Bool() ? (bool?)null : RegressionService.RndService.Bool();
                        }
                        else if (prop.PropertyType == typeof(int))
                        {
                            newValue = RegressionService.RndService.Int();
                        }
                        else if (prop.PropertyType == typeof(int?))
                        {
                            newValue = RegressionService.RndService.Bool() ? (int?)null : RegressionService.RndService.Int();
                        }
                        else if (prop.PropertyType == typeof(uint))
                        {
                            newValue = (uint)RegressionService.RndService.Int();
                        }
                        else if (prop.PropertyType == typeof(uint?))
                        {
                            newValue = (uint?)(RegressionService.RndService.Bool() ? (uint?)null : (uint?)RegressionService.RndService.Int());
                        }
                        else
                        {
                            throw new NotImplementedException(string.Format("Update validation for type: [{0}] is not supported yet", prop.PropertyType));
                        }

                        trace.WriteLine(string.Format("[INF]\t\tChanging property [{0}] from [{1}] to [{2}]", prop.Name, prop.GetValue(def), newValue));
                        prop.SetValue(def, newValue);
                    }
                }

                trace.WriteLine("");
            });
        }
Esempio n. 10
0
        private void ProcessDefinitionsPropertyUpdateValidation(DefinitionBase def)
        {
            var updatableProps = def.GetType()
                                 .GetProperties()
                                 .Where(p => p.GetCustomAttributes(typeof(ExpectUpdate), true).Count() > 0);


            TraceUtils.WithScope(trace =>
            {
                trace.WriteLine("");

                trace.WriteLine(string.Format("[INF]\tPROPERTY UPDATE VALIDATION"));
                trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def));

                if (updatableProps.Count() == 0)
                {
                    trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping."));
                }
                else
                {
                    foreach (var prop in updatableProps)
                    {
                        object newValue = null;

                        var attrs = prop.GetCustomAttributes(typeof(ExpectUpdate), true);

                        if (attrs.Count(a => a is ExpectUpdateAsLCID) > 0)
                        {
                            var newLocaleIdValue = 1033 + RegressionService.RndService.Int(5);

                            if (prop.PropertyType == typeof(int))
                            {
                                newValue = newLocaleIdValue;
                            }
                            else if (prop.PropertyType == typeof(int?))
                            {
                                newValue = RegressionService.RndService.Bool() ? (int?)null : newLocaleIdValue;
                            }
                            else if (prop.PropertyType == typeof(uint))
                            {
                                newValue = (uint)newLocaleIdValue;
                            }
                            else if (prop.PropertyType == typeof(uint?))
                            {
                                newValue = (uint?)(RegressionService.RndService.Bool() ? (uint?)null : (uint?)newLocaleIdValue);
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsUser) > 0)
                        {
                            var newUserValue = RegressionService.RndService.UserLogin();
                            newValue         = newUserValue;
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsTargetControlType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInTargetControlType.ContentWebParts);
                            values.Add(BuiltInTargetControlType.Custom);
                            values.Add(BuiltInTargetControlType.Refinement);
                            values.Add(BuiltInTargetControlType.SearchBox);
                            values.Add(BuiltInTargetControlType.SearchHoverPanel);
                            values.Add(BuiltInTargetControlType.SearchResults);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(List <string>))
                            {
                                var result       = new List <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsWebPartPageLayoutTemplate) > 0)
                        {
                            var values = new List <int>();

                            values.Add(BuiltInWebpartPageTemplateId.spstd1);
                            values.Add(BuiltInWebpartPageTemplateId.spstd2);
                            values.Add(BuiltInWebpartPageTemplateId.spstd3);
                            values.Add(BuiltInWebpartPageTemplateId.spstd4);
                            values.Add(BuiltInWebpartPageTemplateId.spstd5);
                            values.Add(BuiltInWebpartPageTemplateId.spstd6);
                            values.Add(BuiltInWebpartPageTemplateId.spstd7);

                            if (prop.PropertyType == typeof(int))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldCalendarType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInCalendarType.Gregorian);
                            values.Add(BuiltInCalendarType.Korea);
                            values.Add(BuiltInCalendarType.Hebrew);
                            values.Add(BuiltInCalendarType.GregorianArabic);
                            values.Add(BuiltInCalendarType.SakaEra);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsFieldUserSelectionMode) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInFieldUserSelectionMode.PeopleAndGroups)
                            {
                                newValue = BuiltInFieldUserSelectionMode.PeopleOnly;
                            }
                            else
                            {
                                newValue = BuiltInFieldUserSelectionMode.PeopleAndGroups;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldCalendarType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInCalendarType.Gregorian);
                            values.Add(BuiltInCalendarType.Korea);
                            values.Add(BuiltInCalendarType.Hebrew);
                            values.Add(BuiltInCalendarType.GregorianArabic);
                            values.Add(BuiltInCalendarType.SakaEra);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldDisplayFormat) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInDateTimeFieldFormatType.DateOnly)
                            {
                                newValue = BuiltInDateTimeFieldFormatType.DateTime;
                            }
                            else
                            {
                                newValue = BuiltInDateTimeFieldFormatType.DateOnly;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldFriendlyDisplayFormat) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInDateTimeFieldFriendlyFormatType.Disabled)
                            {
                                newValue = BuiltInDateTimeFieldFriendlyFormatType.Relative;
                            }
                            else if (curentValue == BuiltInDateTimeFieldFriendlyFormatType.Relative)
                            {
                                newValue = BuiltInDateTimeFieldFriendlyFormatType.Unspecified;
                            }
                            else if (curentValue == BuiltInDateTimeFieldFriendlyFormatType.Unspecified)
                            {
                                newValue = BuiltInDateTimeFieldFriendlyFormatType.Disabled;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsByte) > 0)
                        {
                            if (prop.PropertyType == typeof(int?) ||
                                prop.PropertyType == typeof(int?))
                            {
                                newValue = Convert.ToInt32(RegressionService.RndService.Byte().ToString());
                            }
                            else
                            {
                                // TODO, as per case
                                newValue = RegressionService.RndService.Byte();
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsCamlQuery) > 0)
                        {
                            newValue =
                                string.Format(
                                    "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">{0}</Value></Eq></Where>",
                                    RegressionService.RndService.String());
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsIntRange) > 0)
                        {
                            var attr =
                                attrs.FirstOrDefault(a => a is ExpectUpdateAsIntRange) as ExpectUpdateAsIntRange;

                            var minValue = attr.MinValue;
                            var maxValue = attr.MaxValue;

                            var tmpValue = minValue + RegressionService.RndService.Int(maxValue - minValue);

                            if (prop.PropertyType == typeof(double?) ||
                                prop.PropertyType == typeof(double))
                            {
                                newValue = Convert.ToDouble(tmpValue);
                            }
                            else
                            {
                                // TODO, as per case
                                newValue = tmpValue;
                            }
                        }

                        else if (attrs.Count(a => a is ExpectUpdateAsUrl) > 0)
                        {
                            var attr =
                                attrs.FirstOrDefault(a => a is ExpectUpdateAsUrl) as ExpectUpdateAsUrl;
                            var fileExtension = attr.Extension;

                            if (!fileExtension.StartsWith("."))
                            {
                                fileExtension = "." + fileExtension;
                            }

                            newValue = string.Format("http://regression-ci.com/{0}{1}", RegressionService.RndService.String(), fileExtension);
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsFileName) > 0)
                        {
                            var attr =
                                attrs.FirstOrDefault(a => a is ExpectUpdateAsFileName) as ExpectUpdateAsFileName;
                            var fileExtension = attr.Extension;

                            if (!fileExtension.StartsWith("."))
                            {
                                fileExtension = "." + fileExtension;
                            }

                            newValue = string.Format("{0}{1}", RegressionService.RndService.String(), fileExtension);
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsInternalFieldName) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInInternalFieldNames.ID);
                            values.Add(BuiltInInternalFieldNames.Edit);
                            values.Add(BuiltInInternalFieldNames.Created);
                            values.Add(BuiltInInternalFieldNames._Author);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsPageLayoutFileName) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInPublishingPageLayoutNames.ArticleLeft);
                            values.Add(BuiltInPublishingPageLayoutNames.ArticleLinks);
                            values.Add(BuiltInPublishingPageLayoutNames.ArticleRight);
                            values.Add(BuiltInPublishingPageLayoutNames.BlankWebPartPage);
                            values.Add(BuiltInPublishingPageLayoutNames.CatalogArticle);
                            values.Add(BuiltInPublishingPageLayoutNames.CatalogWelcome);
                            values.Add(BuiltInPublishingPageLayoutNames.EnterpriseWiki);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsUrlFieldFormat) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInUrlFieldFormatType.Hyperlink)
                            {
                                newValue = BuiltInUrlFieldFormatType.Image;
                            }
                            else
                            {
                                newValue = BuiltInUrlFieldFormatType.Hyperlink;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsCalculatedFieldFormula) > 0)
                        {
                            newValue = string.Format("=ID*{0}", RegressionService.RndService.Int(100));
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAssCalculatedFieldOutputType) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInFieldTypes.Number)
                            {
                                newValue = BuiltInFieldTypes.Text;
                            }
                            else
                            {
                                newValue = BuiltInFieldTypes.Number;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAssCalculatedFieldReferences) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInInternalFieldNames.ID);
                            values.Add(BuiltInInternalFieldNames.FileRef);
                            values.Add(BuiltInInternalFieldNames.FileType);
                            values.Add(BuiltInInternalFieldNames.File_x0020_Size);
                            values.Add(BuiltInInternalFieldNames.FirstName);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsBasePermission) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInBasePermissions.AddAndCustomizePages);
                            values.Add(BuiltInBasePermissions.AnonymousSearchAccessWebLists);
                            values.Add(BuiltInBasePermissions.ApproveItems);
                            values.Add(BuiltInBasePermissions.CancelCheckout);
                            values.Add(BuiltInBasePermissions.CreateSSCSite);
                            values.Add(BuiltInBasePermissions.EditMyUserInfo);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsPublishingPageContentType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInPublishingContentTypeId.ArticlePage);
                            values.Add(BuiltInPublishingContentTypeId.EnterpriseWikiPage);
                            values.Add(BuiltInPublishingContentTypeId.ErrorPage);
                            values.Add(BuiltInPublishingContentTypeId.RedirectPage);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsUIVersion) > 0)
                        {
                            var values = new List <string>();

                            values.Add("4");
                            values.Add("15");

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }

                            if (prop.PropertyType == typeof(List <string>))
                            {
                                var result       = new List <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else
                        {
                            // all this needs to be refactored, we know

                            if (prop.PropertyType == typeof(byte[]))
                            {
                                if (def is WebPartGalleryFileDefinition &&
                                    prop.Name == "Content")
                                {
                                    // change web part
                                    var webPartXmlString = Encoding.UTF8.GetString(prop.GetValue(def) as byte[]);
                                    var webPartXml       = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString);

                                    webPartXml.SetTitleUrl(RegressionService.RndService.HttpUrl());

                                    newValue = Encoding.UTF8.GetBytes(webPartXml.ToString());
                                }
                                else
                                {
                                    newValue = RegressionService.RndService.Content();
                                }
                            }
                            else if (prop.PropertyType == typeof(string))
                            {
                                newValue = RegressionService.RndService.String();
                            }
                            else if (prop.PropertyType == typeof(bool))
                            {
                                newValue = RegressionService.RndService.Bool();
                            }
                            else if (prop.PropertyType == typeof(bool?))
                            {
                                var oldValue = prop.GetValue(def) as bool?;

                                if (oldValue == null || !oldValue.HasValue)
                                {
                                    newValue = RegressionService.RndService.Bool();
                                }
                                else
                                {
                                    newValue = !oldValue.Value;
                                }
                            }
                            else if (prop.PropertyType == typeof(int))
                            {
                                newValue = RegressionService.RndService.Int();
                            }
                            else if (prop.PropertyType == typeof(int?))
                            {
                                newValue = RegressionService.RndService.Bool()
                                    ? (int?)null
                                    : RegressionService.RndService.Int();
                            }
                            else if (prop.PropertyType == typeof(uint))
                            {
                                newValue = (uint)RegressionService.RndService.Int();
                            }
                            else if (prop.PropertyType == typeof(uint?))
                            {
                                newValue =
                                    (uint?)
                                    (RegressionService.RndService.Bool()
                                            ? (uint?)null
                                            : (uint?)RegressionService.RndService.Int());
                            }
                            else if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var resultLength = RegressionService.RndService.Int(10);
                                var values       = new List <string>();

                                var result = new Collection <string>();

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(RegressionService.RndService.String());
                                }

                                newValue = result;
                            }
                            else if (prop.PropertyType == typeof(List <string>))
                            {
                                var resultLength = RegressionService.RndService.Int(10);
                                var values       = new List <string>();

                                var result = new List <string>();

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(RegressionService.RndService.String());
                                }

                                newValue = result;
                            }


                            else if (prop.PropertyType == typeof(double?) ||
                                     prop.PropertyType == typeof(double))
                            {
                                newValue = (double)RegressionService.RndService.Int();
                            }
                            else
                            {
                                throw new NotImplementedException(
                                    string.Format("Update validation for type: [{0}] is not supported yet",
                                                  prop.PropertyType));
                            }
                        }

                        trace.WriteLine(string.Format("[INF]\t\tChanging property [{0}] from [{1}] to [{2}]", prop.Name, prop.GetValue(def), newValue));
                        prop.SetValue(def, newValue);
                    }
                }

                trace.WriteLine("");
            });
        }
Esempio n. 11
0
        public string GetDefinitionIdentityKey(DefinitionBase def)
        {
            var result = string.Empty;

            var definitionType = def.GetType();

            var isSingleIdenity = definitionType.GetCustomAttributes(typeof(SingletonIdentityAttribute), true).Any();
            var isInstanceIdentity = !definitionType.GetCustomAttributes(typeof(SingletonIdentityAttribute), true).Any();

            if (isSingleIdenity)
            {
                throw new SPMeta2ReverseException("isSingleIdenity is true. Was not implemented yet");
            }

            if (isInstanceIdentity)
            {
                var props = definitionType.GetProperties();

                var identityKeyNames = props
                    .Where(p => p.GetCustomAttributes(typeof(IdentityKeyAttribute), true).Any())
                    .Select(p => p.Name)
                    .OrderBy(s => s)
                    .ToList();

                if (def is ContentTypeFieldLinkDefinition)
                {
                    identityKeyNames.Clear();
                    identityKeyNames.Add("FieldId");
                }

                if (def is ContentTypeLinkDefinition)
                {
                    identityKeyNames.Clear();
                    identityKeyNames.Add("ContentTypeName");
                }

                // url gets transformed by SharePoint to the full one
                // so that lookup by identity won't work
                // rely only on title for the time being
                if (def is NavigationNodeDefinitionBase)
                {
                    identityKeyNames.Remove("Url");
                }

                // skipping list view URLs fro the tiime being
                if (def is ListViewDefinition)
                {
                    identityKeyNames.Remove("Url");
                }

                foreach (var keyName in identityKeyNames)
                {
                    var prop = props.FirstOrDefault(p => p.Name == keyName);
                    var keyValue = ConvertUtils.ToString(prop.GetValue(def, null));

                    result += keyValue;
                }

            }

            return result;
        }