Base class used to parse all XML responses from the fabric
 /// <summary>
 /// Used to get and instance of the BaseParser that will parse the Xml response from the Fabric
 /// </summary>
 /// <param name="response">the HttpWebResponse that is returned</param>
 /// <param name="root">the root element neededs</param>
 /// <param name="baseParser">used to parse the response coming back</param>
 /// <returns>A dynamic type based on the expected return</returns>
 public static dynamic Parse(HttpWebResponse response, string root, BaseParser baseParser = null)
 {
     BaseParser parser = BaseParser.GetInstance(response, root, baseParser);
     parser.Parse();
     return parser.CommandResponse;
 }
        /// <summary>
        /// Gets an instance of the BaseParser type to use and parse response - implementation of CoR pattern
        /// </summary>
        public static BaseParser GetInstance(HttpWebResponse response, string rootVerb, BaseParser parser = null
                                             /* used when there are more than one parser with the same root node - have to change pattern not ideal */)
        {
            XDocument document;

            try
            {
                document = XDocument.Load(response.GetResponseStream());
            }
            catch (Exception)
            {
                throw new ApplicationException("XML document not present in response stream");
            }
            // parser needs to be checked if it's a duplicate root element - discard the CoR check - yuck!
            if (parser != null)
            {
                parser.Document = document;
                return(parser);
            }

            var parserList = new List <BaseParser>
            {
                new AddNewSqlAzureServerParser(document),
                new GetHostedServiceListParser(document),
                new ListStorageAccountsParser(document),
                new GetSubscriptionParser(document),
                new GetSubscriberLocationsParser(document),
                new GetAggregateDeploymentStatusParser(document),
                new GetRoleStatusParser(document),
                new GetHostedServicePropertiesParser(document)
            };

            foreach (BaseParser baseParser in parserList)
            {
                if (baseParser.RootElement == rootVerb)
                {
                    return(baseParser);
                }
            }
            throw new ApplicationException("Unknown response - parser not available");
        }
        /// <summary>
        /// Gets an instance of the BaseParser type to use and parse response - implementation of CoR pattern
        /// </summary>
        public static BaseParser GetInstance(HttpWebResponse response, string rootVerb, BaseParser parser = null
            /* used when there are more than one parser with the same root node - have to change pattern not ideal */)
        {
            XDocument document;
            try
            {
                document = XDocument.Load(response.GetResponseStream());
            }
            catch (Exception)
            {
                throw new ApplicationException("XML document not present in response stream");
            }
            // parser needs to be checked if it's a duplicate root element - discard the CoR check - yuck!
            if (parser != null)
            {
                parser.Document = document;
                return parser;
            }

            var parserList = new List<BaseParser>
                                 {
                                     new AddNewSqlAzureServerParser(document),
                                     new GetHostedServiceListParser(document),
                                     new ListStorageAccountsParser(document),
                                     new GetSubscriptionParser(document),
                                     new GetSubscriberLocationsParser(document),
                                     new GetAggregateDeploymentStatusParser(document),
                                     new GetRoleStatusParser(document),
                                     new GetHostedServicePropertiesParser(document)
                                 };
            foreach (BaseParser baseParser in parserList)
            {
                if (baseParser.RootElement == rootVerb)
                    return baseParser;
            }
            throw new ApplicationException("Unknown response - parser not available");
        }