Commit for development environment setup
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
using System.Web.Services.Protocols;
|
||||
|
||||
public class CslaCredentials : SoapHeader
|
||||
{
|
||||
public string Username;
|
||||
public string Password;
|
||||
}
|
@@ -0,0 +1,300 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using ProjectTracker.Library;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Web Service interface for the ProjectTracker application.
|
||||
/// </summary>
|
||||
[WebService(Namespace = "http://ws.lhotka.net/")]
|
||||
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
||||
public class PTService : System.Web.Services.WebService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Credentials for custom authentication.
|
||||
/// </summary>
|
||||
public CslaCredentials Credentials = new CslaCredentials();
|
||||
|
||||
#region Projects
|
||||
|
||||
[WebMethod(Description="Get a list of projects")]
|
||||
public ProjectData[] GetProjectList()
|
||||
{
|
||||
// anonymous access allowed
|
||||
Security.UseAnonymous();
|
||||
|
||||
try
|
||||
{
|
||||
ProjectList list = ProjectList.GetProjectList();
|
||||
List<ProjectData> result = new List<ProjectData>();
|
||||
foreach (ProjectInfo item in list)
|
||||
{
|
||||
ProjectData info = new ProjectData();
|
||||
Csla.Data.DataMapper.Map(item, info);
|
||||
result.Add(info);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod(Description="Get a project")]
|
||||
public ProjectData GetProject(ProjectRequest request)
|
||||
{
|
||||
// anonymous access allowed
|
||||
Security.UseAnonymous();
|
||||
|
||||
try
|
||||
{
|
||||
Project proj = Project.GetProject(request.Id);
|
||||
ProjectData result = new ProjectData();
|
||||
Csla.Data.DataMapper.Map(proj, result, "Resources");
|
||||
foreach (ProjectResource resource in proj.Resources)
|
||||
{
|
||||
ProjectResourceData info = new ProjectResourceData();
|
||||
Csla.Data.DataMapper.Map(resource, info, "FullName");
|
||||
result.AddResource(info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod(Description="Add a project")]
|
||||
[SoapHeader("Credentials")]
|
||||
public ProjectData AddProject(
|
||||
string name, string started, string ended, string description)
|
||||
{
|
||||
// user credentials required
|
||||
Security.Login(Credentials);
|
||||
|
||||
try
|
||||
{
|
||||
Project proj = Project.NewProject();
|
||||
proj.Name = name;
|
||||
proj.Started = started;
|
||||
proj.Ended = ended;
|
||||
proj.Description = description;
|
||||
proj = proj.Save();
|
||||
|
||||
ProjectData result = new ProjectData();
|
||||
Csla.Data.DataMapper.Map(proj, result, "Resources");
|
||||
return result;
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod(Description = "Edit a project")]
|
||||
[SoapHeader("Credentials")]
|
||||
public ProjectData EditProject(Guid id, string name,
|
||||
string started, string ended,
|
||||
string description)
|
||||
{
|
||||
// user credentials required
|
||||
Security.Login(Credentials);
|
||||
|
||||
try
|
||||
{
|
||||
Project proj = Project.GetProject(id);
|
||||
proj.Name = name;
|
||||
proj.Started = started;
|
||||
proj.Ended = ended;
|
||||
proj.Description = description;
|
||||
proj = proj.Save();
|
||||
|
||||
ProjectData result = new ProjectData();
|
||||
Csla.Data.DataMapper.Map(proj, result, "Resources");
|
||||
return result;
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Resources
|
||||
|
||||
[WebMethod(Description="Get a list of resources")]
|
||||
public ResourceData[] GetResourceList()
|
||||
{
|
||||
// anonymous access allowed
|
||||
Security.UseAnonymous();
|
||||
|
||||
try
|
||||
{
|
||||
ResourceList list = ResourceList.GetResourceList();
|
||||
List<ResourceData> result = new List<ResourceData>();
|
||||
foreach (ProjectTracker.Library.ResourceInfo item in list)
|
||||
{
|
||||
ResourceData info =
|
||||
new ResourceData();
|
||||
Csla.Data.DataMapper.Map(item, info);
|
||||
result.Add(info);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod(Description="Get a resource")]
|
||||
public ResourceData GetResource(ResourceRequest request)
|
||||
{
|
||||
// anonymous access allowed
|
||||
Security.UseAnonymous();
|
||||
|
||||
try
|
||||
{
|
||||
Resource res = Resource.GetResource(request.Id);
|
||||
ResourceData result = new ResourceData();
|
||||
result.Id = res.Id;
|
||||
result.Name = res.FullName;
|
||||
foreach (ResourceAssignment resource in res.Assignments)
|
||||
{
|
||||
ResourceAssignmentData info = new ResourceAssignmentData();
|
||||
Csla.Data.DataMapper.Map(resource, info);
|
||||
result.AddProject(info);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod(Description="Change a resource's name")]
|
||||
[SoapHeader("Credentials")]
|
||||
public ResourceData ChangeResourceName(int id,
|
||||
string firstName, string lastName)
|
||||
{
|
||||
// user credentials required.
|
||||
Security.Login(Credentials);
|
||||
|
||||
try
|
||||
{
|
||||
Resource res = Resource.GetResource(id);
|
||||
res.FirstName = firstName;
|
||||
res.LastName = lastName;
|
||||
res = res.Save();
|
||||
|
||||
ResourceData result = new ResourceData();
|
||||
result.Id = res.Id;
|
||||
result.Name = string.Format("{1}, {0}", res.FirstName, res.LastName);
|
||||
return result;
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Assign Resource to Project
|
||||
|
||||
[WebMethod(Description="Assign resource to a project")]
|
||||
[SoapHeader("Credentials")]
|
||||
public void AssignResource(int resourceId, Guid projectId)
|
||||
{
|
||||
// user credentials required
|
||||
Security.Login(Credentials);
|
||||
|
||||
try
|
||||
{
|
||||
Resource res = Resource.GetResource(resourceId);
|
||||
res.Assignments.AssignTo(projectId);
|
||||
res.Save();
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Roles
|
||||
|
||||
[WebMethod(Description="Get a list of roles")]
|
||||
public RoleInfo[] GetRoles()
|
||||
{
|
||||
// anonymous access allowed
|
||||
Security.UseAnonymous();
|
||||
|
||||
try
|
||||
{
|
||||
RoleList list = RoleList.GetList();
|
||||
List<RoleInfo> result = new List<RoleInfo>();
|
||||
foreach (RoleList.NameValuePair role in list)
|
||||
{
|
||||
RoleInfo info = new RoleInfo();
|
||||
info.Id = role.Key;
|
||||
info.Name = role.Value;
|
||||
result.Add(info);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Csla.DataPortalException ex)
|
||||
{
|
||||
throw ex.BusinessException;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ProjectData
|
||||
{
|
||||
private Guid _id;
|
||||
private string _name;
|
||||
private string _started;
|
||||
private string _ended;
|
||||
private string _description;
|
||||
private List<ProjectResourceData>
|
||||
_resources = new List<ProjectResourceData>();
|
||||
|
||||
public Guid Id
|
||||
{
|
||||
get { return _id; }
|
||||
set { _id = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
public string Started
|
||||
{
|
||||
get { return _started; }
|
||||
set { _started = value; }
|
||||
}
|
||||
|
||||
public string Ended
|
||||
{
|
||||
get { return _ended; }
|
||||
set { _ended = value; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return _description; }
|
||||
set { _description = value; }
|
||||
}
|
||||
|
||||
public void AddResource(ProjectResourceData resource)
|
||||
{
|
||||
_resources.Add(resource);
|
||||
}
|
||||
|
||||
public ProjectResourceData[] ProjectResources
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_resources.Count > 0)
|
||||
return _resources.ToArray();
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
_resources = new List<ProjectResourceData>(value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
public class ProjectRequest
|
||||
{
|
||||
private Guid _id;
|
||||
|
||||
public Guid Id
|
||||
{
|
||||
get { return _id; }
|
||||
set { _id = value; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
public class ProjectResourceData
|
||||
{
|
||||
private int _resourceId;
|
||||
private string _firstName;
|
||||
private string _lastName;
|
||||
private string _assigned;
|
||||
private int _role;
|
||||
|
||||
public int ResourceId
|
||||
{
|
||||
get { return _resourceId; }
|
||||
set { _resourceId = value; }
|
||||
}
|
||||
|
||||
public string FirstName
|
||||
{
|
||||
get { return _firstName; }
|
||||
set { _firstName = value; }
|
||||
}
|
||||
|
||||
public string LastName
|
||||
{
|
||||
get { return _lastName; }
|
||||
set { _lastName = value; }
|
||||
}
|
||||
|
||||
public string Assigned
|
||||
{
|
||||
get { return _assigned; }
|
||||
set { _assigned = value; }
|
||||
}
|
||||
|
||||
public int Role
|
||||
{
|
||||
get { return _role; }
|
||||
set { _role = value; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
public class ResourceAssignmentData
|
||||
{
|
||||
private Guid _projectId;
|
||||
private string _projectName;
|
||||
private string _assigned;
|
||||
private int _role;
|
||||
|
||||
public Guid ProjectId
|
||||
{
|
||||
get { return _projectId; }
|
||||
set { _projectId = value; }
|
||||
}
|
||||
|
||||
public string ProjectName
|
||||
{
|
||||
get { return _projectName; }
|
||||
set { _projectName = value; }
|
||||
}
|
||||
|
||||
public string Assigned
|
||||
{
|
||||
get { return _assigned; }
|
||||
set { _assigned = value; }
|
||||
}
|
||||
|
||||
public int Role
|
||||
{
|
||||
get { return _role; }
|
||||
set { _role = value; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ResourceData
|
||||
{
|
||||
private int _id;
|
||||
private string _name;
|
||||
private List<ResourceAssignmentData> _projects = new List<ResourceAssignmentData>();
|
||||
|
||||
public int Id
|
||||
{
|
||||
get { return _id; }
|
||||
set { _id = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
public void AddProject(ResourceAssignmentData project)
|
||||
{
|
||||
_projects.Add(project);
|
||||
}
|
||||
|
||||
public ResourceAssignmentData[] ResourceAssignments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_projects.Count > 0)
|
||||
return _projects.ToArray();
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
_projects = new List<ResourceAssignmentData>(value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
public class ResourceRequest
|
||||
{
|
||||
private int _id;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get { return _id; }
|
||||
set { _id = value; }
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
public class RoleInfo
|
||||
{
|
||||
private int _id;
|
||||
private string _name;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get { return _id; }
|
||||
set { _id = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Security.Principal;
|
||||
using ProjectTracker.Library.Security;
|
||||
|
||||
public static class Security
|
||||
{
|
||||
public static void UseAnonymous()
|
||||
{
|
||||
// setting an unauthenticated principal when running
|
||||
// under the VShost causes serialization issues
|
||||
// and isn't strictly necessary anyway
|
||||
if (UrlIsHostedByVS(HttpContext.Current.Request.Url))
|
||||
return;
|
||||
ProjectTracker.Library.Security.PTPrincipal.Logout();
|
||||
}
|
||||
|
||||
public static void Login(CslaCredentials credentials)
|
||||
{
|
||||
if (string.IsNullOrEmpty(credentials.Username))
|
||||
throw new System.Security.SecurityException(
|
||||
"Valid credentials not provided");
|
||||
|
||||
// set to unauthenticated principal
|
||||
PTPrincipal.Logout();
|
||||
|
||||
PTPrincipal.Login(credentials.Username, credentials.Password);
|
||||
|
||||
if (!Csla.ApplicationContext.User.Identity.IsAuthenticated)
|
||||
{
|
||||
// the user is not valid, raise an error
|
||||
throw
|
||||
new System.Security.SecurityException(
|
||||
"Invalid user or password");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool UrlIsHostedByVS(Uri uri)
|
||||
{
|
||||
if (uri.Port >= 1024 && string.Compare(uri.Host, "localhost", StringComparison.OrdinalIgnoreCase) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user