GetAsDatabaseType() public method

Returns the object as Database Type.
public GetAsDatabaseType ( ) : dynamic
return dynamic
 /// <summary>
 /// This method shows the use and the functionality of some repository methods.
 /// <c>
 /// Insert a new Track in the Database, Count all elements and the Load it all! Then delete a item and Load it all again
 /// </c>
 /// </summary>
 public static void InsertCountLoadAllDeleteAndLoadAgain()
 {
     ExampleHelper.ExampleMethodPrint("Insert a new Track in the Database, Count all elements and the Load it all!\n"+
                                         "Then delete a item and Load it all again", MethodInfo.GetCurrentMethod());
     TrackModel track = new TrackModel(@"..\..\Resource\Garden.mp3");
     ExampleHelper.DumpObjectProperties(track.GetAsDatabaseType());
     Console.WriteLine("Save Response : " + _trackRep.Save(track));
     Console.WriteLine("Count : " + _trackRep.Count<TrackModel.Track>());
     List<TrackModel.Track> list = new List<TrackModel.Track>();
     Console.WriteLine("GetAll Response : " + _trackRep.GetAll(list));
     foreach (TrackModel.Track t in list)
     {
         ExampleHelper.DumpObjectProperties(t);
     }
     TrackModel anotherTrack = new TrackModel();
     Console.WriteLine("Delete Response: " + _trackRep.Delete<TrackModel.Track>(list.First().Id));
     list.Clear();
     Console.WriteLine("GetAll Response : " + _trackRep.GetAll(list));
     foreach (TrackModel.Track t in list)
     {
         ExampleHelper.DumpObjectProperties(t);
     }
 }
 /// <summary>
 /// This example shows how to load from the repository a previously stored track.
 /// </summary>
 public static void LoadTrackFromDb()
 {
     ExampleHelper.ExampleMethodPrint("Load a TrackModel from the database",MethodInfo.GetCurrentMethod());
     TrackModel track= new TrackModel();
     RepositoryResponse resp = _trackRep.GetByKey<TrackModel.Track>(_hid, track);
     Console.WriteLine("Response : "+resp);
     if (resp>=0) {
         ExampleHelper.DumpObjectProperties(track.GetAsDatabaseType());
     }
 }
 /// <summary>
 /// This example shows how to save a track in a generic repository
 /// </summary>
 public static void StoreTrackInDb()
 {
     ExampleHelper.ExampleMethodPrint("Create a TrackModel from file and store it in the database",MethodInfo.GetCurrentMethod());
     TrackModel track = new TrackModel("..\\..\\Resource\\SevenMP3.mp3");
     _hid = track.GetAsDatabaseType().Id;
     ExampleHelper.DumpObjectProperties(track.GetAsDatabaseType());
     Console.WriteLine("Response : "+_trackRep.Save(track));
 }
Example #4
0
 /// <summary>
 /// <see cref="PeerLibrary.IPeer"/>
 /// </summary>
 /// <param name="filename">filename of the file to download</param>
 /// <returns>true if the filename have been store; false otherwise</returns>
 public bool StoreFile(string filename)
 {
     log.Info("Storing file:" + filename);
     TrackModel track = new TrackModel(filename);
     TrackModel sameTk = new TrackModel();
     this.trackRep.GetByKey<TrackModel.Track>(track.GetAsDatabaseType().Id, sameTk);
     if ((sameTk != null) && (sameTk.GetAsDatabaseType().Id == track.GetAsDatabaseType().Id))
     {
         log.Warn("Unable to store duplicate file "+filename+" !");
         return false;
     }
     else
     {
         this.trackRep.Save(track);
         this.kademliaLayer.Put(filename);
         return true;
     }
 }