コード例 #1
0
        /// <summary>
        /// Validates the ResourceTypeSetting instance with the current properties of a Core.ResourceType object.
        /// </summary>
        /// <param name="resourceType">The Core.ResourceType instance to do the validation against.</param>
        /// <param name="resourceTypeSetting">The instance of ResourceTypeSetting.</param>
        /// <returns>Return true if success else false.</returns>
        internal static bool ValidateResourceTypeSetting(this Core.ResourceType resourceType, PivotConfig.ResourceTypeSetting resourceTypeSetting)
        {
            Globals.TraceMessage(TraceEventType.Verbose, string.Empty, Properties.Messages.StartedFunctionMessage);
            bool validationSuccess = true;

            PivotConfig.ResourceTypeSetting currentResourceTypeSetting = resourceType.ToResourceTypeSetting();
            if (resourceTypeSetting.Facets == null)
            {
                return(false);
            }

            List <PivotConfig.Facet> resourceTypeFacets = new List <PivotConfig.Facet>();

            resourceTypeSetting.Facets.ToList().ForEach(f =>
            {
                if (f != null && !string.IsNullOrWhiteSpace(f.PropertyName) && !string.IsNullOrEmpty(f.PropertyName))
                {
                    resourceTypeFacets.Add(f);
                }
            });
            PivotConfig.FacetNameComparer facetComparer = new PivotConfig.FacetNameComparer();

            IEnumerable <PivotConfig.Facet> missingFacets = resourceTypeFacets.Except(currentResourceTypeSetting.Facets, facetComparer);

            if (missingFacets.Count() > 0)
            {
                validationSuccess = false;
                while (missingFacets.Count() > 0)
                {
                    var facetToRemove = missingFacets.FirstOrDefault();
                    if (facetToRemove != null)
                    {
                        resourceTypeFacets.Remove(facetToRemove);
                    }
                }
            }

            resourceTypeFacets.ForEach(facet =>
            {
                if (facet.DataType == PivotConfig.FacetDataType.Link || facet.DataType == PivotConfig.FacetDataType.LongString)
                {
                    facet.ShowInFilter = false;
                }
            });

            IEnumerable <string> duplicateFacet = resourceTypeFacets.GroupBy(f => f.DisplayName).Where(f => f.Count() > 1).Select(f => f.Key).AsEnumerable();

            if (duplicateFacet.Count() > 0)
            {
                throw new FaultException(new FaultReason(string.Format(Properties.Messages.DuplicateFacetsNotAllowed, string.Join(",", duplicateFacet))));
            }

            resourceTypeSetting.Facets = resourceTypeFacets.ToArray();
            Globals.TraceMessage(TraceEventType.Verbose, string.Empty, Properties.Messages.FinishedFunctionMessage);
            return(validationSuccess);
        }
コード例 #2
0
        /// <summary>
        /// Serializes to ResourceTypeSetting to XElement.
        /// </summary>
        /// <param name="settingElement">An instance of the ResourceTypeSetting class.</param>
        /// <returns>XElement instance containing the serialized ResourceTypeSetting</returns>
        internal static XElement SerializeToXElement(this PivotConfig.ResourceTypeSetting settingElement)
        {
            Globals.TraceMessage(TraceEventType.Verbose, string.Empty, Properties.Messages.StartedFunctionMessage);
            if (settingElement != null)
            {
                Globals.TraceMessage(TraceEventType.Verbose, string.Empty, Properties.Messages.FinishedFunctionMessage);
                return(ExtensionMethods.Serialize(settingElement));
            }

            Globals.TraceMessage(TraceEventType.Verbose, Properties.Messages.NullEmptyMessage, Properties.Messages.NullEmptyTitle);
            return(null);
        }
コード例 #3
0
 /// <summary>
 /// Creates a default ResourceTypeSetting instance from a Core.ResourceType object
 /// </summary>
 /// <param name="resourceType">An instance of Core.ResourceType.</param>
 /// <returns>A default ResourceTypeSetting instance</returns>
 internal static PivotConfig.ResourceTypeSetting ToResourceTypeSetting(this Core.ResourceType resourceType)
 {
     Globals.TraceMessage(TraceEventType.Verbose, string.Empty, Properties.Messages.StartedFunctionMessage);
     PivotConfig.ResourceTypeSetting newSetting = new PivotConfig.ResourceTypeSetting
     {
         Name   = resourceType.Name,
         Visual = new PivotConfig.Visual
         {
             PropertyName = string.Empty,
             Type         = PivotConfig.VisualType.Default
         },
         Link = new PivotConfig.Link {
             PropertyName = string.Empty
         }
     };
     newSetting.Facets = GetConfigFacetList(resourceType).ToArray();
     Globals.TraceMessage(TraceEventType.Verbose, string.Empty, Properties.Messages.FinishedFunctionMessage);
     return(newSetting);
 }