示例#1
0
        public async static Task Main()
        {
            //    MapDAO mdao = new MapDAO(Constants.MapSQLConnection);
            //    LogDAO ldao = new LogDAO(Constants.NOSQLConnection);
            //    StoreDAO sdao = new StoreDAO(Constants.SQLConnection);
            //    AnonymousUserDAO adao = new AnonymousUserDAO(Constants.SQLConnection);
            //    UploadDAO updao = new UploadDAO(Constants.SQLConnection);
            //    UserDAO udao = new UserDAO(Constants.SQLConnection);

            //    MaskingService mservice = new MaskingService(mdao);

            //    DataStoreLoggingService dsls = new DataStoreLoggingService(ldao, mservice);
            //    FlatFileLoggingService ffls = new FlatFileLoggingService(mservice);

            //    LoggingManager lmanager = new LoggingManager(ffls, dsls);
            //    GoogleImageAnalysisService gias = new GoogleImageAnalysisService();
            //    StoreService sservice = new StoreService(sdao);
            //    UploadService uservice = new UploadService(updao);
            //    UserManagementService umanage = new UserManagementService(udao, adao, dsls, ffls, mservice);

            //    UploadManager manager = new UploadManager(lmanager, gias, sservice, uservice, umanage);

            //    Bitmap bmp = new Bitmap(@"C:\Users\Eli\Desktop\Test\CVS\IMG_20200420_185009.jpg");
            //    byte[] byteArray = File.ReadAllBytes(@"C:\Users\Eli\Desktop\Test\CVS\IMG_20200420_185009.jpg");


            // DIRECTIONS: comment out the admin check in this method to create the admin

            //await umanage.CreateUserAsync(false, new UserRecord("System", "testname", "*****@*****.**", "9498675309", "password", 0, Constants.AdminUserType, "salt", Constants.NoValueLong, "090909", 0, 0, 0, 0, 0)).ConfigureAwait(false);

            //============================================================================

            //await gias.AnalyzeAsync(Image.FromFile(@"C:\Users\Eli\Desktop\Test\CVS\IMG_20200420_185009.jpg"), Constants.ExogredientCategories).ConfigureAwait(false);


            //UploadPost post = new UploadPost(byteArray, "packaged/bottled products", "thesmokinggun42", "172.88.196.101", DateTime.Now, "Nutter Butter", "deez nutz", 5, 4.20, "item");



            var    userdao     = new UserDAO(Constants.SQLConnection);
            var    anonUserdao = new AnonymousUserDAO(Constants.SQLConnection);
            LogDAO _logDAO     = new LogDAO(Constants.NOSQLConnection);
            MapDAO _mapDAO     = new MapDAO(Constants.MapSQLConnection);

            MaskingService _maskingService = new MaskingService(_mapDAO);

            DataStoreLoggingService _dsLoggingService = new DataStoreLoggingService(_logDAO, _maskingService);
            FlatFileLoggingService  _ffLoggingService = new FlatFileLoggingService(_maskingService);

            var usrmngser = new UserManagementService(userdao, anonUserdao, _dsLoggingService, _ffLoggingService, _maskingService);


            usrmngser.CreateUserAsync(false, new UserRecord("System", "sys", Constants.SystemAdminEmailAddress, "5625555555", "123123", 0, "Admin", "12345678", 0, "0", 0, 0, 0, 0, 0));
        }
示例#2
0
        public static async Task Main(string[] args)
        {
            var mapDAO      = new MapDAO(Constants.MapSQLConnection);
            var logDAO      = new LogDAO(Constants.NOSQLConnection);
            var userDAO     = new UserDAO(Constants.SQLConnection);
            var uploadDAO   = new UploadDAO(Constants.SQLConnection);
            var snapshotDAO = new SnapshotDAO(Constants.NOSQLConnection);

            var maskService      = new MaskingService(mapDAO);
            var ffLoggingService = new FlatFileLoggingService(maskService);

            var dsLoggingService = new DataStoreLoggingService(logDAO, maskService);
            var snapshotService  = new SnapshotService(logDAO, userDAO, uploadDAO, snapshotDAO);

            var loggingManager    = new LoggingManager(ffLoggingService, dsLoggingService);
            var createSnapManager = new CreateSnapshotManager(loggingManager, snapshotService);

            // Script called at the beginning of every month.
            // Get the year and month according the Utc time.
            var year  = DateTime.UtcNow.Year;
            var month = DateTime.UtcNow.Month;

            // We want to create a snapshot of the previous month so we have to subtract 1 to the month if it is not 1 (January).
            // If it is 1, then change month to 12, and subtract 1 from year instead.
            if (month == 1)
            {
                year  = year - 1;
                month = 12;
            }
            else
            {
                month = month - 1;
            }

            var tries = 0;
            var createSnapshotSuccess = false;

            // If the createsnapshot was a failure, there are 3 extra tries. It can stop if it was successful though.
            while (!createSnapshotSuccess && tries < 4)
            {
                createSnapshotSuccess = await createSnapManager.CreateSnapshotAsync(tries, year, month).ConfigureAwait(false);

                if (!createSnapshotSuccess)
                {
                    tries++;
                }
            }
        }
        public void Log50Times_Pass()
        {
            //Arrange
            bool   result = false;
            string dir    = _endDir;
            string op     = "Authorization";
            string msg    = "Invalid Access Error";
            int    tries  = _tries;
            //Act
            FlatFileLoggingService l = null;

            try
            {
                l = new FlatFileLoggingService(dir, tries);
            }
            catch (Exception)
            {
                result = false;
            }
            for (int i = 0; i < 50; i++)
            {
                if (i == 17)
                {
                    op  = "Authentication";
                    msg = "Invalid Claim Error";
                }
                if (i == 32)
                {
                    op  = "Registration";
                    msg = "Data Store Error";
                }
                string id = i.ToString();
                try
                {
                    result = l.Log(op, msg, id);
                    Thread.Sleep(60);
                }
                catch (Exception)
                {
                    result = false;
                }
            }
            //Assert
            Assert.IsTrue(result);
        }
        public void CreateLoggingInstance_Pass()
        {
            //Arrange
            bool   result = true;
            string dir    = _endDir;
            int    tries  = _tries;

            //Act
            try
            {
                var l = new FlatFileLoggingService(dir, tries);
            }
            catch (Exception)
            {
                result = false;
            }
            //Assert
            Assert.IsTrue(result);
        }
示例#5
0
      public async Task<IActionResult> SearchIngredientAtStoreAsync(string ingredientName, int storeID, int pagination, string username, string ipAddress)
        {

            // New up DAL
            UploadDAO uploadDAO = new UploadDAO(Constants.SQLConnection);
            var mapDao = new MapDAO(Constants.MapSQLConnection);
            var logDao = new LogDAO(Constants.SQLConnection);

            // New up Service
            var uploadService = new UploadService(uploadDAO);
            var maskingService = new MaskingService(mapDao);
            var ffLoggingService = new FlatFileLoggingService(maskingService);
            var dsLoggingService = new DataStoreLoggingService(logDao, maskingService);

            // New up Managers
            var loggingManager = new LoggingManager(ffLoggingService, dsLoggingService);
            var ingredientManager = new IngredientManager( uploadService, loggingManager);

            return Ok(await ingredientManager.GetUploadsByIngredientNameandStoreId(ingredientName, storeID, pagination, Constants.InitialFailureCount, username, ipAddress).ConfigureAwait(false));
        }
        public void LogInvalidTries_Fail()
        {
            //Arrange
            bool   result = true;
            string dir    = _endDir;
            int    tries  = 0;

            //Act
            try
            {
                var l = new FlatFileLoggingService(dir, tries);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = false;
            }
            //Assert
            Assert.IsTrue(!result);
        }
        public async Task <bool> DownvoteIngredient(int uploadId, string username, string ipAddress)
        {
            // New up DAL
            UploadDAO uploadDAO        = new UploadDAO(Constants.SQLConnection);
            var       mapDao           = new MapDAO(Constants.MapSQLConnection);
            var       logDao           = new LogDAO(Constants.SQLConnection);
            var       userDao          = new UserDAO(Constants.SQLConnection);
            var       anonymousUserDao = new AnonymousUserDAO(Constants.SQLConnection);

            // New up Service
            var uploadService         = new UploadService(uploadDAO);
            var maskingService        = new MaskingService(mapDao);
            var ffLoggingService      = new FlatFileLoggingService(maskingService);
            var dsLoggingService      = new DataStoreLoggingService(logDao, maskingService);
            var userManagementService = new UserManagementService(userDao, anonymousUserDao, dsLoggingService, ffLoggingService, maskingService);

            // New up Managers
            var loggingManager    = new LoggingManager(ffLoggingService, dsLoggingService);
            var ingredientManager = new IngredientManager(uploadService, loggingManager, userManagementService);

            return(await ingredientManager.EditDownvotesonUpload(Constants.PositiveVote, uploadId, Constants.InitialFailureCount, username, ipAddress));
        }
        public void LogValidDirectory_Pass()
        {
            //Arrange
            bool   result;
            string dir   = _endDir;
            string op    = "op";
            string msg   = "";
            string id    = "id";
            int    tries = _tries;

            //Act
            try
            {
                var l = new FlatFileLoggingService(dir, tries);
                result = l.Log(op, msg, id);
            }
            catch (Exception)
            {
                result = false;
            }
            //Assert
            Assert.IsTrue(result);
        }
        public void LogToCSV_Pass()
        {
            //Arrange
            bool   result;
            string dir   = _endDir;
            string op    = "Registration";
            string msg   = "Data Store Error";
            string id    = "0001";
            int    tries = _tries;

            //Act
            try
            {
                var l = new FlatFileLoggingService(dir, tries);
                result = l.Log(op, msg, id);
            }
            catch (Exception)
            {
                result = false;
            }
            //Assert
            Assert.IsTrue(result);
        }
        public async Task <IActionResult> GetIngredientViewPaginationSize(string ingredientName, int storeId, string username, string ipAddress)
        {
            // New up DAL
            UploadDAO uploadDAO        = new UploadDAO(Constants.SQLConnection);
            var       mapDao           = new MapDAO(Constants.MapSQLConnection);
            var       logDao           = new LogDAO(Constants.SQLConnection);
            var       userDao          = new UserDAO(Constants.SQLConnection);
            var       anonymousUserDao = new AnonymousUserDAO(Constants.SQLConnection);

            // New up Service
            var uploadService         = new UploadService(uploadDAO);
            var maskingService        = new MaskingService(mapDao);
            var ffLoggingService      = new FlatFileLoggingService(maskingService);
            var dsLoggingService      = new DataStoreLoggingService(logDao, maskingService);
            var userManagementService = new UserManagementService(userDao, anonymousUserDao, dsLoggingService, ffLoggingService, maskingService);

            // New up Managers
            var loggingManager    = new LoggingManager(ffLoggingService, dsLoggingService);
            var ingredientManager = new IngredientManager(uploadService, loggingManager, userManagementService);

            try
            {
                // Return status code of 200 as well as the content.
                return(Ok(await ingredientManager.GetIngredientViewPaginationSize(ingredientName, storeId, Constants.InitialFailureCount, username, ipAddress).ConfigureAwait(false)));
            }
            catch (ArgumentException ae)
            {
                // Return an 404 error when the resource does not exists.
                return(NotFound(ae.Message));
            }
            catch
            {
                // Return generic server error for all other exceptions.
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public void LogInvalidDirectory_Pass()
        {
            //Arrange
            bool   result;
            string dir   = "logthis";
            string op    = "op";
            string msg   = "";
            string id    = "id";
            int    tries = 3;

            //Act
            try
            {
                var l = new FlatFileLoggingService(dir, tries);
                result = l.Log(op, msg, id);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = false;
            }
            //Assert
            Assert.IsTrue(!result);
        }
示例#12
0
 public LoggingManager(FlatFileLoggingService ffLoggingService, DataStoreLoggingService dsLoggingService)
 {
     _ffLoggingService = ffLoggingService;
     _dsLoggingService = dsLoggingService;
 }