예제 #1
0
        public IMetadataRetrievable ImportSource(HashSet <Type> poDataStructList)
        {
            WonkaImportSource NewAggregateSource = new WonkaImportSource();

            if (poDataStructList != null)
            {
                foreach (Type TempType in poDataStructList)
                {
                    IMetadataRetrievable TempSource = ImportSource(TempType);

                    TempSource.GetAttrCache().ForEach(x => NewAggregateSource.AddAttribute(x));
                    TempSource.GetGroupCache().ForEach(x => NewAggregateSource.AddGroup(x));
                }
            }

            return(NewAggregateSource);
        }
예제 #2
0
        static public string CreateRulesSampleFile(IMetadataRetrievable piMetadata, string psRulesOutputFile)
        {
            StringBuilder sbRulesBody = new StringBuilder();

            if (piMetadata != null)
            {
                var AttrCache = piMetadata.GetAttrCache();

                if (AttrCache.Count >= 2)
                {
                    string sChildBranch1 = "";
                    string sChildBranch2 = "";

                    var AttrNumCache = AttrCache.Where(x => x.IsDecimal || x.IsNumeric);
                    var AttrStrCache = AttrCache.Where(x => !x.IsDecimal && !x.IsNumeric);

                    if (AttrNumCache.Count() >= 2)
                    {
                        sChildBranch1 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY1,
                                          AttrNumCache.ElementAt(0).AttrName,
                                          AttrNumCache.ElementAt(1).AttrName);
                    }
                    else if (AttrNumCache.Count() == 1)
                    {
                        sChildBranch1 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY1,
                                          AttrNumCache.ElementAt(0).AttrName,
                                          AttrNumCache.ElementAt(0).AttrName);
                    }

                    if (AttrStrCache.Count() >= 4)
                    {
                        sChildBranch2 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY2,
                                          AttrStrCache.ElementAt(2).AttrName,
                                          AttrStrCache.ElementAt(3).AttrName);
                    }
                    else if (AttrStrCache.Count() == 3)
                    {
                        sChildBranch2 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY2,
                                          AttrStrCache.ElementAt(1).AttrName,
                                          AttrStrCache.ElementAt(2).AttrName);
                    }
                    else
                    {
                        sChildBranch2 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY2,
                                          AttrStrCache.ElementAt(0).AttrName,
                                          AttrStrCache.ElementAt(1).AttrName);
                    }

                    string sParentBranch =
                        String.Format(CONST_SAMPLE_RULE_FORMAT_MAIN_BODY,
                                      AttrCache[0].AttrName,
                                      AttrCache[1].AttrName,
                                      sChildBranch1,
                                      sChildBranch2);

                    sbRulesBody.Append(sParentBranch);
                }
            }

            if (!String.IsNullOrEmpty(psRulesOutputFile))
            {
                FileInfo OutputFile = new FileInfo(psRulesOutputFile);

                if (OutputFile.Directory.Exists)
                {
                    File.WriteAllText(psRulesOutputFile, sbRulesBody.ToString());
                }
            }

            return(sbRulesBody.ToString());
        }
        private WonkaRefEnvironment(bool bAllMetadata, IMetadataRetrievable pMetadataRetrievable)
        {
            DebugLevel = 1;

            DefaultCommitThreshold = 500;

            IdXref = new WonkaRefIdXref();

            AttrCache           = pMetadataRetrievable.GetAttrCache();
            AttrCollectionCache = pMetadataRetrievable.GetAttrCollectionCache();
            CurrencyCache       = pMetadataRetrievable.GetCurrencyCache();
            FieldCache          = pMetadataRetrievable.GetFieldCache();
            GroupCache          = pMetadataRetrievable.GetGroupCache();
            SourceCache         = pMetadataRetrievable.GetSourceCache();
            SourceFieldCache    = pMetadataRetrievable.GetSourceFieldCache();
            StandardCache       = pMetadataRetrievable.GetStandardCache();

            // NOTE: To be implemented later
            // CodeDefCache           = pMetadataRetrievable.GetCodeDefCache();

            AttrKeys       = new List <WonkaRefAttr>();
            AttrMap        = new Dictionary <int, WonkaRefAttr>();
            FieldMap       = new Dictionary <int, WonkaRefField>();
            GroupMap       = new Dictionary <int, WonkaRefGroup>();
            SourceMap      = new Dictionary <int, WonkaRefSource>();
            SourceFieldMap = new Dictionary <int, WonkaRefSourceField>();

            foreach (WonkaRefAttr TmpAttribute in AttrCache)
            {
                if (TmpAttribute.IsKey)
                {
                    AttrKeys.Add(TmpAttribute);
                }

                if (!IdXref.FieldIdToAttrIds.Keys.Contains(TmpAttribute.FieldId))
                {
                    IdXref.FieldIdToAttrIds[TmpAttribute.FieldId] = new HashSet <int>();
                }

                IdXref.FieldIdToAttrIds[TmpAttribute.FieldId].Add(TmpAttribute.AttrId);

                if (!IdXref.GroupIdToAttrIds.Keys.Contains(TmpAttribute.GroupId))
                {
                    IdXref.GroupIdToAttrIds[TmpAttribute.GroupId] = new HashSet <int>();
                }

                IdXref.GroupIdToAttrIds[TmpAttribute.GroupId].Add(TmpAttribute.AttrId);

                if (!IdXref.GroupIdToFieldIds.Keys.Contains(TmpAttribute.GroupId))
                {
                    IdXref.GroupIdToFieldIds[TmpAttribute.GroupId] = new HashSet <int>();
                }

                IdXref.GroupIdToFieldIds[TmpAttribute.GroupId].Add(TmpAttribute.FieldId);

                if (!String.IsNullOrEmpty(TmpAttribute.ColName) && (TmpAttribute.ColName == GetStandardByStdName("GSCName").StandardValue))
                {
                    IdXref.GroupIdToGroupSeqAttrId[TmpAttribute.GroupId] = TmpAttribute.AttrId;
                }

                AttrMap[TmpAttribute.AttrId] = TmpAttribute;
            }

            foreach (WonkaRefGroup TmpGroup in GroupCache)
            {
                if (TmpGroup.KeyTabCols.Count > 0)
                {
                    IdXref.GroupIdToKeyAttrIds[TmpGroup.GroupId] = new HashSet <int>();

                    foreach (string sTmpKeyTabCol in TmpGroup.KeyTabCols)
                    {
                        int nTargetAttrId = GetAttributeByTabColName(sTmpKeyTabCol).AttrId;
                        IdXref.GroupIdToKeyAttrIds[TmpGroup.GroupId].Add(nTargetAttrId);
                    }
                }

                GroupMap[TmpGroup.GroupId] = TmpGroup;
            }

            foreach (WonkaRefField TmpField in FieldCache)
            {
                FieldMap[TmpField.FieldId] = TmpField;
            }

            foreach (WonkaRefSource TmpSource in SourceCache)
            {
                SourceMap[TmpSource.SourceId] = TmpSource;
            }

            foreach (WonkaRefSourceField TmpSrcField in SourceFieldCache)
            {
                SourceFieldMap[TmpSrcField.SourceFieldId] = TmpSrcField;
            }

            if (bAllMetadata)
            {
                AttrCollectionCache = pMetadataRetrievable.GetAttrCollectionCache();

                // NOTE: To be implemented later
                // CodeDependencyCache    = pMetadataRetrievable.GetCodeDependencyCache();
                // CodeDependencyDefCache = pMetadataRetrievable.GetCodeDependencyDefCache();
            }
        }