/// <summary>
        ///   Get the Unicode Language ID.
        /// </summary>
        /// <param name="variantUppercase">
        ///   Controls the casing of the <see cref="Variants"/>.  The default is <b>false</b>,
        ///   which is lowercase.  When <b>true</b> the variant(s) are in uppecase.
        /// </param>
        /// <returns>
        ///   The unicode language ID, consists of the <see cref="Language"/>, <see cref="Script"/> and
        ///   <see cref="Region"/> and <see cref="Variants"/> separated by "_".
        /// </returns>
        /// <remarks>
        ///   Uses the casing recommendations in [BCP47] for subtag casing.
        ///   The <see cref="Region"/> subtag is in uppercase,
        ///   the <see cref="Script"/> subtag is in title case, and all other subtags are
        ///   in lowercase.
        /// </remarks>
        public string ToUnicodeLanguage(bool variantUppercase = false)
        {
            var variants = (variantUppercase)
                ? Variants.Select(v => v.ToUpperInvariant())
                : Variants;
            var tags = new[] { Language, Script, Region }
            .Where(tag => tag != String.Empty)
            .Concat(variants);

            return(String.Join("_", tags));
        }
Exemple #2
0
        public override string ToString()
        {
            var groups = new string[]
            {
                string.Join("&", Variants.Select(x => x.ToString())),
                string.Join("&", GiftCards.Select(x => x.ToString())),
                string.Join("&", CheckoutAttributes.Select(x => x.ToString()))
            };

            return(string.Join("&", groups.Where(x => x.HasValue())));
        }
        private void SetVariants(List <VariantDto> variantDtos)
        {
            Variants = Variants ?? new List <VariantDomain>();

            List <string> currentVariantIds = Variants.Select(s => s.Id).ToList();
            List <string> targetVariantIds  = variantDtos.Select(s => s.Id).ToList();

            var removedVariantIds = currentVariantIds.Where(w => !targetVariantIds.Contains(w)).ToList();

            foreach (var removedVariantId in removedVariantIds)
            {
                RemoveVariant(removedVariantId);
            }

            foreach (var variantDto in variantDtos)
            {
                var variantDomain = Variants.Where(w => w.Id.Equals(variantDto.Id)).SingleOrDefault();
                if (variantDomain == null)
                {
                    AddVariant(variantDto);
                }
                else
                {
                    UpdateVariant(variantDomain, variantDto);
                }
            }

            var newListVariant = new List <VariantDomain>();

            for (int i = 0; i < variantDtos.Count; i++)
            {
                VariantDomain variantDomain = null;
                for (int j = 0; j < Variants.Count; j++)
                {
                    if (!variantDtos[i].Id.Equals(Variants[j].Id))
                    {
                        continue;
                    }
                    variantDomain = Variants[j];
                    if (i != j && currentVariantIds.Contains(variantDtos[i].Id))
                    {
                        AddIntegratedEvent(ProductEventType.VARIANT_INDEX_CHANGED, variantDtos[i].Id);
                        Modify();
                    }
                }
                newListVariant.Add(variantDomain);
            }
            Variants = newListVariant;
        }
Exemple #4
0
        public override void Draw()
        {
            var options = Variants.Select(t => t.Name).ToList();

            if (CanNullable)
            {
                options.Insert(0, "null");
            }

            if (!options.Any())
            {
                throw new InvalidDataException("options for select in dropdown not contains any element");
            }

            var index            = Variants.FindIndex(t => t.Value.Equals(Selected));
            var current_selected = Selected == null ? 0 : index == -1 ? 0 : index + (CanNullable ? 1 : 0);

            int new_selection;

            if (Label == null)
            {
                new_selection = EditorGUILayout.Popup(current_selected, options.ToArray(), LayoutOptions);
            }
            else
            {
                new_selection = EditorGUILayout.Popup(new GUIContent(Label), current_selected,
                                                      options.Select(t => new GUIContent(t)).ToArray(), LayoutOptions);
            }

            if (current_selected == new_selection)
            {
                return;
            }

            var variantValue = Variants.FirstOrDefault(t => t.Name == options[new_selection]);
            var newSelected  = variantValue == null ? default(T) : variantValue.Value;

            EventChange?.Invoke(newSelected);
            Selected = newSelected;
        }
Exemple #5
0
        private string DetermineDefaultParameterSetName()
        {
            var defaultParameterSet = Variants
                                      .Select(v => v.Metadata.DefaultParameterSetName)
                                      .LastOrDefault(dpsn => dpsn.IsValidDefaultParameterSetName());

            if (String.IsNullOrEmpty(defaultParameterSet))
            {
                var variantParamCountGroups = Variants
                                              .Select(v => (
                                                          variant: v.VariantName,
                                                          paramCount: v.CmdletOnlyParameters.Count(p => p.IsMandatory),
                                                          isSimple: v.CmdletOnlyParameters.Where(p => p.IsMandatory).All(p => p.ParameterType.IsPsSimple())))
                                              .GroupBy(vpc => vpc.isSimple)
                                              .ToArray();
                var variantParameterCounts = (variantParamCountGroups.Any(g => g.Key) ? variantParamCountGroups.Where(g => g.Key) : variantParamCountGroups).SelectMany(g => g).ToArray();
                var smallestParameterCount = variantParameterCounts.Min(vpc => vpc.paramCount);
                defaultParameterSet = variantParameterCounts.First(vpc => vpc.paramCount == smallestParameterCount).variant;
            }

            return(defaultParameterSet);
        }
        /// <summary>
        ///   The search chain for a resource.
        /// </summary>
        /// <returns>
        ///   A sequence of "languages" that should be searched.
        /// </returns>
        /// <remarks>
        ///   The sequence contains a combination of <see cref="Language"/>,
        ///   <see cref="Script"/>, <see cref="Region"/> and <see cref="Variants"/>
        ///   subtags.
        /// </remarks>
        public IEnumerable <string> SearchChain()
        {
            var languageChain = new[]
            {
                $"{Language}_{Script}_{Region}",
                $"{Language}_{Region}",
                $"{Language}_{Script}",
                $"{Language}"
            }
            .Select(s => s.Replace("__", "_").Trim('_'))
            .Where(s => s != String.Empty)
            .Distinct();

            // TODO: Not really sure about the search chain with more than one
            // variant.
            var variant = String.Join("_",
                                      Variants.Select(v => v.ToUpperInvariant())
                                      );

            // Check "u-va-*" for any language variants.
            if (UnicodeExtension.Keywords.ContainsKey("va"))
            {
                variant += "_" + UnicodeExtension.Keywords["va"].ToUpperInvariant();
                variant  = variant.TrimStart('_');
            }

            var variantChain = languageChain
                               .Select(s => s + "_" + variant);

            return(variantChain
                   .Concat(languageChain)
                   .Concat(new[] { "root" })
                   .Select(s => s.Replace("__", "_").Trim('_'))
                   .Where(s => s != String.Empty)
                   .Distinct());
        }
Exemple #7
0
 public ICollection <string> GetDistinctVariantPropertyValues(string propertyName)
 {
     return(Variants.Select(variant => variant.Item[propertyName]).Distinct().Where(x => !string.IsNullOrWhiteSpace(x)).ToList());
 }