/// <summary>
 /// Returns true if web service is reachable.
 /// </summary>
 public bool TestWebService()
 {
     try
     {
         return(WebService.TestWebService());
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates the information entered on the form and returns a list of errors if there are any issues.
        /// </summary>
        private String ValidatePackage()
        {
            StringBuilder errors = new StringBuilder();

            if (string.IsNullOrEmpty(txtBxName.Text.Trim()))
            {
                errors.Append("App name cannot be empty." + Environment.NewLine);
            }
            else
            {
                packageDetails.Name = txtBxName.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtBxVersion.Text.Trim()))
            {
                errors.Append("Version name cannot be empty." + Environment.NewLine);
            }
            else
            {
                try
                {
                    packageDetails.Version = new Version(txtBxVersion.Text.Trim()).ToString();
                }
                catch
                {
                    errors.Append("Please enter a valid version like 0.0 ." + Environment.NewLine);
                }
            }

            if (string.IsNullOrEmpty(txtBxPath.Text.Trim()))
            {
                errors.Append("Path cannot be empty." + Environment.NewLine);
            }
            else
            {
                if (File.Exists(txtBxPath.Text))
                {
                    package = File.ReadAllBytes(txtBxPath.Text);
                }
                else
                {
                    errors.Append(txtBxPath.Text + " does not exist." + Environment.NewLine);
                }
            }

            try
            {
                if (!webService.TestWebService())
                {
                    errors.Append("Cannot reach Mobu web service." + Environment.NewLine);
                }
                else
                {
                    var packageList = webService.GetPackageList();

                    if (packageList.Any(x => x.Name == packageDetails.Name && x.Version == packageDetails.Version))
                    {
                        errors.Append(packageDetails.Name + " " + packageDetails.Version + " is already being hosted." + Environment.NewLine);
                    }
                }
            }
            catch (Exception e)
            {
                errors.Append("Error occured while interacting with Mobu web service. " + e.Message + Environment.NewLine);
            }

            packageDetails.Critical = chkBxCriticalUpdate.Checked;

            return(errors.ToString());
        }