Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/UberStrok.Core.Serialization/DecimalProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.IO;

namespace UberStrok.Core.Serialization.Views
{
public static class DecimalProxy
{
public static void Serialize(Stream bytes, decimal instance)
{
int[] bits = decimal.GetBits(instance);
Int32Proxy.Serialize(bytes, bits[0]);
Int32Proxy.Serialize(bytes, bits[1]);
Int32Proxy.Serialize(bytes, bits[2]);
Int32Proxy.Serialize(bytes, bits[3]);
}

public static decimal Deserialize(Stream bytes)
{
int[] bits = new int[] {
Int32Proxy.Deserialize(bytes),
Int32Proxy.Deserialize(bytes),
Int32Proxy.Deserialize(bytes),
Int32Proxy.Deserialize(bytes)
};
return new decimal(bits);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Compile Include="ByteProxy.cs" />
<Compile Include="Common\ColorProxy.cs" />
<Compile Include="DateTimeProxy.cs" />
<Compile Include="DecimalProxy.cs" />
<Compile Include="DictionaryProxy.cs" />
<Compile Include="EnumProxy.cs" />
<Compile Include="Int16Proxy.cs" />
Expand All @@ -52,6 +53,7 @@
<Compile Include="Views\ApplicationConfigurationViewProxy.cs" />
<Compile Include="Views\AuthenticateApplicationViewProxy.cs" />
<Compile Include="Views\BundleItemViewProxy.cs" />
<Compile Include="Views\BundleViewProxy.cs" />
<Compile Include="Views\CommActorInfoViewProxy.cs" />
<Compile Include="Views\ConnectionAddressViewProxy.cs" />
<Compile Include="Views\DamageEventViewProxy.cs" />
Expand Down
166 changes: 166 additions & 0 deletions src/UberStrok.Core.Serialization/Views/BundleViewProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.IO;
using UberStrok.Core.Common;
using UberStrok.Core.Views;

namespace UberStrok.Core.Serialization.Views
{
public static class BundleViewProxy
{
public static void Serialize(Stream stream, BundleView instance)
{
int num = 0;
using (MemoryStream memoryStream = new MemoryStream())
{
if (instance.AndroidStoreUniqueId != null)
{
StringProxy.Serialize(memoryStream, instance.AndroidStoreUniqueId);
}
else
{
num |= 1;
}
Int32Proxy.Serialize(memoryStream, instance.ApplicationId);
if (instance.Availability != null)
{
ListProxy<ChannelType>.Serialize(memoryStream, instance.Availability, new ListProxy<ChannelType>.Serializer<ChannelType>(EnumProxy<ChannelType>.Serialize));
}
else
{
num |= 2;
}
if (instance.BundleItemViews != null)
{
ListProxy<BundleItemView>.Serialize(memoryStream, instance.BundleItemViews, new ListProxy<BundleItemView>.Serializer<BundleItemView>(BundleItemViewProxy.Serialize));
}
else
{
num |= 4;
}
EnumProxy<BundleCategoryType>.Serialize(memoryStream, instance.Category);
Int32Proxy.Serialize(memoryStream, instance.Credits);
if (instance.Description != null)
{
StringProxy.Serialize(memoryStream, instance.Description);
}
else
{
num |= 8;
}
if (instance.IconUrl != null)
{
StringProxy.Serialize(memoryStream, instance.IconUrl);
}
else
{
num |= 16;
}
Int32Proxy.Serialize(memoryStream, instance.Id);
if (instance.ImageUrl != null)
{
StringProxy.Serialize(memoryStream, instance.ImageUrl);
}
else
{
num |= 32;
}
if (instance.IosAppStoreUniqueId != null)
{
StringProxy.Serialize(memoryStream, instance.IosAppStoreUniqueId);
}
else
{
num |= 64;
}
BooleanProxy.Serialize(memoryStream, instance.IsDefault);
BooleanProxy.Serialize(memoryStream, instance.IsOnSale);
BooleanProxy.Serialize(memoryStream, instance.IsPromoted);
if (instance.MacAppStoreUniqueId != null)
{
StringProxy.Serialize(memoryStream, instance.MacAppStoreUniqueId);
}
else
{
num |= 128;
}
if (instance.Name != null)
{
StringProxy.Serialize(memoryStream, instance.Name);
}
else
{
num |= 256;
}
Int32Proxy.Serialize(memoryStream, instance.Points);
if (instance.PromotionTag != null)
{
StringProxy.Serialize(memoryStream, instance.PromotionTag);
}
else
{
num |= 512;
}
DecimalProxy.Serialize(memoryStream, instance.USDPrice);
DecimalProxy.Serialize(memoryStream, instance.USDPromoPrice);
Int32Proxy.Serialize(stream, ~num);
memoryStream.WriteTo(stream);
}
}

public static BundleView Deserialize(Stream bytes)
{
int num = Int32Proxy.Deserialize(bytes);
BundleView bundleView = new BundleView();
if ((num & 1) != 0)
{
bundleView.AndroidStoreUniqueId = StringProxy.Deserialize(bytes);
}
bundleView.ApplicationId = Int32Proxy.Deserialize(bytes);
if ((num & 2) != 0)
{
bundleView.Availability = ListProxy<ChannelType>.Deserialize(bytes, new ListProxy<ChannelType>.Deserializer<ChannelType>(EnumProxy<ChannelType>.Deserialize));
}
if ((num & 4) != 0)
{
bundleView.BundleItemViews = ListProxy<BundleItemView>.Deserialize(bytes, new ListProxy<BundleItemView>.Deserializer<BundleItemView>(BundleItemViewProxy.Deserialize));
}
bundleView.Category = EnumProxy<BundleCategoryType>.Deserialize(bytes);
bundleView.Credits = Int32Proxy.Deserialize(bytes);
if ((num & 8) != 0)
{
bundleView.Description = StringProxy.Deserialize(bytes);
}
if ((num & 16) != 0)
{
bundleView.IconUrl = StringProxy.Deserialize(bytes);
}
bundleView.Id = Int32Proxy.Deserialize(bytes);
if ((num & 32) != 0)
{
bundleView.ImageUrl = StringProxy.Deserialize(bytes);
}
if ((num & 64) != 0)
{
bundleView.IosAppStoreUniqueId = StringProxy.Deserialize(bytes);
}
bundleView.IsDefault = BooleanProxy.Deserialize(bytes);
bundleView.IsOnSale = BooleanProxy.Deserialize(bytes);
bundleView.IsPromoted = BooleanProxy.Deserialize(bytes);
if ((num & 128) != 0)
{
bundleView.MacAppStoreUniqueId = StringProxy.Deserialize(bytes);
}
if ((num & 256) != 0)
{
bundleView.Name = StringProxy.Deserialize(bytes);
}
bundleView.Points = Int32Proxy.Deserialize(bytes);
if ((num & 512) != 0)
{
bundleView.PromotionTag = StringProxy.Deserialize(bytes);
}
bundleView.USDPrice = DecimalProxy.Deserialize(bytes);
bundleView.USDPromoPrice = DecimalProxy.Deserialize(bytes);
return bundleView;
}
}
}
31 changes: 31 additions & 0 deletions src/UberStrok.Core.Views/BundleView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using UberStrok.Core.Common;

namespace UberStrok.Core.Views
{
[Serializable]
public class BundleView
{
public int Id { get; set; }
public int ApplicationId { get; set; }
public string Name { get; set; }
public string ImageUrl { get; set; }
public string IconUrl { get; set; }
public string Description { get; set; }
public bool IsOnSale { get; set; }
public bool IsPromoted { get; set; }
public decimal USDPrice { get; set; }
public decimal USDPromoPrice { get; set; }
public int Credits { get; set; }
public int Points { get; set; }
public List<BundleItemView> BundleItemViews { get; set; }
public BundleCategoryType Category { get; set; }
public List<ChannelType> Availability { get; set; }
public string PromotionTag { get; set; }
public string MacAppStoreUniqueId { get; set; }
public string IosAppStoreUniqueId { get; set; }
public string AndroidStoreUniqueId { get; set; }
public bool IsDefault { get; set; }
}
}
1 change: 1 addition & 0 deletions src/UberStrok.Core.Views/UberStrok.Core.Views.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Compile Include="AuthenticateApplicationView.cs" />
<Compile Include="BaseUberStrikeItemView.cs" />
<Compile Include="BundleItemView.cs" />
<Compile Include="BundleView.cs" />
<Compile Include="CommActorInfoView.cs" />
<Compile Include="ConnectionAddressView.cs" />
<Compile Include="DamageEventView.cs" />
Expand Down
13 changes: 12 additions & 1 deletion src/UberStrok.WebServices/Core/BaseShopWebService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using log4net;
using System;
using System.IO;
using System.Collections.Generic;
using UberStrok.Core.Common;
using UberStrok.Core.Serialization;
using UberStrok.Core.Serialization.Views;
Expand All @@ -20,6 +21,7 @@ protected BaseShopWebService(WebServiceContext ctx) : base(ctx)

public abstract BuyItemResult OnBuyItem(int itemId, string authToken, UberStrikeCurrencyType currencyType, BuyingDurationType durationType, UberStrikeItemType itemType, BuyingLocationType marketLocation, BuyingRecommendationType recommendationType);
public abstract UberStrikeItemShopClientView OnGetShop();
public abstract List<BundleView> OnGetBundles(ChannelType channel);

byte[] IShopWebServiceContract.BuyBundle(byte[] data)
{
Expand Down Expand Up @@ -167,8 +169,17 @@ byte[] IShopWebServiceContract.GetBundles(byte[] data)
{
try
{
throw new NotImplementedException();
using (var bytes = new MemoryStream(data))
{
var channel = EnumProxy<ChannelType>.Deserialize(bytes);

using (var outBytes = new MemoryStream())
{
EnumProxy<ChannelType>.Serialize(outBytes, channel);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base class should not contain any hardcoded logic, instead rely on the abstract method's implementation.

Suggested change
EnumProxy<ChannelType>.Serialize(outBytes, channel);
List<BundleView> bundles = OnGetBundles(channel);
ListProxy<BundleView>.Serialize(outBytes, bundles, BundleView.Serialize)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BundleView does not contain definition for Serialize

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, apologies that should be BundleViewProxy.Serialize

return outBytes.ToArray();
}
}
}
catch (Exception ex)
{
Log.Error("Unable to handle GetBundles request:");
Expand Down
6 changes: 6 additions & 0 deletions src/UberStrok.WebServices/Core/ShopWebService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using log4net;
using System.ServiceModel;
using System.Collections.Generic;
using UberStrok.Core.Common;
using UberStrok.Core.Views;

Expand Down Expand Up @@ -37,5 +38,10 @@ public override UberStrikeItemShopClientView OnGetShop()
{
return Context.Items.GetShop();
}

public override List<BundleView> OnGetBundles(ChannelType channel)
{
return Context.Items.GetBundles();
}
}
}
7 changes: 7 additions & 0 deletions src/UberStrok.WebServices/ItemManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using UberStrok.Core.Views;
using System.Collections.Generic;

namespace UberStrok.WebServices
{
Expand All @@ -22,10 +23,16 @@ public ItemManager(WebServiceContext ctx)

private readonly UberStrikeItemShopClientView _items;
private readonly WebServiceContext _ctx;
private readonly List<BundleView> _bundles;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not initialized, should be an empty list

Suggested change
private readonly List<BundleView> _bundles;
_bundles = new List<BundleView>();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do that somewhere in the constructor.


public UberStrikeItemShopClientView GetShop()
{
return _items;
}

public List<BundleView> GetBundles()
{
return _bundles;
}
}
}