Exemplo n.º 1
0
        public static TermStore CreateStore(string termName, XmlReader reader, List<string> templateFieldNames)
        {
            TermStore termStore = new TermStore(termName, TermType.ComplexList);
            bool abort = false;

            int outerLoopCount1 = 0;

            //First need to parse out the Fields collection for this ManagedItem Complex List.
            Dictionary<Guid, string> allFieldNames = new Dictionary<Guid, string>();

            using (reader)
            {
                while (!abort)
                {
                    if (outerLoopCount1++ > TermStore.maxLoopCount)
                    {
                        throw new Exception(string.Format("Complex List CreateStore stopped at outerLoopCount1 {0:D} for termName '{1}'", outerLoopCount1, termName));
                    }
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == XMLNames._E_Fields)
                    {
                        int innerLoopCount1 = 0;
                        while (reader.Read() && !abort)
                        {
                            if (innerLoopCount1++ > TermStore.maxLoopCount)
                            {
                                throw new Exception(string.Format("Complex List CreateStore stopped at innerLoopCount1 {0:D} for termName '{1}'", innerLoopCount1, termName));
                            }
                            if (reader.NodeType == XmlNodeType.Element && reader.Name == XMLNames._E_Field)
                            {
                                //NOTE - Allow for some ComplexLists that do not have FieldID's assigned...
                                try
                                {
                                    allFieldNames.Add(new Guid(reader.GetAttribute(XMLNames._A_ID)), reader.GetAttribute(XMLNames._A_Name));
                                }
                                catch
                                {
                                    abort = true;
                                }
                            }
                            if (reader.NodeType == XmlNodeType.EndElement && reader.Name == XMLNames._E_Fields)
                            {
                                abort = true;
                            }
                        }
                    }
                    else
                    {
                        abort = !reader.Read();
                    }
                }

                if (allFieldNames.Count > 0)
                {
                    //Create a new collection of the Complex List fields that are in common with the ones found in the Template.
                    Dictionary<Guid, string> matchedFieldNames = new Dictionary<Guid, string>();
                    foreach (string templateFieldName in templateFieldNames)
                    {
                        if (allFieldNames.ContainsValue(templateFieldName))
                        {
                            foreach (KeyValuePair<Guid, string> kvp in allFieldNames)
                            {
                                if (kvp.Value == templateFieldName)
                                {
                                    matchedFieldNames.Add(kvp.Key, kvp.Value);
                                    break;
                                }
                            }
                        }
                    }

                    abort = false;
                    //Now we need to parse out the Items collection.
                    int outerLoopCount2 = 0;
                    while (!abort)
                    {
                        if (outerLoopCount2++ > TermStore.maxLoopCount)
                        {
                            throw new Exception(string.Format("Complex List CreateStore stopped at outerLoopCount2 {0:D} for termName '{1}'", outerLoopCount2, termName));
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == XMLNames._E_Items)
                        {
                            int innerLoopCount2 = 0;
                            while (reader.Read() && !abort)
                            {
                                if (innerLoopCount2++ > TermStore.maxLoopCount)
                                {
                                    throw new Exception(string.Format("Complex List CreateStore stopped at innerLoopCount2 {0:D} for termName '{1}'", innerLoopCount2, termName));
                                }
                                if (reader.NodeType == XmlNodeType.Element && reader.Name == XMLNames._E_Item)
                                {
                                    Dictionary<string, string> item = ComplexListItem.CreateComplexListItemStore(reader.ReadSubtree(), matchedFieldNames);
                                    if (item != null)
                                        termStore.AddFieldValue(item);
                                }
                                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == XMLNames._E_Items)
                                {
                                    abort = true;
                                }
                            }
                        }
                        else
                        {
                            abort = !reader.Read();
                        }
                    }
                }
            }
            return termStore;
        }
Exemplo n.º 2
0
        public static TermStore CreateStore(string termName, XmlReader reader)
        {
            using (reader)
            {
                reader.Read();
                TermStore termStore = new TermStore(reader.GetAttribute(XMLNames._A_Name), TermType.MSO);
                Dictionary<string, string> item = new Dictionary<string, string>();

                item.Add(_MSO_FieldName, reader.GetAttribute(XMLNames._A_MSOValue));
                item.Add(_MSO_Address1FieldName, reader.GetAttribute(XMLNames._A_Address1Value));
                item.Add(_MSO_Address2FieldName, reader.GetAttribute(XMLNames._A_Address2Value));
                item.Add(_MSO_CityFieldName, reader.GetAttribute(XMLNames._A_CityValue));
                item.Add(_MSO_StateFieldName, reader.GetAttribute(XMLNames._A_StateValue));
                item.Add(_MSO_ZipFieldName, reader.GetAttribute(XMLNames._A_ZipValue));
                item.Add(_MSO_PhoneFieldName, reader.GetAttribute(XMLNames._A_PhoneValue));
                termStore.AddFieldValue(item);

                return termStore;
            }
        }
Exemplo n.º 3
0
        public static TermStore CreateStore(string termName, ExternalTerm externalTerm, Guid managedItemID)
        {
            if (externalTerm == null)
                throw new Exception(string.Format("External Term named '{0}' not found within the template", termName));

            TermStore termStore = new TermStore(termName, TermType.External);
            DataTable dt = Data.ExternalTerm.GetValues(managedItemID, externalTerm._interfaceConfig.Name);
            string previousKeyValue = string.Empty;
            Dictionary<string, string> item = new Dictionary<string, string>();

            for (int index = 0; index < dt.Rows.Count; index++)
            {
                DataRow dr = dt.Rows[index];
                string keyValue = (string)dr[Data.DataNames._C_KeyValue];
                if (index == 0)
                    previousKeyValue = keyValue;
                if (!item.ContainsKey((string)dr[1]))
                    item.Add((string)dr[1], (string)dr[2]);
                if (index == dt.Rows.Count - 1)
                    termStore.AddFieldValue(item);
                else
                {
                    if (keyValue != previousKeyValue)
                    {
                        termStore.AddFieldValue(item);
                        previousKeyValue = keyValue;
                        item = new Dictionary<string, string>();
                        item.Add((string)dr[1], (string)dr[2]);
                    }
                }
            }

            return termStore;
        }