예제 #1
0
        public async Task TrySolve(string number, string input, SocketGuildUser solver)
        {
            if (IsFinished != true)
            {
                if (CurrentLockNumber.HasValue)
                {
                    var curLock = Locks.FirstOrDefault(x => x.LockNumber == CurrentLockNumber.Value);
                    if (curLock.TrySolve(number, input, solver))
                    {
                        CurrentOrderIndex++;
                        if (CurrentOrderIndex >= 10)
                        {
                            IsFinished = true;
                            StringBuilder builder = new StringBuilder();
                            builder.AppendLine("```LOCK::LIFTED");
                            builder.AppendLine("SOLVERS::PRINT()");
                            var users = Locks.Select(x => x.Solver).Distinct();
                            foreach (var user in users)
                            {
                                int amountSolved = Locks.Count(x => x.Solver.Id == user.Id);
                                builder.AppendLine($"SOLVER::{user.Nickname}|ID::{user.Id}|SOLVED::{amountSolved}");
                            }
                            builder.AppendLine($"|{new string('-', 10)}PUZZLE_OVER{new string('-', 10)}|```");
                            await PresentationMessage.ModifyAsync(x => x.Content = builder.ToString());

                            PuzzleSolved?.Invoke(this.Guid);
                        }
                        else
                        {
                            if (CurrentOrderIndex > 0)
                            {
                                PreviousLockNumber = NumbersOrder[CurrentOrderIndex - 1];
                            }
                            else
                            {
                                PreviousLockNumber = null;
                            }
                            if (NumbersOrder.ElementAtOrDefault(CurrentOrderIndex) != 10)
                            {
                                CurrentLockNumber = NumbersOrder[CurrentOrderIndex];
                            }
                            else
                            {
                                CurrentLockNumber = null;
                            }
                            if (NumbersOrder.ElementAtOrDefault(CurrentOrderIndex + 1) != 0)
                            {
                                NextLockNumber = NumbersOrder[CurrentOrderIndex + 1];
                            }
                            else
                            {
                                NextLockNumber = null;
                            }
                            await LockSolved?.Invoke();
                        }
                    }
                }
            }
        }
예제 #2
0
        public async Task SendMessage(string callEmoji, string closeEmoji)
        {
            PresentationMessage = await Channel.SendMessageAsync(GetMessageText());

            var emojis = UserLists.Select(x => x.JoinEmote).ToList();

            emojis.Add(new Emoji(callEmoji));
            emojis.Add(new Emoji(closeEmoji));
            await PresentationMessage.AddReactionsAsync(emojis.ToArray());
        }
예제 #3
0
 public async Task ReloadGroup()
 {
     foreach (var list in UserLists)
     {
         var listCheckTreshold = list.UserLimit ?? 50;
         var reactions         = (await PresentationMessage.GetReactionUsersAsync(list.JoinEmote, listCheckTreshold).FlattenAsync()).Cast <SocketGuildUser>();
         list.Users = list.Users.Intersect(reactions).Take(listCheckTreshold).ToList();
     }
     await UpdateMessage();
 }
예제 #4
0
        public async Task CloseMessage()
        {
            switch (Type)
            {
            case GroupType.Simple:
                await PresentationMessage.ModifyAsync(m =>
                {
                    m.Content = $"Сбор группы {Host.Mention} ({Description}) завершен.";
                });

                break;

            case GroupType.Poll:
                break;
            }
            await PresentationMessage.RemoveAllReactionsAsync();
        }
예제 #5
0
        private void SetStatusMessageSnackBar(string text)
        {
            // Do not change the state control during application closing.
            if (m_bExit)
            {
                return;
            }

            if (this.SnackBarFingerPrints.Dispatcher.Thread == Thread.CurrentThread)
            {
                PresentationMessage.ShowMessegeQueue(this.SnackBarFingerPrints.MessageQueue, text);
            }
            else
            {
                SetStatusMessageCallBack d = new SetStatusMessageCallBack(this.SetStatusMessageSnackBar);
                SnackBarFingerPrints.Dispatcher.BeginInvoke(d, new object[] { text });
            }
        }
        private void DeleteClient_Click(object sender, RoutedEventArgs e)
        {
            var salir = MessageBox.Show("Deseas eliminar el registro.", "KallpaBox", MessageBoxButton.YesNoCancel);

            if (salir == MessageBoxResult.Yes)
            {
                var clientViewModel = _clientRepository.GetClientViewModelById(_clientId);
                var sessions        = _sessionRepository.GetAllSessionGymViewByClientIdView(_clientId);

                try
                {
                    if (clientViewModel != null)
                    {
                        _clientRepository.DeleteClient(clientViewModel.Id, clientViewModel);
                    }
                    if (sessions.Any())
                    {
                        foreach (var i in sessions)
                        {
                            _sessionRepository.DeleteSessionGymView(i.ClientId);
                        }
                    }

                    PresentationMessage.ShowMessegeQueue(this.SnackBarDeleteClients.MessageQueue, "Cliente Eliminado con exito");


                    this.EliminarButton.IsEnabled = false;

                    Thread.Sleep(5000);

                    ProcesarAbrirVentana.AbrirVentana(ConstantsClients.NameWindowClientsList, typeof(ClientsList), null);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format(CultureInfo.CurrentCulture, "Error: {0})", ex.Message));
                }
            }
        }
예제 #7
0
 public async Task UpdateMessage()
 {
     await PresentationMessage.ModifyAsync(x => x.Content = GetMessageText());
 }
예제 #8
0
        private void InsertClient_Click(object sender, RoutedEventArgs e)
        {
            if (!InValidContext())
            {
                PresentationMessage.ShowMessegeQueue(this.SnackBarClients.MessageQueue, "Por favor llene todos los campos para crear el cliente.");
                return;
            }
            var clientViewModel = new ClientViewModel()
            {
                Name           = Name.Text,
                MiddleName     = MiddleName.Text,
                LastName       = LastName.Text,
                SecondSurName  = SecondSurName.Text,
                Age            = int.Parse(Age.Text),
                Address        = Address.Text,
                Identification = Identification.Text,
                Phone          = Phone.Text
            };

            try
            {
                var rutaDesktop = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\KallpaBox\\Assets";
                var idClient    = _clientRepository.CreateClient(clientViewModel);
                PresentationMessage.ShowMessegeQueue(this.SnackBarClients.MessageQueue, "Cliente creado con exito");

                var photo = new Photo()
                {
                    ClientId    = idClient,
                    PhotoClient = rutaDesktop + "\\" + idClient + ".jpg",
                };

                if (ImageClient.Source != null)
                {
                    if (!(Directory.Exists(rutaDesktop)))
                    {
                        Directory.CreateDirectory(rutaDesktop);
                    }

                    if (Directory.Exists(rutaDesktop))
                    {
                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.UriSource = new Uri(_fileName);
                        bitmap.EndInit();
                        BitmapEncoder encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(bitmap));

                        FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Write, rutaDesktop);
                        f.AllLocalFiles = FileIOPermissionAccess.Write;
                        try
                        {
                            f.Demand();
                        }
                        catch (SecurityException s)
                        {
                            Console.WriteLine(s.Message);
                        }

                        using (var fileStream = new FileStream(photo.PhotoClient, FileMode.Create))
                        {
                            encoder.Save(fileStream);
                        }

                        photo.LengthPhoto = FileInfoExtension.ObtenerTamanoArchivo(photo.PhotoClient);

                        _photoRepository.CreatePhoto(photo);
                    }
                }

                CleanControls();
            }
            catch (Exception ex)
            {
                throw new Exception("Error en aplicativo contacte con el administrador. {0}", ex);
            }
        }
        private void EditClient_Click(object sender, RoutedEventArgs e)
        {
            if (!InValidContext())
            {
                return;
            }
            var clientViewModel = new ClientViewModel()
            {
                Id             = int.Parse(Id.Text),
                Name           = Name.Text,
                MiddleName     = MiddleName.Text,
                LastName       = LastName.Text,
                SecondSurName  = SecondSurName.Text,
                Age            = int.Parse(Age.Text),
                Address        = Address.Text,
                Identification = Identification.Text,
                IdentityGuid   = IdentityGuid.Text,
                Phone          = Phone.Text
            };

            try
            {
                _clientRepository.UpateClient(clientViewModel.Id, clientViewModel);
                var rutaBorrar  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\KallpaBox\\TempAssets";
                var rutaDesktop = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\KallpaBox\\Assets";
                var photo       = _photoRepository.GetPhotoClientId(_idClient);
                var rutaTemp    = rutaBorrar + "\\" + _idClient + ".jpg";
                if (ImageClient.Source != null)
                {
                    if (!(Directory.Exists(rutaDesktop)))
                    {
                        Directory.CreateDirectory(rutaDesktop);
                    }

                    if (!(Directory.Exists(rutaBorrar)))
                    {
                        Directory.CreateDirectory(rutaBorrar);
                    }

                    var imagetemp = ImageClient.Source as BitmapSource;

                    ImageClient.Source = null;
                    ImageClient.UpdateLayout();
                    File.Delete(photo.PhotoClient);
                    Thread.Sleep(1000);

                    if (photo != null)
                    {
                        photo.PhotoClient = rutaDesktop + "\\" + _idClient + ".jpg";
                        _photoRepository.UpdatePhoto(photo);
                    }
                    else
                    {
                        photo = new Photo()
                        {
                            ClientId    = _idClient,
                            PhotoClient = rutaDesktop + "\\" + _idClient + ".jpg",
                            LengthPhoto = FileInfoExtension.ObtenerTamanoArchivo(photo.PhotoClient)
                        };

                        _photoRepository.CreatePhoto(photo);
                    }


                    BitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(imagetemp));

                    FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Write, rutaDesktop);
                    f.AllLocalFiles = FileIOPermissionAccess.Write;
                    try
                    {
                        f.Demand();
                    }
                    catch (SecurityException s)
                    {
                        Console.WriteLine(s.Message);
                    }

                    using (var fileStream = new FileStream(photo.PhotoClient, FileMode.Create))
                    {
                        encoder.Save(fileStream);
                    }
                }

                CleanControls();
                PresentationMessage.ShowMessegeQueue(this.SnackBarEditClients.MessageQueue, "Cliente editado con exito");
            }
            catch (Exception ex)
            {
                throw new Exception($"Error {ex.Message}", ex);
            }
        }