📄 data2xml.cs
字号:
xmlWriter.WriteStartElement( "Interface" );
xmlWriter.WriteAttributeString( "Name", interfaceData.Name );
xmlWriter.WriteAttributeString( "AccessType", interfaceData.AccessType.ToString() );
xmlWriter.WriteAttributeString( "Comment", interfaceData.DocComment );
if( IsWriteObjectInfo == true )
{
xmlWriter.WriteAttributeString( "Parent", interfaceData.Parent.ToString() );
xmlWriter.WriteAttributeString( "VSObjectReference", interfaceData.VSObjectReference.ToString() );
xmlWriter.WriteAttributeString( "ParentNameSpace", interfaceData.ParentNameSpaceName );
}
// Bulid parent class name to ClassData.BaseList
if( interfaceData.BaseList.Count > 0 )
{
for( int i = 0; i < interfaceData.BaseList.Count; i ++ )
{
xmlWriter.WriteAttributeString( "BaseClass", interfaceData.BaseList[i].ToString() );
}
}
// Check weather this class contain members
if( interfaceData.Element.Count > 0 )
{
for( int i = 0; i < interfaceData.Element.Count; i ++ )
{
WriteElements( xmlWriter, (ElementData) interfaceData.Element[i] );
}
}
xmlWriter.WriteFullEndElement();
}
private static void WriteNameSpaceData( XmlTextWriter xmlWriter, NameSpaceData namespaceData )
{
///
/// Namespace Type
///
xmlWriter.WriteStartElement( "Namespace" );
xmlWriter.WriteAttributeString( "Name", namespaceData.Name );
xmlWriter.WriteAttributeString( "Comment", namespaceData.DocComment );
if( IsWriteObjectInfo == true )
{
xmlWriter.WriteAttributeString( "Parent", namespaceData.Parent.ToString() );
xmlWriter.WriteAttributeString( "VSObjectReference", namespaceData.VSObjectReference.ToString() );
}
// Check if it has elements
if( namespaceData.Element.Count > 0 )
{
for( int i = 0 ; i < namespaceData.Element.Count ; i ++ )
{
WriteElements( xmlWriter, (ElementData) namespaceData.Element[i] );
}
}
xmlWriter.WriteFullEndElement();
}
private static void WritePropertyData( XmlTextWriter xmlWriter, PropertyData propertyData )
{
///
/// Property Type
///
xmlWriter.WriteStartElement( "Property" );
xmlWriter.WriteAttributeString( "Name", propertyData.Name );
xmlWriter.WriteAttributeString( "AccessType", propertyData.AccessType.ToString() );
xmlWriter.WriteAttributeString( "Comment", propertyData.DocComment );
// ***************************************************************//
// I don't know why propertyData.Setter always break out exception
// ***************************************************************//
// Change those two function to the members
// Modify 06/10/2002.
/*
try
{
WriteElements( xmlWriter, propertyData.Getter );
}
catch(Exception e)
{
}
try
{
WriteElements( xmlWriter, propertyData.Setter );
}
catch(Exception e)
{
}
*/
if( IsWriteObjectInfo == true )
{
xmlWriter.WriteAttributeString( "Parent", propertyData.Parent.ToString() );
xmlWriter.WriteAttributeString( "VSObjectReference", propertyData.VSObjectReference.ToString() );
xmlWriter.WriteAttributeString( "ParentNameSpace", propertyData.ParentNameSpaceName );
}
// Save the Phototypes data
xmlWriter.WriteStartElement( "Phototypes" );
PropertyData destination = propertyData;
{
xmlWriter.WriteAttributeString( "ClassName",destination.PhotoType.className );
xmlWriter.WriteAttributeString( "fullName",destination.PhotoType.fullName );
xmlWriter.WriteAttributeString( "noName",destination.PhotoType.noName );
xmlWriter.WriteAttributeString( "paramDefaultValus",destination.PhotoType.paramDefaultValus );
xmlWriter.WriteAttributeString( "paramNames",destination.PhotoType.paramNames );
xmlWriter.WriteAttributeString( "paramTypes",destination.PhotoType.paramTypes );
xmlWriter.WriteAttributeString( "phototypeInitExpression",destination.PhotoType.phototypeInitExpression );
xmlWriter.WriteAttributeString( "phototypeType",destination.PhotoType.phototypeType );
xmlWriter.WriteAttributeString( "uniqueSignature",destination.PhotoType.uniqueSignature );
}
xmlWriter.WriteFullEndElement();
// Check if it has elements
if( propertyData.Element.Count > 0 )
{
for( int i = 0 ; i < propertyData.Element.Count ; i ++ )
{
WriteElements( xmlWriter, (ElementData) propertyData.Element[i] );
}
}
xmlWriter.WriteFullEndElement();
}
private static void WriteStructData( XmlTextWriter xmlWriter, StructData structData )
{
///
/// Struct Type
///
xmlWriter.WriteStartElement( "Struct" );
xmlWriter.WriteAttributeString( "Name", structData.Name );
xmlWriter.WriteAttributeString( "AccessType", structData.AccessType.ToString() );
xmlWriter.WriteAttributeString( "Comment", structData.DocComment );
xmlWriter.WriteAttributeString( "IsAbstract", XmlConvert.ToString(structData.IsAbstract ));
if( IsWriteObjectInfo == true )
{
xmlWriter.WriteAttributeString( "Parent", structData.Parent.ToString() );
xmlWriter.WriteAttributeString( "VSObjectReference", structData.VSObjectReference.ToString() );
xmlWriter.WriteAttributeString( "ParentNameSpace", structData.ParentNameSpaceName );
}
// Bulid parent class name to ClassData.BaseList
if( structData.BaseList.Count > 0 )
{
for( int i = 0; i < structData.BaseList.Count; i ++ )
{
xmlWriter.WriteAttributeString( "BaseClass", structData.BaseList[i].ToString() );
}
}
// Check weather this class contain members
if( structData.Element.Count > 0 )
{
for( int i = 0; i < structData.Element.Count; i ++ )
{
WriteElements( xmlWriter, (ElementData) structData.Element[i] );
}
}
xmlWriter.WriteFullEndElement();
}
private static void WriteVariableData( XmlTextWriter xmlWriter, VariableData variableData )
{
///
/// Variable Data
///
xmlWriter.WriteStartElement( "Variable" );
xmlWriter.WriteAttributeString( "Name", variableData.Name );
xmlWriter.WriteAttributeString( "AccessType", variableData.AccessType.ToString() );
xmlWriter.WriteAttributeString( "InitExpression", variableData.InitExpression.ToString() );
xmlWriter.WriteAttributeString( "IsShared", variableData.IsShared.ToString() );
xmlWriter.WriteAttributeString( "IsConstant", variableData.IsConstant.ToString() );
xmlWriter.WriteAttributeString( "Comment", variableData.DocComment );
if( IsWriteObjectInfo == true )
{
xmlWriter.WriteAttributeString( "Parent", variableData.Parent.ToString() );
xmlWriter.WriteAttributeString( "VSObjectReference", variableData.VSObjectReference.ToString() );
}
// Save the Phototypes data
xmlWriter.WriteStartElement( "Phototypes" );
VariableData destination = variableData;
{
xmlWriter.WriteAttributeString( "ClassName",destination.PhotoType.className );
xmlWriter.WriteAttributeString( "fullName",destination.PhotoType.fullName );
xmlWriter.WriteAttributeString( "noName",destination.PhotoType.noName );
xmlWriter.WriteAttributeString( "paramDefaultValus",destination.PhotoType.paramDefaultValus );
xmlWriter.WriteAttributeString( "paramNames",destination.PhotoType.paramNames );
xmlWriter.WriteAttributeString( "paramTypes",destination.PhotoType.paramTypes );
xmlWriter.WriteAttributeString( "phototypeInitExpression",destination.PhotoType.phototypeInitExpression );
xmlWriter.WriteAttributeString( "phototypeType",destination.PhotoType.phototypeType );
xmlWriter.WriteAttributeString( "uniqueSignature",destination.PhotoType.uniqueSignature );
}
xmlWriter.WriteFullEndElement();
xmlWriter.WriteFullEndElement();
}
/// <summary>
/// Write XML file header
/// Version data etc...
/// </summary>
/// <param name="xmlWriter"></param>
private static void WriteHeader( XmlTextWriter xmlWriter )
{
}
#endregion // end Writer
#region Load Code Data from XML File
/// <summary>
/// Load UML data from specify file to CodeData object
/// </summary>
/// <param name="fileName"></param>
/// <param name="codeData"></param>
public static void ReadFromFile( String fileName, CodeData codeData )
{
try
{
// Create XML reader object
XmlTextReader xmlReader = new XmlTextReader( fileName );
// First read the Solution information and bulid the solution
ReadHeader( xmlReader, codeData );
// Read and parse the elements
while( xmlReader.Read() )
{
if( xmlReader.NodeType == XmlNodeType.Element )
{
if( xmlReader.Name == "Solution" )
ReadSolution( xmlReader, codeData );
}
}
}
catch( Exception e )
{
}
}
/// <summary>
/// Read the UML - XML header
/// </summary>
/// <param name="xmlReader"></param>
/// <param name="codeData"></param>
private static void ReadHeader( XmlTextReader xmlReader, CodeData codeData )
{
}
private static void ReadSolution( XmlTextReader xmlReader, CodeData codeData )
{
// Read the solution Data
// and Store Solution data
if( xmlReader.AttributeCount <= 0 )
throw new Exception( "Solution attribute cannot be zero! This is not my fault" );
// Here solution has ONLY ONE attribute
SolutionData sluData = new SolutionData();
codeData.AddSolution( sluData );
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "Name" )
{
sluData.Parent = codeData;
sluData.Name = xmlReader.Value;
}
}
bool bJumpHigher = false;
do
{
bJumpHigher = DispatchReadAction( xmlReader, sluData );
}while( bJumpHigher == false );
}
/// <summary>
/// Read the element data ( attribute )
/// </summary>
/// <param name="xmlReader">XMLTextReader class</param>
/// <param name="elementData">ElementData class</param>
private static void ReadProject( XmlTextReader xmlReader, ElementData elementData )
{
// Read project information and also build
if( xmlReader.AttributeCount <= 0 )
throw new Exception( "Project attribute cannot be zero! This is not my fault" );
ProjectData prjData = new ProjectData();
elementData.AddMember( prjData );
// here i should be 1
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "Name" )
{
prjData.Parent = elementData;
prjData.Name = xmlReader.Value;
}
}
//*****************************************************//
// Build data
// ProjectItemData
// CodeModelData
// CodeElementsData
//******************************************************//
// Here ProjectItem Should be a number of, but, because //
// ProjectItem store file name information. It's no use //
// for us, so i decided to ignore it. 04/10/2002 //
//******************************************************//
//************* MODIFY BY 06/10/2002 ******************//
// I DECIDED TO USE PROJECT ITEM //
//******************************************************//
// dispatch to project item
{
bool bJumpHigher = false;
do
{
bJumpHigher = DispatchReadAction( xmlReader, prjData );
}while( bJumpHigher == false );
}
}
/// <summary>
/// Read the element data ( attribute )
/// </summary>
/// <param name="xmlReader">XMLTextReader class</param>
/// <param name="elementData">ElementData class</param>
private static void ReadProjectItem( XmlTextReader xmlReader, ElementData elementData )
{
// Read project Item information and also build
// CodeModelData
// CodeElementsData
if( xmlReader.AttributeCount <= 0 )
throw new Exception( "Project Item attribute cannot be zero! This is not my fault" );
ProjectItemData prjItemData = new ProjectItemData();
elementData.AddMember( prjItemData );
prjItemData.Parent = elementData;
// here i should be 1
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "Name" )
{
prjItemData.Name = xmlReader.Value;
}
}
// Build Code Model Data
CodeModelData codeModel = new CodeModelData();
codeModel.Parent = prjItemData;
prjItemData.AddMember( codeModel );
// Build Code Elements Data
CodeElementsData codeElements = new CodeElementsData();
codeElements.Parent = codeModel;
codeModel.AddMember( codeElements );
// Next parse
{
bool bJumpHigher = false;
do
{
bJumpHigher = DispatchReadAction( xmlReader, codeElements );
}while( bJumpHigher == false );
}
}
/// <summary>
/// Read the element data ( attribute )
/// </summary>
/// <param name="xmlReader">XMLTextReader class</param>
/// <param name="elementData">ElementData class</param>
private static void ReadDelegate( XmlTextReader xmlReader, ElementData elementData )
{
if( xmlReader.AttributeCount <= 0 )
throw new Exception( "DelegateData Item attribute cannot be zero! This is not my fault" );
DelegateData delegateData = new DelegateData();
elementData.AddMember( delegateData );
int nLevel = xmlReader.Depth;
delegateData.Parent = elementData;
// here i should be 3
for( int i = 0 ; i < xmlReader.AttributeCount ; i ++ )
{
xmlReader.MoveToAttribute(i);
if( xmlReader.Name == "Name" )
{
delegateData.Name = xmlReader.Value;
}
else if( xmlReader.Name == "Access Type" )
{
delegateData.AccessType = AssignAccessType ( xmlReader.Value );
}
else if( xmlReader.Name == "Comment" )
{
delegateData.DocComment = xmlReader.Value;
}
}
// Read PhotoTypes
// This are MUST be PhotoTypes, otherwise send exception error message
xmlReader.Read();
DelegateData itemData = delegateData;
if( xmlReader.Name == "Phototypes" )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -