using System;
using Yavsc;
using System.Collections.Specialized;
using Yavsc.Model.WorkFlow;
using Yavsc.Model.FileSystem;
using System.Web;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace Yavsc.Model.FrontOffice
{
///
/// Commande.
///
public abstract class Command
{
///
/// Gets or sets the creation date.
///
/// The creation date.
public DateTime CreationDate { get; set; }
///
/// Gets or sets the identifier.
///
/// The identifier.
public long Id { get; set; }
///
/// Gets or sets the product reference.
///
/// The prod reference.
public CommandStatus Status { get; set; }
///
/// Gets or sets the product reference.
///
/// The product reference.
public string ProductRef { get; set; }
///
/// The parameters.
///
public Dictionary Parameters = new Dictionary ();
IEnumerable Files {
get {
return UserFileSystemManager.GetFiles (Id.ToString());
}
}
///
/// Initializes a new instance of the class.
///
public Command()
{
}
///
/// Froms the post.
///
/// Collection.
/// Files.
private void FromPost(NameValueCollection collection, NameObjectCollectionBase files)
{
// string catref=collection["catref"]; // Catalog Url from which formdata has been built
ProductRef=collection["ref"]; // Required product reference
CreationDate = DateTime.Now;
Status = CommandStatus.Inserted;
// stores the parameters:
Parameters.Clear ();
foreach (string key in collection.AllKeys) {
if (key!="ref")
Parameters.Add (key, collection [key]);
}
WorkFlowManager.RegisterCommand (this); // gives a value to this.Id
string strcmdid = Id.ToString ();
UserFileSystemManager.Put(Path.Combine("commandes",strcmdid),files);
}
///
/// Creates a command using the specified collection
/// as command parameters, handles the files upload.
///
/// Collection.
/// Files.
public static Command CreateCommand (NameValueCollection collection, NameObjectCollectionBase files)
{
var cmd = CreateCommand (collection ["type"]);
cmd.FromPost (collection, files);
return cmd;
}
///
/// Creates the command.
///
/// The command.
/// Class name.
public static Command CreateCommand (string className)
{
var type = Type.GetType (className);
ConstructorInfo ci = type.GetConstructor(new Type[]{});
var cmd = ci.Invoke (new object[]{}) as Command;
return cmd;
}
}
}