public Boolean addNewGp(int gpID, string firstName, string lastName, string address, string phone, string email) { try { int maxId = 0; //need some code to avoid dulicate usernames //maybe add some logic (busiess rules) about password policy //IUser user = new User(name, password, userType); // Construct a User Object foreach (Gp gp in GpList) { if (gp.GpID > maxId) { maxId = gp.GpID; } } IGp theGp = GpFactory.GetGp(maxId + 1, firstName, lastName, address, phone, email); // Using a Factory to create the user entity object. ie seperating object creation from business logic GpList.Add(theGp); // Add a reference to the newly created object to the Models UserList DataLayer.addNewGpToDB(theGp); //Gets the DataLayer to add the new user to the DB. return(true); } catch (System.Exception excep) { return(false); } }
public static TabFile CreateFromGp(Stream stream) { TabFile file = new TabFile(); var gpFile = GpFactory.CreateFile(stream); int tracksCount = gpFile.Body.Tracks.Length; int measureTrackPairsCount = gpFile.Body.MeasureTrackPairs.Length; int measureCount = gpFile.Body.Measures.Length; //tracks init for (int i = 0; i < tracksCount; i++) { //TODO: init track header Track track = new Track { Index = i, Name = gpFile.Body.Tracks[i].Name, IsDrum = gpFile.Body.Tracks[i].IsDrumsTrack, StringNumber = gpFile.Body.Tracks[i].StringNumber }; for (int j = 0; j < measureCount; j++) { // if ((j + i) % tracksCount != 0) // continue;//other track measure //TODO init measure Measure measure = new Measure(); measure.NumeratorSignature = gpFile.Body.Measures[j].NumeratorSignature; measure.DenominatorSignature = gpFile.Body.Measures[j].DenominatorSignature; measure.StringsNumber = gpFile.Body.Tracks[i].StringNumber; //TODO: ambiguous usage foreach (var gpBeat in gpFile.Body.MeasureTrackPairs[j * tracksCount + i].Beats) { //TODO init beat Beat beat = new Beat(); beat.Duration = (Tablature.Duration)gpBeat.Duration; beat.Tuplet = gpBeat.NTuplet; beat.IsDotted = gpBeat.DottedNotes; //TODO this is for 6-strings only var stringCount = gpBeat.Strings.Length; beat.Notes = new List <Note>(); for (int s = 0; s < stringCount; s++) { beat.Notes.Add(new Note() { Fret = "" }); } int noteIndex = 0; for (int stringIndex = 0; stringIndex < stringCount; stringIndex++) { var gpIdx = stringCount - 1 - stringIndex; if (!gpBeat.Strings[gpIdx]) { continue; } var effects = gpBeat.Notes[noteIndex].Effects ?? new EffectsOnNote(); beat.Notes[stringIndex] = new Note() { Fret = gpBeat.Notes[noteIndex].FretNumber.ToString(), IsLegato = effects.HammerOnPullOff, Bend = effects.Bend == null ? null : new Bend(), Slide = effects.Slide == PhoneGuitarTab.Tablature.GuitarPro.Slide.NoSlide ? null : new Slide() }; noteIndex++; } measure.Beats.Add(beat); } track.Measures.Add(measure); } file.Tracks.Add(track); } return(file); }