예제 #1
0
        private void OnNoteOff(int channel, MidiEvent @event)
        {
            byte     note     = @event.MidiMessage.GetBytes()[1];
            TempNote tempNote = noteCache?[channel]?[note];

            if (tempNote == null)
            {
                // A note was turned off when that note was never indicated as having been turned on
                return;
            }
            noteCache[channel].Remove(note);
            CheckTime(tempNote.StartTick);

            long   durationInTicks = @event.AbsoluteTicks - tempNote.StartTick;
            double durationInBeats = GetDurationInBeats(durationInTicks);
            byte   noteOffVelocity = @event.MidiMessage.GetBytes()[2];

            expectedTimeInBeats[currentChannel] = currentTimeInBeats[currentChannel] + durationInBeats;

            Note noteObject = new Note(note)
            {
                Duration    = GetDurationInBeats(durationInTicks),
                OnVelocity  = tempNote.NoteOnVelocity,
                OffVelocity = noteOffVelocity
            };

            OnNoteReleased(new Note(note)
            {
                OffVelocity = noteOffVelocity
            });
            OnNoteParsed(noteObject);
        }
예제 #2
0
        public bool Create()
        {
            AppLog.Info("CREATE BUG - Starting...");


            //Checks that data is valid before attempting upload
            AppLog.Info("CREATE BUG - Validating...");
            if (!Validate())
            {
                AppLog.Info("CREATE BUG - Bug failed validation");
                return(false);
            }
            AppLog.Info("CREATE BUG - Bug validated successfully");

            _DateTimeCreated = DateTime.Now;
            _DateTimeEdited  = DateTime.Now;
            _EditedByUserId  = Data.ActiveUser.Id;

            //Need to check for offline mode here. Also need to do GET for TagType

            AppLog.Info("CREATE BUG - Attempting to CREATE BUG on online database...");
            try //Online
            {
                using (SqlConnection conn = new SqlConnection(OnlineConnStr))
                {
                    AppLog.Info("CREATE BUG - Attempting to open connection to online database...");
                    conn.Open();
                    AppLog.Info("CREATE BUG - Connection to online database opened successfully");

                    //This is a check to see weather the bug already exists on the database. Obviously
                    //if it's already there, it doesn't need creating again, but this might be called
                    //if for example the bug did not exist on the local database, so the Create() function
                    //needed to be able to account for that.
                    AppLog.Info("CREATE BUG - Checking that bug doesn't already exist on online database");
                    bool OnlineBugExists;

                    SqlCommand CheckOnlineDb = new SqlCommand("SELECT * FROM t_Bugs WHERE Id = @Id", conn);
                    CheckOnlineDb.Parameters.Add(new SqlParameter("Id", Id));
                    using (SqlDataReader reader = CheckOnlineDb.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            OnlineBugExists = true;
                            AppLog.Info("CREATE BUG - Bug already exists in online database!");
                        }
                        else
                        {
                            OnlineBugExists = false;
                        }
                    }
                    if (!OnlineBugExists)
                    {
                        AppLog.Info("CREATE BUG - Bug does not exist in online database. Creating bug on " +
                                    "online database");

                        SqlCommand CreateBug = new SqlCommand("INSERT INTO t_Bugs (Id, ProductId, RaisedByUserId, Title, " +
                                                              "Severity, DateTimeCreated, DateTimeEdited, EditedByUserId) VALUES (@Id, @ProductId, @RaisedByUserId, " +
                                                              "@Title, @Severity, @DateTimeCreated, @DateTimeEdited, @EditedByUserId);", conn);

                        CreateBug.Parameters.Add(new SqlParameter("Id", _Id));
                        CreateBug.Parameters.Add(new SqlParameter("ProductId", _ProductId));
                        CreateBug.Parameters.Add(new SqlParameter("RaisedByUserId", _RaisedById));
                        CreateBug.Parameters.Add(new SqlParameter("Title", _Title));
                        CreateBug.Parameters.Add(new SqlParameter("Severity", _Severity));
                        CreateBug.Parameters.Add(new SqlParameter("DateTimeCreated", _DateTimeCreated));
                        CreateBug.Parameters.Add(new SqlParameter("DateTimeEdited", _DateTimeEdited));
                        CreateBug.Parameters.Add(new SqlParameter("EditedByUserId", _EditedByUserId));

                        CreateBug.ExecuteNonQuery();

                        if (_Description != null && _Description != "")
                        {
                            SqlCommand CreateBug_Description = new SqlCommand("UPDATE t_Bugs SET Description = " +
                                                                              "@Description WHERE Id = @Id", conn);
                            CreateBug_Description.Parameters.Add(new SqlParameter("Description", _Description));
                            CreateBug_Description.Parameters.Add(new SqlParameter("Id", _Id));

                            CreateBug_Description.ExecuteNonQuery();
                        }
                    }
                }
                Uploaded = true;
                AppLog.Info(String.Format("CREATE BUG - Bug {0} created on online database successfully", Title));
            }
            catch (SqlException e)
            {
                _ErrMsg = "Error whilst creating bug on the online database";
                AppLog.Error("CREATE BUG - " + _ErrMsg + ": " + e);
                return(false);
            }

            /*AppLog.Info("CREATE BUG - Attempting to create bug on local database...");
             * try //Local
             * {
             *  using (SqlConnection conn = new SqlConnection(LocalConnStr))
             *  {
             *      AppLog.Info("CREATE BUG - Attempting to open connection to local database...");
             *      conn.Open();
             *      AppLog.Info("CREATE BUG - Connection to local database opened successfully");
             *
             *      //This is a check to see weather the bug already exists on the database. Obviously
             *      //if it's already there, it doesn't need creating again, but this might be called
             *      //if for example the bug did not exist on the local database, so the Create() function
             *      //needed to be able to account for that.
             *      AppLog.Info("CREATE BUG - Checking that bug doesn't already exist on local database");
             *      bool LocalBugExists;
             *
             *      SqlCommand CheckLocalDb = new SqlCommand("SELECT * FROM Bugs WHERE Id = @Id", conn);
             *      CheckLocalDb.Parameters.Add(new SqlParameter("Id", Id));
             *      using (SqlDataReader reader = CheckLocalDb.ExecuteReader())
             *      {
             *          if (reader.Read())
             *          {
             *              LocalBugExists = true;
             *              AppLog.Info("CREATE BUG - Bug already exists in local database!");
             *          }
             *          else
             *          {
             *              LocalBugExists = false;
             *          }
             *      }
             *      if (!LocalBugExists)
             *      {
             *          SqlCommand CreateBug = new SqlCommand("INSERT INTO Bugs (Id, ProductId, RaisedByUserId, Title, Severity, " +
             *              "DateTimeCreated, DateTimeEdited, EditedByUserId) VALUES (@Id, @ProductId, @RaisedByUserId, @Title, " +
             *              "@Severity, @DateTimeCreated, @DateTimeEdited, @EditedByUserId);", conn);
             *          CreateBug.Parameters.Add(new SqlParameter("Id", _Id));
             *          CreateBug.Parameters.Add(new SqlParameter("ProductId", _ProductId));
             *          CreateBug.Parameters.Add(new SqlParameter("RaisedByUserId", _RaisedById));
             *          CreateBug.Parameters.Add(new SqlParameter("Title", _Title));
             *          CreateBug.Parameters.Add(new SqlParameter("Severity", _Severity));
             *          CreateBug.Parameters.Add(new SqlParameter("DateTimeCreated", _DateTimeCreated));
             *          CreateBug.Parameters.Add(new SqlParameter("DateTimeEdited", _DateTimeEdited));
             *          CreateBug.Parameters.Add(new SqlParameter("EditedByUserId", _EditedByUserId));
             *
             *          CreateBug.ExecuteNonQuery();
             *
             *          if (_Description != null && _Description != "")
             *          {
             *              SqlCommand CreateBug_Description = new SqlCommand("UPDATE Bugs SET Description = @Description " +
             *                  "WHERE Id = @Id",conn);
             *              CreateBug_Description.Parameters.Add(new SqlParameter("Description", _Description));
             *              CreateBug_Description.Parameters.Add(new SqlParameter("Id", _Id));
             *
             *              CreateBug_Description.ExecuteNonQuery();
             *          }
             *      }
             *  }
             *  AppLog.Info(String.Format("CREATE BUG - Bug {0} created on local database successfully", Title));
             * }
             * catch (SqlException e)
             * {
             *      _ErrMsg = "Error while creating bug on local database. Changes were not saved";
             *      AppLog.Error("CREATE BUG - " + _ErrMsg + ": " + e);
             *      return false;
             * }*/


            //### New Functionality
            foreach (Note TempNote in Data.Notes)
            {
                if (TempNote.BugId.ToString() == Id.ToString())
                {
                    TempNote.Create();
                }
            }

            foreach (Assignee TempAssignee in Data.Assignees)
            {
                if (TempAssignee.BugId.ToString() == Id.ToString())
                {
                    TempAssignee.Create();
                }
            }

            foreach (Tag TempTag in Data.Tags)
            {
                if (TempTag.BugId.ToString() == Id.ToString())
                {
                    TempTag.Create();
                }
            }

            AppLog.Debug("CREATE BUG - Attempting to add bug to DATA...");
            Data.Bugs.Add(this);
            AppLog.Debug("CREATE BUG - ...Success! Added bug to DATA");
            AppLog.Info("CREATE BUG - Success!");
            return(true);
        }