Пример #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (algorithmCase_ == AlgorithmOneofCase.SelectedAlgorithm)
            {
                hash ^= SelectedAlgorithm.GetHashCode();
            }
            if (AlphaReal != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AlphaReal);
            }
            if (AlphaImag != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AlphaImag);
            }
            if (Beta != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Beta);
            }
            if (dotDimensionNumbers_ != null)
            {
                hash ^= DotDimensionNumbers.GetHashCode();
            }
            if (BatchSize != 0L)
            {
                hash ^= BatchSize.GetHashCode();
            }
            hash ^= (int)algorithmCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #2
0
        private void UpdateQuality()
        {
            long time = SelectedAlgorithm.Contour(Qualities[QualityIndex]);

            System.Text.StringBuilder text = new System.Text.StringBuilder();

            text.Append(SelectedAlgorithm.Name).Append(" - ");

            string topology_type = (SelectedAlgorithm.Is3D ? "Triangles" : "Lines");

            if (SelectedAlgorithm.IsIndexed)
            {
                text.Append((SelectedAlgorithm.IndexCount / (SelectedAlgorithm.Is3D ? 3 : 2)) + " " + topology_type + ", " + SelectedAlgorithm.VertexCount + " Vertices");
            }
            else
            {
                text.Append((SelectedAlgorithm.VertexCount / (SelectedAlgorithm.Is3D ? 3 : 2)) + " " + topology_type);
            }

            if (SelectedAlgorithm.ExtraInformation != "")
            {
                text.Append(", " + SelectedAlgorithm.ExtraInformation);
            }

            text.Append(" (" + time + " ms)");

            text.Append(" - Quality " + Qualities[QualityIndex]);

            Window.Title = text.ToString();
        }
Пример #3
0
        protected override void Draw(GameTime gameTime)
        {
            if (SelectedAlgorithm.Is3D)
            {
                GraphicsDevice.Clear(Color.DimGray);
            }
            else
            {
                GraphicsDevice.Clear(Color.WhiteSmoke);
            }

            if (SelectedAlgorithm.Is3D)
            {
                effect.World = Matrix.CreateTranslation(new Vector3(-Resolution / 2, -Resolution / 2, -Resolution / 2));
            }
            else
            {
                effect.World = Matrix.Identity;
            }

            if (SelectedAlgorithm.Is3D && WireframeMode == (WireframeModes.Fill | WireframeModes.Wireframe))
            {
                RasterizerState rs = new RasterizerState();
                rs.CullMode  = CullMode.None;
                rs.FillMode  = FillMode.Solid;
                rs.DepthBias = 0;
                GraphicsDevice.RasterizerState = rs;
            }

            SelectedAlgorithm.Draw(effect, false, DrawMode);

            if (SelectedAlgorithm.Is3D && WireframeMode == (WireframeModes.Fill | WireframeModes.Wireframe))
            {
                RasterizerState rs = new RasterizerState();
                rs.CullMode  = CullMode.None;
                rs.FillMode  = FillMode.WireFrame;
                rs.DepthBias = -0.0001f;
                GraphicsDevice.RasterizerState = rs;
                effect.VertexColorEnabled      = false;
                SelectedAlgorithm.Draw(effect, false, DrawMode);
                effect.VertexColorEnabled = true;
            }

            base.Draw(gameTime);
        }
        private void CommandExecuted(object o)
        {
            var pboxes = (object[])o;
            var sb     = new StringBuilder();

            char[] password1 = ((PasswordBox)pboxes[0]).Password.ToArray();
            char[] password2 = ((PasswordBox)pboxes[1]).Password.ToArray();
            if (password1.Length == 0)
            {
                sb.Append("please enter a password").Append(Environment.NewLine);
            }
            if (!password1.SequenceEqual(password2))
            {
                sb.Append("password and confirm do not match").Append(Environment.NewLine);
            }
            if (Path.IsNullOrEmpty())
            {
                sb.Append("please select a path ").Append(Environment.NewLine);
            }
            if (AlgorithmRequired && SelectedAlgorithm.IsNullOrEmpty())
            {
                sb.Append("please select an algorithm ").Append(Environment.NewLine);
            }
            Array.Clear(password1, 0, password1.Length);
            Array.Clear(password2, 0, password2.Length);
            var errors = sb.ToString();

            if (!errors.IsNullOrEmpty())
            {
                MessageBoxContent = new MessageBoxViewModel(CloseMessageBox,
                                                            MessageBoxModel.Error("Error exporting to file - " +
                                                                                  Environment.NewLine + errors));
                IsMessageBoxVisible = true;
                return;
            }
            char[] password = ((PasswordBox)pboxes[0]).Password.ToArray();
            if (AlgorithmRequired)
            {
                _action.Invoke(_entry, SelectedAlgorithm, password, Path);
            }
            else
            {
                _exportPkcs12Action.Invoke(_entry, Path, password);
            }
        }
Пример #5
0
        protected override void MoveCar(object sender, DoWorkEventArgs e)
        {
            try
            {
                while (!_backgroundWorker.CancellationPending)
                {
                    Thread.Sleep((int)(Interval / Speed));

                    Record record = new Record(Car.Center, Car.Left, Car.Forward, Car.Right, Degree);
                    Recorder.Add(record);
                    Degree = SelectedAlgorithm.GetDegree(Car.Forward, Car.Left, Car.Right);
                    Car.Move(Degree);
                }
            }
            catch (NullReferenceException)
            {
                _backgroundWorker.CancelAsync();
                MessageBox.Show("Please specify the alogrithm");
                _status = Status.Stop;
            }
        }
Пример #6
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (!last_state.IsKeyDown(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                QualityIndex = (QualityIndex + 1) % Qualities.Length;
                UpdateQuality();
            }
            if (!last_state.IsKeyDown(Keys.Tab) && Keyboard.GetState().IsKeyDown(Keys.Tab))
            {
                NextAlgorithm();
            }

            if (!last_state.IsKeyDown(Keys.F) && Keyboard.GetState().IsKeyDown(Keys.F))
            {
                SelectedAlgorithm = (ISurfaceAlgorithm)Activator.CreateInstance(SelectedAlgorithm.GetType(), GraphicsDevice, Resolution, TileSize);
                ModelIndex        = (ModelIndex + 1) % Models.Length;
                Sampler.ReadData(Models[ModelIndex], Resolution);
                UpdateQuality();
            }

            if (!last_state.IsKeyDown(Keys.D1) && Keyboard.GetState().IsKeyDown(Keys.D1))
            {
                if (DrawMode != DrawModes.Mesh)
                {
                    DrawMode ^= DrawModes.Mesh;
                }
            }
            if (!last_state.IsKeyDown(Keys.D2) && Keyboard.GetState().IsKeyDown(Keys.D2))
            {
                if (DrawMode != DrawModes.Outline)
                {
                    DrawMode ^= DrawModes.Outline;
                }
            }

            if (!last_state.IsKeyDown(Keys.D3) && Keyboard.GetState().IsKeyDown(Keys.D3))
            {
                if (WireframeMode == WireframeModes.Fill)
                {
                    WireframeMode = WireframeModes.Fill | WireframeModes.Wireframe;
                }
                else if (WireframeMode == (WireframeModes.Fill | WireframeModes.Wireframe))
                {
                    WireframeMode = WireframeModes.Wireframe;
                }
                else
                {
                    WireframeMode = WireframeModes.Fill;
                }

                if (WireframeMode != (WireframeModes.Fill | WireframeModes.Wireframe))
                {
                    RState          = new RasterizerState();
                    RState.CullMode = CullMode.None;
                    RState.FillMode = (WireframeMode == WireframeModes.Fill ? FillMode.Solid : FillMode.WireFrame);
                    GraphicsDevice.RasterizerState = RState;
                }
            }

            if (!last_state.IsKeyDown(Keys.C) && Keyboard.GetState().IsKeyDown(Keys.C))
            {
                Camera.MouseLocked = !Camera.MouseLocked;
            }

            if (!last_state.IsKeyDown(Keys.M) && Keyboard.GetState().IsKeyDown(Keys.M))
            {
                if (SelectedAlgorithm.GetType() == typeof(ManifoldDC.MDC3D))
                {
                    ((ManifoldDC.MDC3D)SelectedAlgorithm).EnforceManifold = !((ManifoldDC.MDC3D)SelectedAlgorithm).EnforceManifold;
                    UpdateQuality();
                }
            }

            if (SelectedAlgorithm.Is3D)
            {
                Camera.Update(true);
                effect.View = Camera.View;
            }

            last_state = Keyboard.GetState();

            base.Update(gameTime);
        }
Пример #7
0
        protected override void Draw(GameTime gameTime)
        {
            if (SelectedAlgorithm.SupportsDeferred)
            {
                DeferredRenderer.Draw(SelectedAlgorithm, Camera);
                return;
            }

            if (SelectedAlgorithm.Is3D)
            {
                GraphicsDevice.Clear(Color.DimGray);
            }
            else
            {
                GraphicsDevice.Clear(Color.WhiteSmoke);
            }

            Effect e = (SelectedAlgorithm.SpecialShader ? dn_effect : reg_effect);

            if (SelectedAlgorithm.Is3D)
            {
                e.Parameters["World"].SetValue(Matrix.CreateTranslation(new Vector3(-Resolution / 2, -Resolution / 2, -Resolution / 2)));
            }
            else
            {
                e.Parameters["World"].SetValue(Matrix.Identity);
            }

            if (SelectedAlgorithm.Is3D && (int)(WireframeMode & WireframeModes.Fill) != 0)
            {
                RasterizerState rs = new RasterizerState();
                rs.CullMode  = (Sampler.ImageData != null ? CullMode.CullCounterClockwiseFace : CullMode.CullClockwiseFace);
                rs.FillMode  = FillMode.Solid;
                rs.DepthBias = 0;
                GraphicsDevice.RasterizerState = rs;
            }

            if (!SelectedAlgorithm.Is3D || WireframeMode != WireframeModes.Wireframe)
            {
                SelectedAlgorithm.Draw(e, false, DrawMode);
            }

            if (SelectedAlgorithm.Is3D && (int)(WireframeMode & WireframeModes.Wireframe) != 0 && !SelectedAlgorithm.SupportsDeferred)
            {
                if (!SelectedAlgorithm.CustomWireframe)
                {
                    RasterizerState rs = new RasterizerState();
                    rs.CullMode = (Sampler.ImageData != null ? CullMode.CullCounterClockwiseFace : CullMode.CullClockwiseFace);
                    rs.FillMode = FillMode.WireFrame;
                    //rs.DepthBias = -0.0001f;
                    GraphicsDevice.RasterizerState = rs;
                    e.Parameters["ColorEnabled"].SetValue(false);
                    SelectedAlgorithm.Draw(e, false, DrawMode);
                    e.Parameters["ColorEnabled"].SetValue(true);
                }
                else
                {
                    //effect.Parameters["ColorEnabled"].SetValue(false);
                    SelectedAlgorithm.DrawWireframe(Camera, wire_effect, Matrix.CreateTranslation(new Vector3(-Resolution / 2, -Resolution / 2, -Resolution / 2)));
                    //effect.Parameters["ColorEnabled"].SetValue(true);
                }
            }

            base.Draw(gameTime);
        }
Пример #8
0
        public SignToolMainVM()
        {
            #region add signature and keys to list

            SigningAlgorithms = new ObservableCollection <ISignature>
            {
                new RSADigitalSignClass(),
                new ElGamalDigitalSignClass(),
                new DSAClass()
            };
            _keys = new List <IKey>
            {
                new RsaKey(),
                new ElGamalKey(),
                new DSAKey()
            };
            RaisePropertyChanged(nameof(SigningAlgorithms));
            SelectedAlgorithm = SigningAlgorithms.First();

            #endregion

            GenerateKey = new DelegateCommand(() =>
            {
                try
                {
                    Key.GenerateKey();
                    RaisePropertyChanged(nameof(Key));
                    MessageBox.Show("Keys generated successfully!");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            });

            ShowKey = new DelegateCommand(() =>
            {
                try
                {
                    if (Key.IsKeyEmpty())
                    {
                        throw new ApplicationException("Firstly, generate keys");
                    }
                    MessageBox.Show($"Key Info:\nGeneral Parameter: {Key.GeneralParameter}\nOpen Parameter: {Key.OpenParameter}\nSecret Parameter: {Key.SecretParameter}");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            });

            Sign = new DelegateCommand(() =>
            {
                try
                {
                    if (Key.IsKeyEmpty())
                    {
                        throw new ApplicationException("Firstly, generate keys");
                    }
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Title          = "Choose file to sign";
                    if (ofd.ShowDialog() == true)
                    {
                        string filePath     = ofd.FileName;
                        byte[] hash         = SHA1.GetHash(filePath);
                        byte[] signature    = SelectedAlgorithm.Sign(Key, hash);
                        filePath            = Path.GetDirectoryName(filePath) + @"\signature";
                        using FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
                        fs.Write(signature);
                        MessageBox.Show("Signature generated!");
                    }
                    else
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            });

            VerifySignature = new DelegateCommand(() =>
            {
                try
                {
                    if (Key.IsKeyEmpty())
                    {
                        throw new ApplicationException("Firstly, generate keys");
                    }
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Title          = "Choose file to verify";
                    if (ofd.ShowDialog() == true)
                    {
                        string filePath  = ofd.FileName;
                        byte[] hash      = SHA1.GetHash(filePath);
                        byte[] signature = default;
                        ofd.Title        = "Choose signature";
                        if (ofd.ShowDialog() == true)
                        {
                            filePath            = ofd.FileName;
                            using FileStream fs = new FileStream(filePath, FileMode.Open);
                            signature           = new byte[fs.Length];
                            fs.Read(signature);
                        }
                        if (signature == default)
                        {
                            return;
                        }
                        bool isSignatureValid = SelectedAlgorithm.VerifySignature(hash, signature, Key);
                        if (isSignatureValid)
                        {
                            MessageBox.Show("Signature is valid");
                        }
                        else
                        {
                            MessageBox.Show("Signature is not valid");
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            });

            WriteKeyToFile = new DelegateCommand(() =>
            {
                CommonOpenFileDialog dialog = new CommonOpenFileDialog();
                if (Key.IsKeyEmpty())
                {
                    throw new ApplicationException("Firstly, generate keys");
                }
                dialog.InitialDirectory = "C:\\Users";
                dialog.IsFolderPicker   = true;
                if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    KeyWorkerClass.WriteKeyToFile(Key, dialog.FileName);
                }
                else
                {
                    return;
                }
            });

            LoadKeyFromFile = new DelegateCommand(() =>
            {
                try
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    if (ofd.ShowDialog() == true)
                    {
                        string filePath    = ofd.FileName;
                        GeneralKeyType key = KeyWorkerClass.LoadKeyFromFile(filePath);
                        IKey loadedKey     = _keys.Find((k) => k.Name == _selectedAlgorithm.Name);
                        string type        = loadedKey.LoadKey(key);
                        MessageBox.Show($"{type} key is loaded successfully!");
                    }
                    else
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            });
        }
Пример #9
0
        // Xử lý trường hợp người chơi nhấn Esc
        private void HandleInput()
        {
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                Camera.Move(new Vector2(0, -Camera.Speed));
            }

            if (keyboardState.IsKeyDown(Keys.Down))
            {
                Camera.Move(new Vector2(0, Camera.Speed));
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                Camera.Move(new Vector2(-Camera.Speed, 0));
            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                Camera.Move(new Vector2(Camera.Speed, 0));
            }

            if (keyboardState.IsKeyDown(Keys.D1))
            {
                SelectedTool = SelectedTool.Start;
            }

            if (keyboardState.IsKeyDown(Keys.D2))
            {
                SelectedTool = SelectedTool.End;
            }

            if (keyboardState.IsKeyDown(Keys.D3))
            {
                SelectedTool = SelectedTool.D5;
            }

            if (keyboardState.IsKeyDown(Keys.D4))
            {
                SelectedTool = SelectedTool.D10;
            }

            if (keyboardState.IsKeyDown(Keys.D5))
            {
                SelectedTool = SelectedTool.D20;
            }

            if (keyboardState.IsKeyDown(Keys.D6))
            {
                SelectedTool = SelectedTool.D40;
            }

            if (keyboardState.IsKeyDown(Keys.D7))
            {
                SelectedTool = SelectedTool.Wall;
            }

            if (keyboardState.IsKeyDown(Keys.D8))
            {
                SelectedTool = SelectedTool.Erase;
            }

            if (keyboardState.IsKeyDown(Keys.D9))
            {
                SelectedAlgorithm = SelectedAlgorithm.AStar;
            }

            if (keyboardState.IsKeyDown(Keys.D0))
            {
                SelectedAlgorithm = SelectedAlgorithm.Dijkstra;
            }

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                Reset();
            }

            if ((keyboardState.IsKeyDown(Keys.LeftControl)
                 ||
                 keyboardState.IsKeyDown(Keys.RightControl))
                &&
                keyboardState.IsKeyDown(Keys.S))
            {
                System.Windows.Forms.SaveFileDialog sfd =
                    new System.Windows.Forms.SaveFileDialog();
                sfd.DefaultExt = ".map";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK
                    &&
                    sfd.FileName != "")
                {
                    Map.Save(sfd.FileName);
                }
            }

            if ((keyboardState.IsKeyDown(Keys.LeftControl)
                 ||
                 keyboardState.IsKeyDown(Keys.RightControl))
                &&
                keyboardState.IsKeyDown(Keys.L))
            {
                System.Windows.Forms.OpenFileDialog lfd =
                    new System.Windows.Forms.OpenFileDialog();
                lfd.DefaultExt = ".map";
                if (lfd.ShowDialog() == System.Windows.Forms.DialogResult.OK
                    &&
                    lfd.FileName != "")
                {
                    Map.Load(lfd.FileName);
                }
            }
        }