00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.ObjectModel;
00014 using System.Diagnostics;
00015 using System.Web.Services.Protocols;
00016 using Microsoft.Office.Project.Server.Library;
00017
00018 namespace Mcs.Epm.MicrosoftProject.mpFx
00019 {
00020
00021
00022
00023 public class Errors
00024 {
00025 #region Public Static Methods
00026
00027
00028
00029
00030
00031
00032
00033 public static string GetGetErrorFriendlyName(PSErrorID errorId)
00034 {
00035 string errorDescription = errorId.ToString();
00036
00037 try
00038 {
00039 errorDescription = ProjectServer._ResourceManager.GetString(errorDescription) ?? errorId.ToString();
00040 }
00041 catch (Exception exception)
00042 {
00043
00044 Debug.Print(exception.Message);
00045 }
00046
00047 return errorDescription;
00048 }
00049
00050 public static Collection<PSErrorID> GetMSProjectErrorCodes(SoapException soapException)
00051 {
00052 PSClientError error = new PSClientError(soapException);
00053 PSErrorInfo[] errors = error.GetAllErrors();
00054 Collection<PSErrorID> errorCodes = new Collection<PSErrorID>();
00055
00056 foreach (PSErrorInfo thisError in errors)
00057 {
00058 errorCodes.Add(thisError.ErrId);
00059 }
00060
00061 return errorCodes;
00062 }
00063
00064 public static string ProcessMSProjectErrors(SoapException soapException)
00065 {
00066 PSClientError error = new PSClientError(soapException);
00067 PSErrorInfo[] errors = error.GetAllErrors();
00068
00069 string errorMessage = FormatProjectError(errors, soapException.Message);
00070
00071 return errorMessage;
00072 }
00073
00074 public static string FormatProjectError(PSErrorInfo[] errors, string soapMessage)
00075 {
00076 string errorMessage = "==============================\r\nError: \r\n";
00077
00078 for (int i = 0; i < errors.Length; i++)
00079 {
00080 errorMessage += string.Format("\n{0}\r\n", soapMessage);
00081 errorMessage += string.Format("{0}\r\nPSCLientError Output:\r\n \r\n", "".PadRight(30, '='));
00082 errorMessage += string.Format("{0}\r\n", GetGetErrorFriendlyName(errors[i].ErrId));
00083
00084 for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
00085 {
00086 errorMessage += string.Format("\r\n\t{0}: {1}", errors[i].ErrorAttributeNames()[j], errors[i].ErrorAttributes[j]);
00087 }
00088 errorMessage += ("\r\n").PadRight(30, '=');
00089 }
00090 return errorMessage;
00091 }
00092
00093 public static string ProcessMpFxException(MpFxException exception)
00094 {
00095 if (exception.ErrorInfo.Count > 0 )
00096 {
00097 return ProcessMSProjectErrors((SoapException) exception.Exception);
00098 }
00099
00100 return exception.Message;
00101 }
00102
00103 #endregion
00104 }
00105 }