示例#1
0
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails)
        {
            HttpStatusCode httpStatusCode = 0;
            string         str            = null;

            return(ServiceManagementHelper.TryGetExceptionDetails(exception, out errorDetails, out httpStatusCode, out str));
        }
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails)
        {
            HttpStatusCode httpStatusCode;
            string         operationId;

            return(TryGetExceptionDetails(exception, out errorDetails, out httpStatusCode, out operationId));
        }
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
        {
            errorDetails = null;
            httpStatusCode = 0;
            operationId = null;

            if (exception == null)
            {
                return false;
            }

            if (exception.Message == "Internal Server Error")
            {
                httpStatusCode = HttpStatusCode.InternalServerError;
                return true;
            }

            var wex = exception.InnerException as WebException;

            if (wex == null)
            {
                return false;
            }

            var response = wex.Response as HttpWebResponse;
            if (response == null)
            {
                return false;
            }

            if (response.Headers != null)
            {
                operationId = response.Headers[Constants.OperationTrackingIdHeader];
            }

            using (var s = response.GetResponseStream())
            {
                try
                {
                    if (s == null || s.Length == 0)
                    {
                        return false;
                    }

                    var reader = XmlDictionaryReader.CreateTextReader(s, new XmlDictionaryReaderQuotas());
                    var ser = new DataContractSerializer(typeof(ServiceManagementError));
                    errorDetails = (ServiceManagementError)ser.ReadObject(reader, true);
                }
                catch (Exception)
                {
                    return false;
                }
            }

            return true;
        }
 public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails)
 {
     HttpStatusCode httpStatusCode;
     string operationId;
     return TryGetExceptionDetails(exception, out errorDetails, out httpStatusCode, out operationId);
 }
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
        {
            errorDetails   = null;
            httpStatusCode = 0;
            operationId    = null;

            if (exception == null)
            {
                return(false);
            }

            if (exception.Message == "Internal Server Error")
            {
                httpStatusCode = HttpStatusCode.InternalServerError;
                return(true);
            }

            WebException wex = exception.InnerException as WebException;

            if (wex == null)
            {
                return(false);
            }

            HttpWebResponse response = wex.Response as HttpWebResponse;

            if (response == null)
            {
                return(false);
            }

            httpStatusCode = response.StatusCode;
            if (httpStatusCode == HttpStatusCode.Forbidden)
            {
                return(true);
            }

            if (response.Headers != null)
            {
                operationId = response.Headers[Constants.OperationTrackingIdHeader];
            }

            using (var s = response.GetResponseStream())
            {
                if (s.Length == 0)
                {
                    return(false);
                }

                try
                {
                    using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(s, new XmlDictionaryReaderQuotas()))
                    {
                        DataContractSerializer ser = new DataContractSerializer(typeof(ServiceManagementError));
                        errorDetails = (ServiceManagementError)ser.ReadObject(reader, true);
                    }
                }
                catch (SerializationException)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#6
0
		public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
		{
			bool flag;
			errorDetails = null;
			httpStatusCode = 0;
			operationId = null;
			if (exception != null)
			{
				if (exception.Message != "Internal Server Error")
				{
					WebException innerException = exception.InnerException as WebException;
					if (innerException != null)
					{
						HttpWebResponse response = innerException.Response as HttpWebResponse;
						if (response != null)
						{
							if (response.Headers != null)
							{
								operationId = response.Headers["x-ms-request-id"];
							}
							if (response.StatusCode != HttpStatusCode.NotFound)
							{
								Stream responseStream = response.GetResponseStream();
								using (responseStream)
								{
									if (responseStream.Length != (long)0)
									{
										try
										{
											errorDetails = new ServiceManagementError();
											responseStream.Seek((long)0, SeekOrigin.Begin);
											StreamReader streamReader = new StreamReader(responseStream);
											using (StringReader stringReader = new StringReader(streamReader.ReadToEnd()))
											{
												XmlReader xmlReader = XmlReader.Create(stringReader);
												while (xmlReader.Read())
												{
													XmlNodeType nodeType = xmlReader.NodeType;
													if (nodeType != XmlNodeType.Element)
													{
														continue;
													}
													if (xmlReader.Name != "Code")
													{
														if (xmlReader.Name != "Message")
														{
															continue;
														}
														xmlReader.Read();
														errorDetails.Message = xmlReader.Value;
													}
													else
													{
														xmlReader.Read();
														errorDetails.Code = xmlReader.Value;
													}
												}
											}
										}
										catch (SerializationException serializationException)
										{
											flag = false;
											return flag;
										}
										return true;
									}
									else
									{
										flag = false;
									}
								}
								return flag;
							}
							else
							{
								errorDetails = new ServiceManagementError();
								errorDetails.Message = string.Concat(response.ResponseUri.AbsoluteUri, " does not exist.");
								errorDetails.Code = response.StatusCode.ToString();
								return false;
							}
						}
						else
						{
							return false;
						}
					}
					else
					{
						return false;
					}
				}
				else
				{
					httpStatusCode = HttpStatusCode.InternalServerError;
					return true;
				}
			}
			else
			{
				return false;
			}
		}
示例#7
0
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
        {
            bool flag;

            errorDetails   = null;
            httpStatusCode = 0;
            operationId    = null;
            if (exception != null)
            {
                if (exception.Message != "Internal Server Error")
                {
                    WebException innerException = exception.InnerException as WebException;
                    if (innerException != null)
                    {
                        HttpWebResponse response = innerException.Response as HttpWebResponse;
                        if (response != null)
                        {
                            httpStatusCode = response.StatusCode;
                            if ((int)httpStatusCode != 0x193)
                            {
                                if (response.Headers != null)
                                {
                                    operationId = response.Headers["x-ms-request-id"];
                                }
                                Stream responseStream = response.GetResponseStream();
                                using (responseStream)
                                {
                                    if (responseStream.Length != (long)0)
                                    {
                                        try
                                        {
                                            XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateTextReader(responseStream, new XmlDictionaryReaderQuotas());
                                            using (xmlDictionaryReader)
                                            {
                                                DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(ServiceManagementError));
                                                errorDetails = (ServiceManagementError)dataContractSerializer.ReadObject(xmlDictionaryReader, true);
                                            }
                                        }
                                        catch (SerializationException serializationException)
                                        {
                                            flag = false;
                                            return(flag);
                                        }
                                        return(true);
                                    }
                                    else
                                    {
                                        flag = false;
                                    }
                                }
                                return(flag);
                            }
                            else
                            {
                                try
                                {
                                    Stream stream = response.GetResponseStream();
                                    using (stream)
                                    {
                                        XmlDictionaryReader xmlDictionaryReader1 = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas());
                                        using (xmlDictionaryReader1)
                                        {
                                            DataContractSerializer dataContractSerializer1 = new DataContractSerializer(typeof(ServiceManagementError));
                                            errorDetails = (ServiceManagementError)dataContractSerializer1.ReadObject(xmlDictionaryReader1, true);
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                return(true);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    httpStatusCode = HttpStatusCode.InternalServerError;
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
示例#8
0
		public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails)
		{
			HttpStatusCode httpStatusCode = 0;
			string str = null;
			return ServiceManagementHelper.TryGetExceptionDetails(exception, out errorDetails, out httpStatusCode, out str);
		}
示例#9
0
		public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
		{
			bool flag;
			errorDetails = null;
			httpStatusCode = 0;
			operationId = null;
			if (exception != null)
			{
				if (exception.Message != "Internal Server Error")
				{
					WebException innerException = exception.InnerException as WebException;
					if (innerException != null)
					{
						HttpWebResponse response = innerException.Response as HttpWebResponse;
						if (response != null)
						{
							httpStatusCode = response.StatusCode;
							if ((int)httpStatusCode != 0x193)
							{
								if (response.Headers != null)
								{
									operationId = response.Headers["x-ms-request-id"];
								}
								Stream responseStream = response.GetResponseStream();
								using (responseStream)
								{
									if (responseStream.Length != (long)0)
									{
										try
										{
											XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateTextReader(responseStream, new XmlDictionaryReaderQuotas());
											using (xmlDictionaryReader)
											{
												DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(ServiceManagementError));
												errorDetails = (ServiceManagementError)dataContractSerializer.ReadObject(xmlDictionaryReader, true);
											}
										}
										catch (SerializationException serializationException)
										{
											flag = false;
											return flag;
										}
										return true;
									}
									else
									{
										flag = false;
									}
								}
								return flag;
							}
							else
							{
								try
								{
									Stream stream = response.GetResponseStream();
									using (stream)
									{
										XmlDictionaryReader xmlDictionaryReader1 = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas());
										using (xmlDictionaryReader1)
										{
											DataContractSerializer dataContractSerializer1 = new DataContractSerializer(typeof(ServiceManagementError));
											errorDetails = (ServiceManagementError)dataContractSerializer1.ReadObject(xmlDictionaryReader1, true);
										}
									}
								}
								catch
								{
								}
								return true;
							}
						}
						else
						{
							return false;
						}
					}
					else
					{
						return false;
					}
				}
				else
				{
					httpStatusCode = HttpStatusCode.InternalServerError;
					return true;
				}
			}
			else
			{
				return false;
			}
		}
示例#10
0
        protected void RethrowCommunicationError(CommunicationException ce, ServiceManagementError error)
        {
            String message = ce.Message;

            if (error != null)
            {
                message = error.Message + " (" + error.Code + ")";
            }
            else if (ce is MessageSecurityException)
            {
                message =
                    ce.Message + ". Check SubscriptionId is correct: " + SubscriptionId + " " +
                    "Check certificate with the thumbrint " + CertificateThumbprint + " " +
                    "is configured as management certificate in azure portal.";

            }
            throw new CSManageException(message, ce);
        }