Exemple #1
0
        private static bool CompareWithDateTimeZoneParser(string valueA, string valueB, bool ignoreTimeZone)
        {
            try
            {
                DateTimeZoneParser tempA = new DateTimeZoneParser(valueA, true);
                DateTimeZoneParser tempB = new DateTimeZoneParser(valueB, true);
                if (tempA.InputAsDateTimeOffset == tempB.InputAsDateTimeOffset)
                {
                    return(true);
                }

                if (tempA.ToString(OutputDateTimeKind.ConvertToUniversal, null) == tempB.ToString(OutputDateTimeKind.ConvertToUniversal, null))
                {
                    return(true);
                }

                if (ignoreTimeZone)
                {
                    if ((tempA.DatePart == tempB.DatePart) && (tempA.TimePart == tempB.TimePart))
                    {
                        return(true);
                    }
                }
            }
            catch
            {
            }

            return(false);
        }
Exemple #2
0
        private XmlNode ConvertXmlNode(string parentPath, XmlDocument outputDoc, XmlNode sourceNode)
        {
            switch (sourceNode.NodeType)
            {
            case XmlNodeType.Element:
            {
                var sourceElement = (XmlElement)sourceNode;
                return(ConvertXmlElement(parentPath, outputDoc, sourceElement));
            }

            case XmlNodeType.Text:
            {
                var  newTextFormat = CustomXmlTransformTextFormat.Unchanged;
                bool pathMatched   = false;
                foreach (CustomXmlTransformRule mapping in _mappings.Values)
                {
                    // search mappings for output formatting rules
                    if ((mapping.Kind == CustomXmlTransformRuleKind.ContentFormat) &&
                        sourceNode.Name.Equals(mapping.OldNodeName)
                        )
                    //&& ((mapping.OldXsiTypeName == null) || (mapping.OldXsiTypeName.Equals(oldXsiTypeName))))
                    {
                        // possible node - check path matches
                        if (mapping.OldHeadPath != null)
                        {
                            pathMatched = mapping.OldTailPath != null?parentPath.Equals(mapping.OldHeadPath + "/" + mapping.OldTailPath) : parentPath.StartsWith(mapping.OldHeadPath);
                        }
                        else
                        {
                            pathMatched = mapping.OldTailPath == null || parentPath.EndsWith(mapping.OldTailPath);
                        }
                        if (pathMatched)
                        {
                            // match!
                            newTextFormat = mapping.NewTextFormat;
                            break;
                        }
                    }
                }
                if (pathMatched)
                {
                    string newTextValue = sourceNode.Value;
                    switch (newTextFormat)
                    {
                    case CustomXmlTransformTextFormat.Unchanged:
                        break;

                    case CustomXmlTransformTextFormat.XsdTimeOnly:
                    {
                        var dtz = new DateTimeZoneParser(newTextValue, false);
                        if (!dtz.Faulted)
                        {
                            newTextValue = dtz.ToString(_outputDateTimeKind, _customOffset, false, true, false);
                        }
                    }
                    break;

                    case CustomXmlTransformTextFormat.XsdDateTime:
                    {
                        var dtz = new DateTimeZoneParser(newTextValue, false);
                        if (!dtz.Faulted)
                        {
                            newTextValue = dtz.ToString(_outputDateTimeKind, _customOffset, true, true, null);
                        }
                    }
                    break;

                    default:
                        throw new NotImplementedException();
                    }
                    return(outputDoc.CreateTextNode(newTextValue));
                }
                DateTime oldDateTimeValue;
                if (DateTime.TryParse(sourceNode.Value, out oldDateTimeValue))
                {
                    var dtz = new DateTimeZoneParser(sourceNode.Value, false);
                    if (dtz.Faulted)
                    {
                        return(outputDoc.ImportNode(sourceNode, true));
                    }
                    return(outputDoc.CreateTextNode(dtz.ToString(_outputDateTimeKind, _customOffset)));
                }
                return(outputDoc.ImportNode(sourceNode, true));
            }

            default:
                return(outputDoc.ImportNode(sourceNode, true));
            }
        }