Skip to content

Commit

Permalink
Create Warehouse Reports job is done!
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay committed Jan 29, 2014
1 parent 2486f7a commit 9899c1a
Show file tree
Hide file tree
Showing 37 changed files with 926 additions and 226 deletions.
114 changes: 0 additions & 114 deletions src/Services/NuGet.Services.Platform.Client/AzureStorageReference.cs

This file was deleted.

32 changes: 29 additions & 3 deletions src/Services/NuGet.Services.Platform.Client/Client/JsonFormat.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace NuGet.Services.Client
public static class JsonFormat public static class JsonFormat
{ {
private static JsonSerializerSettings _serializerSettings; private static JsonSerializerSettings _serializerSettings;
private static JsonSerializerSettings _nonCamelCasedSettings;
private static JsonMediaTypeFormatter _formatter; private static JsonMediaTypeFormatter _formatter;


public static JsonSerializerSettings SerializerSettings { get { return _serializerSettings; } } public static JsonSerializerSettings SerializerSettings { get { return _serializerSettings; } }
Expand All @@ -38,6 +39,22 @@ static JsonFormat()
TypeNameHandling = TypeNameHandling.None TypeNameHandling = TypeNameHandling.None
}; };
_serializerSettings.Converters.Add(new StringEnumConverter()); _serializerSettings.Converters.Add(new StringEnumConverter());

_nonCamelCasedSettings = new JsonSerializerSettings()
{
// ContractResolver = ...
DateFormatHandling = _serializerSettings.DateFormatHandling,
DateParseHandling = _serializerSettings.DateParseHandling,
DateTimeZoneHandling = _serializerSettings.DateTimeZoneHandling,
DefaultValueHandling = _serializerSettings.DefaultValueHandling,
Formatting = _serializerSettings.Formatting,
MissingMemberHandling = _serializerSettings.MissingMemberHandling,
NullValueHandling = _serializerSettings.NullValueHandling,
ReferenceLoopHandling = _serializerSettings.ReferenceLoopHandling,
TypeNameHandling = _serializerSettings.TypeNameHandling
};
_serializerSettings.Converters.Add(new StringEnumConverter());

_formatter = new JsonMediaTypeFormatter() _formatter = new JsonMediaTypeFormatter()
{ {
SerializerSettings = _serializerSettings SerializerSettings = _serializerSettings
Expand All @@ -52,8 +69,10 @@ public static T Deserialize<T>(string content)
return JsonConvert.DeserializeObject<T>(content, _serializerSettings); return JsonConvert.DeserializeObject<T>(content, _serializerSettings);
} }


public static string Serialize(object data) public static string Serialize(object data) { return Serialize(data, camelCase: true); }
public static string Serialize(object data, bool camelCase)
{ {
var settings = camelCase ? _serializerSettings : _nonCamelCasedSettings;
return JsonConvert.SerializeObject(data, _serializerSettings); return JsonConvert.SerializeObject(data, _serializerSettings);
} }


Expand All @@ -62,9 +81,11 @@ public static Task<T> DeserializeAsync<T>(string content)
return JsonConvert.DeserializeObjectAsync<T>(content, _serializerSettings); return JsonConvert.DeserializeObjectAsync<T>(content, _serializerSettings);
} }


public static Task<string> SerializeAsync(object data) public static Task<string> SerializeAsync(object data) { return SerializeAsync(data, camelCase: true); }
public static Task<string> SerializeAsync(object data, bool camelCase)
{ {
return JsonConvert.SerializeObjectAsync(data, _serializerSettings.Formatting, _serializerSettings); var settings = camelCase ? _serializerSettings : _nonCamelCasedSettings;
return JsonConvert.SerializeObjectAsync(data, settings.Formatting, settings);
} }
} }


Expand All @@ -77,5 +98,10 @@ protected override JsonDictionaryContract CreateDictionaryContract(Type objectTy
contract.PropertyNameResolver = new Func<string, string>(s => s); contract.PropertyNameResolver = new Func<string, string>(s => s);
return contract; return contract;
} }

protected override JsonObjectContract CreateObjectContract(Type objectType)
{
return base.CreateObjectContract(objectType);
}
} }
} }
21 changes: 21 additions & 0 deletions src/Services/NuGet.Services.Platform.Client/Constants.cs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuGet.Services
{
public static class BlobContainerNames
{
public static readonly string LegacyPackages = "packages";
public static readonly string LegacyStats = "stats";

public static readonly string Backups = "ng-backups";
}

public static class MimeTypes
{
public static readonly string Json = "application/json";
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AzureStorageReference.cs" />
<Compile Include="Client\JsonFormat.cs" /> <Compile Include="Client\JsonFormat.cs" />
<Compile Include="Client\ServiceResponse.cs" /> <Compile Include="Client\ServiceResponse.cs" />
<Compile Include="Constants.cs" />
<Compile Include="CredentialProviderHandler.cs" /> <Compile Include="CredentialProviderHandler.cs" />
<Compile Include="ICredentialProvider.cs" /> <Compile Include="ICredentialProvider.cs" />
<Compile Include="Models\AssemblyFullNameConverter.cs" /> <Compile Include="Models\AssemblyFullNameConverter.cs" />
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class StorageConfiguration : ICustomConfigurationSection
{ {
public Dictionary<KnownStorageAccount, CloudStorageAccount> Accounts { get; private set; } public Dictionary<KnownStorageAccount, CloudStorageAccount> Accounts { get; private set; }


public CloudStorageAccount Primary { get { return GetAccount(KnownStorageAccount.Primary); } }
public CloudStorageAccount Legacy { get { return GetAccount(KnownStorageAccount.Legacy); } }
public CloudStorageAccount Backup { get { return GetAccount(KnownStorageAccount.Backup); } }

public CloudStorageAccount GetAccount(KnownStorageAccount account) public CloudStorageAccount GetAccount(KnownStorageAccount account)
{ {
CloudStorageAccount connectionString; CloudStorageAccount connectionString;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


namespace NuGet.Services namespace NuGet.Services
{ {
[EventSource("Outercurve-NuGet-Services")] [EventSource(Name="Outercurve-NuGet-Services")]
public class ServicePlatformEventSource : EventSource public class ServicePlatformEventSource : EventSource
{ {
public static readonly ServicePlatformEventSource Log = new ServicePlatformEventSource(); public static readonly ServicePlatformEventSource Log = new ServicePlatformEventSource();
Expand Down
31 changes: 0 additions & 31 deletions src/Services/NuGet.Services.Platform/Storage/StorageHub.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,37 +40,6 @@ public StorageHub(StorageAccountHub primary, StorageAccountHub backup, StorageAc
Legacy = legacy; Legacy = legacy;
} }


public StorageAccountHub GetAccount(AzureStorageReference reference)
{
if (String.Equals(reference.AccountName, ".", StringComparison.OrdinalIgnoreCase))
{
// Emulator!
return new StorageAccountHub(CloudStorageAccount.DevelopmentStorageAccount);
}

Func<StorageHub, StorageAccountHub> handler;
if (!_knownAccounts.TryGetValue(reference.AccountName, out handler))
{
return new StorageAccountHub(
new CloudStorageAccount(
new StorageCredentials(
reference.AccountName,
reference.AccountKey),
useHttps: true));
}
return handler(this);
}

public CloudBlobContainer GetContainer(AzureStorageReference reference)
{
var account = GetAccount(reference);
if (account == null)
{
return null;
}
return account.Blobs.Client.GetContainerReference(reference.Container);
}

private static StorageAccountHub TryLoadAccount(ConfigurationHub configuration, KnownStorageAccount account) private static StorageAccountHub TryLoadAccount(ConfigurationHub configuration, KnownStorageAccount account)
{ {
var connectionString = configuration.Storage.GetAccount(account); var connectionString = configuration.Storage.GetAccount(account);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ namespace NuGet.Services.Work
{ {
public static class PackageHelpers public static class PackageHelpers
{ {
public static readonly string PackageBlobContainer = "packages";
public static readonly string BackupsBlobContainer = "ng-backups";

private const string PackageBlobNameFormat = "{0}.{1}.nupkg"; private const string PackageBlobNameFormat = "{0}.{1}.nupkg";
private const string PackageBackupBlobNameFormat = "packages/{0}/{1}/{2}.nupkg"; private const string PackageBackupBlobNameFormat = "packages/{0}/{1}/{2}.nupkg";


Expand Down
27 changes: 27 additions & 0 deletions src/Services/Work/NuGet.Services.Work/Helpers/ResourceHelpers.cs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace NuGet.Services.Work.Helpers
{
public static class ResourceHelpers
{
public static Task<string> ReadResourceFile(string name)
{
return ReadResourceFile(name, typeof(ResourceHelpers).Assembly);
}

public static async Task<string> ReadResourceFile(string name, Assembly asm)
{
using (var stream = asm.GetManifestResourceStream(name))
using (var reader = new StreamReader(stream))
{
return await reader.ReadToEndAsync();
}
}
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Data.SqlClient; using System.Data.SqlClient;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using Microsoft.WindowsAzure.Storage;


namespace NuGet.Services.Work namespace NuGet.Services.Work
{ {
Expand Down Expand Up @@ -135,7 +136,7 @@ protected virtual void BindProperty(PropertyDescriptor prop, string value)


private IList<TypeConverter> _converters = new List<TypeConverter>() { private IList<TypeConverter> _converters = new List<TypeConverter>() {
new SqlConnectionStringBuilderConverter(), new SqlConnectionStringBuilderConverter(),
new AzureStorageAccountConverter() new CloudStorageAccountConverter()
}; };


protected virtual object ConvertPropertyValue(PropertyDescriptor prop, string value) protected virtual object ConvertPropertyValue(PropertyDescriptor prop, string value)
Expand Down Expand Up @@ -171,31 +172,26 @@ public override object ConvertFrom(ITypeDescriptorContext context, System.Global
} }
} }


private class AzureStorageAccountConverter : TypeConverter private class CloudStorageAccountConverter : TypeConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{ {
return sourceType == typeof(string) || sourceType == typeof(Uri); return sourceType == typeof(string);
} }


public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{ {
return destinationType == typeof(AzureStorageReference); return destinationType == typeof(CloudStorageAccount);
} }


public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{ {
Uri url = value as Uri; string strVal = value as string;
if (url == null) if (strVal == null)
{ {
string strVal = value as string; return null;
if (strVal == null)
{
return null;
}
url = new Uri(strVal);
} }
return AzureStorageReference.Create(url); return CloudStorageAccount.Parse(strVal);
} }
} }
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ COMMIT TRANSACTION
"; ";
} }


[EventSource("Outercurve-NuGet-Jobs-AggregateStatistics")] [EventSource(Name="Outercurve-NuGet-Jobs-AggregateStatistics")]
public class AggregateStatisticsEventSource : EventSource public class AggregateStatisticsEventSource : EventSource
{ {
public static readonly AggregateStatisticsEventSource Log = new AggregateStatisticsEventSource(); public static readonly AggregateStatisticsEventSource Log = new AggregateStatisticsEventSource();
Expand Down
Loading

0 comments on commit 9899c1a

Please sign in to comment.