/// <summary>
        /// Serializes a QueryRelated to an XML stream for StartRow and RelatedOids (LinkedTo).
        /// </summary>
        /// <param name="writer">XML stream to write.</param>
        /// <param name="queryRelated">QueryRelated.</param>
        /// <returns>XML stream with the QueryRelated.</returns>
        public static XmlWriter Serialize(XmlWriter writer, QueryRelated queryRelated)
        {
            #region Serialize <StartRow>
            if (queryRelated.Oid != null)
            {
                writer.WriteStartElement(DTD.Request.QueryRequest.QueryRelated.TagStartRow);
                XMLAdaptorOIDSerializer.Serialize(writer, queryRelated.Oid);
                writer.WriteEndElement();
            }
            #endregion Serialize <StartRow>

            #region Serialize <LinkedTo>
            if (queryRelated.LinkedTo != null)
            {
                writer.WriteStartElement(DTD.Request.QueryRequest.QueryRelated.TagLinkedTo);
                foreach (string lRole in queryRelated.LinkedTo.Keys)
                {
                    writer.WriteStartElement(DTD.Request.QueryRequest.QueryRelated.LinkedTo.TagLinkItem);
                    writer.WriteAttributeString(DTD.Request.QueryRequest.QueryRelated.LinkedTo.TagRole, lRole);
                    XMLAdaptorOIDSerializer.Serialize(writer, queryRelated.LinkedTo[lRole]);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            #endregion Serialize <LinkedTo>
            return(writer);
        }
Пример #2
0
 /// <summary>
 /// Serializes an Agent to an XML stream.
 /// </summary>
 /// <param name="writer">XML stream to write.</param>
 /// <param name="agent">Agent.</param>
 /// <returns>XML stream with the agent.</returns>
 internal static XmlWriter Serialize(XmlWriter writer, Oids.Oid agent)
 {
     if (agent != null && agent.IsValid())
     {
         writer.WriteStartElement(DTD.Request.TagAgent);
         XMLAdaptorOIDSerializer.Serialize(writer, agent);
         writer.WriteEndElement();
     }
     return(writer);
 }
Пример #3
0
        /// <summary>
        /// Serializes an ChangeDetectionItem to an XML file.
        /// </summary>
        /// <param name="writer">XMLWriter where the ChangeDetectionItem is stored.</param>
        /// <param name="ChangeDetectionItem">ChangeDetectionItem to serialize.</param>
        /// <returns>Returns the XMLWriter with the ChangeDetectionItem.</returns>
        public static XmlWriter Serialize(XmlWriter writer, ChangeDetectionItem item)
        {
            writer.WriteStartElement(DTD.Request.ServiceRequest.ChangeDetectionItems.TagChangeDetectionItem);
            writer.WriteAttributeString(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagName, item.Name);
            ModelType modelType = Convert.StringTypeToMODELType(item.Type);

            if (modelType == ModelType.Oid)
            {
                writer.WriteAttributeString(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagType, item.ClassName);
            }
            else
            {
                writer.WriteAttributeString(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagType, item.Type);
            }

            if (item.Value != null)
            {
                if (item.Value is Oids.AlternateKey)
                {
                    XMLAlternateKeySerializer.Serialize(writer, (Oids.AlternateKey)item.Value);
                }
                else if (item.Value is Oids.Oid)
                {
                    XMLAdaptorOIDSerializer.Serialize(writer, item.Value as Oids.Oid);
                }
                else                                                          // <Literal>
                {
                    string lvalue = Convert.TypeToXml(item.Type, item.Value); //<-- Convert TypeToXML()!!!!
                    if (lvalue.Length > 0)
                    {
                        string lvalueTrim = lvalue.Trim();
                        if (lvalueTrim.Length > 0)
                        {
                            writer.WriteStartElement(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagLiteral);
                            writer.WriteValue(lvalue);
                            writer.WriteEndElement();
                        }
                        else                        // if is string White spaces it value is <NULL>
                        {
                            writer.WriteElementString(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagNull, string.Empty);
                        }
                    }
                    else                     // Is <NULL>
                    {
                        writer.WriteElementString(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagNull, string.Empty);
                    }
                }
            }
            else             // Is <NULL>
            {
                writer.WriteElementString(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagNull, string.Empty);
            }
            writer.WriteEndElement();
            return(writer);
        }
        /// <summary>
        /// Serializes a filter variable to an XML file.
        /// </summary>
        /// <param name="writer">XMLWriter where the argument is stored.</param>
        /// <param name="argument">Argument to serialize.</param>
        /// <returns>Returns the XMLWriter with the argument.</returns>
        public static XmlWriter Serialize(XmlWriter writer, Argument argument)
        {
            writer.WriteStartElement(DTD.Request.QueryRequest.QueryFilter.FilterVariables.TagFilterVariable);
            writer.WriteAttributeString(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagName, argument.Name);
            ModelType modelType = Convert.StringTypeToMODELType(argument.Type);

            if (modelType == ModelType.Oid)
            {
                writer.WriteAttributeString(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagType, argument.ClassName);
            }
            else
            {
                writer.WriteAttributeString(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagType, argument.Type);
            }
            if (argument.Value == null)
            {
                writer.WriteElementString(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagNull, string.Empty);
            }
            else
            {
                if (argument.Value is Oids.AlternateKey)
                {
                    XMLAlternateKeySerializer.Serialize(writer, (Oids.AlternateKey)argument.Value);
                }
                else if (argument.Value is Oids.Oid)
                {
                    XMLAdaptorOIDSerializer.Serialize(writer, argument.Value as Oids.Oid);
                }
                else                                                                  // <Literal>
                {
                    string lvalue = Convert.TypeToXml(argument.Type, argument.Value); //<-- Convert TypeToXML()!!!!
                    if (lvalue.Length > 0)
                    {
                        // Check White spaces.
                        string lvalueTrim = lvalue.Trim();
                        if (lvalueTrim.Length > 0)
                        {
                            writer.WriteStartElement(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagLiteral);
                            writer.WriteValue(lvalue);
                            writer.WriteEndElement();
                        }
                        else                        // if is White spaces is <NULL>
                        {
                            writer.WriteElementString(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagNull, string.Empty);
                        }
                    }
                    else                     // Is <NULL>
                    {
                        writer.WriteElementString(DTD.Request.QueryRequest.QueryFilter.FilterVariables.FilterVariable.TagNull, string.Empty);
                    }
                }
            }
            writer.WriteEndElement();
            return(writer);
        }
Пример #5
0
        public static ServiceResponse Deserialize(XmlReader reader, ServiceResponse serviceResponse)
        {
            if (reader.IsStartElement(DTD.Response.TagServiceResponse))
            {
                if (serviceResponse == null)
                {
                    serviceResponse = new ServiceResponse();
                }

                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                    do
                    {
                        #region <ERROR>
                        if (reader.IsStartElement(DTD.Response.ServiceResponse.TagError))
                        {
                            if (int.Parse(reader.GetAttribute(DTD.Error.TagNumber)) != 0)
                            {
                                throw XMLErrorSerializer.Deserialize(reader.ReadSubtree());
                            }
                            else
                            {
                                reader.Skip();
                            }
                        }
                        #endregion <ERROR>

                        #region <OID>
                        if (reader.IsStartElement(DTD.TagOID))
                        {
                            serviceResponse.Oid = XMLAdaptorOIDSerializer.Deserialize(reader.ReadSubtree());
                        }
                        #endregion <OID>

                        #region <Arguments>
                        if (reader.IsStartElement(DTD.Response.ServiceResponse.TagArguments))
                        {
                            serviceResponse.Arguments = XMLArgumentsSerializer.Deserialize(reader.ReadSubtree());
                        }
                        #endregion <Arguments>
                    } while (reader.Read());
                }
                else
                {
                    reader.Skip();
                }
            }
            else
            {
                throw new ArgumentException("Xml Reader don't have the Service.Response in Start Element.", "XmlReader reader");
            }
            return(serviceResponse);
        }
Пример #6
0
        public static XmlWriter Serialize(XmlWriter writer, ServiceResponse serviceResponse)
        {
            writer.WriteStartElement(DTD.Response.TagServiceResponse);
            writer.WriteElementString(DTD.Error.TagError, string.Empty);

            XMLAdaptorOIDSerializer.Serialize(writer, serviceResponse.Oid);
            XMLArgumentsSerializer.Serialize(writer, serviceResponse.Arguments);

            writer.WriteEndElement();
            return(writer);
        }
 /// <summary>
 /// Serializes QueryInstance to an XML stream.
 /// </summary>
 /// <param name="writer">XML stream to write.</param>
 /// <param name="queryInstance">QueryInstance.</param>
 /// <returns>XML stream with the QueryInstance.</returns>
 public static XmlWriter Serialize(XmlWriter writer, QueryInstance queryInstance)
 {
     writer.WriteStartElement(DTD.Request.QueryRequest.TagQueryInstance);
     if (queryInstance.Oid is Oids.AlternateKey)
     {
         XMLAlternateKeySerializer.Serialize(writer, queryInstance.GetAlternateKey());
     }
     else
     {
         XMLAdaptorOIDSerializer.Serialize(writer, queryInstance.Oid);
     }
     writer.WriteEndElement();
     return(writer);
 }
        public static object Deserialize(XmlReader reader, string type, string className)
        {
            object value = null;

            if ((reader.IsStartElement(DTD.Error.ChangedItems.ChangedItem.TagChangedItemOldValue)) ||
                (reader.IsStartElement(DTD.Error.ChangedItems.ChangedItem.TagChangedItemNewValue)))
            {
                reader.ReadStartElement();

                switch (reader.LocalName)
                {
                case DTD.Error.ChangedItems.ChangedItem.TagNull:
                    try
                    {
                        value = Convert.XmlToType(type, null);
                    }
                    catch
                    {                            // the ChangedItem is an object-valued ChangedItem
                        value = null;
                    }
                    reader.Skip();
                    break;

                case DTD.Error.ChangedItems.ChangedItem.TagLiteral:
                {
                    if (reader.IsEmptyElement)
                    {
                        value = string.Empty;
                        reader.Skip();
                    }
                    else
                    {
                        value = Convert.XmlToType(type, reader.ReadString());
                        reader.ReadEndElement();
                    }
                }
                break;

                case DTD.TagOID:
                    value = XMLAdaptorOIDSerializer.Deserialize(reader.ReadSubtree());
                    reader.ReadEndElement();
                    break;
                }
                reader.ReadEndElement();
            }
            return(value);
        }
        /// <summary>
        /// Serializes a navigational filtering argument info into an XML file.
        /// </summary>
        /// <param name="writer">XMLWriter where the argument is stored.</param>
        /// <param name="argument">Argument to serialize.</param>
        /// <returns>Returns the XMLWriter with the argument.</returns>
        public static XmlWriter Serialize(XmlWriter writer, ArgumentInfo argument)
        {
            writer.WriteStartElement(DTD.Request.ServiceRequest.Arguments.TagArgument);
            writer.WriteAttributeString(DTD.Request.ServiceRequest.Arguments.Argument.TagName, argument.Name);
            if (argument.Type == ModelType.Oid)
            {
                writer.WriteAttributeString(DTD.Request.ServiceRequest.Arguments.Argument.TagType, argument.ClassName);
            }
            else
            {
                writer.WriteAttributeString(DTD.Request.ServiceRequest.Arguments.Argument.TagType, Convert.MODELTypeToStringType(argument.Type));
            }

            if (argument.Value != null)
            {
                if (argument.Value is Oids.AlternateKey)
                {
                    XMLAlternateKeySerializer.Serialize(writer, (Oids.AlternateKey)argument.Value);
                }
                else if (argument.Value is Oids.Oid)
                {
                    XMLAdaptorOIDSerializer.Serialize(writer, argument.Value as Oids.Oid);
                }
                else
                {
                    string lvalue = Convert.TypeToXml(argument.Type, argument.Value);                     //<-- Convert TypeToXML()!!!!
                    if (lvalue.Length > 0)
                    {
                        writer.WriteStartElement(DTD.Request.ServiceRequest.Arguments.Argument.TagLiteral);
                        writer.WriteValue(lvalue);
                        writer.WriteEndElement();
                    }
                    else                     // Is <NULL>
                    {
                        writer.WriteElementString(DTD.Request.ServiceRequest.Arguments.Argument.TagNull, string.Empty);
                    }
                }
            }
            else             // Is <NULL>
            {
                writer.WriteElementString(DTD.Request.ServiceRequest.Arguments.Argument.TagNull, string.Empty);
            }
            writer.WriteEndElement();
            return(writer);
        }
Пример #10
0
 /// <summary>
 /// Deserializes Agent from an XML stream.
 /// </summary>
 /// <param name="reader">XML stream.</param>
 /// <returns>Oid (agent).</returns>
 public static Oids.Oid Deserialize(XmlReader reader)
 {
     Oids.Oid lResult = null;
     if (reader.IsStartElement(DTD.Request.TagAgent))
     {
         if (!reader.IsEmptyElement)
         {
             reader.ReadStartElement();
             lResult = XMLAdaptorOIDSerializer.Deserialize(reader);
         }
         else
         {
             reader.Skip();
         }
     }
     else
     {
         throw new ArgumentException("Xml Reader don't have the Agent in Start Element.", "XmlReader reader");
     }
     return(lResult);
 }
Пример #11
0
        /// <summary>
        /// Deserializes an ChangeDetectionItem from an XML file.
        /// </summary>
        /// <param name="reader">XMLReader where the ChangeDetectionItem is.</param>
        /// <returns>ChangeDetectionItem.</returns>
        public static ChangeDetectionItem Deserialize(XmlReader reader)
        {
            ChangeDetectionItem lResult = null;

            if (reader.IsStartElement(DTD.Request.ServiceRequest.ChangeDetectionItems.TagChangeDetectionItem))
            {
                lResult = new ChangeDetectionItem();
                string    stringModelType = reader.GetAttribute(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagType);
                ModelType modelType       = Convert.StringTypeToMODELType(stringModelType);

                if (modelType == ModelType.Oid)
                {
                    lResult.Type      = Convert.MODELTypeToStringType(ModelType.Oid);
                    lResult.ClassName = stringModelType;
                }
                else
                {
                    lResult.Type      = stringModelType;
                    lResult.ClassName = string.Empty;
                }
                lResult.Name = reader.GetAttribute(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagName);

                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                    // if the ChangeDetectionItem is OutBound
                    if (reader.IsStartElement(DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagValue))
                    {
                        reader.Read();
                    }
                    switch (reader.LocalName)
                    {
                    case DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagNull:
                        try
                        {
                            lResult.Value = Convert.XmlToType(lResult.Type, null);
                        }
                        catch
                        {
                            // the ChangeDetectionItem is an object-valued ChangeDetectionItem
                            lResult.Value = null;
                        }
                        reader.Skip();
                        break;

                    case DTD.Request.ServiceRequest.ChangeDetectionItems.ChangeDetectionItem.TagLiteral:
                    {
                        if (reader.IsEmptyElement)
                        {
                            lResult.Value = string.Empty;
                            reader.Skip();
                        }
                        else
                        {
                            lResult.Value = Convert.XmlToType(lResult.Type, reader.ReadString());
                            reader.ReadEndElement();
                        }
                    }
                    break;

                    case DTD.TagOID:
                        lResult.Value = XMLAdaptorOIDSerializer.Deserialize(reader.ReadSubtree());
                        break;
                    }
                    reader.ReadEndElement();
                }
                else
                {
                    reader.Skip();
                }
            }
            else
            {
                throw new ArgumentException("Xml Reader don't have the ChangeDetectionItem in Start Element.", "XmlReader reader");
            }
            return(lResult);
        }
        /// <summary>
        /// Serializes a NavigationalFiltering to an XML stream.
        /// </summary>
        /// <param name="writer">XML stream to write.</param>
        /// <param name="navigationalFiltering">NavigationalFiltering.</param>
        /// <returns>XML stream with the NavigationalFiltering.</returns>
        public static XmlWriter Serialize(XmlWriter writer, NavigationalFiltering navigationalFiltering)
        {
            #region <NavFilt>
            writer.WriteStartElement(DTD.Request.QueryRequest.TagNavFilt);

            if (navigationalFiltering.IsNavigationalArgument)
            {
                #region <NavFilt.Argument>
                writer.WriteStartElement(DTD.Request.QueryRequest.NavFilt.TagNavFiltArgument);
                writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.NaviFiltArgument.TagClass, navigationalFiltering.Argument.ClassName);
                writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.NaviFiltArgument.TagService, navigationalFiltering.Argument.ServiceName);
                writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.NaviFiltArgument.TagArgument, navigationalFiltering.Argument.ArgumentName);

                #region <Arguments>
                XMLNavigationalFilteringArgumentsListSerializer.Serialize(writer, navigationalFiltering.Argument.Arguments);
                #endregion <Arguments>

                writer.WriteEndElement();
                #endregion <NavFilt.Argument>
            }
            else if (navigationalFiltering.IsNavigationalFilterVariable)
            {
                #region <NavFilt.Variable>
                writer.WriteStartElement(DTD.Request.QueryRequest.NavFilt.TagNavFiltVariable);
                writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.NaviFiltVariable.TagClass, navigationalFiltering.FilterVariable.ClassName);
                writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.NaviFiltVariable.TagFilter, navigationalFiltering.FilterVariable.FilterName);
                writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.NaviFiltVariable.TagVariable, navigationalFiltering.FilterVariable.ArgumentName);

                #region <Filter.Variables>
                XMLNavigationalFilteringVariablesListSerializer.Serialize(writer, navigationalFiltering.FilterVariable.Arguments);
                #endregion <Filter.Variables>

                writer.WriteEndElement();
                #endregion <NavFilt.Variable>
            }
            else if (navigationalFiltering.IsNavigationalSelectObject)
            {
                #region <NavFilt.SelectedObject>
                writer.WriteStartElement(DTD.Request.QueryRequest.NavFilt.TagNavFiltSelectedObject);

                #region <NavFilt.SelectedObject NavFilterID Attribute>
                if (navigationalFiltering.SelectedObject.NavigationalFilterID.Length > 0)
                {
                    writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.TagNavFilterID, navigationalFiltering.SelectedObject.NavigationalFilterID);
                }
                #endregion <NavFilt.SelectedObject NavFilterID Attribute>

                #region OID
                XMLAdaptorOIDSerializer.Serialize(writer, navigationalFiltering.SelectedObject.SelectedObjectOID);
                #endregion OID

                writer.WriteEndElement();
                #endregion <NavFilt.SelectedObject>
            }
            else if (navigationalFiltering.IsNavigationalServiceIU)
            {
                #region <NavFilt.ServiceIU>
                writer.WriteStartElement(DTD.Request.QueryRequest.NavFilt.TagNavFiltServiceIU);

                #region <NavFilt.ServiceIU NavFilterID Attribute>
                if (navigationalFiltering.ServiceIU.NavigationalFilterID.Length > 0)
                {
                    writer.WriteAttributeString(DTD.Request.QueryRequest.NavFilt.TagNavFilterID, navigationalFiltering.ServiceIU.NavigationalFilterID);
                }
                #endregion <NavFilt.ServiceIU NavFilterID Attribute>

                #region <Arguments>
                XMLNavigationalFilteringArgumentsListSerializer.Serialize(writer, navigationalFiltering.ServiceIU.Arguments);
                #endregion <Arguments>

                writer.WriteEndElement();
                #endregion <NavFilt.ServiceIU>
            }

            writer.WriteEndElement();
            return(writer);

            #endregion <NavFilt>
        }