Ejemplo n.º 1
0
        //public virtual ObservableCollection<DynamicPropertyObjectValueEntity> ObjectValues { get; set; }


        public virtual DynamicProperty ToModel(DynamicProperty dynamicProp)
        {
            if (dynamicProp == null)
            {
                throw new ArgumentNullException(nameof(dynamicProp));
            }

            dynamicProp.Id             = Id;
            dynamicProp.CreatedBy      = CreatedBy;
            dynamicProp.CreatedDate    = CreatedDate;
            dynamicProp.ModifiedBy     = ModifiedBy;
            dynamicProp.ModifiedDate   = ModifiedDate;
            dynamicProp.Description    = Description;
            dynamicProp.DisplayOrder   = DisplayOrder;
            dynamicProp.IsArray        = IsArray;
            dynamicProp.IsDictionary   = IsDictionary;
            dynamicProp.IsMultilingual = IsMultilingual;
            dynamicProp.IsRequired     = IsRequired;
            dynamicProp.Name           = Name;
            dynamicProp.ObjectType     = ObjectType;

            dynamicProp.ValueType    = EnumUtility.SafeParse(ValueType, DynamicPropertyValueType.LongText);
            dynamicProp.DisplayNames = DisplayNames.Select(x => x.ToModel(AbstractTypeFactory <DynamicPropertyName> .TryCreateInstance())).ToArray();
            //if (dynamicProp is DynamicObjectProperty dynamicObjectProp)
            //{
            //    dynamicObjectProp.Values = ObjectValues.Select(x => x.ToModel(AbstractTypeFactory<DynamicPropertyObjectValue>.TryCreateInstance())).ToArray();
            //}
            return(dynamicProp);
        }
Ejemplo n.º 2
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as Property;

            if (Attributes != null)
            {
                result.Attributes = Attributes.Select(x => x.Clone()).OfType <PropertyAttribute>().ToList();
            }
            if (DictionaryValues != null)
            {
                result.DictionaryValues = DictionaryValues.Select(x => x.Clone()).OfType <PropertyDictionaryValue>().ToList();
            }
            if (DisplayNames != null)
            {
                result.DisplayNames = DisplayNames.Select(x => x.Clone()).OfType <PropertyDisplayName>().ToList();
            }
            if (ValidationRules != null)
            {
                result.ValidationRules = ValidationRules.Select(x => x.Clone()).OfType <PropertyValidationRule>().ToList();
            }
            if (Values != null)
            {
                result.Values = Values.Select(x => x.Clone()).OfType <PropertyValue>().ToList();
            }
            return(result);
        }
Ejemplo n.º 3
0
        private void BuildDataMap()
        {
            _stringDic.Clear();
            _dicMap.Clear();
            foreach (int enumI in Enum.GetValues(typeof(TValue)))
            {
                string stringKey = ((int)enumI).ToString();
                string stringVal = Enum.GetName(typeof(TValue), enumI);
                TValue enumVal   = (TValue)Enum.ToObject(typeof(TValue), enumI);

                if (Exclude != null && Exclude.Contains(enumVal))
                {
                    continue;
                }

                if (DisplayNames != null && DisplayNames.ContainsKey(enumVal))
                {
                    _stringDic.Add(stringKey, DisplayNames[enumVal]);
                }
                else
                {
                    _stringDic.Add(stringKey, stringVal);
                }

                _dicMap.Add(stringKey, enumVal);
            }
        }
        public static string GetDisplayName(this Enum enumValue, UserType?userType = null)
        {
            if (enumValue == null)
            {
                return(string.Empty);
            }

            DisplayNames.TryGetValue(enumValue, out var displayName);

            if (userType.HasValue)
            {
                switch (userType)
                {
                case UserType.Employer:
                    if (DisplayNamesEmployer.TryGetValue(enumValue, out var displayNameEmployer))
                    {
                        displayName = displayNameEmployer;
                    }
                    break;

                case UserType.Provider:
                    if (DisplayNamesProvider.TryGetValue(enumValue, out var displayNameProvider))
                    {
                        displayName = displayNameProvider;
                    }
                    break;
                }
            }

            return(displayName ?? enumValue.ToString());
        }
Ejemplo n.º 5
0
        public virtual void Patch(PropertyEntity target)
        {
            target.PropertyValueType = PropertyValueType;
            target.IsEnum            = IsEnum;
            target.IsMultiValue      = IsMultiValue;
            target.IsLocaleDependant = IsLocaleDependant;
            target.IsRequired        = IsRequired;
            target.TargetType        = TargetType;
            target.Name = Name;

            target.CatalogId  = CatalogId;
            target.CategoryId = CategoryId;

            if (!PropertyAttributes.IsNullCollection())
            {
                var attributeComparer = AnonymousComparer.Create((PropertyAttributeEntity x) => x.IsTransient() ? x.PropertyAttributeName : x.Id);
                PropertyAttributes.Patch(target.PropertyAttributes, attributeComparer, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset));
            }
            if (!DictionaryItems.IsNullCollection())
            {
                var dictItemComparer = AnonymousComparer.Create((PropertyDictionaryItemEntity x) => $"{x.Alias}-${x.PropertyId}");
                DictionaryItems.Patch(target.DictionaryItems, dictItemComparer, (sourceDictItem, targetDictItem) => sourceDictItem.Patch(targetDictItem));
            }
            if (!DisplayNames.IsNullCollection())
            {
                var displayNamesComparer = AnonymousComparer.Create((PropertyDisplayNameEntity x) => $"{x.Name}-{x.Locale}");
                DisplayNames.Patch(target.DisplayNames, displayNamesComparer, (sourceDisplayName, targetDisplayName) => sourceDisplayName.Patch(targetDisplayName));
            }

            if (!ValidationRules.IsNullCollection())
            {
                ValidationRules.Patch(target.ValidationRules, (sourceRule, targetRule) => sourceRule.Patch(targetRule));
            }
        }
Ejemplo n.º 6
0
 public override void PopulateDisplayName()
 {
     ItemName = DisplayNames.GetPizzaDisplayName(PizzaType);
     if (MajorMamaInfo == MajorOrMama.Major)
     {
         ItemName += " - MAJOR";
     }
 }
Ejemplo n.º 7
0
 public Dessert(DessertType dessertType)
 {
     DessertType = dessertType;
     DbItemId    = MenuFood.GetDbItemId(dessertType);
     ItemName    = DisplayNames.GetDessertDisplayName(dessertType)[0];
     ShortName   = DisplayNames.GetDessertDisplayName(dessertType)[1];
     PopulateBasePrice();
     PopulatePricePerItem();
 }
Ejemplo n.º 8
0
 public virtual void Patch(DynamicPropertyDictionaryItemEntity target)
 {
     target.Name = Name;
     if (!DisplayNames.IsNullCollection())
     {
         var comparer = AnonymousComparer.Create((DynamicPropertyDictionaryItemNameEntity v) => string.Join("-", v.Locale, v.Name));
         DisplayNames.Patch(target.DisplayNames, comparer, (sourceItem, targetItem) => { });
     }
 }
Ejemplo n.º 9
0
        public static string GetDisplayName(this Enum enumValue)
        {
            if (enumValue == null)
            {
                return(string.Empty);
            }

            DisplayNames.TryGetValue(enumValue, out var displayName);
            return(displayName ?? enumValue.ToString());
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Get the display name for the specified key name.
 /// If no display name is stored for the key the
 /// key value itself will be returned.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public string GetDisplayName(string key)
 {
     if (DisplayNames.ContainsKey(key))
     {
         return(DisplayNames[key]);
     }
     else
     {
         return(key);
     }
 }
Ejemplo n.º 11
0
 public PluginInterface()
 {
     _dn = new DisplayNames
     {
         name   = "tfs",
         id     = "Changeset",
         author = "Committer",
         date   = "CreationDate",
         log    = "Comment",
         parent = "Parent",
     };
 }
        public virtual DynamicPropertyDictionaryItem ToModel(DynamicPropertyDictionaryItem dictItem)
        {
            if (dictItem == null)
            {
                throw new ArgumentNullException(nameof(dictItem));
            }

            dictItem.PropertyId   = PropertyId;
            dictItem.Name         = Name;
            dictItem.DisplayNames = DisplayNames.Select(x => x.ToModel(AbstractTypeFactory <DynamicPropertyDictionaryItemName> .TryCreateInstance())).ToArray();
            return(dictItem);
        }
Ejemplo n.º 13
0
 public PluginInterface()
 {
     _dn = new DisplayNames
     {
         name   = "SQLiteCache",
         id     = "id",
         parent = "parent",
         author = "User",
         log    = "Comment",
         date   = "date",
     };
 }
Ejemplo n.º 14
0
        public void LoadConfigDisplayInfo()
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();
            bool userFound = false;

            if (CurConfig == null)
            {
                return;
            }

            // Load Available Display Names
            displayNames       = new ObservableCollection <string>();
            ConfigDisplayTable = new ObservableCollection <ExperimentDisplay>();

            List <ExperimentDisplay> expDisplayAll = (from eD in db.ExperimentDisplays
                                                      join uIc in db.UsersInConfigs on
                                                      new { eD.UserID, ConfigID = CurConfig.ConfigID }
                                                      equals
                                                      new { uIc.UserID, uIc.ConfigID }
                                                      where eD.ExperimentID == CurExperimentID
                                                      select eD).ToList();

            foreach (ExperimentDisplay expDisplay in expDisplayAll)
            {
                // Make sure all users in configuration have access to this display
                foreach (User user in UsersInConfig)
                {
                    userFound = false;
                    foreach (ExperimentDisplay expDisplay2 in expDisplayAll)
                    {
                        if ((expDisplay2.UserID == user.UserID) &&
                            (expDisplay2.DisplayID == expDisplay.DisplayID))
                        {
                            userFound = true;
                            break;
                        }
                    }
                    if (!userFound)
                    {
                        break;
                    }
                }
                if ((userFound) && (!DisplayNames.Contains(expDisplay.Display.Name)))
                {
                    // Add this Display to the available Display list
                    ConfigDisplayTable.Add(expDisplay);
                    DisplayNames.Add(expDisplay.Display.Name);
                }
            }

            OnPropertyChanged("DisplayNames");
        }
        private static void RegisterTacticDatas()
        {
            Type targetSelectionTacticDataType = typeof(TargetSelectionTactic);
            IEnumerable <Type> tacticDataTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(targetSelectionTacticDataType));

            foreach (var type in tacticDataTypes)
            {
                TargetSelectionTactic tactic = (TargetSelectionTactic)Activator.CreateInstance(type);

                int count = TacticDatas.Count;

                string name = tactic.Name;
                if (NameToID.ContainsKey(name))
                {
                    throw new Exception($"A {nameof(TargetSelectionTactic)} of name '{name}' has already been added!");
                }

                if (count >= DefaultTacticID)
                {
                    throw new Exception($"Data limit of {DefaultTacticID} reached!");
                }

                TacticDatas.Add(tactic);
                DisplayNames.Add(tactic.DisplayName);
                Descriptions.Add(tactic.Description);
                string texture = tactic.Texture;
                Textures.Add(ModContent.GetTexture(texture));
                OutlineTextures.Add(ModContent.GetTexture(texture + "_Outline"));
                SmallTextures.Add(ModContent.GetTexture(texture + "_Small"));

                byte id = (byte)count;
                Count++;
                TypeToID[type] = id;
                NameToID[name] = id;
                tactic.ID      = id;
            }

            OrderedIds = new List <byte>
            {
                //First row
                GetTactic <ClosestEnemyToMinion>().ID,
                GetTactic <StrongestEnemy>().ID,
                GetTactic <LeastDamagedEnemy>().ID,
                GetTactic <SpreadOut>().ID,

                //Second row
                GetTactic <ClosestEnemyToPlayer>().ID,
                GetTactic <WeakestEnemy>().ID,
                GetTactic <MostDamagedEnemy>().ID,
                GetTactic <AttackGroups>().ID,
            };
        }
Ejemplo n.º 16
0
        public AlgoService(IContainer container, ILogger <AlgoService> logger, IEventAggregator eventAggregator)
        {
            _logger          = logger;
            _eventAggregator = eventAggregator;

            Algos = container.GetAll <IAlgo>().ToDictionary(_ => Guid.NewGuid());
            _logger.LogInformation("Found {count} algorithms of type {type}", Algos.Count, "dotnet");

            foreach (var algo in Algos)
            {
                DisplayNames.Add(algo.Key, algo.Value.Name);
            }
        }
Ejemplo n.º 17
0
        public virtual void TryInheritFrom(IEntity parent)
        {
            if (parent is Property parentProperty)
            {
                IsInherited     = true;
                Id              = parentProperty.Id;
                CreatedBy       = parentProperty.CreatedBy;
                ModifiedBy      = parentProperty.ModifiedBy;
                CreatedDate     = parentProperty.CreatedDate;
                ModifiedDate    = parentProperty.ModifiedDate;
                Required        = parentProperty.Required;
                Dictionary      = parentProperty.Dictionary;
                Multivalue      = parentProperty.Multivalue;
                Multilanguage   = parentProperty.Multilanguage;
                ValueType       = parentProperty.ValueType;
                Type            = parentProperty.Type;
                Attributes      = parentProperty.Attributes;
                DisplayNames    = parentProperty.DisplayNames;
                ValidationRules = parentProperty.ValidationRules;

                if (Values.IsNullOrEmpty() && !parentProperty.Values.IsNullOrEmpty())
                {
                    Values = new List <PropertyValue>();
                    foreach (var parentPropValue in parentProperty.Values)
                    {
                        var propValue = AbstractTypeFactory <PropertyValue> .TryCreateInstance();

                        propValue.TryInheritFrom(parentPropValue);
                        Values.Add(propValue);
                    }
                }
                foreach (var propValue in Values ?? Array.Empty <PropertyValue>())
                {
                    propValue.PropertyId = parentProperty.Id;
                    propValue.ValueType  = parentProperty.ValueType;
                }
            }

            if (parent is Catalog catalog)
            {
                var displayNamesComparer            = AnonymousComparer.Create((PropertyDisplayName x) => $"{x.LanguageCode}");
                var displayNamesForCatalogLanguages = catalog.Languages.Select(x => new PropertyDisplayName {
                    LanguageCode = x.LanguageCode
                }).ToList();
                //Leave display names only with catalog languages
                DisplayNames = DisplayNames.Intersect(displayNamesForCatalogLanguages, displayNamesComparer).ToList();
                //Add missed
                DisplayNames.AddRange(displayNamesForCatalogLanguages.Except(DisplayNames, displayNamesComparer));
                IsManageable = true;
            }
        }
Ejemplo n.º 18
0
        public ToppingsPageModel(Pizza currentPizza)
        {
            ThisPizza = currentPizza;
            string pizzaName = ThisPizza.ItemName;

            BaseSelections = new string[]
            {
                "Pesto Base", "White Base", "Regular Base"
            };
            CookSelections = new string[]
            {
                "Crispy Cook", "Kid Cook", "Light Cook", "Regular Cook"
            };

            var toppingsList = Toppings.AllToppings;

            ToppingSelectionsList = new ObservableCollection <ToppingSelection>();
            for (int i = 0; i < toppingsList.Count; i++)
            {
                var toppingSelection = new ToppingSelection(this);
                toppingSelection.ListTopping                = toppingsList[i];
                toppingSelection.SelectionIndex             = i;
                toppingSelection.SelectionColor             = Xamarin.Forms.Color.Black;
                toppingSelection.WButtonTextColor           = Color.White;
                toppingSelection.AreWholeHalfColumnsVisible = true;
                if (toppingsList[i].ToppingName == ToppingName.HalfMajor)
                {
                    toppingSelection.WButtonTextColor = Color.Black;
                }
                ToppingSelectionsList.Add(toppingSelection);

                //If the pizza type is a slice, don't display whole/halfa/halfb options.

                toppingSelection.AreWholeHalfColumnsVisible = true;
                if (pizzaName.Equals(DisplayNames.GetPizzaDisplayName(PizzaType.ThinSlice)) ||
                    pizzaName.Equals(DisplayNames.GetPizzaDisplayName(PizzaType.PanSlice)))
                {
                    toppingSelection.AreWholeHalfColumnsVisible = false;
                }
            }

            if (ThisPizza != null)
            {
                if (ThisPizza.MajorMamaInfo == MajorOrMama.Major)
                {
                    SelectMajorToppings();
                    ThisPizza.Toppings.AddMajorToppings();
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns the level, task, opcode and keywords of the specified EventRecord object as strings.
        /// </summary>
        /// <param name="evt">EventRecord - the event to return data for.</param>
        /// <param name="level">(out) string - the event level.</param>
        /// <param name="task">(out) string - the string representation of the event Task identifier.</param>
        /// <param name="opcode">(out) string - the string representation of the event OpCode identifier.</param>
        /// <param name="keywords">(out) string - the keyword(s) for the event.</param>
        public void Lookup(EventRecord evt, out string level, out string task, out string opcode, out string keywords)
        {
            var providerId = evt.ProviderId.ToString();

            if (providerId == null)
            {
                providerId = evt.ProviderName;
            }

            ConcurrentDictionary <int, DisplayNames> events = null;

            if (!_cache.TryGetValue(providerId, out events))
            {
                events = new ConcurrentDictionary <int, DisplayNames>();
                _cache.TryAdd(providerId, events);
            }

            DisplayNames names = null;

            if (!events.TryGetValue(evt.Id, out names))
            {
                names = null;
                try
                {
                    names = new DisplayNames
                    {
                        Level    = ValueOrEmpty(evt.LevelDisplayName),
                        Task     = ValueOrEmpty(evt.TaskDisplayName),
                        Opcode   = ValueOrEmpty(evt.OpcodeDisplayName),
                        Keywords = ValueOrEmpty(string.Join(",", evt.KeywordsDisplayNames))
                    };
                }
                catch (Exception)
                {
                    names = new DisplayNames
                    {
                        Level  = ValueOrEmpty(evt.Level.ToString()),
                        Task   = ValueOrEmpty(evt.Task.ToString()),
                        Opcode = ValueOrEmpty(evt.Opcode.ToString())
                    };
                }

                events.TryAdd(evt.Id, names);
            }

            level    = names.Level;
            task     = names.Task;
            opcode   = names.Opcode;
            keywords = names.Keywords;
        }
Ejemplo n.º 20
0
        private void LoadSaladDisplayItems()
        {
            var toppingsList = MenuFood.SaladToppings.Values.ToList();

            SaladToppingSelectionsList = new ObservableCollection <SaladToppingDisplayItem>();
            int toppingSelectionIndex = 0;

            for (int i = 0; i < toppingsList.Count; i++)
            {
                if (!toppingsList[i].ForSalad)
                {
                    continue;
                }
                var toppingSelection = new SaladToppingDisplayItem(this);

                bool toppingAlreadyOnSalad = false;
                if (CurrentSalad != null && CurrentSalad.Toppings != null)
                {
                    foreach (var topping in CurrentSalad.Toppings.CurrentToppings)
                    {
                        if (topping.ToppingName == toppingsList[i].ToppingName)
                        {
                            toppingAlreadyOnSalad                   = true;
                            toppingSelection.SaladTopping           = topping;
                            toppingSelection.SaladToppingIsSelected = true;
                            break;
                        }
                    }
                }
                if (!toppingAlreadyOnSalad)
                {
                    Topping newTopping = toppingsList[i];
                    //Initialize variable items in Topping object:
                    newTopping.ToppingDisplayName = DisplayNames.GetToppingDisplayName(newTopping.ToppingName);
                    newTopping.ToppingModifier    = ToppingModifierType.None;
                    newTopping.ToppingWholeHalf   = ToppingWholeHalf.Whole;
                    newTopping.SequenceSelected   = 0;
                    newTopping.Count = 1;
                    toppingSelection.SaladTopping           = newTopping;
                    toppingSelection.SaladToppingIsSelected = false;
                }

                toppingSelection.SaladSelectionIndex = toppingSelectionIndex;
                toppingSelectionIndex++;

                SaladToppingSelectionsList.Add(toppingSelection);
            }
        }
Ejemplo n.º 21
0
        public PluginInterface()
        {
            ofd                              = new OpenFileDialog();
            ofd.Filter                       = "Monotone db (*.mtn)|*.mtn|All files (*.*)|*.*";
            ofd.Title                        = "Open a monotone database";
            ofd.AutoUpgradeEnabled           = true;
            ofd.CheckFileExists              = true;
            ofd.SupportMultiDottedExtensions = true;

            _dn        = new DisplayNames();
            _dn.name   = "Monotone";
            _dn.author = "Author";
            _dn.date   = "Date";
            _dn.id     = "Revision";
            _dn.log    = "ChangeLog";
            _dn.parent = "Ancester";
        }
Ejemplo n.º 22
0
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validationResults = new List <ValidationResult>();

            if (Files[0] == null)
            {
                validationResults.Add(new SitkaValidationResult <NewProjectDocumentViewModel, List <HttpPostedFileBase> >($"You must select at least one file to upload.", m => m.Files));
            }

            if (DisplayNames.Distinct().Count() < DisplayNames.Count())
            {
                validationResults.Add(new SitkaValidationResult <NewProjectDocumentViewModel, List <string> >($"Cannot submit multiple files with the same Display Name for a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Document", m => m.DisplayNames));
            }

            for (int key = 0; key < Files.Count; key++)
            {
                if (DisplayNames[key].IsNullOrWhiteSpace())
                {
                    validationResults.Add(new SitkaValidationResult <NewProjectDocumentViewModel, List <string> >($"Display Name is a required field.", m => m.DisplayNames));
                }


                if (Descriptions[key].Length > Models.ProjectDocument.FieldLengths.Description)
                {
                    validationResults.Add(new SitkaValidationResult <NewProjectDocumentViewModel, List <string> >($"Display Name \"{Descriptions[key]}\" is longer than the allowed {Models.ProjectDocument.FieldLengths.Description} character maximum.", m => m.Descriptions));
                }

                if (DisplayNames[key].Length > Models.ProjectDocument.FieldLengths.DisplayName)
                {
                    validationResults.Add(new SitkaValidationResult <NewProjectDocumentViewModel, List <string> >($"Display Name \"{DisplayNames[key]}\" is longer than the allowed {Models.ProjectDocument.FieldLengths.DisplayName} character maximum.", m => m.DisplayNames));
                }

                FileResource.ValidateFileSize(Files[key], validationResults, "Files");

                var displayNameToLower = DisplayNames[key].ToLower();

                if (HttpRequestStorage.DatabaseEntities.ProjectDocuments.Where(x => x.ProjectID == ParentID)
                    .Any(x => x.DisplayName.ToLower() == displayNameToLower))
                {
                    validationResults.Add(new SitkaValidationResult <NewProjectDocumentViewModel, List <string> >($"There is already a document with the Display Name \"{DisplayNames[key]}\" attached to this {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}. Display Name must be unique for each Document attached to a {Models.FieldDefinition.Project.GetFieldDefinitionLabel()}", m => m.DisplayNames));
                }
            }

            return(validationResults);
        }
Ejemplo n.º 23
0
 private void ChangeLunchSpecialDiscount(bool giveDiscount)
 {
     if (giveDiscount)
     {
         if (Toppings.ToppingsTotal > 0)
         {
             decimal lunchDiscount = Prices.GetLunchSpecialDiscount();
             ItemName = "Lunch Special Pizza Slice";
             Toppings.ToppingsDiscount = lunchDiscount;
             Toppings.UpdateToppingsTotal();
         }
     }
     else
     {
         ItemName = DisplayNames.GetPizzaDisplayName(PizzaType);
         Toppings.ToppingsDiscount = 0M;
         Toppings.UpdateToppingsTotal();
     }
 }
Ejemplo n.º 24
0
        public virtual void TryInheritFrom(IEntity parent)
        {
            if (parent is Property parentProperty)
            {
                IsInherited     = true;
                Id              = parentProperty.Id ?? Id;
                Name            = parentProperty.Name ?? Name;
                CreatedBy       = parentProperty.CreatedBy ?? CreatedBy;
                ModifiedBy      = parentProperty.ModifiedBy ?? ModifiedBy;
                CreatedDate     = parentProperty.CreatedDate;
                ModifiedDate    = parentProperty.ModifiedDate ?? ModifiedDate;
                Required        = parentProperty.Required;
                Dictionary      = parentProperty.Dictionary;
                Multivalue      = parentProperty.Multivalue;
                Multilanguage   = parentProperty.Multilanguage;
                ValueType       = parentProperty.ValueType;
                Type            = parentProperty.Type;
                Attributes      = parentProperty.Attributes;
                DisplayNames    = parentProperty.DisplayNames;
                ValidationRules = parentProperty.ValidationRules;
                CatalogId       = parentProperty.CatalogId;
                CategoryId      = parentProperty.CategoryId;
                Hidden          = parentProperty.Hidden;

                foreach (var propValue in (Values ?? Array.Empty <PropertyValue>()).Where(x => x != null))
                {
                    propValue.PropertyId = parentProperty.Id;
                    propValue.ValueType  = parentProperty.ValueType;
                }
            }

            if (parent is Catalog catalog)
            {
                var displayNamesComparer            = AnonymousComparer.Create((PropertyDisplayName x) => $"{x.LanguageCode}");
                var displayNamesForCatalogLanguages = catalog.Languages.Select(x => new PropertyDisplayName {
                    LanguageCode = x.LanguageCode
                }).ToList();
                //Leave display names only with catalog languages
                DisplayNames = DisplayNames.Intersect(displayNamesForCatalogLanguages, displayNamesComparer).ToList();
                //Add missed
                DisplayNames.AddRange(displayNamesForCatalogLanguages.Except(DisplayNames, displayNamesComparer));
            }
        }
Ejemplo n.º 25
0
        public JObject GetJson()
        {
            var ordered = Stats.OrderByDescending(x => x.Value.TotalSent).Where(x => x.Key != 0).Select(x => x.Key).ToList();

            if (ordered.Count > max)
            {
                var os = new ValueStats();
                Stats[0]        = os;
                DisplayNames[0] = $"Other ({max - ordered.Count})";
                foreach (var other in ordered.Skip(max))
                {
                    // new = old + (val - old / n)
                    var ex = Stats[other];
                    for (int i = 0; i < ex.TotalSent; i++)
                    {
                        os.TotalSent++;
                        os.AddAverage(ex.AverageLength, ref os.AverageLength);
                        os.AddAverage(ex.AverageSecondsIntoDay, ref os.AverageSecondsIntoDay);
                    }
                }
                ordered = ordered.Take(max).ToList();
                ordered.Add(0);
            }
            var jobj = new JObject();

            jobj["total"] = AllStats.ToJson();
            foreach (var id in ordered)
            {
                var stats  = Stats[id];
                var key    = DisplayNames.GetValueOrDefault(id, id.ToString());
                var user   = Program.Client.GetUser(id);
                var obj    = new JObject();
                var usrObj = new JObject();
                usrObj["username"]  = user?.Username ?? key;
                usrObj["avatar"]    = user?.GetAnyAvatarUrl() ?? "n/a";
                obj["user"]         = usrObj;
                obj["stats"]        = stats.ToJson();
                jobj[id.ToString()] = obj;
            }
            jobj["words"] = JObject.FromObject(GetWords());
            return(jobj);
        }
Ejemplo n.º 26
0
        public virtual void Patch(DynamicPropertyEntity target)
        {
            target.Name         = Name;
            target.Description  = Description;
            target.IsRequired   = IsRequired;
            target.IsArray      = IsArray;
            target.DisplayOrder = DisplayOrder;

            if (!DisplayNames.IsNullCollection())
            {
                var comparer = AnonymousComparer.Create((DynamicPropertyNameEntity x) => string.Join("-", x.Locale, x.Name));
                DisplayNames.Patch(target.DisplayNames, comparer, (sourceItem, targetItem) => { });
            }

            //if (!ObjectValues.IsNullCollection())
            //{
            //    var comparer = AnonymousComparer.Create((DynamicPropertyObjectValueEntity x) => $"{x.ObjectId}:{x.ObjectType}:{x.Locale}:{x.GetValue(EnumUtility.SafeParse(x.ValueType, DynamicPropertyValueType.LongText))}");
            //    ObjectValues.Patch(target.ObjectValues, comparer, (sourceValue, targetValue) => sourceValue.Patch(targetValue));
            //}
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Convert this data set to a delimiter-separated string,
        /// suitable for writing out to a text file.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            // Title bar
            sb.Append("[KEY NAME]");
            sb.Append(Delimiter);
            sb.Append("[DISPLAY NAME]");
            sb.Append(Delimiter);
            sb.Append("[TOOLTIP]");
            sb.AppendLine();

            foreach (var kvp in DisplayNames)
            {
                sb.Append(kvp.Key);
                sb.Append(Delimiter);
                sb.Append(kvp.Value);
                if (ToolTips.ContainsKey(kvp.Key))
                {
                    sb.Append(Delimiter);
                    sb.Append(ToolTips[kvp.Key]);
                }
                sb.AppendLine();
            }
            // Write any tooltips that were missed
            foreach (var kvp in ToolTips)
            {
                if (!DisplayNames.ContainsKey(kvp.Key))
                {
                    sb.Append(kvp.Key);
                    sb.Append(Delimiter);
                    sb.Append(Delimiter);
                    sb.Append(kvp.Value);
                    sb.AppendLine();
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (Child == null)
     {
         throw new ValidationException(ValidationRules.CannotBeNull, "Child");
     }
     if (DisplayNames != null)
     {
         if (DisplayNames.Count > 6)
         {
             throw new ValidationException(ValidationRules.MaxItems, "DisplayNames", 6);
         }
         if (DisplayNames.Count < 0)
         {
             throw new ValidationException(ValidationRules.MinItems, "DisplayNames", 0);
         }
         if (DisplayNames.Count != DisplayNames.Distinct().Count())
         {
             throw new ValidationException(ValidationRules.UniqueItems, "DisplayNames");
         }
     }
     if (Capacity >= 100)
     {
         throw new ValidationException(ValidationRules.ExclusiveMaximum, "Capacity", 100);
     }
     if (Capacity <= 0)
     {
         throw new ValidationException(ValidationRules.ExclusiveMinimum, "Capacity", 0);
     }
     if (Image != null)
     {
         if (!System.Text.RegularExpressions.Regex.IsMatch(Image, "http://\\w+"))
         {
             throw new ValidationException(ValidationRules.Pattern, "Image", "http://\\w+");
         }
     }
 }
Ejemplo n.º 29
0
        public virtual Property ToModel(Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            property.Id           = Id;
            property.CreatedBy    = CreatedBy;
            property.CreatedDate  = CreatedDate;
            property.ModifiedBy   = ModifiedBy;
            property.ModifiedDate = ModifiedDate;

            property.CatalogId  = CatalogId;
            property.CategoryId = CategoryId;

            property.Name          = Name;
            property.Required      = IsRequired;
            property.Multivalue    = IsMultiValue;
            property.Multilanguage = IsLocaleDependant;
            property.Dictionary    = IsEnum;
            property.Hidden        = IsHidden;
            property.ValueType     = (PropertyValueType)PropertyValueType;
            property.Type          = EnumUtility.SafeParse(TargetType, PropertyType.Catalog);


            property.Attributes      = PropertyAttributes.Select(x => x.ToModel(AbstractTypeFactory <PropertyAttribute> .TryCreateInstance())).ToList();
            property.DisplayNames    = DisplayNames.Select(x => x.ToModel(AbstractTypeFactory <PropertyDisplayName> .TryCreateInstance())).ToList();
            property.ValidationRules = ValidationRules.Select(x => x.ToModel(AbstractTypeFactory <PropertyValidationRule> .TryCreateInstance())).ToList();

            foreach (var rule in property.ValidationRules)
            {
                rule.Property = property;
            }

            return(property);
        }
Ejemplo n.º 30
0
 public override void PopulateDisplayName()
 {
     ItemName = DisplayNames.GetSaladDisplayName(SizeOfSalad);
 }