Merge branch 'develop'

This commit is contained in:
Mark McDowall 2014-01-06 17:16:33 -08:00
commit 8b5811cc62
13 changed files with 93 additions and 26 deletions

View File

@ -2,4 +2,5 @@
<configuration>
<dllmap os="osx" dll="MediaInfo.dll" target="libmediainfo.dylib"/>
<dllmap os="linux" dll="MediaInfo.dll" target="libmediainfo.so.0" />
<dllmap os="freebsd" dll="MediaInfo.dll" target="libmediainfo.so.0" />
</configuration>

View File

@ -0,0 +1,67 @@
using System;
using System.Data;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(33)]
public class add_api_key_to_pushover : NzbDroneMigrationBase
{
private const string API_KEY = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
protected override void MainDbUpgrade()
{
Execute.WithConnection(UpdatePushoverSettings);
}
private void UpdatePushoverSettings(IDbConnection conn, IDbTransaction tran)
{
using (IDbCommand selectCommand = conn.CreateCommand())
{
selectCommand.Transaction = tran;
selectCommand.CommandText = @"SELECT * FROM Notifications WHERE ConfigContract = 'PushoverSettings'";
using (IDataReader reader = selectCommand.ExecuteReader())
{
while (reader.Read())
{
var idIndex = reader.GetOrdinal("Id");
var settingsIndex = reader.GetOrdinal("Settings");
var id = reader.GetInt32(idIndex);
var settings = Json.Deserialize<PushoverSettingsForV33>(reader.GetString(settingsIndex));
settings.ApiKey = API_KEY;
//Set priority to high if its currently emergency
if (settings.Priority == 2)
{
settings.Priority = 1;
}
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = String.Format("UPDATE Notifications " +
"SET Settings = '{0}'" +
"WHERE Id = {1}",
settings.ToJson(), id
);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;
updateCmd.ExecuteNonQuery();
}
}
}
}
}
private class PushoverSettingsForV33
{
public String ApiKey { get; set; }
public String UserKey { get; set; }
public Int32 Priority { get; set; }
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using System.IO;
using Newtonsoft.Json;
using NLog;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;

View File

@ -44,10 +44,10 @@ namespace NzbDrone.Core.Download
var downloadClientId = downloadClient.DownloadNzb(remoteEpisode);
var episodeGrabbedEvent = new EpisodeGrabbedEvent(remoteEpisode);
episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name;
if (!String.IsNullOrWhiteSpace(downloadClientId))
{
episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name;
episodeGrabbedEvent.DownloadClientId = downloadClientId;
}

View File

@ -132,14 +132,20 @@ namespace NzbDrone.Core.Download
private void PublishDownloadFailedEvent(List<History.History> historyItems, string message)
{
var historyItem = historyItems.First();
string downloadClient;
string downloadClientId;
historyItem.Data.TryGetValue(DOWNLOAD_CLIENT, out downloadClient);
historyItem.Data.TryGetValue(DOWNLOAD_CLIENT_ID, out downloadClientId);
_eventAggregator.PublishEvent(new DownloadFailedEvent
{
SeriesId = historyItem.SeriesId,
EpisodeIds = historyItems.Select(h => h.EpisodeId).ToList(),
Quality = historyItem.Quality,
SourceTitle = historyItem.SourceTitle,
DownloadClient = historyItem.Data[DOWNLOAD_CLIENT],
DownloadClientId = historyItem.Data[DOWNLOAD_CLIENT_ID],
DownloadClient = downloadClient,
DownloadClientId = downloadClientId,
Message = message
});
}

View File

@ -103,10 +103,10 @@ namespace NzbDrone.Core.History
history.Data.Add("NzbInfoUrl", message.Episode.Release.InfoUrl);
history.Data.Add("ReleaseGroup", message.Episode.ParsedEpisodeInfo.ReleaseGroup);
history.Data.Add("Age", message.Episode.Release.Age.ToString());
history.Data.Add("DownloadClient", message.DownloadClient);
if (!String.IsNullOrWhiteSpace(message.DownloadClientId))
{
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClientId", message.DownloadClientId);
}

View File

@ -20,14 +20,14 @@ namespace NzbDrone.Core.Notifications.Pushover
{
const string title = "Episode Grabbed";
_pushoverProxy.SendNotification(title, message, Settings.UserKey, (PushoverPriority)Settings.Priority);
_pushoverProxy.SendNotification(title, message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority);
}
public override void OnDownload(DownloadMessage message)
{
const string title = "Episode Downloaded";
_pushoverProxy.SendNotification(title, message.Message, Settings.UserKey, (PushoverPriority)Settings.Priority);
_pushoverProxy.SendNotification(title, message.Message, Settings.ApiKey, Settings.UserKey, (PushoverPriority)Settings.Priority);
}
public override void AfterRename(Series series)

View File

@ -5,6 +5,6 @@
Quiet = -1,
Normal = 0,
High = 1,
Emergency = 2
//Emergency = 2
}
}

View File

@ -6,19 +6,18 @@ namespace NzbDrone.Core.Notifications.Pushover
{
public interface IPushoverProxy
{
void SendNotification(string title, string message, string userKey, PushoverPriority priority);
void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority);
}
public class PushoverProxy : IPushoverProxy, IExecute<TestPushoverCommand>
{
private const string TOKEN = "yz9b4U215iR4vrKFRfjNXP24NMNPKJ";
private const string URL = "https://api.pushover.net/1/messages.json";
public void SendNotification(string title, string message, string userKey, PushoverPriority priority)
public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority)
{
var client = new RestClient(URL);
var request = new RestRequest(Method.POST);
request.AddParameter("token", TOKEN);
request.AddParameter("token", apiKey);
request.AddParameter("user", userKey);
request.AddParameter("title", title);
request.AddParameter("message", message);
@ -32,7 +31,7 @@ namespace NzbDrone.Core.Notifications.Pushover
const string title = "Test Notification";
const string body = "This is a test message from NzbDrone";
SendNotification(title, body, message.UserKey, (PushoverPriority)message.Priority);
SendNotification(title, body, message.ApiKey, message.UserKey, (PushoverPriority)message.Priority);
}
}
}

View File

@ -18,10 +18,13 @@ namespace NzbDrone.Core.Notifications.Pushover
{
private static readonly PushoverSettingsValidator Validator = new PushoverSettingsValidator();
[FieldDefinition(0, Label = "User Key", HelpLink = "https://pushover.net/")]
[FieldDefinition(0, Label = "API Key", HelpLink = "https://pushover.net/apps/clone/nzbdrone")]
public String ApiKey { get; set; }
[FieldDefinition(1, Label = "User Key", HelpLink = "https://pushover.net/")]
public String UserKey { get; set; }
[FieldDefinition(1, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
[FieldDefinition(2, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority) )]
public Int32 Priority { get; set; }
public bool IsValid

View File

@ -12,6 +12,8 @@ namespace NzbDrone.Core.Notifications.Pushover
return true;
}
}
public string ApiKey { get; set; }
public string UserKey { get; set; }
public int Priority { get; set; }
}

View File

@ -189,6 +189,7 @@
<Compile Include="Datastore\Migration\031_delete_old_naming_config_columns.cs" />
<Compile Include="Datastore\Migration\030_add_season_folder_format_to_naming_config.cs" />
<Compile Include="Datastore\Migration\032_set_default_release_group.cs" />
<Compile Include="Datastore\Migration\033_add_api_key_to_pushover.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

View File

@ -29,7 +29,6 @@ define(
var tryingToReconnect = false;
var messengerId = 'signalR';
var reconnectTimeout;
this.signalRconnection = $.connection('/signalr');
@ -47,19 +46,9 @@ define(
}
tryingToReconnect = true;
reconnectTimeout = window.setTimeout(function () {
Messenger.show({
id : messengerId,
type : 'info',
hideAfter : 0,
message : 'Connection to backend lost, attempting to reconnect'
});
}, 10000);
});
this.signalRconnection.reconnected(function() {
window.clearTimeout(reconnectTimeout);
tryingToReconnect = false;
var currentVersion = StatusModel.get('version');