Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion Examples/CodePushDemoApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react": "16.0.0-alpha.6",
"react-native": "^0.43.2",
"react-native-code-push": "file:../../",
"react-native-windows": "0.40.0-rc.1"
"react-native-windows": "^0.43.0-rc.0"
},
"devDependencies": {
"babel-jest": "19.0.0",
Expand Down
12 changes: 10 additions & 2 deletions Examples/CodePushDemoApp/windows/CodePushDemoApp.Wpf/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props')" />
<Import Project="..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -102,7 +102,7 @@
<ItemGroup>
<Reference Include="Facebook.Yoga, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Facebook.Yoga.1.0.1-pre\lib\netstandard\Facebook.Yoga.dll</HintPath>
<HintPath>..\packages\Facebook.Yoga.1.2.0-pre1\lib\net45\Facebook.Yoga.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -170,10 +170,10 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
<Error Condition="!Exists('..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
<Error Condition="!Exists('..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets'))" />
</Target>
<Import Project="..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets" Condition="Exists('..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets')" />
<Import Project="..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets" Condition="Exists('..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Facebook.Yoga" version="1.0.1-pre" targetFramework="net46" />
<package id="Microsoft.ChakraCore" version="1.4.1-preview-00010-42060" targetFramework="net46" developmentDependency="true" />
<package id="Facebook.Yoga" version="1.2.0-pre1" targetFramework="net46" />
<package id="Microsoft.ChakraCore" version="1.4.1" targetFramework="net46" developmentDependency="true" />
</packages>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"Facebook.Yoga": "1.0.1-pre",
"Facebook.Yoga": "1.2.0-pre1",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
},
"frameworks": {
Expand Down
14 changes: 13 additions & 1 deletion windows/CodePush.Net46.Test/CodePush.Net46.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Examples\CodePushDemoApp\windows\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<Choose>
Expand All @@ -81,20 +86,27 @@
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="ApplicationDataContainerTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TelemetryManagerTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodePush.Net46\CodePush.Net46.csproj">
<Project>{4dfe3f9f-5e15-4f17-8fd4-33ff0519348e}</Project>
<Name>CodePush.Net46</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
117 changes: 117 additions & 0 deletions windows/CodePush.Net46.Test/TelemetryManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using CodePush.ReactNative;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace CodePush.Net46.Test
{
/// <summary>
/// Some tests for telemetry manager
/// As implementation of TelemetryManager was ported from android version, we do not test logic here.
/// Here are tests for some tricky parts of implementation, or check some data transformation that
/// has no full equvalent in C#
/// </summary>
[TestClass]
public class TelemetryManagerTest
{
#region Constants from TelemetryManager
//private static readonly string APP_VERSION_KEY = "appVersion";
private static readonly string DEPLOYMENT_FAILED_STATUS = "DeploymentFailed";
private static readonly string DEPLOYMENT_KEY_KEY = "deploymentKey";
private static readonly string DEPLOYMENT_SUCCEEDED_STATUS = "DeploymentSucceeded";
private static readonly string LABEL_KEY = "label";
private static readonly string LAST_DEPLOYMENT_REPORT_KEY = "CODE_PUSH_LAST_DEPLOYMENT_REPORT";
//private static readonly string PACKAGE_KEY = "package";
//private static readonly string PREVIOUS_DEPLOYMENT_KEY_KEY = "previousDeploymentKey";
//private static readonly string PREVIOUS_LABEL_OR_APP_VERSION_KEY = "previousLabelOrAppVersion";
private static readonly string RETRY_DEPLOYMENT_REPORT_KEY = "CODE_PUSH_RETRY_DEPLOYMENT_REPORT";
private static readonly string STATUS_KEY = "status";
#endregion

[TestMethod]
public void TestGetUpdateReportNoPreviousUpdate()
{
var input = new JObject();
input.Add(DEPLOYMENT_KEY_KEY, "depKeyParam");
input.Add(LABEL_KEY, "labelParam");

var output = TelemetryManager.GetUpdateReport(input);
Assert.IsNotNull(output);
Assert.IsTrue(output.ToString(Formatting.None).Contains("\"status\":\"DeploymentSucceeded\""));
}

[TestMethod]
public void TestGetUpdateReportWithPreviousUpdate()
{
SettingsManager.SetString(LAST_DEPLOYMENT_REPORT_KEY, "prevKey:prevLabel");
var input = new JObject();
input.Add(DEPLOYMENT_KEY_KEY, "depKeyParam");
input.Add(LABEL_KEY, "labelParam");

var output = TelemetryManager.GetUpdateReport(input);
Assert.IsNotNull(output);
Assert.IsTrue(output.ToString(Formatting.None).Contains("\"status\":\"DeploymentSucceeded\""));
Assert.IsTrue(output.ToString(Formatting.None).Contains("\"previousDeploymentKey\":\"prevKey\",\"previousLabelOrAppVersion\":\"prevLabel\""));

//Clean Up
SettingsManager.RemoveString(LAST_DEPLOYMENT_REPORT_KEY);
}

[TestMethod]
public void TestGetUpdateReportNegative()
{
var inputNoLabel = new JObject();
inputNoLabel.Add(DEPLOYMENT_KEY_KEY, "depKeyParam");
Assert.IsNull(TelemetryManager.GetUpdateReport(inputNoLabel));

var inputNoKey = new JObject();
inputNoKey.Add(LABEL_KEY, "labelParam");
Assert.IsNull(TelemetryManager.GetUpdateReport(inputNoKey));
}

[TestMethod]
public void TestRecordStatusReportWithRollback()
{
var report = new JObject();
report.Add(STATUS_KEY, DEPLOYMENT_FAILED_STATUS);

TelemetryManager.RecordStatusReported(report);
Assert.IsTrue(true);
}

[TestMethod]
public void TestRecordStatusReportWithoutRollback()
{
var reportSuccess = new JObject();
reportSuccess.Add(STATUS_KEY, DEPLOYMENT_SUCCEEDED_STATUS);
TelemetryManager.RecordStatusReported(reportSuccess);

var reportNoStatus = new JObject();
TelemetryManager.RecordStatusReported(reportNoStatus);

Assert.IsTrue(true);
}

[TestMethod]
public void TestStatusReportForRetrySerialization()
{
SettingsManager.RemoveString(RETRY_DEPLOYMENT_REPORT_KEY);
var original = new JObject();
original.Add("keyString", "stringValue");
original.Add("keyInt", 42);
original.Add("keyBool", true);

TelemetryManager.SaveStatusReportForRetry(original);

var stringified = SettingsManager.GetString(RETRY_DEPLOYMENT_REPORT_KEY);
SettingsManager.RemoveString(RETRY_DEPLOYMENT_REPORT_KEY);

Assert.IsNotNull(stringified);
var result = JObject.Parse(stringified);

Assert.IsTrue((bool)result.GetValue("keyBool"));
Assert.AreEqual(42, (int)result.GetValue("keyInt"));
Assert.AreEqual("stringValue", (string)result.GetValue("keyString"));
}
}
}
11 changes: 11 additions & 0 deletions windows/CodePush.Net46.Test/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
4 changes: 4 additions & 0 deletions windows/CodePush.Net46.Test/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
</packages>
3 changes: 0 additions & 3 deletions windows/CodePush.Net46/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;


[assembly: InternalsVisibleTo("CodePush.Net46.UnitTest")]

namespace CodePush.ReactNative
{
internal class UpdateManager
Expand Down
1 change: 1 addition & 0 deletions windows/CodePush.Shared/CodePush.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)InstallMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MinimumBackgroundListener.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SettingsManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TelemetryManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UpdateState.cs" />
</ItemGroup>
</Project>
71 changes: 67 additions & 4 deletions windows/CodePush.Shared/CodePushNativeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ internal class CodePushNativeModule : ReactContextNativeModuleBase
private MinimumBackgroundListener _minimumBackgroundListener;
private ReactContext _reactContext;

public CodePushNativeModule(ReactContext reactContext, CodePushReactPackage codePush) : base(reactContext)
public CodePushNativeModule(ReactContext reactContext, CodePushReactPackage codePush)
: base(reactContext)
{
_reactContext = reactContext;
_codePush = codePush;
Expand Down Expand Up @@ -174,10 +175,60 @@ public async void getUpdateMetadata(UpdateState updateState, IPromise promise)


[ReactMethod]
public void getNewStatusReport(IPromise promise)
public async void getNewStatusReport(IPromise promise)
{
// TODO implement this
promise.Resolve("");
await Task.Run(() =>
{
if (_codePush.NeedToReportRollback)
{
_codePush.NeedToReportRollback = false;

var failedUpdates = SettingsManager.GetFailedUpdates();
if (failedUpdates != null && failedUpdates.Count > 0)
{
var lastFailedPackage = (JObject)failedUpdates[failedUpdates.Count - 1];
var failedStatusReport = TelemetryManager.GetRollbackReport(lastFailedPackage);
if (failedStatusReport != null)
{
promise.Resolve(failedStatusReport);
return;
}
}
}
else if (_codePush.DidUpdate)
{
var currentPackage = _codePush.UpdateManager.GetCurrentPackageAsync().Result;
if (currentPackage != null)
{
var newPackageStatusReport = TelemetryManager.GetUpdateReport(currentPackage);
if (newPackageStatusReport != null)
{
promise.Resolve(newPackageStatusReport);
return;
}
}
}
else if (_codePush.IsRunningBinaryVersion)
{
var newAppVersionStatusReport = TelemetryManager.GetBinaryUpdateReport(_codePush.AppVersion);
if (newAppVersionStatusReport != null)
{
promise.Resolve(newAppVersionStatusReport);
return;
}
}
else
{
var retryStatusReport = TelemetryManager.GetRetryStatusReport();
if (retryStatusReport != null)
{
promise.Resolve(retryStatusReport);
return;
}
}

promise.Resolve("");
}).ConfigureAwait(false);
}

[ReactMethod]
Expand Down Expand Up @@ -245,6 +296,18 @@ public async void restartApp(bool onlyIfUpdateIsPending)
}
}

[ReactMethod]
public async void recordStatusReported(JObject statusReport)
{
await Task.Run(() => TelemetryManager.RecordStatusReported(statusReport)).ConfigureAwait(false);
}

[ReactMethod]
public async void saveStatusReportForRetry(JObject statusReport)
{
await Task.Run(() => TelemetryManager.SaveStatusReportForRetry(statusReport)).ConfigureAwait(false);
}

internal async Task LoadBundleAsync()
{
// #1) Get the private ReactInstanceManager, which is what includes
Expand Down
Loading