Commit for development environment setup

This commit is contained in:
2023-06-19 16:12:33 -04:00
parent be72063a3c
commit bbce2ad0a6
2209 changed files with 1171775 additions and 625 deletions

View File

@@ -0,0 +1,8 @@
using System;
using System.Web.Services.Protocols;
public class CslaCredentials : SoapHeader
{
public string Username;
public string Password;
}

View File

@@ -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
}

View File

@@ -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);
}
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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);
}
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1 @@
<%@ WebService Language="C#" CodeBehind="~/App_Code/PTService.cs" Class="PTService" %>

View File

@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings>
<add key="CslaAuthentication" value="Csla" />
<!--<add key="CslaDataPortalProxy"
value="Csla.DataPortalClient.RemotingProxy, Csla"/>
<add key="CslaDataPortalUrl"
value="http://localhost:3187/RemotingHost/RemotingPortal.rem"/>-->
<add key="CslaDataPortalProxy"
value="Csla.DataPortalClient.WebServicesProxy, Csla"/>
<add key="CslaDataPortalUrl"
value="http://localhost:4334/WebServicesHost/WebServicePortal.asmx"/>
<!--<add key="CslaDataPortalProxy"
value="EnterpriseServicesHost.EnterpriseServicesProxy, EnterpriseServicesHostvb"/>-->
</appSettings>
<connectionStrings>
<add name="PTracker"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\Visual Studio Projects\csla20\ProjectTracker20cs\PTracker.mdf&quot;;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
<add name="Security"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\Visual Studio Projects\csla20\ProjectTracker20cs\Security.mdf&quot;;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false">
<assemblies>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>