From: <br...@us...> - 2008-06-19 23:03:16
|
Revision: 268 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=268&view=rev Author: brus07 Date: 2008-06-19 16:03:23 -0700 (Thu, 19 Jun 2008) Log Message: ----------- Added test solution for testing Data. Working whit XML for Submit/Result. Modified Paths: -------------- ACMServer/trunk/ACMServer/ACMMediator.sln ACMServer/trunk/ACMServer/Library/Data/Data.csproj ACMServer/trunk/ACMServer/Library/Data/Submit.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/Xml.cs ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs Added Paths: ----------- ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs ACMServer/trunk/ACMServer/Library/testData/ ACMServer/trunk/ACMServer/Library/testData/Program.cs ACMServer/trunk/ACMServer/Library/testData/Properties/ ACMServer/trunk/ACMServer/Library/testData/Properties/AssemblyInfo.cs ACMServer/trunk/ACMServer/Library/testData/submitList.xml ACMServer/trunk/ACMServer/Library/testData/submitList.xsd ACMServer/trunk/ACMServer/Library/testData/testData.csproj Modified: ACMServer/trunk/ACMServer/ACMMediator.sln =================================================================== --- ACMServer/trunk/ACMServer/ACMMediator.sln 2008-06-19 15:15:40 UTC (rev 267) +++ ACMServer/trunk/ACMServer/ACMMediator.sln 2008-06-19 23:03:23 UTC (rev 268) @@ -23,6 +23,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data", "Library\Data\Data.csproj", "{30C0EFA3-36A8-4C6F-8FEC-28F771D4933F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testData", "Library\testData\testData.csproj", "{4EB54D66-105B-4CFD-8883-CBE7CA70AFA5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ {30C0EFA3-36A8-4C6F-8FEC-28F771D4933F}.Debug|Any CPU.Build.0 = Debug|Any CPU {30C0EFA3-36A8-4C6F-8FEC-28F771D4933F}.Release|Any CPU.ActiveCfg = Release|Any CPU {30C0EFA3-36A8-4C6F-8FEC-28F771D4933F}.Release|Any CPU.Build.0 = Release|Any CPU + {4EB54D66-105B-4CFD-8883-CBE7CA70AFA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4EB54D66-105B-4CFD-8883-CBE7CA70AFA5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4EB54D66-105B-4CFD-8883-CBE7CA70AFA5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4EB54D66-105B-4CFD-8883-CBE7CA70AFA5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -69,6 +75,7 @@ {211DD6A5-2D73-439E-8722-ED2C89ED1DDB} = {9AC82C0B-F256-41DD-9B4A-A59EC7EB4890} {A8135069-F8BA-4E5D-835F-3FF3F350AA5D} = {9AC82C0B-F256-41DD-9B4A-A59EC7EB4890} {30C0EFA3-36A8-4C6F-8FEC-28F771D4933F} = {9AC82C0B-F256-41DD-9B4A-A59EC7EB4890} + {4EB54D66-105B-4CFD-8883-CBE7CA70AFA5} = {9AC82C0B-F256-41DD-9B4A-A59EC7EB4890} {E4F4B91E-CC25-410B-B53A-E2507EFA4FCB} = {D80861F5-3751-4D49-884B-1A10FE1BCB07} {69FB4176-F298-4AF7-B714-B6758AA9A58E} = {D80861F5-3751-4D49-884B-1A10FE1BCB07} {B75187D7-2032-44F3-AC12-20804C7229AC} = {E4F4B91E-CC25-410B-B53A-E2507EFA4FCB} Modified: ACMServer/trunk/ACMServer/Library/Data/Data.csproj =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/Data.csproj 2008-06-19 15:15:40 UTC (rev 267) +++ ACMServer/trunk/ACMServer/Library/Data/Data.csproj 2008-06-19 23:03:23 UTC (rev 268) @@ -29,12 +29,14 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> + <Reference Include="System.XML" /> </ItemGroup> <ItemGroup> <Compile Include="DataMediator.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Result.cs" /> <Compile Include="Submit.cs" /> + <Compile Include="SubmitList.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\LibraryExtention\LibraryExtention.csproj"> Modified: ACMServer/trunk/ACMServer/Library/Data/Submit.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/Submit.cs 2008-06-19 15:15:40 UTC (rev 267) +++ ACMServer/trunk/ACMServer/Library/Data/Submit.cs 2008-06-19 23:03:23 UTC (rev 268) @@ -7,36 +7,21 @@ public class Submit { int id; + string sourceCode; + int language; + string temp; public Submit(string message) { //TODO - message = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"+ -@"<submitList> - <submit> - <id>123</id> - <sourceCode>asd asd asd asd</sourceCode> - <language>2</language> - </submit> - <submit> - <id>123</id> - <sourceCode>asd asd asd asd</sourceCode> - <language>2</language> - </submit> - <submit> - <id>123</id> - <sourceCode>asd asd asd asd</sourceCode> - <language>0</language> - </submit> -</submitList> -"; - TextReader reader = new StreamReader("submit.xsd"); + TextReader reader = new StreamReader("submitList.xsd"); string schema = reader.ReadToEnd(); - string xml = Xml.GetOuterXmlOfSingleNodeFromXpath(message, "submitList"); - bool good = Xml.ValidateXmlWithSchema(xml, schema); - id = Convert.ToInt32(message.Substring(0,message.IndexOf('$'))); - temp = message.Substring(message.IndexOf('$')+1); + bool good = Xml.ValidateXmlWithSchema(message, schema); + if (good == false) + throw new Exception("Submit: ValidateXmlWithSchema - error"); + //id = Convert.ToInt32(message.Substring(0,message.IndexOf('$'))); + //temp = message.Substring(message.IndexOf('$')+1); } //HACK: \xE4\xEB\xFF \xF2\xE5\xF1\xF2\xF3 \xF5\xE0\xE9 \xE1\xF3\xE4\xE5 \xF2\xE0\xEA, \xE0\xEB\xE5 \xEC\xE0\xBA \xE1\xF3\xF2\xE8 \xF7\xE5\xF0\xE5\xE7 XML Added: ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Data/SubmitList.cs 2008-06-19 23:03:23 UTC (rev 268) @@ -0,0 +1,8 @@ +using System; + +namespace Data +{ + class SubmitList + { + } +} Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/Xml.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/Xml.cs 2008-06-19 15:15:40 UTC (rev 267) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/Xml.cs 2008-06-19 23:03:23 UTC (rev 268) @@ -38,8 +38,19 @@ { //XmlNodeList nodes = doc.SelectNodes("descendant::root/submit"); XmlDocument document = new XmlDocument(); - document.LoadXml(fullXml); - return document.SelectSingleNode("descendant::" + xmlPath).OuterXml; + string result = null; + try + { + document.LoadXml(fullXml); + XmlNode node = document.SelectSingleNode("descendant::" + xmlPath); + if (node != null) + result = node.OuterXml; + } + catch (XmlException ex) + { + throw ex; + } + return result; } public static bool ValidateXmlWithSchema(string xml, string schema) Modified: ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs 2008-06-19 15:15:40 UTC (rev 267) +++ ACMServer/trunk/ACMServer/Library/LibraryExtention/XML/XmlValidator.cs 2008-06-19 23:03:23 UTC (rev 268) @@ -20,8 +20,9 @@ public bool Validate(string xmlSchema) { XmlSchema schema = new XmlSchema(); - XmlSchema.Read(new StringReader(xmlSchema), ValidationCallBack); + schema = XmlSchema.Read(new StringReader(xmlSchema), ValidationXmlSchemaCallBack); + // Create the XmlSchemaSet class. XmlSchemaSet schemas = new XmlSchemaSet(); @@ -32,7 +33,7 @@ XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas = schemas; - settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); + settings.ValidationEventHandler += new ValidationEventHandler(ValidationXmlCallBack); // Create the XmlReader object. XmlReader reader = XmlReader.Create(new StringReader(xmlDocument), settings); @@ -45,16 +46,15 @@ return validity; } - // Happen validation errors. - private void ValidationCallBack1(object sender, ValidationEventArgs e) + // Happen validation errors when read XmlSchema + private void ValidationXmlSchemaCallBack(object sender, ValidationEventArgs e) { throw new XmlSchemaException(e.Message); } - // Happen validation errors. - private void ValidationCallBack(object sender, ValidationEventArgs e) + // Happen validation errors when read Xml + private void ValidationXmlCallBack(object sender, ValidationEventArgs e) { - //Console.WriteLine("Validation Error: {0}", e.Message); validity = false; } } Property changes on: ACMServer/trunk/ACMServer/Library/testData ___________________________________________________________________ Name: svn:ignore + bin obj testData.csproj.user Added: ACMServer/trunk/ACMServer/Library/testData/Program.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/testData/Program.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/testData/Program.cs 2008-06-19 23:03:23 UTC (rev 268) @@ -0,0 +1,20 @@ +using System; +using AcmContester.Library.LibraryExtention.Data; +using System.IO; +using AcmContester.AcmLibraryExtention.XML; + +namespace testData +{ + class Program + { + static void Main(string[] args) + { + string message = (new StreamReader("submitList.xml")).ReadToEnd(); + message = Xml.GetOuterXmlOfSingleNodeFromXpath(message, "submitList"); + if (message != null && message != "") + { + Submit submit = new Submit(message); + } + } + } +} Added: ACMServer/trunk/ACMServer/Library/testData/Properties/AssemblyInfo.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/testData/Properties/AssemblyInfo.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/testData/Properties/AssemblyInfo.cs 2008-06-19 23:03:23 UTC (rev 268) @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("testData")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Home")] +[assembly: AssemblyProduct("testData")] +[assembly: AssemblyCopyright("Copyright © Home 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5359de90-a5a3-44e7-87e0-ce0156aa22eb")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] Added: ACMServer/trunk/ACMServer/Library/testData/submitList.xml =================================================================== --- ACMServer/trunk/ACMServer/Library/testData/submitList.xml (rev 0) +++ ACMServer/trunk/ACMServer/Library/testData/submitList.xml 2008-06-19 23:03:23 UTC (rev 268) @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8" ?> +<submitList> + <submit> + <id>123</id> + <sourceCode>asd asd asd asd</sourceCode> + <language>2</language> + </submit> + <submit> + <id>123</id> + <sourceCode>asd asd asd asd</sourceCode> + <language>2</language> + </submit> + <submit> + <id>123</id> + <sourceCode>asd asd asd asd</sourceCode> + <language>1</language> + </submit> +</submitList> Added: ACMServer/trunk/ACMServer/Library/testData/submitList.xsd =================================================================== --- ACMServer/trunk/ACMServer/Library/testData/submitList.xsd (rev 0) +++ ACMServer/trunk/ACMServer/Library/testData/submitList.xsd 2008-06-19 23:03:23 UTC (rev 268) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<xs:schema id="XMLSchema1" elementFormDefault="qualified" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <xs:complexType name="submitType"> + <xs:sequence maxOccurs="1"> + <!-- потрібно щоб ці записи могли слідувати у довільному порядку --> + <xs:element name="id" type="xs:positiveInteger"/> + <xs:element name="sourceCode" type="xs:string" /> + <xs:element name="language"> + <!-- обмеження для ID мови програмування --> + <xs:simpleType> + <xs:restriction base="xs:positiveInteger"> + <xs:maxInclusive value="100" /> + </xs:restriction> + </xs:simpleType> + </xs:element> + </xs:sequence> + </xs:complexType> + + <xs:element name="submitList"> + <xs:complexType> + <xs:sequence> + <xs:sequence> + <xs:element name="submit" type="submitType" maxOccurs="unbounded" minOccurs="0" /> + </xs:sequence> + </xs:sequence> + </xs:complexType> + </xs:element> +</xs:schema> \ No newline at end of file Added: ACMServer/trunk/ACMServer/Library/testData/testData.csproj =================================================================== --- ACMServer/trunk/ACMServer/Library/testData/testData.csproj (rev 0) +++ ACMServer/trunk/ACMServer/Library/testData/testData.csproj 2008-06-19 23:03:23 UTC (rev 268) @@ -0,0 +1,66 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{4EB54D66-105B-4CFD-8883-CBE7CA70AFA5}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>testData</RootNamespace> + <AssemblyName>testData</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Data\Data.csproj"> + <Project>{30C0EFA3-36A8-4C6F-8FEC-28F771D4933F}</Project> + <Name>Data</Name> + </ProjectReference> + <ProjectReference Include="..\LibraryExtention\LibraryExtention.csproj"> + <Project>{A8135069-F8BA-4E5D-835F-3FF3F350AA5D}</Project> + <Name>LibraryExtention</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Content Include="submitList.xml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + </ItemGroup> + <ItemGroup> + <None Include="submitList.xsd"> + <SubType>Designer</SubType> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |