コード例 #1
0
        public void WriteToFileTest()
        {
            //-- Arrange
            var changedItems = new List <ILoggable>();
            var customer     = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName    = "mahmoud",
                LastName     = "youssef",
                AddressList  = null
            };

            changedItems.Add(customer);

            var product = new Product(2)
            {
                ProductName        = "Rake",
                ProductDescription = "Garden cake with steel head",
                CurrentPrice       = 6M
            };

            changedItems.Add(product);

            //-- Act
            LogginService.WriteToFile(changedItems);

            //-- Assert
            //-- Nothing here to Assert
        }
コード例 #2
0
        public void WriteToFileTest()
        {
            //Arrange
            var changeItems = new List <ILoggable>();

            var customer = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName    = "Paul",
                LastName     = "Laspapos",
                AddressList  = null
            };

            changeItems.Add(customer);

            var product = new Product(2)
            {
                ProductName  = "Water",
                Description  = "Sparkling water",
                CurrentPrice = 2.20M
            };

            changeItems.Add(product);

            //Act
            LogginService.WriteToFile(changeItems);

            //Asset
            //nothing
        }
コード例 #3
0
        public void WriteToFileTest()
        {
            // Arrange
            List <ILoggable> changeItems = new List <ILoggable>();

            Customer customer = new Customer(1)
            {
                EmailAddress  = "*****@*****.**"
                , FirstName   = "Colin"
                , LastName    = "Kish"
                , AddressList = null
            };

            changeItems.Add(customer);

            var product = new Product(1)
            {
                ProductName          = "Bike"
                , ProductDescription = "A Nice Bike"
                , CurentPrice        = 1.21M
            };

            changeItems.Add(product);

            // Act
            LogginService.WriteToFile(changeItems);

            // Assert
            // nothing here to assert
        }
コード例 #4
0
        public async Task <HealthRequest> AddOrUpdateRequest(HealthRequest healthRequest)
        {
            try
            {
                //If there is no id assigned to the blog
                if (healthRequest.Id == Guid.Empty)
                {
                    //Then we need to add a new record
                    DbContext.HealthRequests.Add(healthRequest);
                }
                else
                {
                    //Get the blokg from the db
                    var healthrequestDb = await DbContext.HealthRequests.SingleOrDefaultAsync(item => item.Id == healthRequest.Id);

                    //Update the wanted values
                    healthrequestDb.Subject = healthRequest.Subject;
                    healthrequestDb.Content = healthRequest.Content;
                    healthrequestDb.Note    = healthRequest.Note;

                    healthRequest = healthrequestDb;
                    //Mark it as modified
                    DbContext.Entry(healthrequestDb).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(healthRequest);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #5
0
        public void WriteToFileTest()
        {
            //--Arrange
            var changedItems = new List <ILoggable>();
            var customer     = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName    = "Darko",
                LastName     = "Gelevski",
                AddressList  = null
            };

            changedItems.Add(customer);

            var product = new Product(2)
            {
                ProductName        = "PS4",
                ProductDescription = "Gaming Console with the best collection of games",
                CurrentPrice       = 22000M
            };

            changedItems.Add(product);

            //--Act
            LogginService.WriteToFile(changedItems);

            //--Assert
            //--Nothing here to assert
        }
コード例 #6
0
        public void WriteToFile()
        {
            //Arrange
            var changedItems = new List <ILoggable>();

            var customer = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName    = "Frodo",
                LastName     = "Baggins",
                AddressList  = null
            };

            changedItems.Add(customer);

            var product = new Product(2)
            {
                ProductName        = "Rake",
                ProductDescription = "Garden Rake with Steel Head",
                CurrentPrice       = 6M
            };

            changedItems.Add(product);
            //Act
            LogginService.WriteToFile(changedItems);

            //Assert
        }
コード例 #7
0
        public void WriteToFileTest()
        {
            var changedItems = new List <ILoggable>();

            var customer = new CustomerDetails2(1)
            {
                EmailAdrress = "*****@*****.**",
                FirstName    = "Bobo ",
                LastName     = "Smrad",
                AddressList  = null
            };

            changedItems.Add(customer);

            var product = new Product(2)
            {
                ProductName        = "Lightsaber",
                ProductDescription = "An elegant weapon for a more civilized age...",
                CurrentPrice       = 66
            };

            changedItems.Add(product);

            LogginService.WriteToFile(changedItems);
        }
コード例 #8
0
 public async Task <ExternalLink> GetLink(Guid id)
 {
     try
     {
         return(await DbContext.ExternalLinks.SingleOrDefaultAsync(item => item.Id == id));
     }
     catch (Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
 public async Task <IEnumerable <Tennis> > GetTennisRecords()
 {
     try
     {
         return(await DbContext.Tennis.ToListAsync());
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
コード例 #10
0
 public async Task <IEnumerable <HeartDisease> > GetHeartDiseaseRecords()
 {
     try
     {
         return(await DbContext.HeartDiseases.ToListAsync());
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
コード例 #11
0
        public async Task <HealthUser> AddOrUpdateUser(HealthUser user, string roleName)
        {
            try
            {
                //Get the role
                var role = await DbContext.HealthRoles.SingleOrDefaultAsync(item => item.Name == roleName);

                //Check if the role is vaild and if the user is new
                if (user.Id == Guid.Empty)
                {
                    //Assign the role
                    user.Role = role;
                    //Hash the password
                    user.Password = user.Password.GetMD5Hash();
                    //change the email to lower case
                    user.Email = user.Email.ToLower();
                    //Attach the enitity to the context
                    DbContext.Attach(user);
                    //Mark it as added
                    DbContext.Entry(user).State = EntityState.Added;
                }
                else
                {
                    //Get the user from db
                    var userDb = await DbContext.HealthUsers.SingleOrDefaultAsync(item => item.Id == user.Id);

                    //Update the values
                    userDb.Password       = string.IsNullOrEmpty(user.Password) ? userDb.Password : user.Password.GetMD5Hash();
                    userDb.PhoneNumber    = user.PhoneNumber;
                    userDb.Gender         = user.Gender;
                    userDb.DOB            = user.DOB;
                    userDb.MedicalHistory = user.MedicalHistory;
                    userDb.Note           = user.Note;
                    //Check if the role was changed
                    if (role != null)
                    {
                        userDb.Role = role;
                    }
                    //Markt the entity as modified
                    DbContext.Entry(userDb).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(user);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #12
0
        public async Task <HealthRequest> GetHealthRequest(Guid requestId)
        {
            try
            {
                return(await DbContext.HealthRequests.Include(item => item.Replies).SingleOrDefaultAsync(item => item.Id == requestId));
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }

            return(null);
        }
コード例 #13
0
        public async Task <HealthUser> GetUser(Guid id)
        {
            try
            {
                return(await DbContext.HealthUsers
                       .SingleOrDefaultAsync(item => item.Id == id));
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }

            return(null);
        }
コード例 #14
0
 public async Task <Course> GetCourse(string name)
 {
     try
     {
         return(await DbContext.Courses
                .Include(item => item.Links)
                .Include(item => item.Sessions).ThenInclude(item => item.Links)
                .Include(item => item.Homeworks).ThenInclude(item => item.Links)
                .SingleOrDefaultAsync(item => item.ShortName.ToLower() == name.ToLower()));
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
コード例 #15
0
        public async Task <IEnumerable <HealthRequest> > GetHealthRequests(int start, int count, Guid userId, bool isAdmin = false)
        {
            try
            {
                return(await DbContext.HealthRequests.Include(item => item.Replies).Where(item => isAdmin ? true : item.HealthUserId == userId)
                       .OrderBy(item => item.ReplyCount).ThenByDescending(item => item.CreationDate)
                       .Skip(start)
                       .Take(count)
                       .ToListAsync());
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }

            return(null);
        }
コード例 #16
0
        public async Task <Blog> AddOrUpdateBlog(Blog blog)
        {
            try
            {
                //If there is no id assigned to the blog
                if (blog.Id == Guid.Empty)
                {
                    //Then we need to add a new record
                    DbContext.Blogs.Add(blog);
                }
                else
                {
                    //Get the blokg from the db
                    var blogDb = await DbContext.Blogs.SingleOrDefaultAsync(item => item.Id == blog.Id);

                    //Update the wanted values
                    blogDb.Title   = blog.Title;
                    blogDb.Content = blog.Content;
                    //Only update the image if new value provided
                    if (!string.IsNullOrEmpty(blog.ThumbnailMimeType))
                    {
                        blogDb.ThumbnailBase64   = blog.ThumbnailBase64;
                        blogDb.ThumbnailMimeType = blog.ThumbnailMimeType;
                    }
                    blogDb.Note           = blog.Note;
                    blogDb.LastEditUserId = blog.LastEditUserId;
                    blogDb.PreviewContent = blog.PreviewContent;

                    blog = blogDb;
                    //Mark it as modified
                    DbContext.Entry(blogDb).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(blog);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #17
0
        public bool InitailizeDatabase()
        {
            try
            {
                if (DbContext.Database.EnsureCreated())
                {
                    #region Seed data here

                    #endregion

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(false);
        }
コード例 #18
0
        public async Task <Blog> GetBlog(Guid id, bool addVisit = true)
        {
            try
            {
                var blog = await DbContext.Blogs.SingleOrDefaultAsync(item => item.Id == id);

                if (addVisit)
                {
                    blog.VisitCout++;
                    await DbContext.SaveChangesAsync();
                }

                return(blog);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #19
0
        public void WriteToFileTest()
        {
            var changedItems = new List <ILoggable>();

            var customer = new Customer(1);

            customer.FirstName = "Harry";
            customer.LastName  = "Potter";

            var product = new Product(2);

            product.ProductName        = "Cerveja Amanteigada";
            product.ProductDescription = "A famosa Cerveja Amanteigada";
            product.CurrentPrice       = 30.00M;

            changedItems.Add(product);
            changedItems.Add(customer);

            LogginService.WriteToFile(changedItems);
        }
コード例 #20
0
        public async Task <HealthRequestReply> AddOrUpdateRequestReply(HealthRequestReply healthRequestReply)
        {
            try
            {
                //If there is no id assigned to the reply
                if (healthRequestReply.Id == Guid.Empty)
                {
                    //Then we need to add a new record
                    DbContext.HealthRequestReplies.Add(healthRequestReply);

                    //Get the request
                    var healthRequest = await DbContext.HealthRequests.SingleOrDefaultAsync(item => item.Id == healthRequestReply.RequestId);

                    healthRequest.ReplyCount++;

                    DbContext.Entry(healthRequest).State = EntityState.Modified;
                }
                else
                {
                    //Get the blokg from the db
                    var reply = await DbContext.HealthRequestReplies.SingleOrDefaultAsync(item => item.Id == healthRequestReply.Id);

                    //Update the wanted values
                    reply.Content = healthRequestReply.Content;
                    reply.Note    = healthRequestReply.Note;

                    healthRequestReply = reply;
                    //Mark it as modified
                    DbContext.Entry(reply).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(healthRequestReply);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #21
0
        public async Task <bool> DeleteBlog(Guid id)
        {
            try
            {
                //Get the blog
                var blogDb = await DbContext.Blogs.SingleOrDefaultAsync(item => item.Id == id);

                if (blogDb != null)
                {
                    //Mark it as deleted
                    DbContext.Entry(blogDb).State = EntityState.Deleted;
                    //Delete the record
                    await DbContext.SaveChangesAsync();
                }
                return(true);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(false);
        }
コード例 #22
0
        public Task InvokeAsync(HttpContext context)
        {
            // Start the Timer using Stopwatch
            var watch = new Stopwatch();

            watch.Start();
            context.Response.OnStarting(() =>
            {
                try
                {
                    watch.Stop();
                    var req    = context.Request;
                    var claims = context.User.Claims;
                    //Username
                    var user     = KeyCloak.GetProperty(claims, ClaimTypes.Username);
                    var app      = KeyCloak.GetProperty(claims, ClaimTypes.Client);
                    var logEntry = new SqlServerLoggingItem()
                    {
                        Username   = user,
                        Api        = "Launchpad",
                        App        = app,
                        Endpoint   = req.Path,
                        Query      = req.QueryString.Value,
                        Timing     = (int)watch.ElapsedMilliseconds,
                        StatusCode = context.Response.StatusCode
                    };
                    Task.Run(() => LogginService.InsertItem(logEntry));
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine($"Failed to log entry {ex}");
                }

                return(Task.CompletedTask);
            });

            // Call the next delegate/middleware in the pipeline
            return(_next(context));
        }
コード例 #23
0
        public async Task <IEnumerable <object> > GetDbSet(string setName)
        {
            try
            {
                switch (setName.ToLower())
                {
                case "tennis":
                    return(await DbContext.Tennis.ToListAsync());

                case "heartdisease":
                    return(await DbContext.HeartDiseases.ToListAsync());

                default:
                    break;
                }
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #24
0
 public async Task <IEnumerable <Blog> > GetBlogs(int start, int count, bool loadImages)
 {
     try
     {
         return(await DbContext.Blogs.Select(blog => new Blog
         {
             Id = blog.Id,
             AutherId = blog.AutherId,
             PreviewContent = blog.PreviewContent,
             Title = blog.Title,
             CreationDate = blog.CreationDate,
             LastUpdatedDate = blog.LastUpdatedDate,
             ThumbnailBase64 = loadImages ? blog.ThumbnailBase64 : string.IsNullOrEmpty(blog.ThumbnailBase64) ? string.Empty : "Data",
             ThumbnailMimeType = loadImages ? blog.ThumbnailMimeType : "",
             VisitCout = blog.VisitCout
         }).OrderByDescending(item => item.VisitCout).Skip(start).Take(count).ToListAsync());
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
コード例 #25
0
        public void WriteToFileTest()
        {
            var changedItems = new List <ILoggable>();

            var customer = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName    = "Mario",
                LastName     = "Rendon",
                AddressList  = null
            };

            changedItems.Add(customer);

            var product = new Product(2)
            {
                ProductName        = "Rake",
                ProductDescription = "Garden Rake with steel head",
                CurrentPrice       = 6M
            };

            changedItems.Add(product);
            LogginService.WriteToFile(changedItems);
        }
コード例 #26
0
 public HomeController()
 {
     _logginService = new LogginService();
 }
コード例 #27
0
        static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddCommandLine(args)
                         .Build();

            Console.WriteLine("Usage --port xxxx | --ip x.x.x.x | --mongoport");

            var portString      = config.GetSection("port").Value;
            var ipString        = config.GetSection("ip").Value;
            var mongoPortString = config.GetSection("mongoport").Value;

            var port      = string.IsNullOrEmpty(portString) ? 50055 : int.Parse(portString);
            var ip        = string.IsNullOrEmpty(ipString) ? IPAddress.Any : IPAddress.Parse(ipString);
            var mongoPort = string.IsNullOrEmpty(mongoPortString) ? 27017 : int.Parse(mongoPortString);

            Console.WriteLine($"Running rpc on {ip}:{port}");

            var mongoClient = new MongoLoggingService("DraffleBackend", $"mongodb://localhost:{mongoPort}");

            Thread  mongoServerThread = null;
            Process mongoProcess      = null;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                if (mongoClient.IsOnline())
                {
                    Console.WriteLine($"Mongo is already running on port {mongoPort}, will use that instance!");
                }
                else
                {
                    "mkdir -p ~/mongodb/data/db".BashSimple();
                    mongoServerThread =
                        new Thread(() => $"mongod --dbpath ~/mongodb/data/db/ --port {mongoPort}".GetProcessFromBash(out mongoProcess));
                    mongoServerThread.Start();
                    Console.WriteLine($"Mongod server started on port {mongoPort}");
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("ERROR: You are not running on a Linux OS");
                if (!mongoClient.IsOnline())
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Mongo server is not runnin!");
                    Console.WriteLine("Shutting down!");
                    return;
                }

                Console.WriteLine($"Mongo server running on port {mongoPort}");
            }

            var logginServiceServer = new LogginServiceServer(new MongoLoggingService("Draffle", $"mongodb://localhost:{mongoPort}"));

            var server = new Server
            {
                Services = { LogginService.BindService(logginServiceServer) },
                Ports    = { new ServerPort(ip.ToString(), port, ServerCredentials.Insecure) }
            };

            server.Start();

            do
            {
                Console.WriteLine("Type 'Exit' to exit");
            } while (Console.ReadLine().ToLower() != "exit");

            server.ShutdownAsync().Wait();
            Console.WriteLine("Rpc server shutdown!");

            if (mongoServerThread != null)
            {
                mongoProcess.Kill();
                Console.WriteLine("Mongo server was killed!");
                mongoServerThread.Join();
            }
        }