public void PartialyUpdateCampusDatabase(DataToConvert dataToConvert)
        {
            var Campus = new BaseCore(ConnectionStringManger.CampusBd,
                                      String.Format(SQLFileProvider.SelectRangeFromCampusTable, dataToConvert.TableName, string.Join(",", dataToConvert.CampusRows)));
            var Vkd = new BaseCore(ConnectionStringManger.VkdBd,
                                   String.Format(SQLFileProvider.SelectRangeFromViewVKD, dataToConvert.ViewName, string.Join(",", dataToConvert.VkdRows)));

            UpdateDatabase(Campus, Vkd);
        }
Ejemplo n.º 2
0
        // POST: https://localhost:44308/api/QR/GetQRByteArray
        public byte[] GetQRByteArray([FromBody] DataToConvert dataToConvert)
        {
            QRCodeGenerator qrGenerator    = new QRCodeGenerator();
            QRCodeData      qrCodeData     = qrGenerator.CreateQrCode(dataToConvert.Value, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode         = new QRCode(qrCodeData);
            Bitmap          qrCodeAsBitmap = qrCode.GetGraphic(20);

            return(BitmapToBytes(qrCodeAsBitmap));
        }
Ejemplo n.º 3
0
        public void ExtractDataToConvertTrim()
        {
            StreamReader streamReader = MockStreamReaderService.MockContentFile(" EUR   ;550   ; JPY ");

            DataToConvert dataToConvert = (DataToConvert)_privateType.InvokeStatic("ExtractDataToConvert", streamReader);

            Assert.AreEqual(dataToConvert.D1, "EUR");
            Assert.AreEqual(dataToConvert.M, (uint)550);
            Assert.AreEqual(dataToConvert.D2, "JPY");
        }
Ejemplo n.º 4
0
 public ActionResult ValToRub(DataToConvert dataInput)
 {
     try
     {
         ViewBag.result       = (dataInput.SummInVal * GetCourse(dataInput.Currency)).ToString();
         ViewBag.currencyList = DataToConvert.SelectList;
         ViewBag.currency     = "RUB";
         return(View("Result", dataInput));
     }
     catch
     {
         return(RedirectToAction("Index"));
     }
 }
        /// <summary>
        /// Browse the vertices of the shortest path for convert value
        /// </summary>
        /// <param name="path">Shortest path</param>
        /// <param name="dataToConvert">Data to convert</param>
        /// <returns>Converted value</returns>

        private static uint GetConvertedValue(Path path, DataToConvert dataToConvert)
        {
            // Get amount to convert

            decimal amount = dataToConvert.M;

            // Browse all step of the shortest path

            foreach (WayStep way in path.Way.AsEnumerable().Reverse())
            {
                // If the direction is reversed

                bool isReverse = way.IsReverse;

                // Get the start and the end vertex currencies

                string startCurrency = way.Step.VertexStart.Currency;
                string endCurrency   = way.Step.VertexEnd.Currency;

                // Get the rate of the exchange rate

                decimal rate = Math.Round(way.Step.T, 4);

                // Calculates the multiplier

                decimal multiplier = isReverse ? Math.Round(1 / way.Step.T, 4) : rate;

                // Logs

                if (isReverse)
                {
                    Console.Write(endCurrency + " --> " + startCurrency + " : " + amount + " * (1/" + rate + ") = ");
                }
                else
                {
                    Console.Write(startCurrency + " --> " + endCurrency + " : " + amount + " * " + rate + " = ");
                }

                // Calculates the new amount

                amount *= multiplier;
                amount  = Math.Round(amount, 4);

                Console.WriteLine(amount);
            }

            // Returns the amount converted

            return(decimal.ToUInt32(Math.Round(amount)));
        }
Ejemplo n.º 6
0
 public JsonResult EmployeeAdd(DataToConvert selectedToConvert)
 {
     try
     {
         maindirectory.PartialyUpdateCampusDatabase(selectedToConvert);
     }
     catch (Exception ex)
     {
         NLogCore.LogAplicationError(ex.Message);
         NLogCore.LogAplicationError(ex.StackTrace);
         Response.StatusCode = 500;
         return(Json(new { error = ex.Message }, JsonRequestBehavior.AllowGet));
     }
     return(Json("Імпорт даних завершен успішно", JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Extract data from file
        /// </summary>
        /// <param name="path">File path</param>
        /// <returns>Data form data file</returns>

        public static Data ExtractData(string path)
        {
            // Get file

            StreamReader file = new StreamReader(path);

            // Get data to convert

            DataToConvert dataToConvert = ExtractDataToConvert(file);

            // Get exchange rates

            ExchangeRate[] exchangeRates = ExtractExchangeRates(file);

            // Close file reading

            file.Close();

            // Return data from file

            return(new Data(dataToConvert, exchangeRates));
        }
        /// <summary>
        /// Apply dijkstra algorithm for get the shortest path from the initial currency to the target currency
        /// </summary>
        /// <param name="vertices">All currencies</param>
        /// <param name="dataToConvert">Data to convert</param>
        /// <returns>Shortest path from the initial currency to the target currency</returns>

        private static Path GetShortestConvertPath(List <Vertex> vertices, DataToConvert dataToConvert)
        {
            // Store distance from the initial vertex of all vertices

            Dictionary <string, Path> paths = new Dictionary <string, Path>();

            // Store if vertices are visited or not

            Dictionary <string, bool> marks = new Dictionary <string, bool>();

            // Initialize all vertex as unmarked and infinite distance value

            foreach (Vertex vertex in vertices)
            {
                paths.Add(vertex.Currency, new Path(vertex.Currency));
                marks.Add(vertex.Currency, false);
            }

            // Initialize the initial currency distance to 0

            paths[dataToConvert.D1].Dist = 0;

            // Initialize a stop condition if no vertex with minimal distance was found

            bool isFound = false;

            // Browse all vertices

            for (uint i = 0; i < vertices.Count && !isFound; i++)
            {
                // Get the vertex with the minimal distance and unmarked

                Vertex vertexMin = GetMinDist(vertices, paths, marks);

                // If the target currency was found stop browsing

                if (vertexMin.Currency.Equals(dataToConvert.D2))
                {
                    isFound = true;
                    break;
                }

                // Marks the currency

                marks[vertexMin.Currency] = true;

                // Get the path of the minimum distance vertex

                paths.TryGetValue(vertexMin.Currency, out Path path);

                // Browse neighbours of the minimun distance vertex

                foreach (Edge edge in vertexMin.Edges)
                {
                    // Get a neighbour of the minimum distance vertex

                    bool   isReverse = edge.VertexEnd.Equals(vertexMin);
                    Vertex neighbour = isReverse ? edge.VertexStart : edge.VertexEnd;

                    // Get path and if he's marked

                    marks.TryGetValue(neighbour.Currency, out bool isMarked);
                    paths.TryGetValue(neighbour.Currency, out Path pathNeighbour);

                    // Add step on the path of the neighbour only if is unmarked and the minimun vertex path distance is lower than the path of the neighbour path distance

                    if (!isMarked && path.Dist < pathNeighbour.Dist)
                    {
                        pathNeighbour.AddStep(edge, isReverse, path);
                    }
                }
            }

            // If the target vertex is not found

            if (!isFound)
            {
                throw new AlgorithmException("Unreached currency : " + dataToConvert.D2);
            }

            return(paths[dataToConvert.D2]);
        }