Esempio n. 1
0
        public void DownloadSongs(String folderName)
        {
            String tempFolderName = folderName + "\\Temp";

            CloudBlobClient             blobClient = azureService.GetCloudBlobContainer();
            CloudBlobContainer          container  = blobClient.GetContainerReference(containerName);
            IEnumerable <IListBlobItem> blobs      = container.ListBlobs();

            foreach (var blob in blobs)
            {
                Debug.WriteLine("{0}", blob.Uri);
                int id = Convert.ToInt32(blob.Uri.Segments[2]);

                SONG song = null;
                using (var context = new MusicEntities())
                {
                    var result = (from s in context.SONG
                                  where s.ID == id
                                  select s);
                    if (result.Count() > 0)
                    {
//                        song = result.First();
                        OnSongFound(song, folderName);
                    }
                    else
                    {
                        Debug.WriteLine("No song record for blob {0}", id);
                        OnSongNotFound(id.ToString(), tempFolderName);
                    }
                }
            }
        }
Esempio n. 2
0
        public void DownloadSong(SONG song, String folderName)
        {
            try
            {
                FileInfo fileInfo     = new FileInfo(song.LOCATION);
                String[] s            = song.LOCATION.Split(new char[] { '\\' });
                String   artistFolder = null;
                String   name         = fileInfo.Name;
                String   fileName     = null;
                if (s.Length > 3)
                {
                    artistFolder = folderName;
                    for (int i = 2; i < s.Length - 1; i++)
                    {
                        artistFolder = artistFolder + "\\" + s[i];
                        DirectoryInfo directoryInfo = new DirectoryInfo(artistFolder);
                        if (!directoryInfo.Exists)
                        {
                            Directory.CreateDirectory(artistFolder);
                        }
                    }
                    fileName = String.Format("{0}\\{1}", artistFolder, name);
                }
                else
                {
                    fileName = String.Format("{0}\\{1}", folderName, name);
                }

                if (!File.Exists(fileName))
                {
                    Debug.WriteLine(String.Format("Downloading {0}", fileName));
                    azureService.DownloadFile("songs", fileName, song.ID.ToString());
                }
                else
                {
                    Debug.WriteLine(String.Format("Song already exists:  {0}", fileName));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        public void DrainQueue()
        {
            Tuple <String, String> fileInfo;

            while ((running == true) && (queue.Count > 0))
            {
                if (queue.TryDequeue(out fileInfo))
                {
                    try
                    {
                        string filename = fileInfo.Item1;
                        string key      = fileInfo.Item2;
                        FilesUploaded++;
                        Debug.WriteLine("Uploading: " + filename);
                        azureService.StoreFile(filename, containerName, key);
                        var song = new SONG()
                        {
                            ID = Convert.ToInt32(key), UPLOADED = true
                        };
                        musicDao.UpdateSongUploadStatus(song);
                        Debug.WriteLine("Upload succeeded: " + filename);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(String.Format("{0}:{1}", ex.Message, ex.StackTrace));
                    }
                }
                else if (running)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 4
0
 partial void DeleteSONG(SONG instance);
Esempio n. 5
0
 partial void UpdateSONG(SONG instance);
Esempio n. 6
0
 partial void InsertSONG(SONG instance);
Esempio n. 7
0
 public SongLocal(SONG song)
 {
 }