/// <summary>
        /// Initializes a new instance of AzureSMProfile and loads its content from specified path.
        /// Any errors generated in the process are stored in ProfileLoadErrors collection.
        /// </summary>
        /// <param name="path">Location of profile file on disk.</param>
        public AzureSMProfile(string path) : this()
        {
            ProfilePath       = path;
            ProfileLoadErrors = new List <string>();

            if (!AzureSession.DataStore.DirectoryExists(AzureSession.ProfileDirectory))
            {
                AzureSession.DataStore.CreateDirectory(AzureSession.ProfileDirectory);
            }

            if (AzureSession.DataStore.FileExists(ProfilePath))
            {
                string contents = AzureSession.DataStore.ReadFileAsText(ProfilePath);

                IProfileSerializer serializer;

                if (CloudException.IsXml(contents))
                {
                    serializer = new XmlProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
                else if (CloudException.IsJson(contents))
                {
                    serializer = new JsonProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
            }
        }
        private static string FormatString(string content)
        {
            try
            {
                if (CloudException.IsJson(content))
                {
                    return(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(content), Formatting.Indented));
                }
                if (CloudException.IsXml(content))
                {
                    return(XDocument.Parse(content).ToString());
                }
            }
            catch
            {
                return(content);
            }

            if (content.Length > Authentication.Constants.MaxContentLength)
            {
                return(content.Substring(0, Authentication.Constants.MaxContentLength) + "\r\nDATA TRUNCATED DUE TO SIZE\r\n");
            }

            return(content);
        }
 public static string FormatString(string content)
 {
     if (CloudException.IsXml(content))
     {
         return(TryFormatXml(content));
     }
     else if (CloudException.IsJson(content))
     {
         return(TryFormatJson(content));
     }
     else
     {
         return(content);
     }
 }
        /// <summary>
        /// Initializes a new instance of AzureSMProfile and loads its content from specified path.
        /// Any errors generated in the process are stored in ProfileLoadErrors collection.
        /// </summary>
        /// <param name="path">Location of profile file on disk.</param>
        public AzureSMProfile(string path) : this()
        {
            ProfilePath       = path;
            ProfileLoadErrors = new List <string>();

            if (!AzureSession.Instance.DataStore.DirectoryExists(AzureSession.Instance.ProfileDirectory))
            {
                AzureSession.Instance.DataStore.CreateDirectory(AzureSession.Instance.ProfileDirectory);
            }

            if (AzureSession.Instance.DataStore.FileExists(ProfilePath))
            {
                string contents = AzureSession.Instance.DataStore.ReadFileAsText(ProfilePath);

                IProfileSerializer serializer;

                if (CloudException.IsXml(contents))
                {
                    serializer = new XmlProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
                else if (CloudException.IsJson(contents))
                {
                    bool converted = false;
                    // first try legacy conversion
                    try
                    {
                        var legacyProfile = JsonConvert.DeserializeObject <LegacyAzureSMProfile>(contents);
                        converted = legacyProfile.TryConvert(this);
                    }
                    catch
                    {
                    }

                    if (!converted)
                    {
                        serializer = new JsonProfileSerializer();
                        if (!serializer.Deserialize(contents, this))
                        {
                            ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                        }
                    }
                }
            }
        }
 public static string FormatString(string content)
 {
     if (CloudException.IsXml(content))
     {
         return(TryFormatXml(content));
     }
     else if (CloudException.IsJson(content))
     {
         return(TryFormatJson(content));
     }
     else
     {
         return(content.Length <= GeneralUtilities.StreamCutOffSize ?
                content :
                content.Substring(0, StreamCutOffSize) + "\r\nDATA TRUNCATED DUE TO SIZE\r\n");
     }
 }
        private void Load()
        {
            Environments      = new Dictionary <string, AzureEnvironment>(StringComparer.InvariantCultureIgnoreCase);
            Subscriptions     = new Dictionary <Guid, AzureSubscription>();
            Accounts          = new Dictionary <string, AzureAccount>(StringComparer.InvariantCultureIgnoreCase);
            ProfileLoadErrors = new List <string>();

            if (!store.DirectoryExists(AzureSession.ProfileDirectory))
            {
                store.CreateDirectory(AzureSession.ProfileDirectory);
            }

            if (store.FileExists(profilePath))
            {
                string contents = store.ReadFileAsText(profilePath);

                IProfileSerializer serializer;

                if (CloudException.IsXml(contents))
                {
                    serializer = new XmlProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
                else if (CloudException.IsJson(contents))
                {
                    serializer = new JsonProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
            }

            // Adding predefined environments
            foreach (AzureEnvironment env in AzureEnvironment.PublicEnvironments.Values)
            {
                Environments[env.Name] = env;
            }
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of AzureProfile and loads its content from specified path.
        /// Any errors generated in the process are stored in ProfileLoadErrors collection.
        /// </summary>
        /// <param name="path">Location of profile file on disk.</param>
        public AzureProfile(string path)
        {
            ProfilePath       = path;
            Environments      = new Dictionary <string, AzureEnvironment>(StringComparer.InvariantCultureIgnoreCase);
            Subscriptions     = new Dictionary <Guid, AzureSubscription>();
            Accounts          = new Dictionary <string, AzureAccount>(StringComparer.InvariantCultureIgnoreCase);
            ProfileLoadErrors = new List <string>();

            if (!AzureSession.DataStore.DirectoryExists(AzureSession.ProfileDirectory))
            {
                AzureSession.DataStore.CreateDirectory(AzureSession.ProfileDirectory);
            }

            if (AzureSession.DataStore.FileExists(ProfilePath))
            {
                string contents = AzureSession.DataStore.ReadFileAsText(ProfilePath);

                IProfileSerializer serializer;

                if (CloudException.IsXml(contents))
                {
                    serializer = new XmlProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
                else if (CloudException.IsJson(contents))
                {
                    serializer = new JsonProfileSerializer();
                    if (!serializer.Deserialize(contents, this))
                    {
                        ProfileLoadErrors.AddRange(serializer.DeserializeErrors);
                    }
                }
            }

            LoadDefaultEnvironments();
        }
示例#8
0
 public void IsXmlWorksWithValidation(string body, bool expectedResult)
 {
     Assert.Equal(expectedResult, CloudException.IsXml(body, true));
 }