Exemple #1
0
        public void WebLibraryTest_IncorrectUri_Fail()
        {
            //Arrange
            string address  = "ranorex.com";
            string fileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);

            //Act and Assert
            Assert.Throws <InvalidOperationException>(
                () => WebLibrary.DownloadFile(address, fileName));
        }
Exemple #2
0
        public void WebLibraryTest_NoLocalPath_Fail()
        {
            //Arrange
            string address  = "https://www.ranorex.com/release-notes.html";
            string fileName = null;
            var    logger   = new TestReportLogger();

            Report.AttachLogger(logger);

            //Act
            WebLibrary.DownloadFile(address, fileName);

            //Assert
            Report.DetachLogger(logger);
            Assert.AreEqual(string.Format("Downloading a file from: {0} failed for the following reason:\r\nValue cannot be null.\r\nParameter name: fileName", address), logger.LastLogMessage);
        }
Exemple #3
0
        public void WebLibraryTest_DownloadExeToSystemDir_Fail()
        {
            //Arrange
            string address  = "https://www.ranorex.com/download/Ranorex-7.2.0.exe";
            string fileName = Path.Combine(Environment.SystemDirectory, "Ranorex-7.2.0.exe");
            var    logger   = new TestReportLogger();

            Report.AttachLogger(logger);

            //Act
            WebLibrary.DownloadFile(address, fileName);

            //Assert
            Report.DetachLogger(logger);
            Assert.AreEqual(string.Format("Downloading a file from: {0} failed for the following reason:\r\nAn exception occurred during a WebClient request.\r\nAccess to the path '{1}' is denied.", address, fileName), logger.LastLogMessage);
        }
Exemple #4
0
        public void WebLibraryTest_NoUri_Fail()
        {
            //Arrange
            string address  = null;
            string fileName = null;
            var    logger   = new TestReportLogger();

            Report.AttachLogger(logger);

            //Act
            WebLibrary.DownloadFile(address, fileName);

            //Assert
            Report.DetachLogger(logger);
            Assert.AreEqual(string.Format("Downloading a file from: {0} failed for the following reason:\r\nValue cannot be null.\r\nParameter name: address", address), logger.LastLogMessage);
        }
        public void WebLibraryTest_NoUri_Fail()
        {
            //Arrange
            string address  = null;
            string fileName = null;
            var    logger   = new TestReportLogger();

            Report.AttachLogger(logger);

            //Act
            WebLibrary.DownloadFile(address, fileName);

            //Assert
            Report.DetachLogger(logger);
            StringAssert.StartsWith(string.Format("Downloading a file from: {0} failed for the following reason:", address), logger.LastLogMessage);
        }
Exemple #6
0
        public void WebLibraryTest_DownloadHtmlToCurrentDirWithFilePath_Success()
        {
            //Arrange
            string address  = "https://www.ranorex.com/release-notes.html";
            string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "release-notes.html");

            File.Delete(fileName);
            var logger = new TestReportLogger();

            Report.AttachLogger(logger);

            //Act
            WebLibrary.DownloadFile(address, fileName);

            //Assert
            Report.DetachLogger(logger);
            Assert.AreEqual(string.Format("File successfully downloaded to {0}", fileName), logger.LastLogMessage);
            Assert.IsTrue(File.Exists(fileName));
            File.Delete(fileName);
        }
Exemple #7
0
        public void WebLibraryTest_ResponseStatusCode_501()
        {
            string statusCode = WebLibrary.GetHttpStatusCode("https://httpstat.us/501");

            Assert.AreEqual("501", statusCode);
        }
Exemple #8
0
        public async Task <WebLibrary> DeployAsync(IPackage package, RevisionSource source, int publisherId)
        {
            #region Preconditions

            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            #endregion

            var metadata = GetMetadata(package);

            var version = metadata.Version;

            // var existing = await registry.GetAsync(registry.Lookup(metadata.Name), metadata.Version);

            // if (existing != null) throw new PublishingConflict(existing);

            var mainPath = metadata.Main;

            var bowerFile = package.Find("bower.json");

            if (bowerFile != null)
            {
                try
                {
                    var bowerFileStream = await bowerFile.OpenAsync().ConfigureAwait(false);

                    var bower = PackageMetadata.Parse(bowerFileStream);

                    if (bower.Main != null)
                    {
                        mainPath = bower.Main;
                    }
                }
                catch { }
            }

            if (mainPath == null)
            {
                throw new Exception("A main property found in package.json or bower.json.");
            }

            var mainFile = package.Find(mainPath);

            if (mainFile == null)
            {
                throw new Exception($"The main file '{mainPath}' was not found");
            }

            var mainText = await mainFile.ReadAllTextAsync().ConfigureAwait(false);

            if (mainText.Length == 0)
            {
                throw new Exception($"{mainPath} is empty");
            }

            var mainBlobStream = new MemoryStream(Encoding.UTF8.GetBytes(mainText));

            var mainName = mainPath.Split('/').Last();

            if (!mainName.EndsWith(".js"))
            {
                throw new Exception($"Must end with js. was {mainName}");
            }

            var mainBlob = new Blob(
                key: $"libs/{metadata.Name}/{version}/{mainName}",
                stream: mainBlobStream,
                properties: new BlobProperties {
                ContentType = "application/javascript"
            }
                );

            var mainHash = Hash.ComputeSHA256(mainBlobStream);

            // Push to CDN
            await bucket.PutAsync(mainBlob).ConfigureAwait(false);

            if (metadata.Files != null)
            {
                // TODO: Copy over everything from files[] (excluding main)
                foreach (var fileName in metadata.Files)
                {
                    var fn = fileName;

                    if (fn.StartsWith("./"))
                    {
                        fn = fileName.Substring(2);
                    }

                    if (fn == mainPath)
                    {
                        continue;
                    }

                    var asset = package.Find(fn);

                    var format = asset.Key.Split('.').Last();

                    var n = asset.Key.Split('/').Last();

                    var ms = new MemoryStream();

                    using (var data = await asset.OpenAsync().ConfigureAwait(false))
                    {
                        data.CopyTo(ms);

                        ms.Position = 0;
                    }

                    var blob = new Blob(
                        key: $"libs/{metadata.Name}/{version}/{n}",
                        stream: ms,
                        properties: new BlobProperties {
                        ContentType = GetMime(format)
                    }
                        );

                    await bucket.PutAsync(blob).ConfigureAwait(false);
                }
            }

            var release = new WebLibrary(metadata.Name, version)
            {
                MainName   = mainName,
                MainSha256 = mainHash,
                Source     = source.ToString()
            };

            return(release);
        }
        /// <summary>
        /// Update Product Details
        /// </summary>
        protected void UpdateProduct()
        {
            string productName = TextBoxProductName.Text;

            #region Update Product Details

            #region Get the schema of SQL Table
            string   connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
            string[] saltString       = ConfigurationManager.AppSettings.GetValues("ProductPasswordSaltString");

            StringBuilder sbSqlQuery = new StringBuilder("Select * From M_PRODUCTS where PRDCT_ID = '" + HiddenProductID.Value + "'");

            SqlConnection sqlConn = new SqlConnection(connectionString);
            sqlConn.Open();
            SqlDataAdapter    daProducts = new SqlDataAdapter(sbSqlQuery.ToString(), connectionString);
            SqlCommandBuilder cbFields   = new SqlCommandBuilder(daProducts);
            #endregion

            #region Assign product Details to SQL Table Data
            if (cbFields != null)
            {
                DataSet dsProducts = new DataSet();
                dsProducts.Locale = CultureInfo.InvariantCulture;

                daProducts.FillSchema(dsProducts, SchemaType.Mapped, "Product");
                daProducts.Fill(dsProducts, "Product");

                DataRow drowProduct = dsProducts.Tables[0].Rows.Find(TextBoxProductCode.Text);
                if (drowProduct != null)
                {
                    drowProduct.BeginEdit();
                    drowProduct["COMPANY_ID"]          = DropDownListProductCompany.SelectedValue;
                    drowProduct["PRDCT_NAME"]          = productName;
                    drowProduct["PRDCT_CODE"]          = TextBoxProductCode.Text;
                    drowProduct["PRDCT_FAMILY"]        = TextBoxProductFamily.Text;
                    drowProduct["PRDCT_VERSION"]       = TextBoxProductVersion.Text;
                    drowProduct["PRDCT_BUILD"]         = TextBoxProductBuild.Text;
                    drowProduct["PRDCT_ACESSID"]       = WebLibrary.GetHashCode(saltString[0] + TextBoxProductCode.Text);;
                    drowProduct["PRDCT_ACESSPASSWORD"] = WebLibrary.GetHashCode(TextBoxProductCode.Text + saltString[0]);
                    try
                    {
                        if (FileUploadProductLogo.HasFile)
                        {
                            byte[] productLogo = null;
                            int    logoHeight  = 50;
                            int    logoWidth   = 250;

                            productLogo = FileUploadProductLogo.FileBytes;
                            Bitmap productLogoBitmap = (Bitmap)Bitmap.FromStream(new MemoryStream(productLogo));
                            bool   modifyLogo        = false;
                            if (productLogoBitmap.Height > logoHeight)
                            {
                                modifyLogo = true;
                            }
                            else
                            {
                                logoHeight = productLogoBitmap.Height;
                            }
                            if (productLogoBitmap.Width > logoWidth)
                            {
                                modifyLogo = true;
                            }
                            else
                            {
                                logoWidth = productLogoBitmap.Width;
                            }

                            if (modifyLogo)
                            {
                                Bitmap       modifiedProductLogo = new Bitmap(productLogoBitmap, new Size(logoWidth, logoHeight));
                                MemoryStream ms = new MemoryStream();
                                modifiedProductLogo.Save(ms, ImageFormat.Gif);
                                byte[] bitmapData = ms.ToArray();
                                drowProduct["PRDCT_LOGO"] = bitmapData;
                            }
                            else
                            {
                                drowProduct["PRDCT_LOGO"] = FileUploadProductLogo.FileBytes;
                            }
                        }
                    }
                    catch (InvalidCastException)
                    {
                        LabelError.Text = Resources.FailureMessages.InvalidProductLogoFile;
                        return;
                    }
                    catch (ArgumentException)
                    {
                        LabelError.Text = Resources.FailureMessages.InvalidProductLogoFile;
                        return;
                    }
                    drowProduct["REC_USER"]   = Session["UserSystemID"].ToString();
                    drowProduct["REC_ACTIVE"] = CheckBoxProductActive.Checked;
                    drowProduct["REC_DATE"]   = DateTime.Now;
                    drowProduct.EndEdit();
                    daProducts.Update(dsProducts, "Product");
                }
                sqlConn.Close();
            }
            #endregion

            #endregion

            #region Redirect to Products Page
            Response.Redirect("Products.aspx?ActionStatus=Success&Mode=U");
            #endregion
        }
        /// <summary>
        /// Add the product definition to SQL Table
        /// </summary>
        protected void AddProduct()
        {
            if (DataProvider.IsProductExists(TextBoxProductCode.Text))
            {
                #region Display Error Message if product already exists
                GetMasterPage().DisplayActionMessage('F', null, Resources.FailureMessages.ProductAlreadyExists);
                #endregion
            }
            else
            {
                #region Add Product to SQL table

                string productName = TextBoxProductName.Text;

                #region Get the schema of SQL Table
                string   connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
                string[] saltString       = ConfigurationManager.AppSettings.GetValues("ProductPasswordSaltString");
                string   sqlQuery         = "Select * From M_PRODUCTS where 1 = 2";

                SqlConnection sqlConn = new SqlConnection(connectionString);
                sqlConn.Open();
                SqlDataAdapter    daProducts = new SqlDataAdapter(sqlQuery, connectionString);
                SqlCommandBuilder cbFields   = new SqlCommandBuilder(daProducts);
                #endregion

                #region Assign product Details to SQL Table Data
                if (cbFields != null)
                {
                    DataSet dsProducts = new DataSet();
                    dsProducts.Locale = CultureInfo.InvariantCulture;

                    daProducts.FillSchema(dsProducts, SchemaType.Mapped, "Product");

                    DataRow drowProduct = dsProducts.Tables["Product"].NewRow();

                    drowProduct["COMPANY_ID"]          = DropDownListProductCompany.SelectedValue;
                    drowProduct["PRDCT_NAME"]          = productName;
                    drowProduct["PRDCT_CODE"]          = TextBoxProductCode.Text;
                    drowProduct["PRDCT_FAMILY"]        = TextBoxProductFamily.Text;
                    drowProduct["PRDCT_VERSION"]       = TextBoxProductVersion.Text;
                    drowProduct["PRDCT_BUILD"]         = TextBoxProductBuild.Text;
                    drowProduct["PRDCT_ACESSID"]       = WebLibrary.GetHashCode(saltString[0] + TextBoxProductCode.Text);;
                    drowProduct["PRDCT_ACESSPASSWORD"] = WebLibrary.GetHashCode(TextBoxProductCode.Text + saltString[0]);

                    #region Get the data from selected Product Logo file
                    try
                    {
                        if (FileUploadProductLogo.HasFile)
                        {
                            byte[] productLogo = null;
                            // Get the configured Logo height and width from SQL Table: M_CONFIG
                            int logoHeight = int.Parse(DataProvider.GetDBConfigValue("Product Logo Height"), CultureInfo.InvariantCulture);
                            int logoWidth  = int.Parse(DataProvider.GetDBConfigValue("Product Logo Width"), CultureInfo.InvariantCulture);;

                            productLogo = FileUploadProductLogo.FileBytes;
                            Bitmap productLogoBitmap = (Bitmap)Bitmap.FromStream(new MemoryStream(productLogo));
                            bool   modifyLogo        = false;
                            if (productLogoBitmap.Height > logoHeight)
                            {
                                modifyLogo = true;
                            }
                            else
                            {
                                logoHeight = productLogoBitmap.Height;
                            }
                            if (productLogoBitmap.Width > logoWidth)
                            {
                                modifyLogo = true;
                            }
                            else
                            {
                                logoWidth = productLogoBitmap.Width;
                            }

                            if (modifyLogo)
                            {
                                Bitmap       modifiedProductLogo = new Bitmap(productLogoBitmap, new Size(logoWidth, logoHeight));
                                MemoryStream ms = new MemoryStream();
                                modifiedProductLogo.Save(ms, ImageFormat.Gif);
                                byte[] bitmapData = ms.ToArray();
                                drowProduct["PRDCT_LOGO"] = bitmapData;
                            }
                            else
                            {
                                drowProduct["PRDCT_LOGO"] = FileUploadProductLogo.FileBytes;
                            }
                        }
                    }
                    catch (InvalidCastException)
                    {
                        LabelError.Text = Resources.FailureMessages.InvalidProductLogoFile;
                        return;
                    }
                    catch (ArgumentException)
                    {
                        LabelError.Text = Resources.FailureMessages.InvalidProductLogoFile;
                        return;
                    }
                    #endregion

                    drowProduct["REC_USER"] = Session["UserSystemID"].ToString();

                    drowProduct["REC_ACTIVE"] = CheckBoxProductActive.Checked;
                    drowProduct["REC_DATE"]   = DateTime.Now;
                    dsProducts.Tables["Product"].Rows.Add(drowProduct);
                    daProducts.Update(dsProducts, "Product");
                    sqlConn.Close();
                }
                #endregion

                #region Redirect to Products Page
                Response.Redirect("Products.aspx?ActionStatus=Success&Mode=A");
                #endregion

                #endregion
            }
        }