コード例 #1
0
        private List <GcFile> MapValuesFromGcToEpi(IContentData content, ContentType contentType, GcDynamicTemplateMappings currentMapping,
                                                   IGcItem gcItem)
        {
            // fetch all the GcFile collection for this item.
            var gcFiles = Client.GetFilesByItemId(gcItem.Id).ToList();

            // This list contains the fields of the attachments for which the media has to be imported.
            var mediaFieldsToImport = new List <string>();

            // Get all the configs of this item.
            var gcConfigs = gcItem.Config.ToList();

            foreach (var map in currentMapping.EpiFieldMaps)
            {
                // First part of the string contains Epi field name and second part contains the Gc field name.
                var fieldSplitStrings = map.Split('~');
                var epiFieldName      = fieldSplitStrings[0];
                var gcFieldName       = fieldSplitStrings[1];

                // Add the fields to 'mediaFieldsToImport' list whose Epi counter part is 'Import-Attachments'.
                if (!gcFiles.IsNullOrEmpty())
                {
                    if (gcFiles.Any(i => i.Field == gcFieldName && epiFieldName == "Import-Attachments"))
                    {
                        mediaFieldsToImport.Add(gcFieldName);
                    }
                }

                /*
                 *  <summary>
                 *      For the field name that matches the field name of Epi content type, find the GcElement whose name is
                 *      the extracted gcFieldName. Call a parser based on the GcElement type. (Files gets imported differently.)
                 *  </summary>
                 */
                var propDef = contentType.PropertyDefinitions.ToList().Find(p => p.Name == epiFieldName);
                if (propDef == null)
                {
                    continue;
                }
                foreach (var gcConfig in gcConfigs)
                {
                    foreach (var gcElement in gcConfig.Elements.ToList())
                    {
                        if (gcElement.Name != gcFieldName)
                        {
                            continue;
                        }
                        if (gcElement.Type == "text")
                        {
                            content.Property[propDef.Name].Value =
                                GcEpiContentParser.TextParser(gcElement.Value, propDef.Type.Name);
                        }
                        else if (gcElement.Type == "section")
                        {
                            content.Property[propDef.Name].Value =
                                GcEpiContentParser.TextParser(gcElement.Subtitle, propDef.Type.Name);
                        }

                        /*else if (gcElement.Type == "choice_radio" || gcElement.Type == "choice_checkbox")
                         *  content.Property[propDef.Name].Value =
                         *      GcEpiContentParser.ChoiceParser(gcElement.Options, gcElement.Type, propDef);*/
                    }
                }
            }

            // Return all the files if the selected value of that
            // field is 'Import-Attachments' and is in 'mediaFieldsToImport' list.
            return(gcFiles.Where(i => mediaFieldsToImport.Contains(i.Field)).ToList());
        }