yavsc/yavscModel/WorkFlow/WorkFlowManager.cs

132 lines
3.7 KiB
C#

12 years ago
using System;
11 years ago
using Yavsc.Model.WorkFlow;
using System.Configuration;
11 years ago
using Yavsc.Model.WorkFlow.Configuration;
using System.Collections.Specialized;
11 years ago
using Yavsc.Model.FrontOffice;
12 years ago
11 years ago
namespace Yavsc.Model.WorkFlow
12 years ago
{
11 years ago
/// <summary>
/// Work flow manager.
/// It takes orders store them and raise some events for modules
/// It publishes estimates and invoices
/// </summary>
public class WorkFlowManager
12 years ago
{
public static Catalog Catalog { get; set; }
public long RegisterCommand(Commande com)
{
return ContentProvider.RegisterCommand (com);
}
public void UpdateEstimate (Estimate estim)
11 years ago
{
ContentProvider.UpdateEstimate (estim);
11 years ago
}
/// <summary>
/// Gets the estimate.
/// </summary>
/// <returns>The estimate.</returns>
/// <param name="estid">Estid.</param>
public Estimate GetEstimate (long estid)
{
return ContentProvider.GetEstimate (estid);
}
11 years ago
public Estimate [] GetEstimates (string client)
{
return ContentProvider.GetEstimates (client);
}
11 years ago
public void UpdateWritting (Writting wr)
{
ContentProvider.UpdateWritting (wr);
}
public void DropWritting (long wrid)
{
ContentProvider.DropWritting (wrid);
}
public void DropEstimate (long estid)
{
ContentProvider.DropEstimate(estid);
}
IContentProvider contentProvider;
public IContentProvider ContentProvider {
get {
WorkflowConfiguration c = (WorkflowConfiguration) ConfigurationManager.GetSection ("system.web/workflow");
if (c == null)
throw new Exception ("No system.web/workflow configuration section found");
WFProvider confprov = c.Providers.GetElement (c.DefaultProvider);
if (confprov == null)
throw new Exception ("Default workflow provider not found (system.web/workflow@defaultProvider)");
string clsName = confprov.Type;
if (clsName == null)
throw new Exception ("Provider type not specified (system.web/workflow@type)");
if (contentProvider != null)
{
if (contentProvider.GetType ().Name != clsName)
contentProvider = null;
}
if (contentProvider == null)
{
Type cpt = Type.GetType (clsName);
if (cpt == null)
throw new Exception (string.Format("Type not found : {0} (wrong name, or missing assembly reference?)",clsName));
System.Reflection.ConstructorInfo ci =cpt.GetConstructor (System.Type.EmptyTypes);
contentProvider = (IContentProvider)ci.Invoke (System.Type.EmptyTypes);
}
NameValueCollection config = new NameValueCollection ();
config.Add ("name", confprov.Name);
config.Add ("connectionStringName", confprov.ConnectionStringName);
config.Add ("applicationName", confprov.ApplicationName);
contentProvider.Initialize (confprov.Name, config);
return contentProvider;
}
}
/// <summary>
/// Creates the estimate.
/// </summary>
/// <returns>The estimate identifier.</returns>
/// <param name="title">Title.</param>
public Estimate CreateEstimate(string responsible, string client, string title, string description)
{
Estimate created = ContentProvider.CreateEstimate (responsible, client, title, description);
return created;
}
public long Write(long estid, string desc, decimal ucost, int count, string productid)
12 years ago
{
if (!string.IsNullOrWhiteSpace(productid)) {
if (Catalog == null)
Refactoring: moving the Catalog manager and model into the Yavsc.Model.FrontOffice namespace * Web.config: * Catalog.xml: * MyClass.cs: * Note.cs: * Euro.cs: * Unit.cs: * Text.cs: * Link.cs: * Price.cs: * Label.cs: * Brand.cs: * Scalar.cs: * Option.cs: * Period.cs: * YavscModel.csproj: * Catalog.cs: * Service.cs: * Product.cs: * YavscClient.csproj: * CatalogManager.cs: * Currency.cs: * CheckBox.cs: * SaleForm.cs: * FormInput.cs: * CatalogProvider.cs: * TextInput.cs: * SelectItem.cs: * SalesCatalog.csproj: * FilesInput.cs: * FormElement.cs: * SelectInput.cs: * IValueProvider.cs: * StockStatus.cs: * RadioButton.cs: * Commande.cs: * ProductImage.cs: * WebCatalogExtensions.cs: * TemplateException.cs: * ProductCategory.cs: * PhysicalProduct.cs: * Note.cs: * Link.cs: * Text.cs: * Euro.cs: * Unit.cs: * WorkFlowManager.cs: * Brand.cs: * Label.cs: * Price.cs: * Scalar.cs: * FrontOfficeController.cs: * Period.cs: * Option.cs: * Product.cs: * Service.cs: * Catalog.cs: * SaleForm.cs: * Currency.cs: * CheckBox.cs: * TextInput.cs: * FrontOfficeApiController.cs: * FormInput.cs: * SelectItem.cs: * FilesInput.cs: * XmlCatalog.cs: * FormElement.cs: * SelectInput.cs: * RadioButton.cs: * StockStatus.cs: * ProductImage.cs: * CatalogHelper.cs: * CatalogManager.cs: * CatalogProvider.cs: * ProductCategory.cs: * PhysicalProduct.cs: * XmlCatalogProvider.cs: * CatalogProviderConfigurationElement.cs: * CatalogProvidersConfigurationSection.cs: * CatalogProvidersConfigurationCollection.cs: * CatalogProviderConfigurationElement.cs: * CatalogProvidersConfigurationSection.cs: * CatalogProvidersConfigurationCollection.cs: * CatalogHelper.cs:
11 years ago
Catalog = CatalogManager.GetCatalog ("/WorkFlowApi");
if (Catalog == null)
throw new Exception ("No catalog");
Product p = Catalog.FindProduct (productid);
if (p == null)
throw new Exception ("Product not found");
// TODO new EstimateChange Event
}
return ContentProvider.Write(estid, desc, ucost, count, productid);
12 years ago
}
public void SetEstimateStatus(long estid, int status, string username)
{
ContentProvider.SetEstimateStatus (estid, status, username);
}
12 years ago
}
}