00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.Generic;
00014 using System.Runtime.Serialization;
00015 using System.Web.Services.Protocols;
00016 using System.Xml;
00017 using Mcs.Epm.MicrosoftProject.mpFx.Interfaces;
00018 using Microsoft.Office.Project.Server.Library;
00019
00020 namespace Mcs.Epm.MicrosoftProject.mpFx
00021 {
00022 [Serializable]
00023 public class MpFxException:Exception
00024 {
00025 #region Public Enums
00026
00027 [Flags]
00028 public enum Options
00029 {
00030
00031 }
00032
00033 #endregion
00034
00035 #region Public Properties
00036
00037 public PSClientError ClientError {get;private set;}
00038 public List<PSErrorInfo> ErrorInfo { get; private set;}
00039 public Exception Exception { get; private set; }
00040 public bool IsProjectError { get; private set; }
00041
00042 #endregion
00043
00044 #region Constructors
00045
00046 public MpFxException() { }
00047
00048 public MpFxException(SoapException exception)
00049 : base(exception.Message, exception.InnerException)
00050 {
00051 Exception = exception;
00052 ClientError = new PSClientError(exception);
00053 ErrorInfo = new List<PSErrorInfo>(ClientError.GetAllErrors());
00054 IsProjectError = true;
00055 }
00056
00057 public MpFxException(PSClientError clientError, ILog log, LogArea area, LogEntryType type)
00058 {
00059 ClientError = clientError;
00060 ErrorInfo = new List<PSErrorInfo>(clientError.GetAllErrors());
00061 IsProjectError = true;
00062
00063 if (log != null)
00064 {
00065 log.WriteEntry(area, type, Errors.ProcessMpFxException(this));
00066 }
00067 }
00068
00069 public MpFxException(string message) : base(message) { }
00070 public MpFxException(string message, Exception inner) : base(message, inner) { }
00071 public MpFxException(Exception inner) : base(inner.Message, inner) { }
00072 public MpFxException(SerializationInfo info, StreamingContext context) : base(info, context) { }
00073
00074 #endregion
00075
00076 #region Factory
00077
00078 public static MpFxException Create(string message)
00079 {
00080 return new MpFxException(message);
00081 }
00082
00083 public static MpFxException Create(string message, Exception inner)
00084 {
00085 return new MpFxException(message, inner);
00086 }
00087
00088 public static MpFxException Create(string message, ILog log, LogArea area, LogEntryType type)
00089 {
00090 if (log != null)
00091 {
00092 log.WriteEntry(area, type, message);
00093 }
00094
00095 return new MpFxException(message);
00096 }
00097
00098 public static MpFxException Create(string message, Exception inner, ILog log, LogArea area, LogEntryType type)
00099 {
00100 if (log != null)
00101 {
00102 log.WriteEntry(area, type, message);
00103 }
00104
00105 return new MpFxException(message, inner);
00106 }
00107
00108 public static MpFxException Create(SoapException exception, ILog log, LogArea area, LogEntryType type)
00109 {
00110 if (log != null)
00111 {
00112 log.WriteEntry(area, type, exception);
00113 }
00114
00115 return new MpFxException(exception);
00116 }
00117
00118 public static Exception Create(Exception exception, ILog log, LogArea area, LogEntryType type)
00119 {
00120 if (log != null)
00121 {
00122 log.WriteEntry(area, type, exception.Message, exception.StackTrace);
00123 }
00124
00125 return new MpFxException(exception);
00126 }
00127
00128 public static void ThrowIfError(string errorMessage, ILog log, LogArea area, LogEntryType type)
00129 {
00130 if (!string.IsNullOrEmpty(errorMessage))
00131 {
00132 PSClientError clientError = new PSClientError(errorMessage);
00133 if (clientError.LastError != PSErrorID.NoError)
00134 {
00135 throw new MpFxException(clientError, log, area, type);
00136 }
00137 }
00138 }
00139
00140 #endregion
00141
00142
00143 }
00144 }