コード例 #1
0
        public void ConvertGbToBytes()
        {
            var valueGB = 5.0;
            var result  = ConvertToBytes.ConvertNumberToBytes(valueGB, "GB");

            Assert.AreEqual((valueGB * 1024 * 1024 * 1024), result);
        }
コード例 #2
0
        public void ConvertBytesToBytes()
        {
            var valueB = 200.0;
            var result = ConvertToBytes.ConvertNumberToBytes(valueB, "Bytes");

            Assert.AreEqual((valueB), result);
        }
コード例 #3
0
        public void ConvertKbToBytes()
        {
            var valueKB = 2.0;
            var result  = ConvertToBytes.ConvertNumberToBytes(valueKB, "KB");

            Assert.AreEqual((valueKB * 1024), result);
        }
コード例 #4
0
        public void ConvertMbToBytes()
        {
            var valueMB = 2.0;
            var result  = ConvertToBytes.ConvertNumberToBytes(valueMB, "MB");

            Assert.AreEqual((valueMB * 1024 * 1024), result);
        }
コード例 #5
0
    public bool OpenMidiFile()
    {
        /*
         * Open stream
         * Set pointer position to 0
         * Send stream Forward
         */

        if (File.Exists(fPath))
        {
            fStream = File.OpenRead(fPath);
        }
        else
        {
            Debug.Log("File at: " + fPath + " doesn't exist.");
            openAndCopied = false;
            return(openAndCopied);
        }

        if (fStream != null)
        {
            byte[] tmp;
            fStream.Position = 0;
            tmp     = File.ReadAllBytes(fPath);
            bReaded = ConvertToBytes.CopyToByteArray(tmp, out openAndCopied);
        }

        Debug.Log("Bytes readed: " + bReaded); // Show number of bytes readed in int format
        fStream.Close();                       // Always remember to close stream
        openAndCopied = true;
        return(openAndCopied);
    }
コード例 #6
0
        public void IncorrectValueToBytes()
        {
            var valueMB = -1.0;
            var ex      = Assert.Throws <ArgumentException>(() => ConvertToBytes.ConvertNumberToBytes(valueMB, "MB"));

            Assert.That(ex.ParamName, Is.EqualTo("size"));
            Assert.That(ex.Message, Is.EqualTo("Size cannot be less than zero (Parameter 'size')"));
        }
コード例 #7
0
        private void GetDetailsProjectGutHub(HtmlDocument htmlDocument)
        {
            // Nodes that have the file or folder page url
            var files = htmlDocument.DocumentNode.SelectNodes("//*[contains(@class,'js-navigation-open link-gray-dark')]");

            foreach (HtmlNode file in files)
            {
                if (file.Attributes.Count > 0)
                {
                    // Downloading the file page to get the data from the lines of code and bytes
                    var urlFile = new Uri(@"https://github.com/" + WebUtility.HtmlDecode(file.Attributes["href"].Value)).AbsoluteUri;
                    htmlDocument = _httpClient.Load(urlFile);

                    var elementRoot        = htmlDocument.DocumentNode;
                    var detailsFileElement = elementRoot.SelectNodes("//*[contains(@class,'text-mono f6 flex-auto pr-3 flex-order-2 flex-md-order-1 mt-2 mt-md-0')]");
                    // If detailsFileElement is not null, then it means it is a file, otherwise it is a folder and
                    //it is necessary to repeat the process walking through the subfolders until you reach the files
                    if (detailsFileElement != null)
                    {
                        var detailsFile = WebUtility.HtmlDecode(detailsFileElement.Single().InnerText.Replace("\n", "").Trim());

                        var    splitDetails = detailsFile.Split("lines");
                        string codeLines    = string.Empty;
                        string bytesStr     = string.Empty;
                        // Obtain codeLines and bytes from string
                        if (splitDetails.Length > 1)
                        {
                            var lines = splitDetails[0];
                            codeLines = Regex.Match(lines, @"\d+").Value;
                            bytesStr  = splitDetails[1];
                        }
                        else
                        {
                            codeLines = "0";
                            bytesStr  = splitDetails[0];
                        }
                        splitDetails = bytesStr.Trim().Split(" ");
                        bytesStr     = splitDetails[splitDetails.Length - 2];
                        var bytesType = splitDetails.Last();

                        var bytes = ConvertToBytes.ConvertNumberToBytes(Convert.ToDouble(bytesStr, System.Globalization.CultureInfo.InvariantCulture), bytesType);

                        //Get extension file and store in dictionary of Project Info
                        var extension = file.InnerHtml.Split(".").Last();

                        Domain.Entities.ProjectInfoGitHub linesBytes;
                        if (_dicProjectInfo.TryGetValue(extension, out linesBytes))
                        {
                            linesBytes.SetBytes(linesBytes.Bytes + bytes);
                            linesBytes.SetCodeLines(linesBytes.Lines + Convert.ToInt64(codeLines));
                            _dicProjectInfo[extension] = linesBytes;
                        }
                        else
                        {
                            var projectInfoGitHub = new Domain.Entities.ProjectInfoGitHub(extension, Convert.ToInt64(codeLines), bytes);
                            _dicProjectInfo.Add(extension, projectInfoGitHub);
                        }
                    }
                    else
                    {
                        //Recursive method case the element be folder
                        GetDetailsProjectGutHub(htmlDocument);
                    }
                }
            }
        }
コード例 #8
0
        public void ConvertGBToBytes()
        {
            var result = ConvertToBytes.ConvertStringNumberToBytes(5, "GB");

            Assert.Equal((5.0 * 1024 * 1024 * 1024), result);
        }