diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest.sln b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest.sln
new file mode 100644
index 0000000..c1765c5
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest.sln
@@ -0,0 +1,38 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkAwarenessTest", "NetworkAwarenessTest\NetworkAwarenessTest.csproj", "{27C10B97-20D1-46F7-92BF-FC07037F900E}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkDetection", "NetworkDetection\NetworkDetection.csproj", "{794D79F0-E898-460D-BDB5-49FED553E0D5}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkNamespaces", "NetworkNamespaces\NetworkNamespaces.csproj", "{41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/App.xaml b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/App.xaml
new file mode 100644
index 0000000..a911d88
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/App.xaml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/App.xaml.cs b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/App.xaml.cs
new file mode 100644
index 0000000..e76c8ec
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/App.xaml.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+
+namespace NetworkAwarenessTest
+{
+ public partial class App : Application
+ {
+ ///
+ /// Provides easy access to the root frame of the Phone Application.
+ ///
+ /// The root frame of the Phone Application.
+ public PhoneApplicationFrame RootFrame { get; private set; }
+
+ ///
+ /// Constructor for the Application object.
+ ///
+ public App()
+ {
+ // Global handler for uncaught exceptions.
+ UnhandledException += Application_UnhandledException;
+
+ // Show graphics profiling information while debugging.
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // Display the current frame rate counters.
+ Application.Current.Host.Settings.EnableFrameRateCounter = true;
+
+ // Show the areas of the app that are being redrawn in each frame.
+ //Application.Current.Host.Settings.EnableRedrawRegions = true;
+
+ // Enable non-production analysis visualization mode,
+ // which shows areas of a page that are being GPU accelerated with a colored overlay.
+ //Application.Current.Host.Settings.EnableCacheVisualization = true;
+ }
+
+ // Standard Silverlight initialization
+ InitializeComponent();
+
+ // Phone-specific initialization
+ InitializePhoneApplication();
+ }
+
+
+ // Code to execute when the application is launching (eg, from Start)
+ // This code will not execute when the application is reactivated
+ private void Application_Launching(object sender, LaunchingEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is activated (brought to foreground)
+ // This code will not execute when the application is first launched
+ private void Application_Activated(object sender, ActivatedEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is deactivated (sent to background)
+ // This code will not execute when the application is closing
+ private void Application_Deactivated(object sender, DeactivatedEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is closing (eg, user hit Back)
+ // This code will not execute when the application is deactivated
+ private void Application_Closing(object sender, ClosingEventArgs e)
+ {
+ }
+
+ // Code to execute if a navigation fails
+ private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // A navigation has failed; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+ }
+
+ // Code to execute on Unhandled Exceptions
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // An unhandled exception has occurred; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+ }
+
+ #region Phone application initialization
+
+ // Avoid double-initialization
+ private bool phoneApplicationInitialized = false;
+
+ // Do not add any additional code to this method
+ private void InitializePhoneApplication()
+ {
+ if (phoneApplicationInitialized)
+ return;
+
+ // Create the frame but don't set it as RootVisual yet; this allows the splash
+ // screen to remain active until the application is ready to render.
+ RootFrame = new PhoneApplicationFrame();
+ RootFrame.Navigated += CompleteInitializePhoneApplication;
+
+ // Handle navigation failures
+ RootFrame.NavigationFailed += RootFrame_NavigationFailed;
+
+ // Ensure we don't initialize again
+ phoneApplicationInitialized = true;
+ }
+
+ // Do not add any additional code to this method
+ private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
+ {
+ // Set the root visual to allow the application to render
+ if (RootVisual != RootFrame)
+ RootVisual = RootFrame;
+
+ // Remove this handler since it is no longer needed
+ RootFrame.Navigated -= CompleteInitializePhoneApplication;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/ApplicationIcon.png b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/ApplicationIcon.png
new file mode 100644
index 0000000..5859393
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/ApplicationIcon.png differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Background.png b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Background.png
new file mode 100644
index 0000000..e46f21d
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Background.png differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/MainPage.xaml b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/MainPage.xaml
new file mode 100644
index 0000000..f974397
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/MainPage.xaml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/MainPage.xaml.cs b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/MainPage.xaml.cs
new file mode 100644
index 0000000..c7fdc25
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/MainPage.xaml.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+
+namespace NetworkAwarenessTest
+{
+ public partial class MainPage : PhoneApplicationPage
+ {
+ string NetType = "";
+ bool online = false;
+
+
+
+ // Constructor
+ public MainPage()
+ {
+ InitializeComponent();
+ Loaded += new RoutedEventHandler(MainPage_Loaded);
+ Unloaded += new RoutedEventHandler(MainPage_Unloaded);
+ }
+
+ void MainPage_Unloaded(object sender, RoutedEventArgs e)
+ {
+ System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged -= new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
+ }
+
+ void MainPage_Loaded(object sender, RoutedEventArgs e)
+ {
+ listBox1.Items.Insert(0, ">>> Refresh Started " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType net = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
+ NetType = net.ToString();
+ listBox1.Items.Insert(1," Refresh Ended " + System.DateTime.Now.ToString("T"));
+ listBox1.Items.Insert(2, " stored at Changed event: " + NetType);
+ listBox1.Items.Insert(3, " Current status: " + net.ToString());
+ if (net == Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet) listBox1.Items.Insert(4, "!!!!! Zune is Connected");
+ SetupNetworkChange();
+ }
+
+ void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
+ {
+ listBox1.Items.Insert(0, "+++++ Changed started " + System.DateTime.Now.ToString("T") + " +++++");
+ if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
+ {
+ if (!online)
+ {
+ online = true;
+ // do what is needed to GoOnline();
+ }
+ }
+ else
+ {
+ if (online)
+ {
+ online = false;
+ listBox1.Items.Insert(0, "----- No network available. -----");
+ // do what is needed to GoOffline();
+ }
+ }
+ listBox1.Items.Insert(1, " Changed GetNetType " + System.DateTime.Now.ToString("T"));
+ Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType net = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
+ NetType = net.ToString();
+ listBox1.Items.Insert(2, " Changed Ended " + System.DateTime.Now.ToString("T"));
+ listBox1.Items.Insert(3, " IsOnline : " + online.ToString());
+ listBox1.Items.Insert(4, " Current status: " + net.ToString());
+ if (net == Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet) listBox1.Items.Insert(5,"!!!!! Zune is Connected");
+ }
+
+ private void SetupNetworkChange()
+ {
+ // Get current network availalability and store the
+ // initial value of the online variable
+ if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
+ {
+ online = true;
+ // do what is needed to GoOnline();
+ }
+ else
+ {
+ online = false;
+ // do what is needed to GoOffline();
+ }
+
+ // Now add a network change event handler to indicate
+ // network availability
+ System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
+ }
+
+ private void buttonRefresh_Click(object sender, RoutedEventArgs e)
+ {
+ listBox1.Items.Insert(0, ">>> Refresh Started " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType net = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
+ //MessageBox.Show("Current status: "+net.ToString(), "stored nettype:" + App.NetType, MessageBoxButton.OK);
+ listBox1.Items.Insert(1, " Refresh Ended " + System.DateTime.Now.ToString("T"));
+ listBox1.Items.Insert(2," stored at Changed event: " + NetType);
+ listBox1.Items.Insert(3, " Current status: " + net.ToString());
+ }
+
+ private void buttonTime_Click(object sender, RoutedEventArgs e)
+ {
+ listBox1.Items.Insert(0, "<<<<< Current Time " + System.DateTime.Now.ToString("T") + " <<<<<<<<<");
+ }
+ }
+}
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/NetworkAwarenessTest.csproj b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/NetworkAwarenessTest.csproj
new file mode 100644
index 0000000..c0e44a0
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/NetworkAwarenessTest.csproj
@@ -0,0 +1,101 @@
+
+
+
+ Debug
+ AnyCPU
+ 10.0.20506
+ 2.0
+ {27C10B97-20D1-46F7-92BF-FC07037F900E}
+ {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
+ Library
+ Properties
+ NetworkAwarenessTest
+ NetworkAwarenessTest
+ v4.0
+ $(TargetFrameworkVersion)
+ WindowsPhone
+ Silverlight
+ true
+
+
+ true
+ true
+ NetworkAwarenessTest.xap
+ Properties\AppManifest.xml
+ NetworkAwarenessTest.App
+ true
+ true
+
+
+ true
+ full
+ false
+ Bin\Debug
+ DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE
+ true
+ true
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ Bin\Release
+ TRACE;SILVERLIGHT;WINDOWS_PHONE
+ true
+ true
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+ App.xaml
+
+
+ MainPage.xaml
+
+
+
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/AppManifest.xml b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/AppManifest.xml
new file mode 100644
index 0000000..a955232
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/AppManifest.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/AssemblyInfo.cs b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..26b058d
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("NetworkAwarenessTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("NetworkAwarenessTest")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("59705a9b-da65-482a-8c30-552b5622a972")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/WMAppManifest.xml b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/WMAppManifest.xml
new file mode 100644
index 0000000..aa5cab2
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/Properties/WMAppManifest.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ ApplicationIcon.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Background.png
+ 0
+ NetworkAwarenessTest
+
+
+
+
+
diff --git a/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/SplashScreenImage.jpg b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/SplashScreenImage.jpg
new file mode 100644
index 0000000..353b192
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkAwarenessTest/SplashScreenImage.jpg differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/App.xaml b/main/Libs/NetworkAwarenessTest/NetworkDetection/App.xaml
new file mode 100644
index 0000000..d5b1cbc
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/App.xaml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/App.xaml.cs b/main/Libs/NetworkAwarenessTest/NetworkDetection/App.xaml.cs
new file mode 100644
index 0000000..f2a78e9
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/App.xaml.cs
@@ -0,0 +1,139 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+
+namespace NetworkDetection
+{
+ public partial class App : Application
+ {
+ ///
+ /// Provides easy access to the root frame of the Phone Application.
+ ///
+ /// The root frame of the Phone Application.
+ public PhoneApplicationFrame RootFrame { get; private set; }
+ //NetworkDetector nd;
+ ///
+ /// Constructor for the Application object.
+ ///
+ public App()
+ {
+ // Global handler for uncaught exceptions.
+ UnhandledException += Application_UnhandledException;
+
+ // Show graphics profiling information while debugging.
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // Display the current frame rate counters.
+ Application.Current.Host.Settings.EnableFrameRateCounter = true;
+
+ // Show the areas of the app that are being redrawn in each frame.
+ //Application.Current.Host.Settings.EnableRedrawRegions = true;
+
+ // Enable non-production analysis visualization mode,
+ // which shows areas of a page that are being GPU accelerated with a colored overlay.
+ //Application.Current.Host.Settings.EnableCacheVisualization = true;
+ }
+
+ // Standard Silverlight initialization
+ InitializeComponent();
+
+ // Phone-specific initialization
+ InitializePhoneApplication();
+
+ }
+
+ NetworkDetector nd;
+ // Code to execute when the application is launching (eg, from Start)
+ // This code will not execute when the application is reactivated
+ private void Application_Launching(object sender, LaunchingEventArgs e)
+ {
+ nd = NetworkDetector.Instance;
+ }
+
+ // Code to execute when the application is activated (brought to foreground)
+ // This code will not execute when the application is first launched
+ private void Application_Activated(object sender, ActivatedEventArgs e)
+ {
+ nd = NetworkDetector.Instance;
+ }
+
+ // Code to execute when the application is deactivated (sent to background)
+ // This code will not execute when the application is closing
+ private void Application_Deactivated(object sender, DeactivatedEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is closing (eg, user hit Back)
+ // This code will not execute when the application is deactivated
+ private void Application_Closing(object sender, ClosingEventArgs e)
+ {
+ }
+
+ // Code to execute if a navigation fails
+ private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // A navigation has failed; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+ }
+
+ // Code to execute on Unhandled Exceptions
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // An unhandled exception has occurred; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+ }
+
+ #region Phone application initialization
+
+ // Avoid double-initialization
+ private bool phoneApplicationInitialized = false;
+
+ // Do not add any additional code to this method
+ private void InitializePhoneApplication()
+ {
+ if (phoneApplicationInitialized)
+ return;
+
+ // Create the frame but don't set it as RootVisual yet; this allows the splash
+ // screen to remain active until the application is ready to render.
+ RootFrame = new PhoneApplicationFrame();
+ RootFrame.Navigated += CompleteInitializePhoneApplication;
+
+ // Handle navigation failures
+ RootFrame.NavigationFailed += RootFrame_NavigationFailed;
+
+ // Ensure we don't initialize again
+ phoneApplicationInitialized = true;
+ }
+
+ // Do not add any additional code to this method
+ private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
+ {
+ // Set the root visual to allow the application to render
+ if (RootVisual != RootFrame)
+ RootVisual = RootFrame;
+
+ // Remove this handler since it is no longer needed
+ RootFrame.Navigated -= CompleteInitializePhoneApplication;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/ApplicationIcon.png b/main/Libs/NetworkAwarenessTest/NetworkDetection/ApplicationIcon.png
new file mode 100644
index 0000000..5859393
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkDetection/ApplicationIcon.png differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/Background.png b/main/Libs/NetworkAwarenessTest/NetworkDetection/Background.png
new file mode 100644
index 0000000..e46f21d
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkDetection/Background.png differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/MainPage.xaml b/main/Libs/NetworkAwarenessTest/NetworkDetection/MainPage.xaml
new file mode 100644
index 0000000..f1946dd
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/MainPage.xaml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/MainPage.xaml.cs b/main/Libs/NetworkAwarenessTest/NetworkDetection/MainPage.xaml.cs
new file mode 100644
index 0000000..5880742
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/MainPage.xaml.cs
@@ -0,0 +1,165 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+
+namespace NetworkDetection
+{
+ public partial class MainPage : PhoneApplicationPage
+ {
+ // Constructor
+ public MainPage()
+ {
+ InitializeComponent();
+ Loaded += new RoutedEventHandler(MainPage_Loaded);
+ }
+
+ NetworkDetector nd = NetworkDetector.Instance;
+ int interval = 500;
+
+ void MainPage_Loaded(object sender, RoutedEventArgs e)
+ {
+ nd.OnAsyncGetNetworkTypeCompleted += new EventHandler(nd_OnAsyncGetNetworkTypeCompleted);
+ nd.OnConnectedBroadbandCdma += new EventHandler(nd_OnConnectedBroadbandCdma);
+ nd.OnConnectedBroadbandGsm += new EventHandler(nd_OnConnectedBroadbandGsm);
+ nd.OnConnectedEthernet += new EventHandler(nd_OnConnectedEthernet);
+ nd.OnConnectedNone += new EventHandler(nd_OnConnectedNone);
+ nd.OnConnectedOther += new EventHandler(nd_OnConnectedOther);
+ nd.OnConnectedWifi += new EventHandler(nd_OnConnectedWifi);
+ nd.OnNetworkChanged += new EventHandler(nd_OnNetworkChanged);
+ nd.OnNetworkOFF += new EventHandler(nd_OnNetworkOFF);
+ nd.OnNetworkON += new EventHandler(nd_OnNetworkON);
+ nd.OnZuneConnected += new EventHandler(nd_OnZuneConnected);
+ nd.OnZuneDisconnected += new EventHandler(nd_OnZuneDisconnected);
+ nd.OnLostNetworkType += new EventHandler(nd_OnLostNetworkType);
+
+ nd.SetNetworkPolling(0,0,interval);
+ }
+
+ void nd_OnLostNetworkType(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnLostNetworkType ->previous Nettype:" + e.NetType.ToString());
+ }
+
+ void nd_OnZuneDisconnected(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnZuneDisconnected ->Nettype:" + e.NetType.ToString());
+ }
+
+ void nd_OnZuneConnected(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnZuneConnected ->Nettype:" + e.NetType.ToString());
+ }
+
+ void nd_OnNetworkON(object sender, NetworkAvailableEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnNetworkON ->Online:" + e.IsOnline.ToString());
+ }
+
+ void nd_OnNetworkOFF(object sender, NetworkAvailableEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnNetworkOFF ->Online:" + e.IsOnline.ToString());
+ }
+
+ void nd_OnNetworkChanged(object sender, NetworkAvailableEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnNetworkChanged ->Online:" + e.IsOnline.ToString());
+ }
+
+ void nd_OnConnectedWifi(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnConnectedWifi " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ void nd_OnConnectedOther(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnConnectedOther " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ void nd_OnConnectedNone(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnConnectedNone " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ void nd_OnConnectedEthernet(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnConnectedEthernet " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ void nd_OnConnectedBroadbandGsm(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnConnectedBroadbandGsm " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ void nd_OnConnectedBroadbandCdma(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnConnectedBroadbandCdma " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ void nd_OnAsyncGetNetworkTypeCompleted(object sender, NetworkDetectorEventArgs e)
+ {
+ listBox1.Items.Insert(0, "OnAsyncGetNetworkTypeCompleted " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ }
+
+ private void buttonMode_Click(object sender, RoutedEventArgs e)
+ {
+ nd.DetailedMode = !nd.DetailedMode;
+ if (nd.DetailedMode) buttonMode.Content = "DT";
+ else buttonMode.Content = "DF";
+ listBox1.Items.Insert(0, " DetailedMode : " + nd.DetailedMode.ToString() + " <<<<<<<<<");
+ }
+
+ private void buttonTime_Click(object sender, RoutedEventArgs e)
+ {
+ listBox1.Items.Insert(0, "<<<<< Current Time " + System.DateTime.Now.ToString("T") + " <<<<<<<<<");
+ }
+
+ private void buttonStoppPoll_Click(object sender, RoutedEventArgs e)
+ {
+ nd.DisableNetworkPolling();
+ }
+
+ private void buttonStartPoll_Click(object sender, RoutedEventArgs e)
+ {
+ nd.SetNetworkPolling(0, 0, interval);
+ }
+
+ private void buttonIncrease_Click(object sender, RoutedEventArgs e)
+ {
+ interval += 100;
+ //if (interval > 1000) interval = 1000;
+ nd.SetNetworkPolling(0, 0, interval);
+ listBox1.Items.Insert(0, " Current polling Time " + interval.ToString() + " <<<<<<<<<");
+ }
+
+ private void buttonClear_Click(object sender, RoutedEventArgs e)
+ {
+ listBox1.Items.Clear();
+ }
+
+ private void buttonDecrease_Click(object sender, RoutedEventArgs e)
+ {
+ interval -= 100;
+ if (interval < 100) interval = 100;
+ nd.SetNetworkPolling(0, 0, interval);
+ listBox1.Items.Insert(0, " Current polling Time " + interval.ToString() + " <<<<<<<<<");
+ }
+
+ private void buttonRefresh_Click(object sender, RoutedEventArgs e)
+ {
+ listBox1.Items.Insert(0, ">>> Refresh Started " + System.DateTime.Now.ToString("T") + " >>>>>>>>");
+ listBox1.Items.Insert(1, " Current status: " + nd.GetCurrentNetworkType().ToString());
+ nd.AsyncGetNetworkType();
+ listBox1.Items.Insert(2, " Refresh Ended " + System.DateTime.Now.ToString("T"));
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/NetworkDetection.csproj b/main/Libs/NetworkAwarenessTest/NetworkDetection/NetworkDetection.csproj
new file mode 100644
index 0000000..87af794
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/NetworkDetection.csproj
@@ -0,0 +1,102 @@
+
+
+
+ Debug
+ AnyCPU
+ 10.0.20506
+ 2.0
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}
+ {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
+ Library
+ Properties
+ NetworkDetection
+ NetworkDetection
+ v4.0
+ $(TargetFrameworkVersion)
+ WindowsPhone
+ Silverlight
+ true
+
+
+ true
+ true
+ NetworkDetection.xap
+ Properties\AppManifest.xml
+ NetworkDetection.App
+ true
+ true
+
+
+ true
+ full
+ false
+ Bin\Debug
+ DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE
+ true
+ true
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ Bin\Release
+ TRACE;SILVERLIGHT;WINDOWS_PHONE
+ true
+ true
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+ App.xaml
+
+
+ MainPage.xaml
+
+
+
+
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/NetworkDetector.cs b/main/Libs/NetworkAwarenessTest/NetworkDetection/NetworkDetector.cs
new file mode 100644
index 0000000..9563127
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/NetworkDetector.cs
@@ -0,0 +1,387 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+
+
+
+/**********************************************/
+/* Copyright of Gabor Dolhai @ 2010 */
+/* under MS-Pl license */
+/* can be used freely for anybody */
+/* If you use this code please send me an */
+/*email about your project to dolhaig at gmail*/
+/*******************Thanks*********************/
+namespace NetworkDetection
+{
+ #region Custom Enums and EventArgs
+ public enum NetworkTypeRequestStatus
+ {
+ Default = 0,
+ Started,//represents BackgroundWorker started
+ Ended//BackgroundWorker Finished
+ }
+
+ public class NetworkAvailableEventArgs : System.EventArgs
+ {
+
+ public NetworkAvailableEventArgs(bool isOnline)
+ {
+ IsOnline = isOnline;
+ }
+
+ public bool IsOnline { get; private set; }
+ }
+
+ public class NetworkDetectorEventArgs : System.EventArgs
+ {
+
+ public NetworkDetectorEventArgs(bool isOnline, Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType netType)
+ {
+ IsOnline = isOnline;
+ NetType = netType;
+ }
+
+ public bool IsOnline { get; private set; }
+ public Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType NetType { get; private set; }
+ }
+ #endregion
+
+ public class NetworkDetector
+ {
+ private static readonly NetworkDetector _instance = new NetworkDetector();
+
+ #region Events
+ public event EventHandler OnNetworkON;
+ public event EventHandler OnNetworkOFF;
+ public event EventHandler OnNetworkChanged;
+
+ public event EventHandler OnZuneConnected;
+ public event EventHandler OnZuneDisconnected;
+ public event EventHandler OnConnectedEthernet;
+ public event EventHandler OnConnectedWifi;
+ public event EventHandler OnConnectedNone;
+ public event EventHandler OnConnectedBroadbandGsm;
+ public event EventHandler OnConnectedBroadbandCdma;
+ public event EventHandler OnConnectedOther;
+ public event EventHandler OnLostNetworkType;
+
+ public event EventHandler OnAsyncGetNetworkTypeCompleted;
+ #endregion
+
+ private System.Windows.Threading.DispatcherTimer updateTimer, pollTimer;
+ private Queue requestQueue; //queue to store the requests timestemps
+ private BackgroundWorker networkWorker;
+ private bool online = false;
+ private Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType net;
+ private NetworkTypeRequestStatus requestStatus; //current status of the BackgroundWorker
+ private bool IsInstantRequestPresent;
+ private bool detailedMode;
+ private bool isZuneConnected;
+
+ private NetworkDetector()
+ {
+ requestQueue = new Queue();
+ requestQueue.Clear();
+ requestStatus = NetworkTypeRequestStatus.Default;
+ updateTimer = new System.Windows.Threading.DispatcherTimer();
+ updateTimer.Tick += new EventHandler(updateTimer_Tick);
+ updateTimer.Interval = new TimeSpan(0, 0, 0, 0, 300);//there is no need to restart the BGWorker sooner then 300 millisec because the ~3request/sec requestlimit
+ //updateTimer.Start();
+ pollTimer = new System.Windows.Threading.DispatcherTimer();
+ pollTimer.Tick += new EventHandler(pollTimer_Tick);
+ networkWorker = new BackgroundWorker();
+ networkWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(networkWorker_RunWorkerCompleted);
+ networkWorker.DoWork += new DoWorkEventHandler(networkWorker_DoWork);
+ IsInstantRequestPresent = false;
+ detailedMode = false; //by default I hide the framework events for better Developer experience
+ isZuneConnected = false;
+
+ SetupNetworkChange(); //signing on the framework event
+ }
+
+ public static NetworkDetector Instance
+ {
+ get
+ {
+ return _instance;
+ }
+ }
+
+ #region BackgroundWorker
+ void networkWorker_DoWork(object sender, DoWorkEventArgs e)
+ {
+ Debug.WriteLine(">>>>> GetNetType started " + System.DateTime.Now.ToString("T") + " >>>>>");
+ e.Result = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
+ }
+ //no need to lock the variables if We do everithing in the completed event handler
+
+ void networkWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+ {
+ DetectOnlineStatus();
+ if ((detailedMode) || (net != (Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType)e.Result))
+ {
+ //there is no need to get events all the time, just when really changing something or the DetailedMode is true
+ if (net != (Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType)e.Result)
+ RaiseNotify(OnLostNetworkType, new NetworkDetectorEventArgs(online, net));
+ net = (Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType)e.Result;
+ Debug.WriteLine(" New NetType: " + net.ToString());
+ if (net == Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet) Debug.WriteLine("!!!!! Zune is Connected");
+ switch (net)
+ {
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet:
+ if (!isZuneConnected)
+ {
+ isZuneConnected = true;
+ RaiseNotify(OnZuneConnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedEthernet, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Wireless80211:
+ if (isZuneConnected)
+ {
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedWifi, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandCdma:
+ if (isZuneConnected)
+ {
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedBroadbandCdma, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandGsm:
+ if (isZuneConnected)
+ {
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedBroadbandGsm, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None:
+ if (!online)
+ {
+ if (isZuneConnected)
+ {
+ /*if we lost all network connection and the Zune was present before,
+ then we lost the Zune too. Normally when Zune is present and then we got
+ a None NetType, the PC just lost the internet connection but not the Zune sync*/
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ }
+ RaiseNotify(OnConnectedNone, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.AsymmetricDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Atm:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.BasicIsdn:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet3Megabit:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.FastEthernetT:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Fddi:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.GenericModem:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.HighPerformanceSerialBus:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.IPOverAtm:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Isdn:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Loopback:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MultiRateSymmetricDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ppp:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.PrimaryIsdn:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.RateAdaptDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Slip:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.SymmetricDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.TokenRing:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Tunnel:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Unknown:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.VeryHighSpeedDsl:
+ default://theoretically we can't get here but better be prepared
+ RaiseNotify(OnConnectedOther, new NetworkDetectorEventArgs(online, net));
+ break;
+ }
+ }
+ for (int i = 0; i < requestQueue.Count; i++)
+ {
+ if (requestQueue.Peek() < System.DateTime.Now.Ticks) requestQueue.Dequeue();
+ //the requests before this moment just got answered
+ //if other requests are coming right after this, they will be served inside the next networkWorker_RunWorkerCompleted
+ }
+ if (requestQueue.Count == 0) updateTimer.Stop();
+ if (IsInstantRequestPresent) //the user requested a single poll
+ {
+ RaiseNotify(OnAsyncGetNetworkTypeCompleted, new NetworkDetectorEventArgs(online, net));
+ IsInstantRequestPresent = false;
+ }
+ requestStatus = NetworkTypeRequestStatus.Ended;
+ Debug.WriteLine("<<<<< GetNetType ended " + System.DateTime.Now.ToString("T") + " <<<<<");
+ }
+ #endregion
+
+ #region Private Functions
+ private void EnqueueRequest()
+ {
+ requestQueue.Enqueue(System.DateTime.Now.Ticks);
+ if (!updateTimer.IsEnabled) updateTimer.Start();
+ }
+
+ private void DetectOnlineStatus() //are we connected to any network or not
+ {
+ if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
+ {
+ if (!online)
+ {
+ online = true; //the network just came back
+ RaiseNotify(OnNetworkON, new NetworkAvailableEventArgs(online));
+ // do what is needed to GoOnline();
+ }
+ }
+ else
+ {
+ if (online)
+ {
+ online = false; //we just lost all network connectivity
+ RaiseNotify(OnNetworkOFF, new NetworkAvailableEventArgs(online));
+ Debug.WriteLine("----- No network available. -----");
+ // do what is needed to GoOffline();
+ }
+ }
+ }
+
+ void pollTimer_Tick(object sender, EventArgs e)
+ {
+ EnqueueRequest();
+ }
+
+ void updateTimer_Tick(object sender, EventArgs e)
+ {
+ if (requestQueue.Count > 0)
+ {
+ if (!networkWorker.IsBusy)
+ {
+ requestStatus = NetworkTypeRequestStatus.Started;
+ networkWorker.RunWorkerAsync();
+ }
+ }
+ }
+
+ #region Event Handling
+ private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
+ {
+ Debug.WriteLine("+++++ Changed started " + System.DateTime.Now.ToString("T") + " +++++");
+ DetectOnlineStatus();
+ if (detailedMode) RaiseNotify(OnNetworkChanged, new NetworkAvailableEventArgs(online));
+ Debug.WriteLine(" IsOnline : " + online.ToString());
+ Debug.WriteLine(" Current NetType: " + net.ToString());
+ Debug.WriteLine("+++++ Changed Ended " + System.DateTime.Now.ToString("T"));
+ Debug.WriteLine(" Changed GetNetType Launch" + System.DateTime.Now.ToString("T"));
+ EnqueueRequest();
+ }
+
+ private void SetupNetworkChange()
+ {
+ // Get current network availalability and store the
+ // initial value of the online variable
+ if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
+ {
+ online = true;
+ // do what is needed to GoOnline();
+ }
+ else
+ {
+ online = false;
+ // do what is needed to GoOffline();
+ }
+ // Now add a network change event handler to indicate network availability
+ EnqueueRequest();
+ System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
+ }
+
+ protected void RaiseNotify(EventHandler handler, NetworkDetectorEventArgs e)
+ {
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+
+ protected void RaiseNotify(EventHandler handler, NetworkAvailableEventArgs e)
+ {
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+ #endregion
+
+ #endregion
+
+ #region Public Functions and Properties
+ public void AsyncGetNetworkType()
+ {
+ //requestQueue.Enqueue(System.DateTime.Now.Ticks);
+ IsInstantRequestPresent = true;
+ if (!networkWorker.IsBusy)
+ {
+ requestStatus = NetworkTypeRequestStatus.Started;
+ networkWorker.RunWorkerAsync();
+ }
+ if (!updateTimer.IsEnabled) updateTimer.Start();
+ }
+
+ public void SetNetworkPolling(int Minutes, int Seconds, int Milliseconds)
+ {
+ pollTimer.Interval = new TimeSpan(0, 0, Minutes, Seconds, Milliseconds);
+ if (!pollTimer.IsEnabled) pollTimer.Start();
+ }
+
+ public void DisableNetworkPolling()
+ {
+ if (pollTimer.IsEnabled) pollTimer.Stop();
+ }
+
+
+
+ public Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType GetCurrentNetworkType()
+ {
+ return net;
+ }
+
+ public NetworkTypeRequestStatus GetRequestStatus()
+ {
+ //NetworkTypeRequestStatus temp = requestStatus;
+ //if (requestStatus == NetworkTypeRequestStatus.Ended) requestStatus = NetworkTypeRequestStatus.Default;
+ //return temp;
+ return requestStatus;
+ }
+
+ public bool DetailedMode
+ {
+ get
+ {
+ return detailedMode;
+ }
+ set
+ {
+ detailedMode = value;
+ }
+ }
+
+ public bool GetZuneStatus()
+ {
+ return isZuneConnected;
+ }
+ #endregion
+ }
+}
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/AppManifest.xml b/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/AppManifest.xml
new file mode 100644
index 0000000..a955232
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/AppManifest.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/AssemblyInfo.cs b/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..94255dc
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("NetworkDetection")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("NetworkDetection")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("2d90f1d3-7fb9-47d0-98c2-18ee1a63a5f5")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/WMAppManifest.xml b/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/WMAppManifest.xml
new file mode 100644
index 0000000..4a55550
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkDetection/Properties/WMAppManifest.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ ApplicationIcon.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Background.png
+ 0
+ NetworkDetection
+
+
+
+
+
diff --git a/main/Libs/NetworkAwarenessTest/NetworkDetection/SplashScreenImage.jpg b/main/Libs/NetworkAwarenessTest/NetworkDetection/SplashScreenImage.jpg
new file mode 100644
index 0000000..353b192
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkDetection/SplashScreenImage.jpg differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/App.xaml b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/App.xaml
new file mode 100644
index 0000000..c13478d
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/App.xaml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/App.xaml.cs b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/App.xaml.cs
new file mode 100644
index 0000000..f0a0fff
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/App.xaml.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+
+namespace NetworkNamespaces
+{
+ public partial class App : Application
+ {
+ ///
+ /// Provides easy access to the root frame of the Phone Application.
+ ///
+ /// The root frame of the Phone Application.
+ public PhoneApplicationFrame RootFrame { get; private set; }
+
+ ///
+ /// Constructor for the Application object.
+ ///
+ public App()
+ {
+ // Global handler for uncaught exceptions.
+ UnhandledException += Application_UnhandledException;
+
+ // Show graphics profiling information while debugging.
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // Display the current frame rate counters.
+ Application.Current.Host.Settings.EnableFrameRateCounter = true;
+
+ // Show the areas of the app that are being redrawn in each frame.
+ //Application.Current.Host.Settings.EnableRedrawRegions = true;
+
+ // Enable non-production analysis visualization mode,
+ // which shows areas of a page that are being GPU accelerated with a colored overlay.
+ //Application.Current.Host.Settings.EnableCacheVisualization = true;
+ }
+
+ // Standard Silverlight initialization
+ InitializeComponent();
+
+ // Phone-specific initialization
+ InitializePhoneApplication();
+ }
+
+ // Code to execute when the application is launching (eg, from Start)
+ // This code will not execute when the application is reactivated
+ private void Application_Launching(object sender, LaunchingEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is activated (brought to foreground)
+ // This code will not execute when the application is first launched
+ private void Application_Activated(object sender, ActivatedEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is deactivated (sent to background)
+ // This code will not execute when the application is closing
+ private void Application_Deactivated(object sender, DeactivatedEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is closing (eg, user hit Back)
+ // This code will not execute when the application is deactivated
+ private void Application_Closing(object sender, ClosingEventArgs e)
+ {
+ }
+
+ // Code to execute if a navigation fails
+ private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // A navigation has failed; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+ }
+
+ // Code to execute on Unhandled Exceptions
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // An unhandled exception has occurred; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+ }
+
+ #region Phone application initialization
+
+ // Avoid double-initialization
+ private bool phoneApplicationInitialized = false;
+
+ // Do not add any additional code to this method
+ private void InitializePhoneApplication()
+ {
+ if (phoneApplicationInitialized)
+ return;
+
+ // Create the frame but don't set it as RootVisual yet; this allows the splash
+ // screen to remain active until the application is ready to render.
+ RootFrame = new PhoneApplicationFrame();
+ RootFrame.Navigated += CompleteInitializePhoneApplication;
+
+ // Handle navigation failures
+ RootFrame.NavigationFailed += RootFrame_NavigationFailed;
+
+ // Ensure we don't initialize again
+ phoneApplicationInitialized = true;
+ }
+
+ // Do not add any additional code to this method
+ private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
+ {
+ // Set the root visual to allow the application to render
+ if (RootVisual != RootFrame)
+ RootVisual = RootFrame;
+
+ // Remove this handler since it is no longer needed
+ RootFrame.Navigated -= CompleteInitializePhoneApplication;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/ApplicationIcon.png b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/ApplicationIcon.png
new file mode 100644
index 0000000..5859393
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/ApplicationIcon.png differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Background.png b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Background.png
new file mode 100644
index 0000000..e46f21d
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Background.png differ
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/MainPage.xaml b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/MainPage.xaml
new file mode 100644
index 0000000..6b37b7c
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/MainPage.xaml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/MainPage.xaml.cs b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/MainPage.xaml.cs
new file mode 100644
index 0000000..9c47357
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/MainPage.xaml.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+
+namespace NetworkNamespaces
+{
+ public partial class MainPage : PhoneApplicationPage
+ {
+ // Constructor
+ public MainPage()
+ {
+ InitializeComponent();
+ System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
+ }
+
+ void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
+ {
+ listBoxPhone.Items.Insert(0,Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable().ToString());
+ listBoxSilverlight.Items.Insert(0,System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable().ToString());
+ if (listBoxSilverlight.Items.Count > 21) listBoxSilverlight.Items.RemoveAt(listBoxSilverlight.Items.Count-1);
+ if (listBoxPhone.Items.Count > 21) listBoxPhone.Items.RemoveAt(listBoxPhone.Items.Count - 1);
+ }
+
+ private void buttonRefresh_Click(object sender, RoutedEventArgs e)
+ {
+ listBoxPhone.Items.Insert(0,Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable().ToString());
+ listBoxSilverlight.Items.Insert(0,System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable().ToString());
+ if (listBoxSilverlight.Items.Count > 21) listBoxSilverlight.Items.RemoveAt(listBoxSilverlight.Items.Count - 1);
+ if (listBoxPhone.Items.Count > 21) listBoxPhone.Items.RemoveAt(listBoxPhone.Items.Count - 1);
+ }
+ }
+}
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/NetworkNamespaces.csproj b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/NetworkNamespaces.csproj
new file mode 100644
index 0000000..7893c37
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/NetworkNamespaces.csproj
@@ -0,0 +1,101 @@
+
+
+
+ Debug
+ AnyCPU
+ 10.0.20506
+ 2.0
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}
+ {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
+ Library
+ Properties
+ NetworkNamespaces
+ NetworkNamespaces
+ v4.0
+ $(TargetFrameworkVersion)
+ WindowsPhone
+ Silverlight
+ true
+
+
+ true
+ true
+ NetworkNamespaces.xap
+ Properties\AppManifest.xml
+ NetworkNamespaces.App
+ true
+ true
+
+
+ true
+ full
+ false
+ Bin\Debug
+ DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE
+ true
+ true
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ Bin\Release
+ TRACE;SILVERLIGHT;WINDOWS_PHONE
+ true
+ true
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+ App.xaml
+
+
+ MainPage.xaml
+
+
+
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/AppManifest.xml b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/AppManifest.xml
new file mode 100644
index 0000000..a955232
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/AppManifest.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/AssemblyInfo.cs b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..2baed08
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("NetworkNamespaces")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("NetworkNamespaces")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("e86f4db7-5169-481a-88c2-7afd0f470c2e")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/WMAppManifest.xml b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/WMAppManifest.xml
new file mode 100644
index 0000000..087d284
--- /dev/null
+++ b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/Properties/WMAppManifest.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ ApplicationIcon.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Background.png
+ 0
+ NetworkNamespaces
+
+
+
+
+
diff --git a/main/Libs/NetworkAwarenessTest/NetworkNamespaces/SplashScreenImage.jpg b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/SplashScreenImage.jpg
new file mode 100644
index 0000000..353b192
Binary files /dev/null and b/main/Libs/NetworkAwarenessTest/NetworkNamespaces/SplashScreenImage.jpg differ
diff --git a/main/MyFriendsAround.Common/Entities/PictureInfo.cs b/main/MyFriendsAround.Common/Entities/PictureInfo.cs
new file mode 100644
index 0000000..d153b69
--- /dev/null
+++ b/main/MyFriendsAround.Common/Entities/PictureInfo.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MyFriendsAround.Common.Entities
+{
+ public class PictureInfo
+ {
+ public virtual string UserId { get; set; }
+ public virtual string Picture { get; set; }
+ }
+}
diff --git a/main/MyFriendsAround.Common/MyFriendsAround.Common.csproj b/main/MyFriendsAround.Common/MyFriendsAround.Common.csproj
index e5f5ff3..eb982b8 100644
--- a/main/MyFriendsAround.Common/MyFriendsAround.Common.csproj
+++ b/main/MyFriendsAround.Common/MyFriendsAround.Common.csproj
@@ -63,6 +63,7 @@
True
MyFriends.Model.tt
+
diff --git a/main/MyFriendsAround.Data.BLL/FriendsRepository.cs b/main/MyFriendsAround.Data.BLL/FriendsRepository.cs
index 1a5c004..69f84c5 100644
--- a/main/MyFriendsAround.Data.BLL/FriendsRepository.cs
+++ b/main/MyFriendsAround.Data.BLL/FriendsRepository.cs
@@ -3,14 +3,28 @@ using System.Collections.Generic;
using System.Data.Objects;
using System.Data.SqlTypes;
using System.Linq;
+using System.Net;
using System.Text;
using Microsoft.SqlServer.Types;
+using Microsoft.WindowsAzure;
+using Microsoft.WindowsAzure.StorageClient;
using MyFriendsAround.Common.Entities;
+using System.IO;
+using System.Configuration;
namespace MyFriendsAround.Data.BLL
{
public static class FriendsRepository
{
+ private static string profilesContainerName = string.Empty;
+ private static string profileImageFormat = string.Empty;
+
+ static FriendsRepository()
+ {
+ profilesContainerName = ConfigurationManager.AppSettings["azureProfilesContainer"];
+ profileImageFormat = ConfigurationManager.AppSettings["profileImageFormat"];
+ }
+
public static List GetFriends()
{
return GetFriends(0, 50);
@@ -32,6 +46,11 @@ namespace MyFriendsAround.Data.BLL
}
}
+ ///
+ /// Publish user info
+ ///
+ /// friend obj
+ /// true if success
public static bool PublishLocation(Friend friend)
{
using (MyFriendsModelContainer ctx = new MyFriendsModelContainer())
@@ -55,7 +74,7 @@ namespace MyFriendsAround.Data.BLL
bool success = ctx.SaveChanges() > 0;
if (success)
{
- //update gegraphy field
+ //update geography field
ctx.ExecuteFunction("UpdateFriendLocationById", new ObjectParameter[]
{
new ObjectParameter("FriendID", friend.Id),
@@ -65,10 +84,78 @@ namespace MyFriendsAround.Data.BLL
}
}
+ private static bool storageInitialized = false;
+ private static object gate = new Object();
+ private static CloudBlobClient blobStorage;
+
public static bool UpdatePicture(string userId, byte[] userPicture)
{
+ bool success = false;
+ try
+ {
+ InitializeStorage();
- return false;
+ // upload the image to blob storage
+ CloudBlobContainer container = blobStorage.GetContainerReference(profilesContainerName);
+ string uniqueBlobName = string.Format(profileImageFormat, userId);
+ CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
+ blob.DeleteIfExists();
+ blob.Properties.ContentType = "image/jpeg";
+ using (MemoryStream ms = new MemoryStream(userPicture))
+ {
+ blob.UploadFromStream(ms);
+ }
+ //
+ System.Diagnostics.Trace.TraceInformation("Uploaded image '{0}' to blob storage as '{1}'", userId, uniqueBlobName);
+ //
+ success = true;
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+
+ return success;
+ }
+
+ private static void InitializeStorage()
+ {
+ if (storageInitialized)
+ {
+ return;
+ }
+
+ lock (gate)
+ {
+ if (storageInitialized)
+ {
+ return;
+ }
+
+ try
+ {
+ // read account configuration settings
+ var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
+
+ // create blob container for images
+ blobStorage = storageAccount.CreateCloudBlobClient();
+ CloudBlobContainer container = blobStorage.GetContainerReference(profilesContainerName);
+ container.CreateIfNotExist();
+
+ // configure container for public access
+ var permissions = container.GetPermissions();
+ permissions.PublicAccess = BlobContainerPublicAccessType.Container;
+ container.SetPermissions(permissions);
+ }
+ catch (WebException)
+ {
+ throw new WebException("Storage services initialization failure. "
+ + "Check your storage account configuration settings. If running locally, "
+ + "ensure that the Development Storage service is running.");
+ }
+
+ storageInitialized = true;
+ }
}
}
diff --git a/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj b/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj
index e542600..479c7ee 100644
--- a/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj
+++ b/main/MyFriendsAround.Data.BLL/MyFriendsAround.BLL.csproj
@@ -49,7 +49,9 @@
..\Libs\Sql\Microsoft.SqlServer.Types.dll
True
+
+
diff --git a/main/MyFriendsAround.WP7/App.xaml b/main/MyFriendsAround.WP7/App.xaml
index 96b5071..cdb5ea9 100644
--- a/main/MyFriendsAround.WP7/App.xaml
+++ b/main/MyFriendsAround.WP7/App.xaml
@@ -19,7 +19,6 @@
-
diff --git a/main/MyFriendsAround.WP7/App.xaml.cs b/main/MyFriendsAround.WP7/App.xaml.cs
index ecc04e9..5805350 100644
--- a/main/MyFriendsAround.WP7/App.xaml.cs
+++ b/main/MyFriendsAround.WP7/App.xaml.cs
@@ -1,21 +1,26 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Net;
+using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
+using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using Microsoft.Phone;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using MyFriendsAround.WP7.ViewModel;
using MyFriendsAround.WP7.Utils;
using GalaSoft.MvvmLight.Threading;
using MyFriendsAround.WP7.Views;
+using NetworkDetection;
namespace MyFriendsAround.WP7
@@ -39,6 +44,9 @@ namespace MyFriendsAround.WP7
// Phone-specific initialization
InitializePhoneApplication();
+ //init NetworkDetector
+ var dummy = NetworkDetector.Instance;
+
//register ViewModelLocator
Container.Instance.RegisterInstance(typeof(ViewModelLocator), "ViewModelLocator");
}
@@ -83,23 +91,29 @@ namespace MyFriendsAround.WP7
MainViewModel mainModel = this.RetrieveFromIsolatedStorage();
if (mainModel != null)
{
+ mainModel.IsLoaded = true;
+ mainModel.IsBusy = false;
Container.Instance.RegisterInstance(mainModel, "MainViewModel");
}
else
{
Container.Instance.RegisterInstance(new MainViewModel(), "MainViewModel");
}
+ //
SettingsViewModel settingsModel = this.RetrieveFromIsolatedStorage();
if (settingsModel != null)
{
+ settingsModel.IsLoaded = true;
Container.Instance.RegisterInstance(settingsModel, "SettingsViewModel");
}
else
{
Container.Instance.RegisterInstance(new SettingsViewModel(), "SettingsViewModel");
}
+
}
+
private void SaveModel()
{
this.SaveToIsolatedStorage(Container.Instance.Resolve("MainViewModel"));
diff --git a/main/MyFriendsAround.WP7/ApplicationIcon.png b/main/MyFriendsAround.WP7/ApplicationIcon.png
index 5859393..5d874b5 100644
Binary files a/main/MyFriendsAround.WP7/ApplicationIcon.png and b/main/MyFriendsAround.WP7/ApplicationIcon.png differ
diff --git a/main/MyFriendsAround.WP7/Background.png b/main/MyFriendsAround.WP7/Background.png
index e46f21d..52c8166 100644
Binary files a/main/MyFriendsAround.WP7/Background.png and b/main/MyFriendsAround.WP7/Background.png differ
diff --git a/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj b/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj
index 7eddc51..d48bc3d 100644
--- a/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj
+++ b/main/MyFriendsAround.WP7/MyFriendsAround.WP7.csproj
@@ -135,6 +135,9 @@
Entities\FriendExt.cs
+
+ Entities\PictureInfo.cs
+
App.xaml
@@ -145,6 +148,10 @@
Code
+
+
+ CropPage.xaml
+
SettingsPage.xaml
@@ -177,6 +184,10 @@
MSBuild:Compile
Designer
+
+ MSBuild:Compile
+ Designer
+
Designer
MSBuild:Compile
@@ -211,6 +222,9 @@
Always
+
+ PreserveNewest
+
PreserveNewest
diff --git a/main/MyFriendsAround.WP7/Service/ServiceAgent.cs b/main/MyFriendsAround.WP7/Service/ServiceAgent.cs
index a97937e..53c6ae8 100644
--- a/main/MyFriendsAround.WP7/Service/ServiceAgent.cs
+++ b/main/MyFriendsAround.WP7/Service/ServiceAgent.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
+using System.Text;
using Hammock;
using Hammock.Web;
using MyFriendsAround.Common.Entities;
@@ -11,7 +12,7 @@ namespace MyFriendsAround.WP7.Service
{
private static int _timeOut = 10;
- private static string baseUrl;
+ public static string baseUrl;
static ServiceAgent()
{
@@ -115,5 +116,58 @@ namespace MyFriendsAround.WP7.Service
}
#endregion
+
+
+ #region PublishMyPicture
+
+
+ public static EventHandler publishmypicturecallback;
+ public static void PublishMyPicture(string userId, byte[] picture, EventHandler callback)
+ {
+ var serializer = new Hammock.Serialization.HammockDataContractJsonSerializer();
+ RestClient client = new RestClient
+ {
+ Authority = baseUrl,
+ Timeout = new TimeSpan(0, 0, 0, _timeOut),
+ Serializer = serializer,
+ Deserializer = serializer
+ };
+ RestRequest request = new RestRequest
+ {
+ Timeout = new TimeSpan(0, 0, 0, _timeOut),
+ Method = WebMethod.Post,
+ Path = "UpdatePicture",
+ Entity = new PictureInfo()
+ {
+ UserId = userId,
+ Picture = Convert.ToBase64String(picture)
+ }
+ };
+ publishmypicturecallback = callback;
+ try
+ {
+ client.BeginRequest(request, new RestCallback(PublishMyPictureCallback));
+ }
+ catch (Exception ex)
+ {
+ publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = ex });
+ }
+
+ }
+
+ public static void PublishMyPictureCallback(RestRequest request, RestResponse response, object userState)
+ {
+ if (response.StatusCode == HttpStatusCode.OK)
+ {
+ bool success = response.ContentEntity;
+ publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = success });
+ }
+ else
+ {
+ publishmypicturecallback.Invoke(null, new PublishLocationEventArgs() { IsSuccess = false, Error = new Exception("Communication Error!") });
+ }
+ }
+
+ #endregion
}
}
diff --git a/main/MyFriendsAround.WP7/SplashScreenImage.jpg b/main/MyFriendsAround.WP7/SplashScreenImage.jpg
index 353b192..25d4976 100644
Binary files a/main/MyFriendsAround.WP7/SplashScreenImage.jpg and b/main/MyFriendsAround.WP7/SplashScreenImage.jpg differ
diff --git a/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs b/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs
index 94dced0..1dce37c 100644
--- a/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs
+++ b/main/MyFriendsAround.WP7/Utils/IsolatedStorageHelper.cs
@@ -45,11 +45,36 @@ namespace MyFriendsAround.WP7.Utils
isoFile.CreateDirectory(imageFolder);
}
string filePath = Path.Combine(imageFolder, imageFileName);
+ if (!isoFile.FileExists(filePath))
+ {
+ return null;
+ }
using (var imageStream = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
{
var imageSource = PictureDecoder.DecodeJpeg(imageStream);
return imageSource;
}
}
+
+ public static byte[] LoadFromLocalStorageArray(string imageFileName, string imageFolder)
+ {
+ var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
+ if (!isoFile.DirectoryExists(imageFolder))
+ {
+ isoFile.CreateDirectory(imageFolder);
+ }
+ string filePath = Path.Combine(imageFolder, imageFileName);
+ if (!isoFile.FileExists(filePath))
+ {
+ return null;
+ }
+ using (var imageStream = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
+ {
+ byte[] buffer = new byte[imageStream.Length];
+ imageStream.Read(buffer, 0, buffer.Length);
+ return buffer;
+ }
+ return null;
+ }
}
}
diff --git a/main/MyFriendsAround.WP7/Utils/NetworkDetector.cs b/main/MyFriendsAround.WP7/Utils/NetworkDetector.cs
new file mode 100644
index 0000000..9563127
--- /dev/null
+++ b/main/MyFriendsAround.WP7/Utils/NetworkDetector.cs
@@ -0,0 +1,387 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+
+
+
+/**********************************************/
+/* Copyright of Gabor Dolhai @ 2010 */
+/* under MS-Pl license */
+/* can be used freely for anybody */
+/* If you use this code please send me an */
+/*email about your project to dolhaig at gmail*/
+/*******************Thanks*********************/
+namespace NetworkDetection
+{
+ #region Custom Enums and EventArgs
+ public enum NetworkTypeRequestStatus
+ {
+ Default = 0,
+ Started,//represents BackgroundWorker started
+ Ended//BackgroundWorker Finished
+ }
+
+ public class NetworkAvailableEventArgs : System.EventArgs
+ {
+
+ public NetworkAvailableEventArgs(bool isOnline)
+ {
+ IsOnline = isOnline;
+ }
+
+ public bool IsOnline { get; private set; }
+ }
+
+ public class NetworkDetectorEventArgs : System.EventArgs
+ {
+
+ public NetworkDetectorEventArgs(bool isOnline, Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType netType)
+ {
+ IsOnline = isOnline;
+ NetType = netType;
+ }
+
+ public bool IsOnline { get; private set; }
+ public Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType NetType { get; private set; }
+ }
+ #endregion
+
+ public class NetworkDetector
+ {
+ private static readonly NetworkDetector _instance = new NetworkDetector();
+
+ #region Events
+ public event EventHandler OnNetworkON;
+ public event EventHandler OnNetworkOFF;
+ public event EventHandler OnNetworkChanged;
+
+ public event EventHandler OnZuneConnected;
+ public event EventHandler OnZuneDisconnected;
+ public event EventHandler OnConnectedEthernet;
+ public event EventHandler OnConnectedWifi;
+ public event EventHandler OnConnectedNone;
+ public event EventHandler OnConnectedBroadbandGsm;
+ public event EventHandler OnConnectedBroadbandCdma;
+ public event EventHandler OnConnectedOther;
+ public event EventHandler OnLostNetworkType;
+
+ public event EventHandler OnAsyncGetNetworkTypeCompleted;
+ #endregion
+
+ private System.Windows.Threading.DispatcherTimer updateTimer, pollTimer;
+ private Queue requestQueue; //queue to store the requests timestemps
+ private BackgroundWorker networkWorker;
+ private bool online = false;
+ private Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType net;
+ private NetworkTypeRequestStatus requestStatus; //current status of the BackgroundWorker
+ private bool IsInstantRequestPresent;
+ private bool detailedMode;
+ private bool isZuneConnected;
+
+ private NetworkDetector()
+ {
+ requestQueue = new Queue();
+ requestQueue.Clear();
+ requestStatus = NetworkTypeRequestStatus.Default;
+ updateTimer = new System.Windows.Threading.DispatcherTimer();
+ updateTimer.Tick += new EventHandler(updateTimer_Tick);
+ updateTimer.Interval = new TimeSpan(0, 0, 0, 0, 300);//there is no need to restart the BGWorker sooner then 300 millisec because the ~3request/sec requestlimit
+ //updateTimer.Start();
+ pollTimer = new System.Windows.Threading.DispatcherTimer();
+ pollTimer.Tick += new EventHandler(pollTimer_Tick);
+ networkWorker = new BackgroundWorker();
+ networkWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(networkWorker_RunWorkerCompleted);
+ networkWorker.DoWork += new DoWorkEventHandler(networkWorker_DoWork);
+ IsInstantRequestPresent = false;
+ detailedMode = false; //by default I hide the framework events for better Developer experience
+ isZuneConnected = false;
+
+ SetupNetworkChange(); //signing on the framework event
+ }
+
+ public static NetworkDetector Instance
+ {
+ get
+ {
+ return _instance;
+ }
+ }
+
+ #region BackgroundWorker
+ void networkWorker_DoWork(object sender, DoWorkEventArgs e)
+ {
+ Debug.WriteLine(">>>>> GetNetType started " + System.DateTime.Now.ToString("T") + " >>>>>");
+ e.Result = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
+ }
+ //no need to lock the variables if We do everithing in the completed event handler
+
+ void networkWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+ {
+ DetectOnlineStatus();
+ if ((detailedMode) || (net != (Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType)e.Result))
+ {
+ //there is no need to get events all the time, just when really changing something or the DetailedMode is true
+ if (net != (Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType)e.Result)
+ RaiseNotify(OnLostNetworkType, new NetworkDetectorEventArgs(online, net));
+ net = (Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType)e.Result;
+ Debug.WriteLine(" New NetType: " + net.ToString());
+ if (net == Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet) Debug.WriteLine("!!!!! Zune is Connected");
+ switch (net)
+ {
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet:
+ if (!isZuneConnected)
+ {
+ isZuneConnected = true;
+ RaiseNotify(OnZuneConnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedEthernet, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Wireless80211:
+ if (isZuneConnected)
+ {
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedWifi, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandCdma:
+ if (isZuneConnected)
+ {
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedBroadbandCdma, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandGsm:
+ if (isZuneConnected)
+ {
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ RaiseNotify(OnConnectedBroadbandGsm, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None:
+ if (!online)
+ {
+ if (isZuneConnected)
+ {
+ /*if we lost all network connection and the Zune was present before,
+ then we lost the Zune too. Normally when Zune is present and then we got
+ a None NetType, the PC just lost the internet connection but not the Zune sync*/
+ isZuneConnected = false;
+ RaiseNotify(OnZuneDisconnected, new NetworkDetectorEventArgs(online, net));
+ }
+ }
+ RaiseNotify(OnConnectedNone, new NetworkDetectorEventArgs(online, net));
+ break;
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.AsymmetricDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Atm:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.BasicIsdn:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet3Megabit:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.FastEthernetT:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Fddi:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.GenericModem:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.HighPerformanceSerialBus:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.IPOverAtm:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Isdn:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Loopback:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MultiRateSymmetricDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ppp:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.PrimaryIsdn:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.RateAdaptDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Slip:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.SymmetricDsl:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.TokenRing:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Tunnel:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Unknown:
+ case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.VeryHighSpeedDsl:
+ default://theoretically we can't get here but better be prepared
+ RaiseNotify(OnConnectedOther, new NetworkDetectorEventArgs(online, net));
+ break;
+ }
+ }
+ for (int i = 0; i < requestQueue.Count; i++)
+ {
+ if (requestQueue.Peek() < System.DateTime.Now.Ticks) requestQueue.Dequeue();
+ //the requests before this moment just got answered
+ //if other requests are coming right after this, they will be served inside the next networkWorker_RunWorkerCompleted
+ }
+ if (requestQueue.Count == 0) updateTimer.Stop();
+ if (IsInstantRequestPresent) //the user requested a single poll
+ {
+ RaiseNotify(OnAsyncGetNetworkTypeCompleted, new NetworkDetectorEventArgs(online, net));
+ IsInstantRequestPresent = false;
+ }
+ requestStatus = NetworkTypeRequestStatus.Ended;
+ Debug.WriteLine("<<<<< GetNetType ended " + System.DateTime.Now.ToString("T") + " <<<<<");
+ }
+ #endregion
+
+ #region Private Functions
+ private void EnqueueRequest()
+ {
+ requestQueue.Enqueue(System.DateTime.Now.Ticks);
+ if (!updateTimer.IsEnabled) updateTimer.Start();
+ }
+
+ private void DetectOnlineStatus() //are we connected to any network or not
+ {
+ if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
+ {
+ if (!online)
+ {
+ online = true; //the network just came back
+ RaiseNotify(OnNetworkON, new NetworkAvailableEventArgs(online));
+ // do what is needed to GoOnline();
+ }
+ }
+ else
+ {
+ if (online)
+ {
+ online = false; //we just lost all network connectivity
+ RaiseNotify(OnNetworkOFF, new NetworkAvailableEventArgs(online));
+ Debug.WriteLine("----- No network available. -----");
+ // do what is needed to GoOffline();
+ }
+ }
+ }
+
+ void pollTimer_Tick(object sender, EventArgs e)
+ {
+ EnqueueRequest();
+ }
+
+ void updateTimer_Tick(object sender, EventArgs e)
+ {
+ if (requestQueue.Count > 0)
+ {
+ if (!networkWorker.IsBusy)
+ {
+ requestStatus = NetworkTypeRequestStatus.Started;
+ networkWorker.RunWorkerAsync();
+ }
+ }
+ }
+
+ #region Event Handling
+ private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
+ {
+ Debug.WriteLine("+++++ Changed started " + System.DateTime.Now.ToString("T") + " +++++");
+ DetectOnlineStatus();
+ if (detailedMode) RaiseNotify(OnNetworkChanged, new NetworkAvailableEventArgs(online));
+ Debug.WriteLine(" IsOnline : " + online.ToString());
+ Debug.WriteLine(" Current NetType: " + net.ToString());
+ Debug.WriteLine("+++++ Changed Ended " + System.DateTime.Now.ToString("T"));
+ Debug.WriteLine(" Changed GetNetType Launch" + System.DateTime.Now.ToString("T"));
+ EnqueueRequest();
+ }
+
+ private void SetupNetworkChange()
+ {
+ // Get current network availalability and store the
+ // initial value of the online variable
+ if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
+ {
+ online = true;
+ // do what is needed to GoOnline();
+ }
+ else
+ {
+ online = false;
+ // do what is needed to GoOffline();
+ }
+ // Now add a network change event handler to indicate network availability
+ EnqueueRequest();
+ System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += new System.Net.NetworkInformation.NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
+ }
+
+ protected void RaiseNotify(EventHandler handler, NetworkDetectorEventArgs e)
+ {
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+
+ protected void RaiseNotify(EventHandler handler, NetworkAvailableEventArgs e)
+ {
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+ #endregion
+
+ #endregion
+
+ #region Public Functions and Properties
+ public void AsyncGetNetworkType()
+ {
+ //requestQueue.Enqueue(System.DateTime.Now.Ticks);
+ IsInstantRequestPresent = true;
+ if (!networkWorker.IsBusy)
+ {
+ requestStatus = NetworkTypeRequestStatus.Started;
+ networkWorker.RunWorkerAsync();
+ }
+ if (!updateTimer.IsEnabled) updateTimer.Start();
+ }
+
+ public void SetNetworkPolling(int Minutes, int Seconds, int Milliseconds)
+ {
+ pollTimer.Interval = new TimeSpan(0, 0, Minutes, Seconds, Milliseconds);
+ if (!pollTimer.IsEnabled) pollTimer.Start();
+ }
+
+ public void DisableNetworkPolling()
+ {
+ if (pollTimer.IsEnabled) pollTimer.Stop();
+ }
+
+
+
+ public Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType GetCurrentNetworkType()
+ {
+ return net;
+ }
+
+ public NetworkTypeRequestStatus GetRequestStatus()
+ {
+ //NetworkTypeRequestStatus temp = requestStatus;
+ //if (requestStatus == NetworkTypeRequestStatus.Ended) requestStatus = NetworkTypeRequestStatus.Default;
+ //return temp;
+ return requestStatus;
+ }
+
+ public bool DetailedMode
+ {
+ get
+ {
+ return detailedMode;
+ }
+ set
+ {
+ detailedMode = value;
+ }
+ }
+
+ public bool GetZuneStatus()
+ {
+ return isZuneConnected;
+ }
+ #endregion
+ }
+}
diff --git a/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs b/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs
index 85e1bb2..43bdbe2 100644
--- a/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs
+++ b/main/MyFriendsAround.WP7/ViewModel/MainViewModel.cs
@@ -6,11 +6,13 @@ using System.IO;
using System.Net;
using System.Security;
using System.ServiceModel.Channels;
+using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
using Coding4Fun.Phone.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
@@ -25,6 +27,7 @@ using MyFriendsAround.Common.Entities;
using MyFriendsAround.WP7.Service;
using MyFriendsAround.WP7.Utils;
using MyFriendsAround.WP7.Views;
+using NetworkDetection;
using Newtonsoft.Json;
using Microsoft.Phone.Tasks;
@@ -68,12 +71,21 @@ namespace MyFriendsAround.WP7.ViewModel
}
}
+ public string PageNameCropping
+ {
+ get
+ {
+ return "Crop";
+ }
+ }
+
///
/// Initializes a new instance of the MainViewModel class.
///
public MainViewModel()
{
//
+ MainLoadCommand = new RelayCommand(() => MainLoad());
PublishLocationCommand = new RelayCommand(() => PublishLocationAction());
DisplayAboutCommand = new RelayCommand(() => DisplayAbout());
NavigateToSettingsCommand = new RelayCommand(() => NavigateToSettings());
@@ -82,6 +94,8 @@ namespace MyFriendsAround.WP7.ViewModel
SaveMySettingsCommand = new RelayCommand(() => SaveMySettings());
CancelMySettingsCommand = new RelayCommand(() => CancelMySettings());
ChoosePhotoCommand = new RelayCommand(() => ChoosePhoto());
+ CropSaveCommand = new RelayCommand(() => CropSave());
+ CropCancelCommand = new RelayCommand(() => CropCancel());
if (IsInDesignMode)
{
@@ -94,17 +108,75 @@ namespace MyFriendsAround.WP7.ViewModel
}
+ public void CropCancel()
+ {
+ //
+ this.PageNav.GoBack();
+ }
+
+ public void CropSave()
+ {
+ //
+ }
+
+
+ private void MainLoad()
+ {
+ if (IsLoaded)
+ {
+ //
+ ThreadPool.QueueUserWorkItem(LoadMyPicture);
+ //
+ IsLoaded = false;
+ }
+ }
+
+ private void LoadMyPicture(object param) //Background thread
+ {
+ Thread.Sleep(500);
+ byte[] img = IsolatedStorageHelper.LoadFromLocalStorageArray("myphoto.jpg", "profiles");
+ if (img != null)
+ {
+ DispatcherHelper.CheckBeginInvokeOnUI(() =>
+ {
+ using (MemoryStream ms = new MemoryStream(img))
+ {
+ Container.Instance.Resolve("MainViewModel").MyPicture = PictureDecoder.DecodeJpeg(ms);
+ }
+ });
+ }
+ else
+ {
+ DispatcherHelper.CheckBeginInvokeOnUI(() =>
+ {
+ Container.Instance.Resolve("MainViewModel").MyPicture = new BitmapImage(new Uri("/icons/anonymousIcon.png", UriKind.RelativeOrAbsolute));
+ });
+ }
+ }
+
+
private void ChoosePhoto()
{
//choose photo
- ShowCameraCaptureTask();
+ //ShowCameraCaptureTask();
//ShowPhotoChooserTask();
+ if (!NetworkDetector.Instance.GetZuneStatus())
+ {
+ this.PageNav.NavigateTo(new Uri("/Views/CropPage.xaml", UriKind.RelativeOrAbsolute));
+ }
+ else
+ {
+ MessageBox.Show("Please disconnect from Zune!");
+ }
}
+ PhotoChooserTask photoChooserTask = new PhotoChooserTask();
private void ShowPhotoChooserTask()
{
- var photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += cameraTask_Completed;
+ //photoChooserTask.PixelHeight = 100;
+ //photoChooserTask.PixelWidth = 100;
+ photoChooserTask.ShowCamera = true;
photoChooserTask.Show();
}
@@ -117,7 +189,7 @@ namespace MyFriendsAround.WP7.ViewModel
private void cameraTask_Completed(object sender, PhotoResult e)
{
- if (e.TaskResult == TaskResult.OK)
+ if (e.ChosenPhoto!=null && e.ChosenPhoto.Length>0) // e.TaskResult == TaskResult.OK)
{
// Get the image temp file from e.OriginalFileName.
// Get the image temp stream from e.ChosenPhoto.
@@ -127,10 +199,11 @@ namespace MyFriendsAround.WP7.ViewModel
// Store the image bytes.
byte[] _imageBytes = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Read(_imageBytes, 0, _imageBytes.Length);
+ //save
+ IsolatedStorageHelper.SaveToLocalStorage("myphoto.jpg", "profiles", _imageBytes);
// Seek back so we can create an image.
e.ChosenPhoto.Seek(0, SeekOrigin.Begin);
-
// Create an image from the stream.
var imageSource = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
MyPicture = imageSource;
@@ -141,12 +214,12 @@ namespace MyFriendsAround.WP7.ViewModel
/// The property's name.
///
public const string MyPicturePropertyName = "MyPicture";
- private BitmapSource _myPicture = new BitmapImage(new Uri("/icons/anonymousIcon.png", UriKind.RelativeOrAbsolute));
+ private ImageSource _myPicture = new BitmapImage(new Uri("/icons/anonymousIcon.png", UriKind.RelativeOrAbsolute));
///
/// Gets the MyPicture property.
///
- public BitmapSource MyPicture
+ public ImageSource MyPicture
{
get
{
@@ -221,7 +294,9 @@ namespace MyFriendsAround.WP7.ViewModel
result.Add(new PushPinModel()
{
PinSource = "/ApplicationIcon.png",
- Location = new GeoCoordinate(f.Latitude, f.Longitude)
+ Location = new GeoCoordinate(f.Latitude, f.Longitude),
+ PinUserName = f.FriendName,
+ PinImageUrl = string.Format("https://myfriendsaround.blob.core.windows.net/profiles/profile_{0}.jpg", f.Id)
});
});
PushPins = result;
@@ -290,13 +365,60 @@ namespace MyFriendsAround.WP7.ViewModel
Messenger.Default.Send(message);
});
}
- //
- //update
- ServiceAgent.GetFriends(this.GetFriendsResult);
+ else
+ {
+ //update also the picture
+ byte[] img = IsolatedStorageHelper.LoadFromLocalStorageArray("myphoto.jpg", "profiles");
+ if (img != null)
+ {
+ ServiceAgent.PublishMyPicture(Identification.GetDeviceId(), img, new EventHandler(PublishMyPictureResult));
+ }
+ else
+ {
+ //update friends list
+ ServiceAgent.GetFriends(this.GetFriendsResult);
+ }
+ }
}
}
+ public void PublishMyPictureResult(object sender, PublishLocationEventArgs args)
+ {
+ //
+ if (args.Error != null)
+ {
+ DispatcherHelper.CheckBeginInvokeOnUI(() =>
+ {
+ IsBusy = false;
+ var exception = new ExceptionPrompt();
+ exception.Show(args.Error);
+ });
+ }
+ else
+ {
+ if (!args.IsSuccess)
+ {
+ DispatcherHelper.CheckBeginInvokeOnUI(() =>
+ {
+ var message = new DialogMessage(
+ "Communication error!", DialogMessageCallback)
+ {
+ Button = MessageBoxButton.OK,
+ Caption = "Error!"
+ };
+
+ Messenger.Default.Send(message);
+ });
+ }
+ else
+ {
+ //update friends list
+ ServiceAgent.GetFriends(this.GetFriendsResult);
+ }
+ }
+ }
+
private void DialogMessageCallback(MessageBoxResult result)
{
if (result == MessageBoxResult.OK)
@@ -309,6 +431,7 @@ namespace MyFriendsAround.WP7.ViewModel
}
}
+ public ICommand MainLoadCommand { get; set; }
public ICommand PublishLocationCommand { get; set; }
public ICommand DisplayAboutCommand { get; set; }
public ICommand NavigateToSettingsCommand { get; set; }
@@ -317,6 +440,9 @@ namespace MyFriendsAround.WP7.ViewModel
public ICommand SaveMySettingsCommand { get; set; }
public ICommand CancelMySettingsCommand { get; set; }
public ICommand ChoosePhotoCommand { get; set; }
+ public ICommand CropSaveCommand { get; set; }
+ public ICommand CropCancelCommand { get; set; }
+
@@ -408,7 +534,6 @@ namespace MyFriendsAround.WP7.ViewModel
return;
}
- var oldValue = _PushPins;
_PushPins = value;
// Update bindings, no broadcast
@@ -420,6 +545,35 @@ namespace MyFriendsAround.WP7.ViewModel
}
+ ///
+ /// The property's name.
+ ///
+ public const string MapZoomPropertyName = "MapZoom";
+
+ private int _mapZoom = 1;
+
+ ///
+ /// Gets the MapZoom property.
+ ///
+ public int MapZoom
+ {
+ get
+ {
+ return _mapZoom;
+ }
+
+ set
+ {
+ if (_mapZoom == value)
+ {
+ return;
+ }
+ _mapZoom = value;
+
+ // Update bindings, no broadcast
+ RaisePropertyChanged(MapZoomPropertyName);
+ }
+ }
///
@@ -487,5 +641,6 @@ namespace MyFriendsAround.WP7.ViewModel
RaisePropertyChanged(IsBusyPropertyName);
}
}
+
}
}
\ No newline at end of file
diff --git a/main/MyFriendsAround.WP7/ViewModel/PushPinModel.cs b/main/MyFriendsAround.WP7/ViewModel/PushPinModel.cs
index 715dc27..64891db 100644
--- a/main/MyFriendsAround.WP7/ViewModel/PushPinModel.cs
+++ b/main/MyFriendsAround.WP7/ViewModel/PushPinModel.cs
@@ -40,6 +40,39 @@ namespace MyFriendsAround.WP7.ViewModel
}
}
+
+ private string _pinUserName;
+
+ public string PinUserName
+ {
+ get { return _pinUserName; }
+ set
+ {
+ if (_pinUserName != value)
+ {
+ _pinUserName = value;
+ OnPropertyChanged("PinUserName");
+ }
+ }
+ }
+
+
+ private string _pinImageUrl;
+
+ public string PinImageUrl
+ {
+ get { return _pinImageUrl; }
+ set
+ {
+ if (_pinImageUrl != value)
+ {
+ _pinImageUrl = value;
+ OnPropertyChanged("PinImageUrl");
+ }
+ }
+ }
+
+
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
diff --git a/main/MyFriendsAround.WP7/ViewModel/ViewModelBase.cs b/main/MyFriendsAround.WP7/ViewModel/ViewModelBase.cs
index d04b85a..490265a 100644
--- a/main/MyFriendsAround.WP7/ViewModel/ViewModelBase.cs
+++ b/main/MyFriendsAround.WP7/ViewModel/ViewModelBase.cs
@@ -14,6 +14,9 @@ namespace MyFriendsAround.WP7.ViewModel
{
public class ViewModelBase : GalaSoft.MvvmLight.ViewModelBase
{
+
+ public bool IsLoaded { get; set; }
+
private object context;
public object Context
{
diff --git a/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs b/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs
index 3a42d0d..d89a811 100644
--- a/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs
+++ b/main/MyFriendsAround.WP7/ViewModel/ViewModelLocator.cs
@@ -15,6 +15,8 @@
*/
using MyFriendsAround.WP7.Helpers.Navigation;
+using NetworkDetection;
+
namespace MyFriendsAround.WP7.ViewModel
{
///
diff --git a/main/MyFriendsAround.WP7/Views/CropPage.xaml b/main/MyFriendsAround.WP7/Views/CropPage.xaml
new file mode 100644
index 0000000..44ced93
--- /dev/null
+++ b/main/MyFriendsAround.WP7/Views/CropPage.xaml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main/MyFriendsAround.WP7/Views/CropPage.xaml.cs b/main/MyFriendsAround.WP7/Views/CropPage.xaml.cs
new file mode 100644
index 0000000..ee04720
--- /dev/null
+++ b/main/MyFriendsAround.WP7/Views/CropPage.xaml.cs
@@ -0,0 +1,179 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using Microsoft.Phone;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Tasks;
+using MyFriendsAround.WP7.Utils;
+using MyFriendsAround.WP7.ViewModel;
+using NetworkDetection;
+
+namespace MyFriendsAround.WP7.Views
+{
+ public partial class CropPage : PhoneApplicationPage
+ {
+ private int imageSize = 200;
+
+ public CropPage()
+ {
+ InitializeComponent();
+ this.Loaded += new RoutedEventHandler(CropPage_Loaded);
+ }
+
+ //private BitmapImage imageSrc;
+ void CropPage_Loaded(object sender, RoutedEventArgs e)
+ {
+ if (!NetworkDetector.Instance.GetZuneStatus())
+ {
+ PhotoChooserTask task = new PhotoChooserTask();
+ task.Show();
+ task.Completed += new EventHandler(task_Completed);
+
+ //TEST
+ //imageSrc = new BitmapImage(new Uri("/icons/Penguins.jpg", UriKind.RelativeOrAbsolute));
+ //image1.Source = imageSrc;
+
+ SetPicture();
+ }
+ else
+ {
+ NavigateBack();
+ }
+ }
+
+ private void NavigateBack()
+ {
+ Container.Instance.Resolve("MainViewModel").CropCancel();
+ }
+
+ void task_Completed(object sender, PhotoResult e)
+ {
+ if (e.TaskResult == TaskResult.OK)
+ {
+ BitmapImage image = new BitmapImage();
+ image.SetSource(e.ChosenPhoto);
+ //
+ image1.Width = this.Width/2;
+ image1.Height = image1.Width*image.PixelHeight/image.PixelWidth;
+ image1.Source = image;
+
+ SetPicture();
+ }
+ else
+ {
+ NavigateBack();
+ }
+ }
+
+ private Rectangle rect;
+ void SetPicture()
+ {
+ rect = new Rectangle();
+ rect.Opacity = .5;
+ rect.Fill = new SolidColorBrush(Colors.White);
+ rect.Height = imageSize;
+ rect.MaxHeight = imageSize;
+ rect.MaxWidth = imageSize;
+ rect.Width = imageSize;
+ rect.Stroke = new SolidColorBrush(Colors.Red);
+ rect.StrokeThickness = 2;
+ rect.Margin = new Thickness(0);
+ ImageContainer.ManipulationDelta += new EventHandler(rect_ManipulationDelta);
+
+ ImageContainer.Children.Add(rect);
+ ImageContainer.Height = this.ActualWidth;
+ ImageContainer.Width = this.ActualWidth;
+ }
+
+ int trX = 0;
+ int trY = 0;
+ double scale = 1;
+
+ void rect_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
+ {
+
+ if (e.DeltaManipulation.Scale.X > 0 && e.DeltaManipulation.Scale.Y > 0)
+ {
+ scale = scale*(e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y)/2;
+ }
+
+ trX += (int) ((double) e.DeltaManipulation.Translation.X /scale);
+ trY += (int) ((int) e.DeltaManipulation.Translation.Y /scale);
+ e.Handled = true;
+
+ TransformGroup tg = new TransformGroup();
+
+ ScaleTransform st = new ScaleTransform();
+ st.CenterX = ImageContainer.ActualWidth / 2 - trX;
+ st.CenterY = ImageContainer.ActualHeight / 2 - trY;
+ st.ScaleX = scale;
+ st.ScaleY = scale;
+ tg.Children.Add(st);
+
+ TranslateTransform tr = new TranslateTransform();
+ tr.X = trX;
+ tr.Y = trY;
+ tg.Children.Add(tr);
+
+
+ image1.RenderTransform = tg;
+
+ //croppingRectangle
+ GeneralTransform gt = image1.TransformToVisual(ImageContainer);
+ Point p = gt.Transform(new Point( 0, 0));
+ RectangleGeometry geo = new RectangleGeometry();
+ geo.Rect = new Rect(-p.X / scale, -p.Y / scale, ImageContainer.ActualWidth / scale, ImageContainer.ActualHeight / scale);
+ image1.Clip = geo;
+ }
+
+ public void Save()
+ {
+ WriteBitmap();
+ }
+
+ void WriteBitmap()
+ {
+ Rectangle r = (Rectangle)(from c in ImageContainer.Children where c.Opacity == .5 select c).First();
+ GeneralTransform gt = r.TransformToVisual(image1);
+ //
+ WriteableBitmap wbm = new WriteableBitmap(imageSize, imageSize);
+ wbm.Render(image1, gt.Inverse as Transform);
+ wbm.Invalidate();
+
+ using (MemoryStream stream = new MemoryStream())
+ {
+ wbm.SaveJpeg(stream, imageSize, imageSize, 0, 100);
+ //
+ stream.Seek(0, SeekOrigin.Begin);
+ byte[] _imageBytes = new byte[stream.Length];
+ stream.Read(_imageBytes, 0, _imageBytes.Length);
+ //save
+ IsolatedStorageHelper.SaveToLocalStorage("myphoto.jpg", "profiles", _imageBytes);
+ //
+ Container.Instance.Resolve("MainViewModel").MyPicture = wbm;
+ }
+ }
+
+ private void Accept_Click(object sender, EventArgs e)
+ {
+ Save();
+ NavigateBack();
+ }
+
+ private void Cancel_Click(object sender, EventArgs e)
+ {
+ NavigateBack();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/main/MyFriendsAround.WP7/Views/MainPage.xaml b/main/MyFriendsAround.WP7/Views/MainPage.xaml
index 5a41441..12575aa 100644
--- a/main/MyFriendsAround.WP7/Views/MainPage.xaml
+++ b/main/MyFriendsAround.WP7/Views/MainPage.xaml
@@ -36,13 +36,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -71,28 +96,24 @@
-->
+ Center="{Binding Path=MapCenter, Mode=TwoWay}"
+ ZoomLevel="{Binding Path=MapZoom, Mode=TwoWay}"
+ >
+ Background="{StaticResource PhoneAccentBrush}"
+ Template="{StaticResource PushpinControlTemplate2}">
-
@@ -107,7 +128,7 @@
@@ -118,9 +139,9 @@
Opacity="1"
>
+ Source="{Binding MyPicture, Mode=OneWay}" Margin="0" Stretch="Fill" >
-
+ Text="{Binding MyName, Mode=OneWay}" />
+
diff --git a/main/MyFriendsAround.WP7/Views/SettingsPage.xaml b/main/MyFriendsAround.WP7/Views/SettingsPage.xaml
index dc16018..bd62f87 100644
--- a/main/MyFriendsAround.WP7/Views/SettingsPage.xaml
+++ b/main/MyFriendsAround.WP7/Views/SettingsPage.xaml
@@ -13,6 +13,12 @@
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
+
+
+
+
+
+
@@ -21,8 +27,9 @@
-
-
+
+
@@ -35,7 +42,8 @@
Margin="6,0,0,6"
>
+ Style="{StaticResource PhoneTextTitle3Style}"
+ />
diff --git a/main/MyFriendsAround.WP7/icons/Penguins.jpg b/main/MyFriendsAround.WP7/icons/Penguins.jpg
new file mode 100644
index 0000000..030ab8a
Binary files /dev/null and b/main/MyFriendsAround.WP7/icons/Penguins.jpg differ
diff --git a/main/MyFriendsAround.Web/Global.asax.cs b/main/MyFriendsAround.Web/Global.asax.cs
index 7390013..465d381 100644
--- a/main/MyFriendsAround.Web/Global.asax.cs
+++ b/main/MyFriendsAround.Web/Global.asax.cs
@@ -41,6 +41,13 @@ namespace MyFriendsAround.Web
protected void Application_Start()
{
+ //setup azure
+ Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
+ {
+ configSetter(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName));
+ });
+
+
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
diff --git a/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj b/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj
index cc5ff59..700b9db 100644
--- a/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj
+++ b/main/MyFriendsAround.Web/MyFriendsAround.Web.csproj
@@ -56,6 +56,9 @@
..\Libs\Sql\Microsoft.SqlServer.Types.dll
True
+
+
+
@@ -97,6 +100,7 @@
myfriends.svc
+
diff --git a/main/MyFriendsAround.Web/Web.config b/main/MyFriendsAround.Web/Web.config
index e053112..5818f40 100644
--- a/main/MyFriendsAround.Web/Web.config
+++ b/main/MyFriendsAround.Web/Web.config
@@ -16,6 +16,8 @@
+
+
@@ -98,5 +100,12 @@
+
+
+
+
+
+
+
diff --git a/main/MyFriendsAround.Web/WebRole.cs b/main/MyFriendsAround.Web/WebRole.cs
new file mode 100644
index 0000000..4f1fa66
--- /dev/null
+++ b/main/MyFriendsAround.Web/WebRole.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.WindowsAzure;
+using Microsoft.WindowsAzure.Diagnostics;
+using Microsoft.WindowsAzure.ServiceRuntime;
+
+namespace MyFriendsAround.Web
+{
+ public class WebRole : RoleEntryPoint
+ {
+ private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs args)
+ {
+ }
+
+
+ public override bool OnStart()
+ {
+ DiagnosticMonitor.Start("DataConnectionString");
+
+ // For information on handling configuration changes
+ // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
+
+
+ #region Setup CloudStorageAccount Configuration Setting Publisher
+
+ // This code sets up a handler to update CloudStorageAccount instances when their corresponding
+ // configuration settings change in the service configuration file.
+ CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
+ {
+ // Provide the configSetter with the initial value
+ configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
+
+ RoleEnvironment.Changed += (sender, arg) =>
+ {
+ if (arg.Changes.OfType()
+ .Any((change) => (change.ConfigurationSettingName == configName)))
+ {
+ // The corresponding configuration setting has changed, propagate the value
+ if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
+ {
+ // In this case, the change to the storage account credentials in the
+ // service configuration is significant enough that the role needs to be
+ // recycled in order to use the latest settings. (for example, the
+ // endpoint has changed)
+ RoleEnvironment.RequestRecycle();
+ }
+ }
+ };
+ });
+ #endregion
+
+ // For information on handling configuration changes
+ // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
+ RoleEnvironment.Changing += RoleEnvironmentChanging;
+
+
+ return base.OnStart();
+ }
+ }
+}
diff --git a/main/MyFriendsAround.Web/myfriends.svc.cs b/main/MyFriendsAround.Web/myfriends.svc.cs
index b2bd9fb..9dea317 100644
--- a/main/MyFriendsAround.Web/myfriends.svc.cs
+++ b/main/MyFriendsAround.Web/myfriends.svc.cs
@@ -30,7 +30,7 @@ namespace MyFriendsAround.Web
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
- public List GetFriends(int skip)
+ public List GetFriendsSkip(int skip)
{
int take = Convert.ToInt32(WebConfigurationManager.AppSettings["takeTopFriends"]);
return FriendsRepository.GetFriends(skip, take);
@@ -46,9 +46,9 @@ namespace MyFriendsAround.Web
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "POST")]
- public bool UpdatePicture(string userId, byte[] userPicture)
+ public bool UpdatePicture(PictureInfo pictureInfo)
{
- return FriendsRepository.UpdatePicture(userId, userPicture);
+ return FriendsRepository.UpdatePicture(pictureInfo.UserId, Convert.FromBase64String(pictureInfo.Picture));
}
}
diff --git a/main/MyFriendsAround.sln b/main/MyFriendsAround.sln
index f1ffe22..8d3013d 100644
--- a/main/MyFriendsAround.sln
+++ b/main/MyFriendsAround.sln
@@ -32,6 +32,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroIoc.Core", "Libs\Micro
EndProject
Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "MyFriendsAroundWindowsAzure", "MyFriendsAroundWindowsAzure\MyFriendsAroundWindowsAzure.ccproj", "{C656965D-5A6E-4BD4-9945-9C906B89128D}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkNamespaces", "Libs\NetworkAwarenessTest\NetworkNamespaces\NetworkNamespaces.csproj", "{41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkDetection", "Libs\NetworkAwarenessTest\NetworkDetection\NetworkDetection.csproj", "{794D79F0-E898-460D-BDB5-49FED553E0D5}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -256,6 +260,48 @@ Global
{C656965D-5A6E-4BD4-9945-9C906B89128D}.Tests|Mixed Platforms.ActiveCfg = Release|Any CPU
{C656965D-5A6E-4BD4-9945-9C906B89128D}.Tests|Mixed Platforms.Build.0 = Release|Any CPU
{C656965D-5A6E-4BD4-9945-9C906B89128D}.Tests|x86.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Release|x86.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|Any CPU.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|Any CPU.Build.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|Any CPU.Deploy.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|Mixed Platforms.Build.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|Mixed Platforms.Deploy.0 = Release|Any CPU
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF}.Tests|x86.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Release|x86.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|Any CPU.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|Any CPU.Build.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|Any CPU.Deploy.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|Mixed Platforms.Build.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|Mixed Platforms.Deploy.0 = Release|Any CPU
+ {794D79F0-E898-460D-BDB5-49FED553E0D5}.Tests|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -266,5 +312,7 @@ Global
{BF7316A8-A2C5-4176-8D7F-672AD12F474D} = {340549A1-45EA-4B49-B194-347C0078BAD8}
{B55A0F90-2B5A-4C4B-88F4-013AA1629866} = {340549A1-45EA-4B49-B194-347C0078BAD8}
{23F63AE9-A436-4B27-9113-4142C09ADD08} = {340549A1-45EA-4B49-B194-347C0078BAD8}
+ {41A5C85F-7E30-418B-BAD2-AB2F40FF22CF} = {340549A1-45EA-4B49-B194-347C0078BAD8}
+ {794D79F0-E898-460D-BDB5-49FED553E0D5} = {340549A1-45EA-4B49-B194-347C0078BAD8}
EndGlobalSection
EndGlobal
diff --git a/main/MyFriendsAroundWindowsAzure/ServiceConfiguration.cscfg b/main/MyFriendsAroundWindowsAzure/ServiceConfiguration.cscfg
index a11180b..0702225 100644
--- a/main/MyFriendsAroundWindowsAzure/ServiceConfiguration.cscfg
+++ b/main/MyFriendsAroundWindowsAzure/ServiceConfiguration.cscfg
@@ -4,6 +4,7 @@
+
\ No newline at end of file
diff --git a/main/MyFriendsAroundWindowsAzure/ServiceDefinition.csdef b/main/MyFriendsAroundWindowsAzure/ServiceDefinition.csdef
index ae81ad3..262c7a8 100644
--- a/main/MyFriendsAroundWindowsAzure/ServiceDefinition.csdef
+++ b/main/MyFriendsAroundWindowsAzure/ServiceDefinition.csdef
@@ -15,6 +15,7 @@
+
\ No newline at end of file