Beispiel #1
0
        public async void SendMessage(Guid selfGuid, Guid chatGuid, string message)
        {
            _logger.Write(LogLevel.Info, DateTime.Now + " " + chatGuid + " " + message);
            var worker = DIFactory.Resolve <IDbSystemWorker>();
            var date   = DateTime.Now;
            await worker.SaveMessage(selfGuid, chatGuid, message, date);

            var updateChatUsers = await worker.GetUserFromChat(chatGuid);

            var updateUser = _users.Where(x => updateChatUsers.Contains(x.UserGuid));

            foreach (var user in updateUser)
            {
                foreach (var callback in user.Callbacks)
                {
                    try
                    {
                        callback.MessageCallback(date, chatGuid, message, selfGuid);
                    }
                    catch (Exception e)
                    {
                        _logger.Write(LogLevel.Error, "Error callback message", e);
                    }
                }
            }
        }
Beispiel #2
0
        public static ObservableCollection <NetworkInterface> GetNetworkInterfaces()
        {
            var logger = DIFactory.Resolve <ILogger>();

            try
            {
                IPGlobalProperties      computerProperties = IPGlobalProperties.GetIPGlobalProperties();
                List <NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where(x =>
                                                                                                (x.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
                                                                                                 x.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) &&
                                                                                                x.Supports(NetworkInterfaceComponent.IPv4) &&
                                                                                                x.OperationalStatus == OperationalStatus.Up).ToList();

                logger.Write(LogLevel.Info, "Interface information for " + computerProperties.HostName + "." + computerProperties.DomainName);
                if (!nics.Any())
                {
                    logger.Write(LogLevel.Warning, "No network interfaces found.");
                    return(null);
                }

                var endpoints = new ObservableCollection <NetworkInterface>();
                foreach (NetworkInterface networkInterface in nics)
                {
                    endpoints.Add(networkInterface);
                }
                return(endpoints);
            }
            catch (Exception e)
            {
                logger.Write(LogLevel.Error, "", e);
                throw;
            }
        }
Beispiel #3
0
        public async Task <GetChatResult> GetChat(Guid chatGuid)
        {
            var worker  = DIFactory.Resolve <IDbSystemWorker>();
            var history = await worker.GetChat(chatGuid);

            return(history);
        }
        private void ManagerOnDisconnected(object sender, EventArgs e)
        {
            var manager = DIFactory.Resolve <IServiceManager>();

            manager.Disconnect((Guid)CurrentUser.Guid);
            CloseWindow?.Invoke(this, EventArgs.Empty);
        }
Beispiel #5
0
        public async Task <ResultBody> ChangePassword(Guid selfGuid, string oldPassword, string newPassword)
        {
            var dbWorker = DIFactory.Resolve <IDbSystemWorker>();
            var result   = await dbWorker.ChangePassword(selfGuid, oldPassword, newPassword);

            return(result);
        }
        private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            var serviceWorker = DIFactory.Resolve <IServiceWorker>();
            var result        = await serviceWorker.GetHotel(new GetHotelRequest());

            var st = result.Status;
        }
Beispiel #7
0
        public ViewLogViewModel(MainViewModel.ChangeScreen changeScreen)
        {
            _changeScreen = changeScreen;
            LogData       = new ViewLogModel();
            var logger = DIFactory.Resolve <ILogger>();

            logger.RaiseLogger += LoggerOnRaiseLogger;
        }
Beispiel #8
0
        // Close
        protected void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
        {
            if (DataContext is MessengerViewModel model)
            {
                var manager = DIFactory.Resolve <IServiceManager>();
                manager.Disconnect(model.CurrentUser.Guid);
            }

            SystemCommands.CloseWindow(this);
        }
Beispiel #9
0
        private void SendAuthorizationMail(Employee employee, string password)
        {
            using (MailMessage m = new MailMessage())
            {
                var fromMail     = _mail;
                var fromPassword = _password;
                m.From = new MailAddress(fromMail);
                m.To.Add(employee.Email);
                m.Subject = "Messenger Authorize";

                var    bodyPath = "SendData\\body.html";
                var    logger   = DIFactory.Resolve <ILogger>();
                string body;
                try
                {
                    body = File.ReadAllText(bodyPath);
                }
                catch (Exception e)
                {
                    logger.Write(LogLevel.Error, e.Message, e);
                    throw e;
                }
                var name = employee.GetName();
                body = body.Replace("@name", name);
                body = body.Replace("@email", employee.Email);
                body = body.Replace("@login", employee.Login);
                body = body.Replace("@password", password);

                m.Body       = body;
                m.IsBodyHtml = true;

                var            logo   = "SendData\\logo.png";
                LinkedResource inline = new LinkedResource(logo);
                inline.ContentId = Guid.NewGuid().ToString();

                body = body.Replace("sukaKartinkaEbanaya", @"cid:" + inline.ContentId + @"");
                AlternateView avHtml = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);
                avHtml.LinkedResources.Add(inline);
                m.AlternateViews.Add(avHtml);

                using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                {
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials           = new NetworkCredential(fromMail, fromPassword);
                    smtp.EnableSsl             = true;
                    smtp.Send(m);
                }
            }
        }
Beispiel #10
0
        public async Task AddEmployee(Employee employee)
        {
            var dbWorker = DIFactory.Resolve <IDbSystemWorker>();
            var password = await dbWorker.AddEmployee(employee);

            try
            {
                SendAuthorizationMail(employee, password);
            }
            catch (Exception e)
            {
                var logger = DIFactory.Resolve <ILogger>();
                logger.Write(LogLevel.Error, e.Message, e);
                await dbWorker.RemoveEmployee(employee);
            }
        }
Beispiel #11
0
        public async void UpdatePhoto(Guid userGuid, byte[] photo)
        {
            var worker = DIFactory.Resolve <IDbSystemWorker>();
            await worker.UpdatePhoto(userGuid, Convert.ToBase64String(photo));

            foreach (var user in _users)
            {
                try
                {
                    NeedUpdateChats(user.UserGuid);
                }
                catch (Exception e)
                {
                    _logger.Write(LogLevel.Error, "Error callback message", e);
                }
            }
        }
Beispiel #12
0
        public async void CreateGroupChat(CreateGroupChatRequest request)
        {
            var dbWorker = DIFactory.Resolve <IDbSystemWorker>();
            await dbWorker.CreateGroupChat(request.ChatName, request.CreatorGuid, request.UserGuids);

            foreach (var user in _users)
            {
                try
                {
                    NeedUpdateChats(user.UserGuid);
                }
                catch (Exception e)
                {
                    _logger.Write(LogLevel.Error, "Error callback message", e);
                }
            }
        }
Beispiel #13
0
        public async void CreateChat(Guid userGuid, Guid creatorGuid)
        {
            var dbWorker = DIFactory.Resolve <IDbSystemWorker>();
            await dbWorker.CreateChat(userGuid, creatorGuid);

            foreach (var user in _users)
            {
                try
                {
                    NeedUpdateChats(user.UserGuid);
                }
                catch (Exception e)
                {
                    _logger.Write(LogLevel.Error, "Error callback message", e);
                }
            }
        }
        public MessengerViewModel(IMessageCallback callback, AuthorizationResult data)
        {
            Chats = new ObservableCollection <ChatModel>();
            Chats.CollectionChanged += ChatsOnCollectionChanged;
            MessengerData            = new MessengerModel();
            var employee = data.Employee;

            MessengerModels = new ObservableCollection <MessengerModel>();

            var emptyPhotoPath = "Images\\emptyImage.png";

            if (File.Exists(emptyPhotoPath))
            {
                _emptyPhoto = ImageHelper.GetImage(emptyPhotoPath);
            }

            CurrentUser = new UserModel
            {
                Login      = employee.Login,
                Name       = employee.Name,
                Surname    = employee.Surname,
                Patronymic = employee.Patronymic,
                Email      = employee.Email,
                Guid       = employee.Guid,
                Position   = employee.Position
            };

            CurrentUser.EmployeePhoto = ImageHelper.ByteToImageSource(employee.Photo) ?? _emptyPhoto;

            callback.CallbackMessage -= CallbackOnCallbackMessage;
            callback.NeedUpdateChats -= CallbackOnNeedUpdateChats;
            callback.CallbackMessage += CallbackOnCallbackMessage;
            callback.NeedUpdateChats += CallbackOnNeedUpdateChats;
            var manager = DIFactory.Resolve <IServiceManager>();

            manager.Disconnected += ManagerOnDisconnected;
        }
Beispiel #15
0
        private async void NeedUpdateChats(Guid employeeGuid)
        {
            var dbWorker  = DIFactory.Resolve <IDbSystemWorker>();
            var employees = await dbWorker.GetEmployees();

            var usersResult = employees.Select(dbEmployee => new Common.Results.User
            {
                Guid          = dbEmployee.Guid,
                Email         = dbEmployee.Email,
                Login         = dbEmployee.Login,
                Surname       = dbEmployee.Surname,
                Patronymic    = dbEmployee.Patronymic,
                Position      = dbEmployee.Position,
                Name          = dbEmployee.Name,
                EmployeePhoto = dbEmployee.Photo,
            }).ToList();

            foreach (var user in _users)
            {
                var single = usersResult.Single(x => x.Guid == user.UserGuid);
                single.IsOnline = user.Callbacks.Any();
            }

            var chats = await dbWorker.GetUserChats(employeeGuid);

            var needUpdateUsers = chats.Where(x => x.UserGuids.Count == 2).Select(x => x.UserGuids.First(y => y != employeeGuid)).Distinct().ToList();

            try
            {
                var selfUser    = _users.SingleOrDefault(x => x.UserGuid == employeeGuid);
                var chatsResult = new UpdateChatsResult();
                chatsResult.Users    = usersResult;
                chatsResult.Chats    = chats;
                chatsResult.InfoBody = new ResultBody {
                    ResultStatus = ResultStatus.Success
                };
                if (selfUser != null)
                {
                    foreach (var callback in selfUser.Callbacks)
                    {
                        try
                        {
                            callback.UpdateChats(chatsResult);
                        }
                        catch (Exception e)
                        {
                            _logger.Write(LogLevel.Error, "Error callback message", e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Write(LogLevel.Error, "Error callback message", e);
            }

            foreach (var updateUser in needUpdateUsers)
            {
                var u = _users.SingleOrDefault(x => x.UserGuid == updateUser);
                if (u != null)
                {
                    foreach (var callback in u.Callbacks)
                    {
                        try
                        {
                            var chatsResult = new UpdateChatsResult();
                            chatsResult.Users = usersResult;
                            chatsResult.Chats = await dbWorker.GetUserChats(updateUser);

                            chatsResult.InfoBody = new ResultBody {
                                ResultStatus = ResultStatus.Success
                            };
                            callback.UpdateChats(chatsResult);
                        }
                        catch (Exception e)
                        {
                            _logger.Write(LogLevel.Error, "Error callback message", e);
                        }
                    }
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     this._reportService = DIFactory.Resolve <IReportService>();
 }
Beispiel #17
0
        public async Task <AuthorizationResult> AuthorizationClient(string login, string password)
        {
            AuthorizationResult result = new AuthorizationResult();
            var callback = Callback;

            if (String.IsNullOrEmpty(login))
            {
                result.InfoBody = new ResultBody
                {
                    ResultStatus = ResultStatus.NotSuccess,
                    Message      = "Login empty!"
                };
                return(result);
            }

            if (String.IsNullOrEmpty(password))
            {
                result.InfoBody = new ResultBody
                {
                    ResultStatus = ResultStatus.NotSuccess,
                    Message      = "Password empty!"
                };
                return(result);
            }

            var dbWorker = DIFactory.Resolve <IDbSystemWorker>();
            var employee = await dbWorker.GetEmployee(login, password);

            if (employee == null)
            {
                result.InfoBody = new ResultBody
                {
                    ResultStatus = ResultStatus.NotSuccess,
                    Message      = "Пользователь с таким логином и паролем не найден!"
                };
                return(result);
            }

            _logger.Write(LogLevel.Info, DateTime.Now + " " + login + " Connect");

            var queueUser = _users.SingleOrDefault(x => x.UserGuid == employee.Guid);

            if (queueUser == null)
            {
                var user = new User();
                user.UserGuid = employee.Guid;
                user.Callbacks.Add(callback);
                _users.Add(user);
            }
            else
            {
                queueUser.Callbacks.Add(callback);
            }

            var employees = await dbWorker.GetEmployees();

            var usersResult = employees.Select(dbEmployee => new Common.Results.User
            {
                Guid          = dbEmployee.Guid,
                Email         = dbEmployee.Email,
                Login         = dbEmployee.Login,
                Surname       = dbEmployee.Surname,
                Patronymic    = dbEmployee.Patronymic,
                Position      = dbEmployee.Position,
                Name          = dbEmployee.Name,
                EmployeePhoto = dbEmployee.Photo,
            }).ToList();

            foreach (var user in _users)
            {
                try
                {
                    NeedUpdateChats(user.UserGuid);
                }
                catch (Exception e)
                {
                    _logger.Write(LogLevel.Error, "Error message: ", e);
                }
            }

            result.Employee = employee;
            result.Users    = usersResult;
            result.InfoBody = new ResultBody {
                ResultStatus = ResultStatus.Success
            };

            return(result);
        }