示例#1
0
        public object GetValue(TaxonomyInfo taxonomy, Attribute attribute, SchemaAttribute schematus)
        {
            if (taxonomy == null && attribute == null)
            {
                return(schematus);
            }

            if (taxonomy == null)
            {
                return(attribute);
            }

            if (attribute == null)
            {
                return(taxonomy);
            }

            var schemaInfo = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute != null && si.Attribute.Equals(attribute));

            if (schematus == null || schemaInfo == null)
            {
                return(null);
            }

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                SchemaData activeSchemaData = schemaInfo.SchemaDatas.FirstOrDefault(sd => sd.Active);
                if (activeSchemaData == null)
                {
                    return(null);
                }

                PropertyInfo valueProperty =
                    activeSchemaData.GetType().GetProperty(schematus.PrimarySchemaAttribute.Replace(" ", String.Empty));
                return(valueProperty.GetValue(activeSchemaData, null));

            case SchemaAttributeType.Meta:
                SchemaMetaData metaSchemaData = (from mi in schemaInfo.SchemaMetaInfos
                                                 where mi.Attribute.Equals(schematus.MetaSchemaAttribute) && mi.SchemaMetaData != null
                                                 select mi.SchemaMetaData).FirstOrDefault();
                return(metaSchemaData);

            case SchemaAttributeType.Special:
                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusIsMapped))
                {
                    SchemaData activeSd = schemaInfo.SchemaDatas.FirstOrDefault(sd => sd.Active);
                    if (activeSd != null)
                    {
                        return("x");
                    }
                }

                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusAttributeType))
                {
                    return(attribute.AttributeType);
                }

                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusListOfValues))
                {
                    var listOfValues = schemaInfo.ListOfValues.Where(lov => lov.Active == true).Select(lov => lov).ToList();
                    if (listOfValues.Any())
                    {
                        string listSep = Currentproject.ProjPreferences.ListSeparator ?? "; ";
                        return(listOfValues.OrderBy(val => val.DisplayOrder).ThenBy(val => val.Value).Select(val => val.Value).Aggregate((current, lov) => current + listSep + lov));
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(null);

            //case SchemaAttributeType.FillRate:
            //    double? fillRate = AryaTools.Instance.AllFillRates.GetFillRate(
            //        taxonomy, attribute, schematus.FillRateSchemaAttribute);
            //    if (fillRate == Double.MinValue)
            //    {
            //        SchemaDataGridView.RefreshGridView = true;
            //        return "Calculating...";
            //    }

            //    return fillRate;

            default:
                return(null);
            }
        }
示例#2
0
        public string SetValue(
            TaxonomyInfo taxonomy, Attribute attribute, bool autoMapSchema, SchemaAttribute schematus, object value, bool suppressAutoMapMessage = false)
        {
            SchemaInfo schemaInfo    = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(attribute));
            bool       newSchemaInfo = false;

            if (schemaInfo == null)
            {
                if (suppressAutoMapMessage)
                {
                    return(null);
                }
                if (!autoMapSchema &&
                    MessageBox.Show(
                        String.Format(
                            "Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?", attribute,
                            taxonomy.TaxonomyData.NodeName), @"Add to Schema", MessageBoxButtons.YesNo) ==
                    DialogResult.No)
                {
                    return(null);
                }
                schemaInfo = new SchemaInfo {
                    Attribute = attribute
                };
                taxonomy.SchemaInfos.Add(schemaInfo);
                newSchemaInfo = true;
            }



            if (schematus == null)
            {
                //Create/Update Schema Info only
                SchemaData currentSchemaData = schemaInfo.SchemaData;
                var        newSchemaData     = new SchemaData();
                if (value != null && value is SchemaData)
                {
                    var fromSchemaData = (SchemaData)value;
                    if (currentSchemaData != null && currentSchemaData.Equals(fromSchemaData))
                    {
                        return(null);
                    }

                    newSchemaData.DataType        = fromSchemaData.DataType;
                    newSchemaData.DisplayOrder    = fromSchemaData.DisplayOrder;
                    newSchemaData.NavigationOrder = fromSchemaData.NavigationOrder;
                    newSchemaData.InSchema        = fromSchemaData.InSchema;
                }

                if (currentSchemaData != null)
                {
                    currentSchemaData.Active = false;
                }
                schemaInfo.SchemaDatas.Add(newSchemaData);
                return(null);
            }

            SchemaData activeSd = schemaInfo.SchemaData;

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                bool reallyNewSd  = false;
                bool reorderRanks = false;

                SchemaData newSchemaData;
                if (activeSd == null)
                {
                    reallyNewSd   = true;
                    newSchemaData = new SchemaData();
                }
                else
                {
                    //activeSd.DeletedBy = AryaTools.Instance.InstanceData.CurrentUser.ID;
                    activeSd.DeletedByUser = CurrentUser;     //fixes Object not found error
                    activeSd.DeletedOn     = DateTime.Now;
                    newSchemaData          = new SchemaData
                    {
                        DataType        = activeSd.DataType, InSchema = activeSd.InSchema,
                        NavigationOrder = activeSd.NavigationOrder,
                        DisplayOrder    = activeSd.DisplayOrder
                    };
                }

                string propertyName = schematus.PrimarySchemaAttribute.Replace(" ", String.Empty);

                PropertyInfo valueProperty = newSchemaData.GetType().GetProperty(propertyName);
                Type         propertyType  = valueProperty.PropertyType;


                if (propertyType == typeof(string))
                {
                    object stringValue = value ?? String.Empty;
                    if (propertyName == "DataType")
                    {
                        stringValue = ValidateDataType(stringValue);
                    }

                    if (!(valueProperty.GetValue(newSchemaData, null) ?? String.Empty).Equals(stringValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, stringValue.ToString(), null);
                    }
                }
                else if (propertyType == typeof(bool))
                {
                    object boolValue = value ?? false;
                    string firstCharacter;
                    try
                    {
                        firstCharacter = boolValue.ToString().Substring(0, 1).ToLower();
                    }
                    catch (Exception)
                    {
                        firstCharacter = "f";
                    }

                    bool newValue = firstCharacter.Equals("t") || firstCharacter.Equals("y") ||
                                    firstCharacter.Equals("1");

                    if (!((bool)valueProperty.GetValue(newSchemaData, null)).Equals(newValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, newValue, null);
                    }
                }
                //else if (propertyType == typeof (decimal))
                //{
                //    object decimalValue = value ?? 0.0;
                //    decimal newDecimalValue;
                //    if (Decimal.TryParse(decimalValue.ToString(), out newDecimalValue))
                //    {
                //        if (!((decimal) valueProperty.GetValue(newSchemaData, null)).Equals(newDecimalValue))
                //        {
                //            reallyNewSd = true;
                //            valueProperty.SetValue(newSchemaData, newDecimalValue, null);
                //            reorderRanks = SchemaDataGridView.AutoOrderRanks;
                //        }
                //    }
                //    else
                //        return String.Format(
                //            "Invalid value [{0}] for [{1}] - [{2}].{3}Expected a decimal value.", decimalValue,
                //            taxonomy.NodeName, attribute, Environment.NewLine);
                //}
                else
                {
                    return(String.Format(
                               "Unknown data type for value [{0}] for [{1}] - [{2}]", value ?? String.Empty,
                               taxonomy.NodeName, attribute));
                }

                if (reallyNewSd)
                {
                    if (activeSd != null)
                    {
                        activeSd.Active = false;
                    }
                    schemaInfo.SchemaDatas.Add(newSchemaData);

                    if (reorderRanks)
                    {
                        AutoOrderRanks(newSchemaData.SchemaInfo.TaxonomyInfo, newSchemaData);
                    }
                }

                return(null);

            case SchemaAttributeType.Meta:
                bool reallyNewSmd = false;

                if (schematus.DataType == typeof(bool))
                {
                    value = value.ToString().StartsWith("y", StringComparison.OrdinalIgnoreCase) ? "Yes" : "No";
                }
                //First check if there is an active SchemaData
                if (activeSd == null)
                {
                    if (suppressAutoMapMessage)
                    {
                        return(null);
                    }

                    if (!newSchemaInfo && !autoMapSchema &&
                        MessageBox.Show(
                            String.Format(
                                "Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?", attribute,
                                taxonomy.TaxonomyData.NodeName), "Add to Schema", MessageBoxButtons.YesNo) ==
                        DialogResult.No)
                    {
                        return(null);
                    }

                    schemaInfo.SchemaDatas.Add(new SchemaData());
                    reallyNewSmd = true;
                }

                SchemaMetaInfo activeSmi = (from mi in schemaInfo.SchemaMetaInfos
                                            where mi.Attribute.Equals(schematus.MetaSchemaAttribute)
                                            select mi).FirstOrDefault();

                if (activeSmi == null)
                {
                    activeSmi = new SchemaMetaInfo {
                        Attribute = schematus.MetaSchemaAttribute
                    };
                    schemaInfo.SchemaMetaInfos.Add(activeSmi);
                    reallyNewSmd = true;
                }

                SchemaMetaData activeSmd = activeSmi.SchemaMetaData;

                if (activeSmd == null)
                {
                    reallyNewSmd = true;
                }
                else if (value == null || !activeSmd.Value.Equals(value))
                {
                    reallyNewSmd     = true;
                    activeSmd.Active = false;
                }

                //if (reallyNewSmd && value != null && !String.IsNullOrEmpty(value.ToString()))
                //{
                //    activeSmi.SchemaMetaDatas.Add(new SchemaMetaData {Value = value.ToString()});
                //    SchemaDataGridView.UpdateAutoCompleteSource(schematus.MetaSchemaAttribute, value.ToString());
                //}

                return(null);

            default:
                return("Unknown Meta-attribute Type! Weird!!!");
            }
        }
示例#3
0
        public void AutoOrderRanks(TaxonomyInfo taxonomy, SchemaData schemaData)
        {
            if (taxonomy == null)
            {
                return;
            }

            Dictionary <SchemaData, decimal[]> sds = (from si in taxonomy.SchemaInfos
                                                      let sd = si.SchemaData
                                                               where sd != null && (sd.NavigationOrder > 0 || sd.DisplayOrder > 0)
                                                               select sd).ToDictionary(
                sd => sd, sd => new[] { sd.NavigationOrder, sd.DisplayOrder });

            if (!sds.Any())
            {
                return;
            }

            decimal baseNavOrder  = schemaData != null ? schemaData.NavigationOrder : 0;
            decimal baseDispOrder = schemaData != null ? schemaData.DisplayOrder : 0;

            List <SchemaData> navs = (from sd in sds
                                      where
                                      sd.Key.NavigationOrder > 0 && sd.Key.NavigationOrder >= baseNavOrder &&
                                      (schemaData == null || !sd.Key.Equals(schemaData))
                                      select sd.Key).ToList();

            foreach (SchemaData nav in navs)
            {
                sds[nav][0] = nav.NavigationOrder + 1;
            }

            int iCtr = 0;

            foreach (SchemaData nav in
                     (from sd in sds
                      where sd.Value[0] > 0
                      orderby sd.Value[0]
                      select sd.Key).ToList())
            {
                sds[nav][0] = ++iCtr;
            }

            List <SchemaData> disps = (from sd in sds
                                       where
                                       sd.Key.DisplayOrder > 0 && sd.Key.DisplayOrder >= baseDispOrder &&
                                       (schemaData == null || !sd.Key.Equals(schemaData))
                                       select sd.Key).ToList();

            foreach (SchemaData disp in disps)
            {
                sds[disp][1] = disp.DisplayOrder + 1;
            }

            iCtr = 0;
            foreach (SchemaData disp in
                     (from sd in sds
                      where sd.Value[1] > 0
                      orderby sd.Value[1]
                      select sd.Key).ToList())
            {
                sds[disp][1] = ++iCtr;
            }

            foreach (var kvp in sds)
            {
                SchemaInfo schemaInfo = kvp.Key.SchemaInfo;
                SetValue(
                    schemaInfo.TaxonomyInfo, schemaInfo.Attribute, false, SchemaAttributeNavigationOrder, kvp.Value[0]);
                SetValue(
                    schemaInfo.TaxonomyInfo, schemaInfo.Attribute, false, SchemaAttributeDisplayOrder, kvp.Value[1]);
            }
        }