Пример #1
0
        /// <summary>
        /// Saves measures to db.
        /// </summary>
        /// <param name="measure">
        /// The measure.
        /// </param>
        /// <returns>
        /// The <see cref="long"/>.
        /// </returns>
        public long CreateMeasure(Measure measure)
        {
            var measureChain = new BaseChain(measure.NoteList.Cast <IBaseObject>().ToList());

            long[] notes = new ElementRepository(db).GetOrCreateNotesInDb(measureChain.Alphabet);

            string localMeasureHash = measure.GetHashCode().ToString();
            var    dbMeasures       = db.Measure.Where(m => m.Value == localMeasureHash).ToList();

            if (dbMeasures.Count > 0)
            {
                foreach (var dbMeasure in dbMeasures)
                {
                    long[] dbAlphabet = db.GetMeasureAlphabet(dbMeasure.Id);
                    if (notes.SequenceEqual(dbAlphabet))
                    {
                        int[] dbBuilding = db.GetMeasureBuilding(dbMeasure.Id);
                        if (measureChain.Building.SequenceEqual(dbBuilding))
                        {
                            if (measure.Attributes.Key.Fifths != dbMeasure.Fifths ||
                                measure.Attributes.Size.BeatBase != dbMeasure.Beatbase ||
                                measure.Attributes.Size.Beats != dbMeasure.Beats)
                            {
                                throw new Exception("Found in db measure is not equal to local measure.");
                            }

                            return(dbMeasure.Id);
                        }
                    }
                }
            }

            return(Create(measure, notes, measureChain.Building));
        }