コード例 #1
0
        public bool addOrchestra(Orchestra orchestra)
        {
            try
            {
                entity.Orchestras.Add(orchestra);
                entity.SaveChanges();
            }
            catch (DbEntityValidationException e) {
                foreach (var eve in e.EntityValidationErrors)
                {
                    string msg = String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                               eve.Entry.Entity.GetType().Name, eve.Entry.State);

                    foreach (var ve in eve.ValidationErrors)
                    {
                        string msg2 = String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                    ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(false);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Gets called when the App suspends
        /// </summary>
        private async void OnAppSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            Orchestra.Disconnect();
            await MusicLibrary.Save();

            MusicLibrary.Close();
        }
コード例 #3
0
        public void UpdateOrchestraTest()
        {
            Orchestra testOrchestra = Orchestra.GetOrchestraByID(-1);

            if (testOrchestra.IsNew)
            {
                testOrchestra.OrchestraID = -1;
            }
            testOrchestra.OrchestraName = "Adage";
            BsoArchiveEntities.Current.Save();

            var orchestraID    = Helper.CreateXElement(Constants.Orchestra.orchestraIDElement, "-1");
            var orchestraNotes = Helper.CreateXElement(Constants.Orchestra.orchestraNotesElement, "Test");
            var orchestraItem  = new System.Xml.Linq.XElement(Constants.Orchestra.orchestraElement, orchestraID, orchestraNotes);
            var eventItem      = new System.Xml.Linq.XElement(Constants.Event.eventElement, orchestraItem);
            var doc            = new System.Xml.Linq.XDocument(eventItem);

            Orchestra orchestra = Orchestra.NewOrchestra();

            orchestra.UpdateData(doc, "OrchestraNote", "eventOrchestraNotes");
            Assert.IsTrue(testOrchestra.OrchestraNote == "Test");

            BsoArchiveEntities.Current.DeleteObject(testOrchestra);
            BsoArchiveEntities.Current.DeleteObject(orchestra);
            BsoArchiveEntities.Current.Save();
        }
コード例 #4
0
        /// <summary>
        /// This Deletes an Orchestra by taking in its id, finding it in the database, then
        /// removing it from the database, then saveing.
        /// </summary>
        /// <param name="id"></param>
        public void DeleteOrchestra(int id)
        {
            Orchestra orchestra = _db.Orchestra.Find(id);

            _db.Orchestra.Remove(orchestra);
            _db.SaveChanges();
        }
コード例 #5
0
        protected void btn_orchadd_Click(object sender, EventArgs e)
        {
            try
            {
                Orchestra orch = new Orchestra();
                orch.OfficialName  = txt_orchname.Text;
                orch.Alias         = txt_orchaliasname.Text;
                orch.URL           = txt_orchurl.Text;
                orch.Address       = txt_orchaddress.Text;
                orch.ZipCode       = txt_orchzipcode.Text;
                orch.TelNO         = txt_orchtelno.Text;
                orch.FaxNo         = txt_orchfaxno.Text;
                orch.ConductorName = txt_orchcondactername.Text;
                orch.Since         = int.Parse(txt_orchsince.Text);

                if (orl.addOrchestra(orch))
                {
                    GridView1.DataSource = orl.getAllOrchestra();
                    GridView1.DataBind();
                    showMsg("Data inserted succssfuly");
                    cleanOrchTextBoxs();
                }
                else
                {
                    showMsg("Please check your inputs");
                }
            }
            catch (Exception ee)
            {
                showMsg("Please check your inputs");
            }
        }
コード例 #6
0
    public void SerializeObject(string filename)
    {
        Orchestras orchastras = new Orchestras();
        Orchestra  orchestra1 = new Orchestra();

        orchastras.orchestras.Add(orchestra1);
        List <Instrument> instruments = new List <Instrument>()
        {
            new Instrument()
            {
                Name = "Brass"
            },
            new Instrument()
            {
                Name = "Percussion"
            }
        };

        orchestra1.Instruments = instruments;
        // Create the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s = new XmlSerializer(typeof(Orchestras));
        // Writing the file requires a TextWriter.
        XmlWriterSettings settings = new XmlWriterSettings();

        settings.Indent = true;
        XmlWriter writer = XmlWriter.Create(filename, settings);
        // Create the object that will be serialized.
        Orchestra band = new Orchestra();

        orchastras.orchestras.Add(band);
        // Create an object of the derived type.
        //Brass i = new Brass();
        //i.Name = "Trumpet";
        //i.IsValved = true;
        //Instrument[] myInstruments = { i };
        //band.Instruments = myInstruments;
        List <Instrument> myInstruments = new List <Instrument>();

        myInstruments.Add(new Brass()
        {
            Name = "Trumpet", IsValved = true
        });
        myInstruments.Add(new Percussion()
        {
            Name = "Percussion", name = "Mridangam"
        });
        band.Instruments = myInstruments;
        band.i           = 128;
        band.f           = 5.678f;
        band.s1          = "Hi!";
        band.s2          = "GOOD!!!";
        B b = new B();

        b.dd    = 2.35674848;
        band.bc = b;
        // Serialize the object.
        s.Serialize(writer, orchastras);
        writer.Close();
    }
コード例 #7
0
ファイル: Program.cs プロジェクト: Sk41d/MidiGremlin
        static void Main(string[] args)
        {
            Orchestra  orchestra = new Orchestra(new WinmmOut(0, 70));
            Instrument bagpipe   = orchestra.AddInstrument(InstrumentType.BagPipe);

            bagpipe.Play(Tone.CSharp, 1);
            orchestra.WaitForFinished();
        }
コード例 #8
0
 public IActionResult Edit(Orchestra orchestra)
 {
     if (ModelState.IsValid)
     {
         _repo.UpdateOrchestra(orchestra);
         return(RedirectToAction("Index"));
     }
     return(View(orchestra));
 }
コード例 #9
0
        public OrchestraTests()
        {
            var dictionary = new Dictionary <int, Activity>();

            for (var i = 0; i < 7; i++)
            {
                dictionary.Add(i, null);
            }
            orchestra = new Orchestra("Test", new HashSet <Musician>(), dictionary, new HashSet <Activity>());
        }
コード例 #10
0
        /// <summary>
        /// This Creates an Orchestra by takeing in a orchestra object and checks to make sure it is not null the sets
        /// the Id to zero and adds the object to the database, then saves the changes. If the
        /// the object is null then it returns the view object information unsaved.
        /// </summary>
        /// <param name="orchestra"></param>
        /// <returns>orchestra</returns>
        public Orchestra CreateOrchestra(Orchestra orchestra)
        {
            if (orchestra != null)
            {
                orchestra.Id = 0;
                _db.Orchestra.Add(orchestra);
                _db.SaveChanges();
            }

            return(orchestra);
        }
コード例 #11
0
        public void AddInstrumentTest(InstrumentType instrumentType, int octave = 3)
        {
            Orchestra orc = new Orchestra(Substitute.For <IMidiOut>(), 8);

            orc.AddInstrument(instrumentType, octave);

            bool test = orc.Instruments.ToList().Exists(item => (item.InstrumentType == instrumentType) && (item.Octave == octave));


            Assert.IsTrue(test);
        }
コード例 #12
0
 private void ConnectDisconnectButtonClick(object sender, RoutedEventArgs e)
 {
     if (Orchestra.IsConnected)
     {
         Orchestra.Disconnect();
     }
     else
     {
         Orchestra.Connect();
     }
 }
コード例 #13
0
        public void AddInstrumentTest1()
        {
            Scale     scale = new Scale(Tone.A, Tone.B, Tone.C);
            Orchestra orc   = new Orchestra(Substitute.For <IMidiOut>(), 8);

            orc.AddInstrument(InstrumentType.Violin, scale, 5);

            bool test = orc.Instruments.ToList().Exists(item => (item.InstrumentType == InstrumentType.Violin) && (item.Octave == 5) && (item.Scale == scale));


            Assert.IsTrue(test);
        }
コード例 #14
0
ファイル: OrchestraTests.cs プロジェクト: fotijr/MetroDom
        public void Start_ThrowsArgumentNullException_WithNullSong()
        {
            // Arrange
            var orchestra = new Orchestra(null);

            // Act
            var exception = Record.Exception(() => orchestra.Start(null));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
コード例 #15
0
ファイル: WinmmOutTests.cs プロジェクト: Sk41d/MidiGremlin
        public void QueueMusicTest()
        {
            using (WinmmOut winMM = new WinmmOut(0))
            {
                Orchestra  o = new Orchestra(winMM);
                Keystroke  n = new Keystroke(Tone.C, 1000);
                Instrument i = o.AddInstrument(InstrumentType.AccousticGrandPiano);

                i.Play(n);

                Thread.Sleep(5000);
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: henockmamo54/weborch
        public Form1()
        {
            InitializeComponent();

            OrchestraLogic ol = new OrchestraLogic();

            System.Diagnostics.Debug.WriteLine(ol.getAllOrchestra().Count);

            Orchestra or = new Orchestra();

            or.OfficialName = "from entitiy model";
            ol.addOrchestra(or);
        }
コード例 #17
0
        // This method initiates the music components.
        internal void MusicSetup()
        {
            // bpm is a constant deciding the tempo of the music.
            // when bpm is set to 60, one beat will last 1 second. 120 for half a second and so forth.
            const int bpm = 60;

            // Here we create a new orchestra using the output type WinmmOut which plays to the MIDI player in windows.
            _o = new Orchestra(new WinmmOut(0, bpm));
            // Here we use the orchestra to create a new Instrument, in this case a choir.
            // We chose to use the chromatic scale from the Scale class, it is however unneccesary since it uses this scale by default.
            _instrument = _o.AddInstrument(InstrumentType.ChoirAahs, Scale.ChromaticScale, 0);
            _isPlaying  = true;
        }
コード例 #18
0
ファイル: OrchestraTests.cs プロジェクト: fotijr/MetroDom
        public void Start_IsSuccessful_WithNullInstruments()
        {
            // Arrange
            var orchestra = new Orchestra(null);
            var song      = new Song(Key.EMajor, new List <SongNote> {
                new SongNote(MetroDom.Core.Note.C, 500)
            });

            // Act
            orchestra.Start(song);

            // Assert
        }
コード例 #19
0
        public void GetOrchestraFromNodeItemTest()
        {
            var orchestraID   = Helper.CreateXElement(Constants.Orchestra.orchestraIDElement, "-1");
            var orchestraName = Helper.CreateXElement(Constants.Orchestra.orchestraNameElement, "TestOrchestraName");
            var orchestraURL  = Helper.CreateXElement(Constants.Orchestra.orchestraURLElement, "TestOrchestraURL");
            var orchestraNote = Helper.CreateXElement(Constants.Orchestra.orchestraNotesElement, "TestOrchestraNotes");
            var orchestraItem = new System.Xml.Linq.XElement(Constants.Orchestra.orchestraElement, orchestraID, orchestraName, orchestraURL, orchestraNote);
            var node          = new System.Xml.Linq.XElement(Constants.Event.eventElement, orchestraItem);

            Orchestra orchestra = Orchestra.GetOrchestraFromNode(node);

            Assert.IsNotNull(orchestra);
            Assert.IsTrue(orchestra.OrchestraID == -1 && orchestra.OrchestraName == "TestOrchestraName");
        }
コード例 #20
0
ファイル: ChordTests.cs プロジェクト: Sk41d/MidiGremlin
        public void WithBaseToneTest(Tone tone, double duration)
        {
            ChordVariety acd = new ChordVariety(1, 4, 7);

            Orchestra         orc = new Orchestra(NSubstitute.Substitute.For <IMidiOut>());
            List <SingleBeat> v   = acd.WithBaseTone(Tone.CSharp, 5).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList();

            List <SingleBeat> comp = new List <SingleBeat>();

            comp.AddRange(new Keystroke(tone, duration).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList());
            comp.AddRange(new Keystroke(Tone.E, duration).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList());
            comp.AddRange(new Keystroke(Tone.G, duration).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList());

            CollectionAssert.AreEqual(comp, v);
        }
コード例 #21
0
        public void NoteTest(Tone tone, double duration, double starttime)
        {
            Note       n = new Note(tone, duration);
            Orchestra  o = new Orchestra(Substitute.For <IMidiOut>());
            Instrument i = o.AddInstrument(InstrumentType.Banjo);

            IEnumerable <SingleBeat> list = n.GetChildren(i, starttime);

            List <SingleBeat> expected = new List <SingleBeat>
            {
                new SingleBeat(i.InstrumentType, (byte)(tone + 60), 64, starttime, starttime + duration),
                new SingleBeat(0, 0xff, 0xff, starttime + duration, starttime + duration)
            };

            CollectionAssert.AreEqual(expected, list);
        }
コード例 #22
0
    public void SerializeObject(string filename)
    {
        /* Each overridden field, property, or type requires
         * an XmlAttributes object. */
        XmlAttributes attrs = new XmlAttributes();

        /* Create an XmlElementAttribute to override the
         * field that returns Instrument objects. The overridden field
         * returns Brass objects instead. */
        XmlElementAttribute attr = new XmlElementAttribute();

        attr.ElementName = "Brass";
        attr.Type        = typeof(Brass);

        // Add the element to the collection of elements.
        attrs.XmlElements.Add(attr);

        // Create the XmlAttributeOverrides object.
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

        /* Add the type of the class that contains the overridden
         * member and the XmlAttributes to override it with to the
         * XmlAttributeOverrides object. */
        attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

        // Create the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(typeof(Orchestra), attrOverrides);

        // Writing the file requires a TextWriter.
        TextWriter writer = new StreamWriter(filename);

        // Create the object that will be serialized.
        Orchestra band = new Orchestra();

        // Create an object of the derived type.
        Brass i = new Brass();

        i.Name     = "Trumpet";
        i.IsValved = true;
        Instrument[] myInstruments = { i };
        band.Instruments = myInstruments;

        // Serialize the object.
        s.Serialize(writer, band);
        writer.Close();
    }
コード例 #23
0
 /// <summary>
 /// Updates an Orchestra that is passed in then cheked to make sure it is not null then it finds the old
 /// orchestra using its Id, makes sure that its not equal to null then replaces all the old properties
 /// with the new ones, and saves it.
 /// </summary>
 /// <param name="orchestra"></param>
 public void UpdateOrchestra(Orchestra orchestra)
 {
     if (orchestra != null)
     {
         var oldOrchestra = FindOrchestra(orchestra.Id);
         if (oldOrchestra != null)
         {
             oldOrchestra.Id           = orchestra.Id;
             oldOrchestra.Name         = orchestra.Name;
             oldOrchestra.AddressLine1 = orchestra.AddressLine1;
             oldOrchestra.AddressLine2 = orchestra.AddressLine2;
             oldOrchestra.City         = orchestra.City;
             oldOrchestra.State        = orchestra.State;
             oldOrchestra.ZipCode      = orchestra.ZipCode;
             oldOrchestra.WebsiteUrl   = orchestra.WebsiteUrl;
             _db.SaveChanges();
         }
     }
 }
コード例 #24
0
ファイル: ChordTests.cs プロジェクト: Sk41d/MidiGremlin
        public void WithBaseToneIndexerTest(double start, double def)
        {
            ChordVariety acd = new ChordVariety(1, 4, 7)
            {
                DefaultDuration = def
            };
            Orchestra  orc = new Orchestra(NSubstitute.Substitute.For <IMidiOut>());
            Instrument ins = orc.AddInstrument(InstrumentType.Violin);

            List <SingleBeat> v    = acd[Tone.CSharp].GetChildren(ins, start).ToList();
            List <SingleBeat> comp = new List <SingleBeat>
            {
                new SingleBeat(InstrumentType.Violin, 61, 64, start, start + acd.DefaultDuration),
                new SingleBeat(InstrumentType.Violin, 64, 64, start, start + acd.DefaultDuration),
                new SingleBeat(InstrumentType.Violin, 67, 64, start, start + acd.DefaultDuration)
            };

            CollectionAssert.AreEqual(comp, v);
        }
コード例 #25
0
    public void DeserializeObject(string filename)
    {
        XmlAttributeOverrides attrOverrides =
            new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Create an XmlElementAttribute to override the Instrument.
        XmlElementAttribute attr = new XmlElementAttribute();

        attr.ElementName = "Brass";
        attr.Type        = typeof(Brass);

        // Add the XmlElementAttribute to the collection of objects.
        attrs.XmlElements.Add(attr);

        attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

        // Create the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(typeof(Orchestra), attrOverrides);

        FileStream fs   = new FileStream(filename, FileMode.Open);
        Orchestra  band = (Orchestra)s.Deserialize(fs);

        Console.WriteLine("Brass:");

        /* The difference between deserializing the overridden
         * XML document and serializing it is this: To read the derived
         * object values, you must declare an object of the derived type
         * (Brass), and cast the Instrument instance to it. */
        Brass b;

        foreach (Instrument i in band.Instruments)
        {
            b = (Brass)i;
            Console.WriteLine(
                b.Name + "\n" +
                b.IsValved);
        }
    }
コード例 #26
0
    static void serialize(string filename)
    {
        Orchestra o = new Orchestra();

        o.Instruments = new Instrument[]
        {
            new Brass
            {
                IsValved = true
            },
            new Brass {
                IsValved = false
            },
            new Guitar {
                Strings = 12
            }
        };
        using (FileStream fs = new FileStream(filename, FileMode.Create))
        {
            s.Serialize(fs, o);
        }
    }
コード例 #27
0
    public void DeserializeObject(string filename)
    {
        XmlAttributeOverrides attrOverrides =
            new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that override the Instrument type.
        XmlElementAttribute attr = new
                                   XmlElementAttribute(typeof(Brass));

        attr.ElementName = "Brass";

        // Adds the element to the collection of elements.
        attrs.XmlElements.Add(attr);
        attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(typeof(Orchestra), attrOverrides);

        FileStream fs   = new FileStream(filename, FileMode.Open);
        Orchestra  band = (Orchestra)s.Deserialize(fs);

        Console.WriteLine("Brass:");

        /* Deserializing differs from serializing. To read the
         * derived-object values, declare an object of the derived
         * type (Brass) and cast the Instrument instance to it. */
        Brass b;

        foreach (Instrument i in band.Instruments)
        {
            b = (Brass)i;
            Console.WriteLine(
                b.Name + "\n" +
                b.IsValved);
        }
    }
コード例 #28
0
    public void SerializeObject(string filename)
    {
        // To write the file, a TextWriter is required.
        TextWriter writer = new StreamWriter(filename);

        XmlAttributeOverrides attrOverrides =
            new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that overrides the Instrument type.
        XmlElementAttribute attr = new
                                   XmlElementAttribute(typeof(Brass));

        attr.ElementName = "Brass";

        // Adds the element to the collection of elements.
        attrs.XmlElements.Add(attr);
        attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(typeof(Orchestra), attrOverrides);

        // Creates the object to serialize.
        Orchestra band = new Orchestra();

        // Creates an object of the derived type.
        Brass i = new Brass();

        i.Name     = "Trumpet";
        i.IsValved = true;
        Instrument[] myInstruments = { i };
        band.Instruments = myInstruments;
        s.Serialize(writer, band);
        writer.Close();
    }
コード例 #29
0
        private void cmdOrchestra_Click(object sender, RoutedEventArgs e)
        {
            var orchestra = new Orchestra();

            orchestra.Show();
        }
コード例 #30
0
        static void Main(string[] args)
        {
            #region Orchestra
            const int midiDeviceId   = 0;           //Most computers will only have this one.
            const int beatsPerSecond = 60;          //Tempo of the music. 60 beats per second 1 one beat equals 1 second.
            IMidiOut  output         = new WinmmOut(midiDeviceId, beatsPerSecond);
            Orchestra orchestra      = new Orchestra(output);

            Instrument piano = orchestra.AddInstrument(InstrumentType.BrightAcousticPiano);
            #endregion

            #region SingleSound

            //Play a single sound
            piano.Play(Tone.C, 1);
            orchestra.WaitForFinished();

            #endregion

            #region MusicObjects
            MusicObject longF  = new Note(Tone.F, 1);
            MusicObject shortF = new Note(Tone.F, 0.5);
            MusicObject longA  = new Note(Tone.A, 1);
            MusicObject shortA = new Note(Tone.A, 0.5);
            MusicObject longG  = new Note(Tone.G, 1);
            MusicObject shortG = new Note(Tone.G, 0.5);


            Console.WriteLine("Press enter to play a single sound");
            Console.ReadLine();
            //We can play any of those on an instrument if we wish
            piano.Play(shortG);
            orchestra.WaitForFinished();

            #endregion

            #region LargeMusicObject

            //Create 2 smaller MusicObjects made out of the base pieces
            MusicObject sequence1 = new SequentialMusicList(longF, shortA, longG, shortA);
            MusicObject sequence2 = new SequentialMusicList(shortA, shortA, shortA, longA, shortF);

            //Now create a bigger MusicObject made of those 2 smaller ones and one new
            SequentialMusicList bigMusicObject = new SequentialMusicList(sequence1, sequence1, sequence2, new Note(Tone.D, 2));

            //We can play this too
            //We can play any of those on an instrument if we wish
            Console.WriteLine("Press enter to play a longer sequence of sound");
            Console.ReadLine();
            piano.Play(bigMusicObject);
            orchestra.WaitForFinished();

            #endregion

            #region Transformation
            //Make the 1st object a little lower on the scale, using a transform
            int[] offsets = { 0, -3, -3, -2 };
            bigMusicObject[1] = bigMusicObject[1].Select <Note>((x, y) => x.OffsetBy(Scale.MajorScale, offsets[y]));

            //Play our final piece.
            Console.WriteLine("Press enter to play \"Drømte mig en drøm i nat\", ");
            Console.ReadLine();
            piano.Play(bigMusicObject);
            orchestra.WaitForFinished();

            //You have just heard https://en.wikipedia.org/wiki/Dr%C3%B8mde_mik_en_dr%C3%B8m_i_nat
            #endregion

            #region OtherInstrument
            //Create a flute
            Instrument flute = orchestra.AddInstrument(InstrumentType.Flute);



            Console.WriteLine("Press enter to play \"Drømte mig en drøm i nat\" on a flute");
            Console.ReadLine();
            flute.Play(bigMusicObject);
            orchestra.WaitForFinished();
            #endregion

            #region TransformToChords
            //Using Select<>() it's also possible to change the type of a MusicObject.
            ChordVariety minor    = ChordVariety.Minor;
            MusicObject  asChords = bigMusicObject.Select <Note>(n => minor.WithBaseTone(n.Keystroke.Tone, n.Pause.Duration));

            Console.WriteLine("Press enter to play \"Drømte mig en drøm i nat\" as minor.");
            Console.ReadLine();

            piano.Play(asChords);

            orchestra.WaitForFinished();
            #endregion
        }