Skip to content

Commit

Permalink
Facut update la schelet.
Browse files Browse the repository at this point in the history
Signed-off-by: Catalin Dumitru <catalin.dumitru@live.com>
  • Loading branch information
colin-dumitru committed Jan 5, 2012
1 parent a810dd4 commit 1306aea
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 142 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.
3 changes: 0 additions & 3 deletions WebServer/Controllers/GetController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public ActionResult Summary(int? id)
if (id == null)
return View("Index", "Home");


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

Expand Down
56 changes: 0 additions & 56 deletions WebServer/Data/ApelareModul.cs

This file was deleted.

22 changes: 0 additions & 22 deletions WebServer/Data/ClientThread.cs

This file was deleted.

103 changes: 42 additions & 61 deletions WebServer/Data/DocumentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,15 @@
using System.Runtime.Serialization.Formatters.Binary;
using WebServer.Models;

namespace WebServer.Data
{
namespace WebServer.Data {

[Serializable]
class DocumentManagerConfig
{
private int _lastid = 0;
class DocumentManagerConfig {


/*numarul folosit la generarea id-urilor unice*/
public int UniqueId
{
get
{
return (this._lastid++);
}
}
}

[Serializable]
public class DocumentException : Exception
{
public class DocumentException : Exception {
public DocumentException() { }
public DocumentException(string message) : base(message) { }
public DocumentException(string message, Exception inner) : base(message, inner) { }
Expand All @@ -37,10 +24,9 @@ protected DocumentException(
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}


public class DocumentManager : IDocumentManager
{

public class DocumentManager : IDocumentManager {
public const String ConfigFile = "config";
public const String TypeMain = "main";
public const String TypeSummary = "summary";
Expand All @@ -50,62 +36,65 @@ public class DocumentManager : IDocumentManager
public const int StatusEmpty = 0;
public const int StatusParsing = 2;

private IDocumentEntityManager _entityManager = null;
/*folosit pentru a adauga documente in baza de date*/
public IDocumentEntityManager EntityManager { get; set; }
public IDocumentEntityManager EntityManager {
get {
return this._entityManager;
}
set {
if (this._moduleManager != null)
this._moduleManager.EntityManager = value;
this._entityManager = value;
}
}

/*se va ocupa de apelarea celorlalte module*/
private ModuleManager _moduleManager = null;
/*configuratia managerului*/
private DocumentManagerConfig _config = null;
private DocumentManagerConfig _config = null;

public DocumentManager() {
this._moduleManager = new ModuleManager() {
EntityManager = this.EntityManager
};

public DocumentManager()
{
/*in constructor deserializam configuratia*/
Stream stream = null;

try
{
try {
stream = File.OpenRead(ConfigFile);
BinaryFormatter bf = new BinaryFormatter();
this._config = bf.Deserialize(stream) as DocumentManagerConfig;

if (this._config == null)
throw new Exception();

}
catch (Exception)
{
} catch (Exception) {
this._config = new DocumentManagerConfig();
}
finally
{
} finally {
if (stream != null)
stream.Close();
}
}

~DocumentManager()
{
~DocumentManager() {
/*in constructor deserializam configuratia*/
Stream stream = null;

try
{
try {
stream = File.OpenWrite(ConfigFile);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream, this._config);
}
catch (Exception ex)
{
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
finally
{
} finally {
if (stream != null)
stream.Close();
}
}

public int StoreDocument(String fileName, Stream fileStream)
{
public int StoreDocument(String fileName, Stream fileStream) {
if (this._config == null || this.EntityManager == null)
throw new DocumentException("Configuratie inexistenta");

Expand All @@ -123,33 +112,25 @@ public int StoreDocument(String fileName, Stream fileStream)
return doc.Id;
}

public String GetDocument(int id)
{
public String GetDocument(int id) {
return null;

}

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

try
{
res = this.EntityManager.GetDocumentOutput(id, type);
if (res == null)
throw new EntityManagerException();
}
catch (EntityManagerException)
{
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;
return this._moduleManager.ValidateDocumentOutput(res);
}


}
}
54 changes: 54 additions & 0 deletions WebServer/Data/ModuleManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using WebServer.Models;

namespace WebServer.Data
{
// numele clasei se poate schimba
// asta mi-a venit pe moment
public class ModuleManager
{
public IDocumentEntityManager EntityManager { get; set; }


/// <summary>
/// Valideaza un document. Daca statusul sau este gol, atunci
/// se porneste parsarea si apelarea celorlalte moduule.
/// </summary>
/// <param name="doc">Documentul ce trebuie validat</param>
/// <returns>Fisierul XML daca exista. Null daca documentul inca nu a fost creat.</returns>
public String ValidateDocumentOutput(DocumentOutput doc)
{
if (this.EntityManager == null)
return null;

switch (doc.Status) {
/*daca fisierul a fost creat, il intoarcems*/
case DocumentManager.StatusOK:
return doc.Document;
/*daca documentul e in curs de parsare, nu facem nimic*/
case DocumentManager.StatusParsing:
return null;
/*daca documentul este gol, pornim workerul ce se ocupa de apelarea modulelor*/
case DocumentManager.StatusEmpty:
this._StartWorker(doc);
return null;
default:
return null;
}
}

private void _StartWorker(DocumentOutput doc) {
ModuleWorker worker = new ModuleWorker(this.EntityManager, doc);

/*cream un thread nou*/
Thread thread = new Thread(new ThreadStart(worker.Run));
thread.Start();

}
}
}
70 changes: 70 additions & 0 deletions WebServer/Data/ModuleWorker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using WebServer.Models;

namespace WebServer.Data
{
// Thread-ul in care se va trata cererea
public class ModuleWorker
{
private IDocumentEntityManager _em = null;
private DocumentOutput _doc = null;

public ModuleWorker(IDocumentEntityManager em, DocumentOutput doc)
{
this._em = em;
this._doc = doc;
}

public void Run()
{
if(this._em == null || this._doc == null)
return;

/*schimbam statusul initial sa spunem ca documentul se parseaza*/
this._doc.Status = DocumentManager.StatusParsing;
this._em.Save();

/*rezultatul apelarii*/
Boolean res = false;

switch (this._doc.Type)
{
case DocumentManager.TypeSummary:
res = this._CreateSummaryDocument();
break;
case DocumentManager.TypeTimeline:
res = this._CreateTimelineDocument();
break;
}

if (res) {
/*daca a reusit parsarea facem update la baza de date*/
this._doc.Status = DocumentManager.StatusOK;
this._em.Save();
} else {
/*mai bagam o fisa*/
this._doc.Status = DocumentManager.StatusEmpty;
this._em.Save();
}
}

private Boolean _CreateSummaryDocument() {
/*apeleaza modulele de sumarizare extragere de informatii si creaza
documentul xml*/

/*daca a reusit apelarea modulelor*/
return false;
}

private Boolean _CreateTimelineDocument() {
/*apeleaza modulele de situatii si timp si ceraza documentul xml*/

/*daca a reusit apelarea modulelor*/
return false;
}
}
}
Loading

0 comments on commit 1306aea

Please sign in to comment.