Skip to content

Commit

Permalink
Catch case where no email accounts are available on iOS. Also handle …
Browse files Browse the repository at this point in the history
…polling sleep durations of int.MaxValue. Updated packages.
  • Loading branch information
MatthewGerber committed Sep 24, 2015
1 parent 9db56ca commit c20f52e
Show file tree
Hide file tree
Showing 8 changed files with 2,022 additions and 3,466 deletions.
5,422 changes: 1,981 additions & 3,441 deletions Sensus.Android/Resources/Resource.Designer.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Sensus.Android/Sensus.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@
<Reference Include="PCLCrypto">
<HintPath>..\packages\PCLCrypto.1.0.2.15130\lib\monoandroid\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.10.6\lib\MonoAndroid10\Xamarin.Insights.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Facebook">
<HintPath>..\packages\Xamarin.Facebook.Android.4.5.1.0\lib\MonoAndroid403\Xamarin.Facebook.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -175,6 +172,9 @@
<Reference Include="AWSSDK.S3">
<HintPath>..\packages\AWSSDK.S3.3.1.3.0\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+xamarinios10+MonoTouch10\AWSSDK.S3.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.11.0\lib\MonoAndroid10\Xamarin.Insights.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AndroidActivityResultRequestCode.cs" />
Expand Down Expand Up @@ -254,8 +254,8 @@
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Import Project="..\packages\Xamarin.Insights.1.10.6\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.10.6\build\MonoAndroid10\Xamarin.Insights.targets')" />
<Import Project="..\packages\Xamarin.Forms.1.5.0.6446\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.1.5.0.6446\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Import Project="..\packages\Xamarin.Insights.1.11.0\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.0\build\MonoAndroid10\Xamarin.Insights.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
2 changes: 1 addition & 1 deletion Sensus.Android/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
<package id="Xamarin.Forms.Maps" version="1.5.0.6446" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Base" version="25.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Maps" version="25.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.Insights" version="1.10.6" targetFramework="MonoAndroid50" />
<package id="Xamarin.Insights" version="1.11.0" targetFramework="MonoAndroid50" />
</packages>
14 changes: 7 additions & 7 deletions Sensus.iOS/Sensus.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@
<Reference Include="PCLCrypto">
<HintPath>..\packages\PCLCrypto.1.0.2.15130\lib\Xamarin.iOS\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.10.6\lib\Xamarin.iOS10\Xamarin.Insights.dll</HintPath>
</Reference>
<Reference Include="PLCrashReporterUnifiedBinding">
<HintPath>..\packages\Xamarin.Insights.1.10.6\lib\Xamarin.iOS10\PLCrashReporterUnifiedBinding.dll</HintPath>
</Reference>
<Reference Include="Facebook">
<HintPath>..\packages\Xamarin.Facebook.iOS.4.5.1.0\lib\Xamarin.iOS10\Facebook.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -201,6 +195,12 @@
<Reference Include="AWSSDK.S3">
<HintPath>..\packages\AWSSDK.S3.3.1.3.0\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+xamarinios10+MonoTouch10\AWSSDK.S3.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.11.0\lib\Xamarin.iOS10\Xamarin.Insights.dll</HintPath>
</Reference>
<Reference Include="PLCrashReporterUnifiedBinding">
<HintPath>..\packages\Xamarin.Insights.1.11.0\lib\Xamarin.iOS10\PLCrashReporterUnifiedBinding.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\Contents.json">
Expand Down Expand Up @@ -328,8 +328,8 @@
<ItemGroup />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Import Project="..\packages\Xamarin.Insights.1.10.6\build\Xamarin.iOS10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.10.6\build\Xamarin.iOS10\Xamarin.Insights.targets')" />
<Import Project="..\packages\Xamarin.Forms.1.5.0.6446\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.1.5.0.6446\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Import Project="..\packages\Xamarin.Insights.1.11.0\build\Xamarin.iOS10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.0\build\Xamarin.iOS10\Xamarin.Insights.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
Expand Down
32 changes: 21 additions & 11 deletions Sensus.iOS/iOSSensusServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,34 @@ public override void ShareFileAsync(string path, string subject)
{
Device.BeginInvokeOnMainThread(() =>
{
MFMailComposeViewController mailer = new MFMailComposeViewController();
mailer.SetSubject(subject);
mailer.AddAttachmentData(NSData.FromUrl(NSUrl.FromFilename(path)), "application/json", Path.GetFileName(path));
mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
if (MFMailComposeViewController.CanSendMail)
{
MFMailComposeViewController mailer = new MFMailComposeViewController();
mailer.SetSubject(subject);
mailer.AddAttachmentData(NSData.FromUrl(NSUrl.FromFilename(path)), "application/json", Path.GetFileName(path));
mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
}
else
SensusServiceHelper.Get().FlashNotificationAsync("You do not have any mail accounts configured. Please configure one before attempting to send emails from Sensus.");
});
}

public override void SendEmailAsync(string toAddress, string subject, string message)
{
Device.BeginInvokeOnMainThread(() =>
{
MFMailComposeViewController mailer = new MFMailComposeViewController();
mailer.SetToRecipients(new string[] { toAddress });
mailer.SetSubject(subject);
mailer.SetMessageBody(message, false);
mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
if (MFMailComposeViewController.CanSendMail)
{
MFMailComposeViewController mailer = new MFMailComposeViewController();
mailer.SetToRecipients(new string[] { toAddress });
mailer.SetSubject(subject);
mailer.SetMessageBody(message, false);
mailer.Finished += (sender, e) => mailer.DismissViewControllerAsync(true);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
}
else
SensusServiceHelper.Get().FlashNotificationAsync("You do not have any mail accounts configured. Please configure one before attempting to send emails from Sensus.");
});
}

Expand Down
2 changes: 1 addition & 1 deletion Sensus.iOS/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
<package id="Xamarin.Facebook.iOS" version="4.5.1.0" targetFramework="xamarinios10" />
<package id="Xamarin.Forms" version="1.5.0.6446" targetFramework="xamarinios10" />
<package id="Xamarin.Forms.Maps" version="1.5.0.6446" targetFramework="xamarinios10" />
<package id="Xamarin.Insights" version="1.10.6" targetFramework="xamarinios10" />
<package id="Xamarin.Insights" version="1.11.0" targetFramework="xamarinios10" />
</packages>
5 changes: 4 additions & 1 deletion SensusService/Probes/PollingProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ public override bool TestHealth(ref string error, ref string warning, ref string
if (Running)
{
double msElapsedSincePreviousStore = (DateTimeOffset.UtcNow - MostRecentStoreTimestamp).TotalMilliseconds;
if (!_isPolling && msElapsedSincePreviousStore > (_pollingSleepDurationMS + 5000)) // system timer callbacks aren't always fired exactly as scheduled, resulting in health tests that identify warning conditions for delayed polling. allow a small fudge factor to ignore these warnings.
int allowedLagMS = 5000;
if (!_isPolling &&
_pollingSleepDurationMS <= int.MaxValue - allowedLagMS && // some probes (iOS HealthKit) have polling delays set to int.MaxValue. if we add to this (as we're about to do in the next check), we'll wrap around to 0 resulting in incorrect statuses. only do the check if we won't wrap around.
msElapsedSincePreviousStore > (_pollingSleepDurationMS + allowedLagMS)) // system timer callbacks aren't always fired exactly as scheduled, resulting in health tests that identify warning conditions for delayed polling. allow a small fudge factor to ignore these warnings.
warning += "Probe \"" + GetType().FullName + "\" has not stored data in " + msElapsedSincePreviousStore + "ms (polling delay = " + _pollingSleepDurationMS + "ms)." + Environment.NewLine;
}

Expand Down
3 changes: 3 additions & 0 deletions SensusService/Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
using SensusService.Exceptions;
using SensusUI.Inputs;
using SensusService.Probes.User;

#if __IOS__
using HealthKit;
using Sensus.iOS.Probes.User.Health;
using Foundation;
#endif

namespace SensusService
{
Expand Down

0 comments on commit c20f52e

Please sign in to comment.