private void PopulateContent(ObservableCollection <IContentEntity> content) { unsorted = new BunnyUnsortedContentGroup(this.ID); content.Add(unsorted); using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "select [name] from [Folders] " + "where parent_folder = @parent " + "order by name desc"; cmd.Parameters.Add(new SQLiteParameter("@parent", this.Name)); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var dir = reader.GetString(0); content.Add(new BunnyContentGroup(Name, dir, this.ID)); } } } } if (!timerStarted) { timer.Change(1000, Timeout.Infinite); timerStarted = true; } }
private void populateContents(ObservableCollection <IContentEntity> contents) { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd2 = conn.CreateCommand()) { cmd2.CommandText = "SELECT * FROM Files t1, LabelFiles t2, Labels t3 where t3.label_id = @labelID and t3.label_id = t2.label_id and t1.file_id = t2.file_id order by t1.event_time asc"; cmd2.Parameters.Add(new SQLiteParameter("@labelID", new Guid(this.ID))); using (var dr2 = cmd2.ExecuteReader()) { while (dr2.Read()) { var deviceID = dr2["device_id"].ToString(); var savedPath = dr2["saved_path"].ToString(); var file = Path.Combine(BunnyDB.ResourceFolder, savedPath); var type = ((long)dr2["type"] == 0) ? ContentType.Photo : ContentType.Video; contents.Add(new BunnyContent(new Uri(file), dr2["file_id"].ToString(), type)); } } } } }
private void refreshRecipients() { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "select * from [LabelShareTo] where label_id = @label"; cmd.Parameters.Add(new SQLiteParameter("@label", new Guid(this.ID))); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var email = reader["email"].ToString(); var name = reader["name"].ToString(); var recipient = new BunnyRecipient(email, name); if (!m_recipients.Contains(recipient)) { m_recipients.Add(recipient); } } } } } }
private void refreshShareProperties() { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "select * from [labels] where label_id = @label"; cmd.Parameters.Add(new SQLiteParameter("@label", new Guid(this.ID))); using (var reader = cmd.ExecuteReader()) { var share_enabled = (bool)reader["share_enabled"]; var share_code = reader["share_code"].ToString(); if (share_enabled != this.ShareEnabled) { this.ShareEnabled = share_enabled; OnPropertyChanged("ShareEnabled"); } if (share_code != this.m_shareCode) { this.m_shareCode = share_code; OnPropertyChanged("ShareURL"); } } } } }
private List <Service> GetServices() { var services = new List <Service>(); using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM Devices"; using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { var folderName = dr["folder_name"].ToString(); var deviceId = dr["device_id"].ToString(); services.Add(new BunnyService(this, folderName, deviceId)); } } } return(services); } }
public static int countUnsortedItems(string deviceID) { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "select count(*) from [PendingFiles] where device_id = @dev"; cmd.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@dev", deviceID)); return((int)(long)cmd.ExecuteScalar()); } } }
public bool IsOnAir(IContentGroup group) { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "select on_air from [Labels] where label_id = @label"; cmd.Parameters.Add(new SQLiteParameter("@label", new Guid(group.ID))); var on_air = cmd.ExecuteScalar(); return(on_air != null && (bool)on_air); } } }
public BunnyContentGroup(string parentFolder, string name, string deviceId) : base(Path.Combine(BunnyDB.ResourceFolder, parentFolder, name).GetHashCode().ToString(), name, new Uri(Path.Combine(BunnyDB.ResourceFolder, parentFolder, name))) { this.parentFolder = parentFolder; this.DeviceId = deviceId; SetContents((contents) => { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); AddSubfolders(contents, conn); AddFiles(contents, conn); } }); }
private bool GetLiked() { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT 1 FROM LabelFiles where file_id = @fid and label_id = @label"; cmd.Parameters.Add(new SQLiteParameter("@fid", new Guid(ID))); cmd.Parameters.Add(new SQLiteParameter("@label", Guid.Empty)); var liked = cmd.ExecuteScalar() != null; return(liked); } } }
private IEnumerable <IContentEntity> GetFavorites() { using (var conn = BunnyDB.CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM Labels where auto_type == 0 and deleted == 0"; using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { var labelID = dr["label_id"].ToString(); var labelName = dr["name"].ToString(); var share_enabled = (bool)dr["share_enabled"]; var share_code = dr["share_code"].ToString(); yield return(new BunnyLabelContentGroup(labelID, labelName, share_enabled, share_code)); } } } } }