Exemple #1
0
        public static FieldMaps CreateFromFile(string fileName)
        {
            UtilityMethods.ValidateXmlFile(fileName, "WorkItemFieldMap.xsd");
            FieldMaps allFieldsMaps = null;

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(FieldMaps));
                using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    allFieldsMaps = (FieldMaps)serializer.Deserialize(stream);
                }
            }
            catch (IOException ioEx)
            {
                throw new ConverterException(ioEx.Message);
            }
            // validate the field map that is does not contain any 1-many or many-1 map
            if (allFieldsMaps != null)
            {
                Dictionary <string, bool> srcFields    = new Dictionary <string, bool>(TFStringComparer.WIConverterFieldRefName);
                Dictionary <string, bool> targetFields = new Dictionary <string, bool>(TFStringComparer.WIConverterFieldRefName);
                foreach (FieldMapsFieldMap fldMap in allFieldsMaps.FieldMap)
                {
                    if (String.IsNullOrEmpty(fldMap.from))
                    {
                        string errMsg = UtilityMethods.Format(CurConResource.NullFromField, fileName);
                        ConverterMain.MigrationReport.WriteIssue(((int)CommonErrorNumbers.NullFromField).ToString(),
                                                                 ReportIssueType.Critical, errMsg, string.Empty, null, CurConResource.Config, null);

                        Logger.Write(LogSource.Common, TraceLevel.Error, errMsg);
                        throw new ConverterException(errMsg);
                    }

                    // validate source field
                    if (!srcFields.ContainsKey(fldMap.from))
                    {
                        srcFields.Add(fldMap.from, false);
                    }
                    else
                    {
                        string errMsg = UtilityMethods.Format(CurConResource.InvalidSourceFieldMap, fldMap.from, fileName);
                        ConverterMain.MigrationReport.WriteIssue(((int)CommonErrorNumbers.InvalidSourceFieldMap).ToString(),
                                                                 ReportIssueType.Critical, errMsg, string.Empty, null, CurConResource.Config, null);

                        Logger.Write(LogSource.Common, TraceLevel.Error, errMsg);
                        throw new ConverterException(errMsg);
                    }
                    //validate target field
                    if (String.IsNullOrEmpty(fldMap.to))
                    {
                        fldMap.to = fldMap.from;
                    }

                    if (!targetFields.ContainsKey(fldMap.to))
                    {
                        targetFields.Add(fldMap.to, false);
                    }
                    else
                    {
                        string errMsg = UtilityMethods.Format(CurConResource.InvalidTargetFieldMap,
                                                              fldMap.to, fileName);
                        ConverterMain.MigrationReport.WriteIssue(((int)CommonErrorNumbers.InvalidTargetFieldMap).ToString(),
                                                                 ReportIssueType.Critical, errMsg, string.Empty, null, CurConResource.Config, null);

                        throw new ConverterException(errMsg);
                    }
                }
            }

            return(allFieldsMaps);
        }
Exemple #2
0
 public WITFieldMappings()
 {
     fieldMappings = new FieldMaps();
 }