コード例 #1
0
        /// <summary>
        /// Load PS Fields Definition and its parent-child relationship
        /// </summary>
        /// <param name="psFieldNames"></param>
        /// <returns></returns>
        public List <PSFieldDefinition> LoadingPSFields(string psFieldNames)
        {
            // Create a new datasotre instance
            DatastoreItemList psDataList = new ProductStudio.DatastoreItemList();

            psDataList.Datastore = this.psDataStore;

            // Craete a blank bug
            psDataList.CreateBlank(PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs);
            DatastoreItem psDataItem = psDataList.DatastoreItems.Add(null, PsApplyRulesMask.psApplyRulesAll);
            Bug           psBug      = (Bug)psDataItem;

            // Get the field list for processing
            string[]      psFieldNameCollection = psFieldNames.Split(';');
            List <string> psFieldNameList       = new List <string>();

            foreach (string psFieldName in psFieldNameCollection)
            {
                psFieldNameList.Add(psFieldName);
            }

            // New PS field definition list
            Dictionary <Int32, PSFieldDefinition> psFieldDefinitionDict = new Dictionary <int, PSFieldDefinition>();

            // Populate the PS field definition
            foreach (Field psField in psBug.Fields)
            {
                // Whether in the request fields
                if (psFieldNameList.Contains(psField.Name) == false)
                {
                    continue;
                }
                // New PSFieldDefinition
                PSFieldDefinition psFieldDefinition = new PSFieldDefinition(psField.ID, psField.Name, psField.FieldDefinition.ToolTip);
                psFieldDefinitionDict.Add(psField.ID, psFieldDefinition);
            }

            List <PSFieldDefinition> psFieldDefinitionList = new List <PSFieldDefinition>();

            // Populate the PS field definition
            foreach (KeyValuePair <Int32, PSFieldDefinition> kvp in psFieldDefinitionDict)
            {
                Field psField = psBug.Fields.get_ItemByID(kvp.Key);

                // Initialize PS field allowed values
                Int32         psFieldAllowedValueCount       = GetFieldAllowedValuesCount(psField);
                Values        psFieldAllowedValues           = this.GetFieldAllowedValues(psField);
                List <object> psFieldDefinitionAllowedValues = new List <object>();
                foreach (object obj in psFieldAllowedValues)
                {
                    psFieldDefinitionAllowedValues.Add(obj);
                }
                kvp.Value.SetAllowedValues(psFieldDefinitionAllowedValues);

                // Add to psFieldDefinitionList
                psFieldDefinitionList.Add(kvp.Value);

                Int32 psFieldValidValueCount = GetFieldValidValuesCount(psField);

                // Detect the dependencies and parent field
                if (psField.FieldDefinition.IsIgnored == false &&
                    psField.FieldDefinition.IsComputed == false &&
                    psFieldAllowedValueCount > 0)
                {
                    if (psFieldAllowedValueCount == 0 || psFieldAllowedValueCount <= psFieldValidValueCount)
                    {
                        continue;
                    }

                    Values psFieldValidValues = GetFieldValidValues(psField);
                    foreach (ProductStudio.Field parentField in psBug.Fields)
                    {
                        if (parentField.ID != psField.ID &&
                            //parentField.IsReadOnly == false &&
                            parentField.EditType == ProductStudio.PsFieldEditTypeEnum.psFieldEditTypeBasicList &&
                            //parentField.Name != "Resolution" &&
                            //parentField.Name != "Status" &&
                            parentField.Name != "TreeType" &&
                            parentField.Name != "Closed By" &&
                            parentField.FieldDefinition.Type != ProductStudio.PsFieldDefinitionTypeEnum.psFieldDefinitionTypeSubObject)
                        {
                            object saved = parentField.Value;

                            // loop through the allowed value list of the parent field instead of the valid value list here
                            // to work with multiple level of dependencies, ex, e.g. Field "Service Pack" depends on "Version", which in
                            // turn depends on "Product" field
                            foreach (object val in GetFieldAllowedValues(parentField))
                            {
                                parentField.Value = val;
                                Values psFieldNewValidValues = GetFieldValidValues(psField);
                                if (!IsSameValueList(psFieldNewValidValues, psFieldValidValues))
                                {
                                    // Find whether parent field is also in the dictionary
                                    if (psFieldDefinitionDict.ContainsKey(parentField.ID) == true)
                                    {
                                        // If we detect two parent fields, throw exception
                                        if (kvp.Value.ParentField != null && kvp.Value.ParentField.Id != parentField.ID)
                                        {
                                            throw new Exception(string.Format("psField {0}:{1} has more than one parent fields: {2}:{3} and {4}:{5}",
                                                                              psField.ID, psField.Name,
                                                                              kvp.Value.ParentField.Id, kvp.Value.ParentField.Name,
                                                                              parentField.ID, parentField.Name));
                                        }
                                        kvp.Value.ParentField = psFieldDefinitionDict[parentField.ID];
                                        List <object> psFieldDefinitionNewValidValues = new List <object>();
                                        foreach (object obj in psFieldNewValidValues)
                                        {
                                            psFieldDefinitionNewValidValues.Add(obj);
                                        }
                                        kvp.Value.SetValidValues(val, psFieldDefinitionNewValidValues);
                                    }
                                }
                            }
                            parentField.Value = saved;
                        }
                    }
                }
            }

            return(psFieldDefinitionList);
        }
コード例 #2
0
ファイル: PSDataAccess.cs プロジェクト: cpm2710/cellbank
        /// <summary>
        /// Load PS Fields Definition and its parent-child relationship
        /// </summary>
        /// <param name="psFieldNames"></param>
        /// <returns></returns>
        public List<PSFieldDefinition> LoadingPSFields(string psFieldNames)
        {
            // Create a new datasotre instance
            DatastoreItemList psDataList = new ProductStudio.DatastoreItemList();
            psDataList.Datastore = this.psDataStore;

            // Craete a blank bug
            psDataList.CreateBlank(PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs);
            DatastoreItem psDataItem = psDataList.DatastoreItems.Add(null, PsApplyRulesMask.psApplyRulesAll);
            Bug psBug = (Bug)psDataItem;

            // Get the field list for processing
            string[] psFieldNameCollection = psFieldNames.Split(';');
            List<string> psFieldNameList = new List<string>();
            foreach (string psFieldName in psFieldNameCollection)
            {
                psFieldNameList.Add(psFieldName);
            }

            // New PS field definition list
            Dictionary<Int32, PSFieldDefinition> psFieldDefinitionDict = new Dictionary<int, PSFieldDefinition>();

            // Populate the PS field definition
            foreach (Field psField in psBug.Fields)
            {
                // Whether in the request fields
                if (psFieldNameList.Contains(psField.Name) == false)
                {
                    continue;
                }
                // New PSFieldDefinition
                PSFieldDefinition psFieldDefinition = new PSFieldDefinition(psField.ID, psField.Name, psField.FieldDefinition.ToolTip);
                psFieldDefinitionDict.Add(psField.ID, psFieldDefinition);
            }

            List<PSFieldDefinition> psFieldDefinitionList = new List<PSFieldDefinition>();

            // Populate the PS field definition
            foreach (KeyValuePair<Int32, PSFieldDefinition> kvp in psFieldDefinitionDict)
            {
                Field psField = psBug.Fields.get_ItemByID(kvp.Key);

                // Initialize PS field allowed values
                Int32 psFieldAllowedValueCount = GetFieldAllowedValuesCount(psField);
                Values psFieldAllowedValues = this.GetFieldAllowedValues(psField);
                List<object> psFieldDefinitionAllowedValues = new List<object>();
                foreach (object obj in psFieldAllowedValues)
                {
                    psFieldDefinitionAllowedValues.Add(obj);
                }
                kvp.Value.SetAllowedValues(psFieldDefinitionAllowedValues);

                // Add to psFieldDefinitionList
                psFieldDefinitionList.Add(kvp.Value);

                Int32 psFieldValidValueCount = GetFieldValidValuesCount(psField);

                // Detect the dependencies and parent field
                if (psField.FieldDefinition.IsIgnored == false &&
                    psField.FieldDefinition.IsComputed == false &&
                    psFieldAllowedValueCount > 0)
                {
                    if (psFieldAllowedValueCount == 0 || psFieldAllowedValueCount <= psFieldValidValueCount)
                    {
                        continue;
                    }

                    Values psFieldValidValues = GetFieldValidValues(psField);
                    foreach (ProductStudio.Field parentField in psBug.Fields)
                    {
                        if (parentField.ID != psField.ID &&
                            //parentField.IsReadOnly == false &&
                            parentField.EditType == ProductStudio.PsFieldEditTypeEnum.psFieldEditTypeBasicList &&
                            //parentField.Name != "Resolution" &&
                            //parentField.Name != "Status" &&
                            parentField.Name != "TreeType" &&
                            parentField.Name != "Closed By" &&
                            parentField.FieldDefinition.Type != ProductStudio.PsFieldDefinitionTypeEnum.psFieldDefinitionTypeSubObject)
                        {
                            object saved = parentField.Value;

                            // loop through the allowed value list of the parent field instead of the valid value list here
                            // to work with multiple level of dependencies, ex, e.g. Field "Service Pack" depends on "Version", which in
                            // turn depends on "Product" field
                            foreach (object val in GetFieldAllowedValues(parentField))
                            {
                                parentField.Value = val;
                                Values psFieldNewValidValues = GetFieldValidValues(psField);
                                if (!IsSameValueList(psFieldNewValidValues, psFieldValidValues))
                                {
                                    // Find whether parent field is also in the dictionary
                                    if (psFieldDefinitionDict.ContainsKey(parentField.ID) == true)
                                    {
                                        // If we detect two parent fields, throw exception
                                        if (kvp.Value.ParentField != null && kvp.Value.ParentField.Id != parentField.ID)
                                        {
                                            throw new Exception(string.Format("psField {0}:{1} has more than one parent fields: {2}:{3} and {4}:{5}",
                                                psField.ID, psField.Name,
                                                kvp.Value.ParentField.Id, kvp.Value.ParentField.Name,
                                                parentField.ID, parentField.Name));
                                        }
                                        kvp.Value.ParentField = psFieldDefinitionDict[parentField.ID];
                                        List<object> psFieldDefinitionNewValidValues = new List<object>();
                                        foreach (object obj in psFieldNewValidValues)
                                        {
                                            psFieldDefinitionNewValidValues.Add(obj);
                                        }
                                        kvp.Value.SetValidValues(val, psFieldDefinitionNewValidValues);
                                    }
                                }
                            }
                            parentField.Value = saved;
                        }
                    }
                }
            }

            return psFieldDefinitionList;
        }