예제 #1
0
        public void Verify(ImportContextBase context)
        {
            ListImportContext listImportContext = context as ListImportContext;

            listInformationCollection.Clear();
            Fetch(context.TargetContext, listImportContext.ListNames);
        }
예제 #2
0
        public void Import(ImportContextBase context)
        {
            Context sourceContext = context.SourceContext;

            ListImportContext listImportContext = context as ListImportContext;

            Fetch(sourceContext, listImportContext.ListNames);

            Context targetContext = context.TargetContext;

            foreach (var listTitle in listInformationCollection.Keys)
            {
                ListInformation listInformation = listInformationCollection[listTitle];

                targetContext.CreateList(listInformation);
                if (context.Include.Fields)
                {
                    targetContext.AddFields(listTitle, listInformation.Fields);
                }
                if (context.Include.ListItems)
                {
                    foreach (ListItem listItem in listInformation.ListItems)
                    {
                        Dictionary <string, string> sourceFieldValues = listItem.FieldValuesAsHtml.FieldValues;
                        Dictionary <string, string> targetFieldValues = new Dictionary <string, string>();
                        foreach (FieldInfo field in listInformation.Fields)
                        {
                            if (field.Type == FieldType.Counter || field.Type == FieldType.Computed || field.Type == FieldType.Attachments || field.Type == FieldType.Calculated || field.Type == FieldType.ModStat || field.Type == FieldType.User)
                            {
                                continue;
                            }
                            string key   = field.InternalName;
                            string value = sourceFieldValues[key];
                            if (!string.IsNullOrEmpty(value))
                            {
                                targetFieldValues.Add(key, value);
                            }
                        }
                        targetContext.AddListItem(listTitle, targetFieldValues);
                        break;
                    }
                }
            }
            ;
        }