Exemplo n.º 1
0
        /// <summary>
        /// Searches the 'copy from' location for the specified SKU, and updates a global boolean variable if there are results.
        /// </summary>
        /// <param name="sku"></param>
        public void Search(string sku)
        {
            Sku              = sku.ToUpper();
            _first           = Sku[0];
            _firstAndSecond  = Sku.Substring(0, 2);
            CopyFromLocation = Path.Combine(_locationRoot + _first + "\\" + _firstAndSecond);
            string skuSubString = Sku.Substring(0, Sku.Length);

            try
            {
                _files = Directory.GetFiles(CopyFromLocation).Where(a => a.Contains(skuSubString, StringComparison.OrdinalIgnoreCase)).ToArray();

                if (_files.Length <= 0)
                {
                    SearchTermHasResults = false;
                    string noResults = $"Search returned no results for {Sku}";
                    Console.WriteLine(noResults);
                    File.AppendAllText(LogFileLocation, noResults + Environment.NewLine);
                }
                else
                {
                    SearchTermHasResults = true;
                    if (_files.Length == 1)
                    {
                        string fileFound = $"1 file found for {Sku}. ";
                        Console.WriteLine(fileFound);
                        File.AppendAllText(LogFileLocation, fileFound);
                    }
                    else
                    {
                        string fileFound = _files.Length + $" files found for {Sku}. ";
                        Console.WriteLine(fileFound);
                        File.AppendAllText(LogFileLocation, fileFound);
                    }
                }
            }
            catch (Exception)
            {
                SearchTermHasResults = false;
                string noResults = $"Search returned no results for {Sku}";
                Console.WriteLine(noResults);
                File.AppendAllText(LogFileLocation, noResults + Environment.NewLine);
            }
        }