Skip to content

Commit

Permalink
- implmentat in mare get controllerul
Browse files Browse the repository at this point in the history
- implementat clasa XmlResult ce intoarce un model serializat ca fisier XML
- implementat ca test in document manager o functie GetDocument
- terminat DocumentEntityManager
- creat clasa DocumentRespone, clasa ce va fi intoarce la cereri de tipul
 Get (contine starea documentului si documentul propriuzis)

cu aceste schimbari se pot lua fisierele xml ce trebuiesc afisate, aflate
la url-urile : /Get/TimeLine/id si /Get/Summary/id.
exemple de fisiere rezultat se gasesc la adresa : http://pastebin.com/qHNV4GDP
exemple de documente propriuze nu au fost adaugate inca
  • Loading branch information
colin-dumitru committed Jan 1, 2012
1 parent 0c3c1a4 commit 12bc0ad
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 13 deletions.
Binary file modified WebServer/App_Data/WebServerDatabase.mdf
Binary file not shown.
Binary file modified WebServer/App_Data/WebServerDatabase_log.LDF
Binary file not shown.
77 changes: 68 additions & 9 deletions WebServer/Controllers/GetController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,58 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebServer.Models;
using WebServer.Data;

namespace WebServer.Controllers
{
public class GetController : Controller
{
private IDocumentManager _documentManager = null;
private IDocumentEntityManager _entityManager = null;
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
public GetController()
{
this._entityManager = new DocumentEntityManager();
this._documentManager = new DocumentManager()
{
EntityManager = this._entityManager
};

}

// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
/// <summary>
/// Actiunea ce intoarce un fisier XML, avand ca date timeline-ul documenutlui impreuna cu
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
/// <summary>
/// Actiunea ce intoarce un fisier XML, avand ca date timeline-ul documenutlui impreuna cu
/// relatiile dintre personaje / relatii etc.
/// </summary>
/// </summary>
/// <param name="id">Id-ul documentului.</param>
public ActionResult TimeLine(int? id)
{
return View();
/*verificam daca a fost specificat documentul*/
if (id == null)
return View("Index", "Home");


/*modelul ce il intorcem*/
DocumentResponse ret = new DocumentResponse();
/*documentul propriuzis*/
DocumentResponse doc = new DocumentResponse();

/*luam documentul cautat*/
try
{
doc.Content = this._documentManager.GetDocument(id ?? 0, DocumentManager.TypeTimeline);
doc.State = (doc.Content != null) ? DocumentResponse.Status.Finished : DocumentResponse.Status.Parsing;
}
catch (DocumentException)
{
doc.State = DocumentResponse.Status.NotFound;
}

return new XmlResult(doc);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Expand All @@ -27,8 +63,30 @@ public ActionResult TimeLine(int? id)
/// informatii generate asupra documentului.
/// </summary>
/// <param name="id">Id-ul documentului.</param>
public ActionResult Summary(int? id) {
return View();
public ActionResult Summary(int? id)
{
/*verificam daca a fost specificat documentul*/
if (id == null)
return View("Index", "Home");


/*modelul ce il intorcem*/
DocumentResponse ret = new DocumentResponse();
/*documentul propriuzis*/
DocumentResponse doc = new DocumentResponse();

/*luam documentul cautat*/
try
{
doc.Content = this._documentManager.GetDocument(id ?? 0, DocumentManager.TypeSummary);
doc.State = (doc.Content != null) ? DocumentResponse.Status.Finished : DocumentResponse.Status.Parsing;
}
catch (DocumentException)
{
doc.State = DocumentResponse.Status.NotFound;
}

return new XmlResult(doc);
}

//------------------------------------------------------------------------------------------
Expand All @@ -39,7 +97,8 @@ public ActionResult Summary(int? id) {
/// </summary>
/// <param name="id">Id-ul documentului.</param>
/// <param name="question">Intrebarea careia trebuie sa ii gasim raspunsul.</param>
public ActionResult Answer(int? id, String question) {
public ActionResult Answer(int? id, String question)
{
return View();
}
//------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions WebServer/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace WebServer.Controllers {
[HandleError]
public class HomeController : Controller {


//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
/// <summary>
Expand Down
37 changes: 37 additions & 0 deletions WebServer/Controllers/XmlResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Serialization;

namespace WebServer.Controllers
{
public class XmlResult : ActionResult
{
private Object _model = null;


// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
public XmlResult(Object model)
{
if(model == null)
throw new ArgumentNullException("The model cannot be null");

this._model = model;
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
var serializer = new XmlSerializer(_model.GetType());

response.ContentType = "text/xml";
serializer.Serialize(response.OutputStream, this._model);
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
}
}
18 changes: 17 additions & 1 deletion WebServer/Data/DocumentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,23 @@ public String GetDocument(int id)

public String GetDocument(int id, string type)
{
throw new NotImplementedException();
DocumentOutput res = null;

try
{
res = this.EntityManager.GetDocumentOutput(id, type);
if (res == null)
throw new EntityManagerException();
}
catch (EntityManagerException)
{
throw new DocumentException("Documentul nu a fost gasit");
}

if (res.Status == StatusOK)
return res.Document;
else
return null;
}


Expand Down
57 changes: 54 additions & 3 deletions WebServer/Models/DocumentEntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ public Document CreateDocument(string documenName) {
//------------------------------------------------------------------------------------------

public Document GetDocument(int documentid) {
throw new NotImplementedException();
if (this._dbContainer == null)
throw new EntityManagerException("Nu suntem conectati la baza de date!");

/*selectam documentele din baza de date ce au id-ul specificat*/
var res = (from d in this._dbContainer.Documents
where d.Id == documentid
select d).ToList();

return (res.Count > 0) ? res[0] : null;
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Expand All @@ -65,6 +72,7 @@ public DocumentOutput AddDocumentOutput(int documentId, string type, int status,
if (this._dbContainer == null)
throw new EntityManagerException("Nu suntem conectati la baza de date!");

/*citim tot ce este in buffer*/
byte[] buffer = new byte[file.Length];
file.Read(buffer, 0, (int)file.Length);

Expand Down Expand Up @@ -111,13 +119,56 @@ public DocumentOutput AddDocumentOutput(int documentId, string type, int status,
//------------------------------------------------------------------------------------------

public DocumentOutput GetDocumentOutput(int documentId, string type) {
throw new NotImplementedException();
if (this._dbContainer == null)
throw new EntityManagerException("Nu suntem conectati la baza de date!");

/*verificam daca exista un document cu id-ul respectiv*/
List<Document> rezDoc = (from d in this._dbContainer.Documents
where d.Id == documentId
select d).ToList();

if (rezDoc.Count != 1)
throw new EntityManagerException("Nu exista un document cu id-ul specificat.");

/*verificam daca mai sunt alte fisiere pentru acelasi document id cu tipul specificat*/
List<DocumentOutput> rezOut = (from d in this._dbContainer.DocumentOutputs
where d.DocumentId == documentId && d.Type == type
select d).ToList();
if (rezOut.Count == 0)
throw new EntityManagerException("Mai exista si alte fisiere cu acelasi tip.");

return rezOut[0];

}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------

public void RemoveDocument(int documentId) {
throw new NotImplementedException();
if (this._dbContainer == null)
throw new EntityManagerException("Nu suntem conectati la baza de date!");

/*verificam daca exista un document cu id-ul respectiv*/
List<Document> rezDoc = (from d in this._dbContainer.Documents
where d.Id == documentId
select d).ToList();

if (rezDoc.Count != 1)
throw new EntityManagerException("Nu exista un document cu id-ul specificat.");

/*verificam daca mai sunt alte fisiere pentru acelasi document id cu tipul specificat*/
List<DocumentOutput> rezOut = (from d in this._dbContainer.DocumentOutputs
where d.DocumentId == documentId
select d).ToList();

/*stergem obiectele din baza de date*/
foreach (var doc in rezOut)
{
this._dbContainer.DocumentOutputs.DeleteObject(doc);
}

/*stergem documentul principal*/
this._dbContainer.Documents.DeleteObject(rezDoc[0]);

}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Expand Down
41 changes: 41 additions & 0 deletions WebServer/Models/DocumentResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;

namespace WebServer.Models
{
[Serializable]
public class DocumentResponse : IXmlSerializable
{
/// <summary>
/// Starea in care se afla un document.
/// </summary>
public enum Status { Finished, Parsing, Empty, NotFound}

public String Content {get; set;}
public Status State { get; set; }

public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}

public void ReadXml(System.Xml.XmlReader reader)
{
throw new NotImplementedException();
}

public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("State", State.ToString());
if (this.Content != null)
{
writer.WriteRaw("<Content>");
writer.WriteRaw(Content);
writer.WriteRaw("</Content>");
}
}
}
}
2 changes: 2 additions & 0 deletions WebServer/WebServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="Controllers\GetController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\LoadController.cs" />
<Compile Include="Controllers\XmlResult.cs" />
<Compile Include="Data\DocumentManager.cs" />
<Compile Include="Data\IDocumentManager.cs" />
<Compile Include="Global.asax.cs">
Expand All @@ -83,6 +84,7 @@
<DependentUpon>DocumentDataModel.edmx</DependentUpon>
</Compile>
<Compile Include="Models\DocumentEntityManager.cs" />
<Compile Include="Models\DocumentResponse.cs" />
<Compile Include="Models\IDocumentEntityManager.cs" />
<Compile Include="ModelView\DocumentModelView.cs" />
<Compile Include="ModelView\ErrorModelView.cs" />
Expand Down
5 changes: 5 additions & 0 deletions WebServer/obj/Debug/WebServer.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ D:\Proiect-AI\WebServer\bin\WebServer.pdb
D:\Proiect-AI\WebServer\obj\Debug\ResolveAssemblyReference.cache
D:\Proiect-AI\WebServer\obj\Debug\WebServer.dll
D:\Proiect-AI\WebServer\obj\Debug\WebServer.pdb
D:\My Work\Dot Net\Ai\PROIECT-AI---GUI\WebServer\bin\WebServer.dll
D:\My Work\Dot Net\Ai\PROIECT-AI---GUI\WebServer\bin\WebServer.pdb
D:\My Work\Dot Net\Ai\PROIECT-AI---GUI\WebServer\obj\Debug\ResolveAssemblyReference.cache
D:\My Work\Dot Net\Ai\PROIECT-AI---GUI\WebServer\obj\Debug\WebServer.dll
D:\My Work\Dot Net\Ai\PROIECT-AI---GUI\WebServer\obj\Debug\WebServer.pdb

0 comments on commit 12bc0ad

Please sign in to comment.