Example #1
0
        public static void UpdateMediaRemoteStatus()
        {
            using (_amazon = new AmazonCloudService()) {

                using (var session = new SongSearchDataSession()) {

                    var contents = session.All<Content>().Where(c => c.HasMediaFullVersion).ToList();

                    var remoteContents = _amazon.GetContentList(MediaVersion.Full);

                    foreach (var content in contents) {
                        string key = _amazon.GetContentKey(content.ContentMedia.FullVersion());
                        var remoteObject = remoteContents.FirstOrDefault(x => x.Key == key);

                        if (remoteObject == null) {
                            content.IsMediaOnRemoteServer = false;
                            Console.WriteLine(String.Format("{0} '{1}' - {2}", content.ContentId,
                                content.Title,
                                "----------------------> missing"));

                        } else {
                            content.IsMediaOnRemoteServer = true;

                        }
                        //Console.WriteLine(String.Format("{0} '{1}' - {2}", content.ContentId,
                        //    content.Title,
                        //    remoteObject != null ? "synced!" : "----------------------> missing"));

                        if (remoteObject != null) {
                        } else {

                        }
                    }

                    session.CommitChanges();

                    Console.WriteLine("Done sync'ing");
                }
            }
        }
Example #2
0
        public static void Upload(MediaVersion version)
        {
            using (_amazon = new AmazonCloudService()) {

                using (var session = new SongSearchDataSession()) {

                    var contents = session.All<Content>().ToList();
                    var remoteContents = _amazon.GetContentList(version);
                    var remoteFolder = _amazon.GetContentPrefix(version);

                    foreach (var content in contents) {
                        var dbContent = session.Single<Content>(c => c.ContentId == content.ContentId);
                        var key = _amazon.GetContentKey(content.Media(version));
                        var filePath = Path.Combine(version == MediaVersion.Full ?
                            SystemConfig.MediaPathFull :
                            SystemConfig.MediaPathPreview,
                            String.Concat(content.ContentId,SystemConfig.MediaDefaultExtension)
                            );

                        var file = new FileInfo(filePath);
                        if (file.Exists) {
                            var remoteFile = remoteContents.SingleOrDefault(x => x.Key == key && x.Size == file.Length);

                            if (remoteFile == null) {

                                try {
                                    Console.WriteLine("Uploading " + file.Name + " to " + remoteFolder);
                                    _amazon.PutContentMedia(file.FullName, content.Media(version));
                                    dbContent.IsMediaOnRemoteServer = true;
                                }
                                catch (Exception ex){
                                    Console.WriteLine("FAILED: " + file.Name + "-------------------");
                                    Console.WriteLine("ERROR: " + ex.Message);
                                    dbContent.IsMediaOnRemoteServer = false;
                                }
                            } else {
                                dbContent.IsMediaOnRemoteServer = true;
                            }
                        } else {
                            dbContent.IsMediaOnRemoteServer = false;
                        }
                        session.CommitChanges();
                    }

                    Console.WriteLine("Done uploading");

                }
            }
        }