Example #1
0
        public static DataPlanInfo FromProfile(ConnectionProfile profile)
        {
            var planStatus = profile.GetDataPlanStatus();

            if (planStatus == null || (planStatus.DataLimitInMegabytes == null && planStatus.DataPlanUsage == null && planStatus.InboundBitsPerSecond == null &&
                                       planStatus.MaxTransferSizeInMegabytes == null && planStatus.NextBillingCycle == null && planStatus.OutboundBitsPerSecond == null))
            {
                return(null);
            }
            var dataPlan = new DataPlanInfo
            {
                DataLimitMegabytes    = planStatus.DataLimitInMegabytes ?? 0,
                InboundBitsPerSecond  = planStatus.InboundBitsPerSecond ?? 0,
                OutboundBitsPerSecond = planStatus.OutboundBitsPerSecond ?? 0,
                NextBillingCycle      = planStatus.NextBillingCycle
            };

            if (planStatus.DataPlanUsage != null)
            {
                dataPlan.MegabytesUsed = planStatus.DataPlanUsage.MegabytesUsed;
                dataPlan.LastSyncTime  = planStatus.DataPlanUsage.LastSyncTime;
            }
            else
            {
                dataPlan.LastSyncTime = null;
            }

            return(dataPlan);
        }
Example #2
0
        public static async Task <ConnectionInfo> FromConnectionProfile(ConnectionProfile profile)
        {
            var connectionInfo = new ConnectionInfo
            {
                Name              = profile.ProfileName,
                IsWlan            = profile.IsWlanConnectionProfile,
                IsWwan            = profile.IsWwanConnectionProfile,
                ConnectivityLevel =
                    profile.GetNetworkConnectivityLevel().ToString(),
                DomainConnectivityLevel =
                    profile.GetDomainConnectivityLevel().ToString()
            };

            var costType = profile.GetConnectionCost();

            connectionInfo.CostType = costType.NetworkCostType.ToString();
            connectionInfo.Flags    = string.Format(
                "{0} {1} {2}",
                costType.ApproachingDataLimit ? "Approaching Data Limit" : string.Empty,
                costType.OverDataLimit ? "Over Data Limit" : string.Empty,
                costType.Roaming ? "Roaming" : string.Empty).Trim();

            connectionInfo.NetworkAdapterId = profile.ServiceProviderGuid;

            if (profile.NetworkAdapter != null)
            {
                connectionInfo.IncomingBitsPerSecond = (long)profile.NetworkAdapter.InboundMaxBitsPerSecond;
                connectionInfo.OutgoingBitsPerSecond = (long)profile.NetworkAdapter.OutboundMaxBitsPerSecond;
                connectionInfo.NetworkType           = profile.NetworkAdapter.NetworkItem.GetNetworkTypes().ToString();
            }

            if (profile.NetworkSecuritySettings != null)
            {
                connectionInfo.AuthenticationType = profile.NetworkSecuritySettings.NetworkAuthenticationType.ToString();
                connectionInfo.EncryptionType     = profile.NetworkSecuritySettings.NetworkEncryptionType.ToString();
            }

            connectionInfo.SignalBars = profile.GetSignalBars();

            connectionInfo.DataPlan = DataPlanInfo.FromProfile(profile);

            var usage =
                await
                profile.GetNetworkUsageAsync(
                    DateTimeOffset.Now.AddDays(-1),
                    DateTimeOffset.Now,
                    DataUsageGranularity.Total,
                    new NetworkUsageStates { Roaming = TriStates.DoNotCare, Shared = TriStates.DoNotCare });

            if (usage != null && usage.Count > 0)
            {
                connectionInfo.BytesReceivedLastDay = usage[0].BytesReceived;
                connectionInfo.BytesSentLastDay     = usage[0].BytesSent;
            }

            return(connectionInfo);
        }
Example #3
0
        private void GenerateDesignMode()
        {
            var random = new Random();

            for (var x = 0; x < 10; x++)
            {
                var connectionInfo = new ConnectionInfo
                {
                    AuthenticationType      = RandomItem(AuthenticationTypes, random),
                    EncryptionType          = RandomItem(EncryptionTypes, random),
                    ConnectivityLevel       = RandomItem(ConnectivityLevels, random),
                    DomainConnectivityLevel = RandomItem(DomainLevels, random),
                    IncomingBitsPerSecond   = random.Next(0, int.MaxValue),
                    OutgoingBitsPerSecond   = random.Next(0, int.MaxValue),
                    IsWlan           = random.Next(0, 1) == 0,
                    IsWwan           = random.Next(0, 1) == 0,
                    Name             = Guid.NewGuid().ToString().Replace('-', ' '),
                    NetworkAdapterId = Guid.NewGuid(),
                    NetworkType      = RandomItem(NetworkTypeList, random),
                    CostType         = RandomItem(CostTypes, random),
                    SignalBars       = (short)random.Next(0, 5),
                    Flags            =
                        string.Format(
                            "{0} {1}",
                            random.Next(0, 1) == 0
                                                         ? (random.Next(0, 1) == 0
                                                                ? "Approaching Data Limit"
                                                                : "Over Data Limit")
                                                         : string.Empty,
                            random.Next(0, 1) == 0 ? "Roaming" : string.Empty)
                        .Trim()
                };
                if (random.Next(0, 1) == 0)
                {
                    var dataPlan = new DataPlanInfo
                    {
                        DataLimitMegabytes    = random.Next(0, int.MaxValue),
                        InboundBitsPerSecond  = (ulong)random.Next(0, int.MaxValue),
                        OutboundBitsPerSecond = (ulong)random.Next(0, int.MaxValue)
                    };
                    if (random.Next(0, 1) == 0)
                    {
                        dataPlan.NextBillingCycle = DateTime.Now.AddDays(random.Next(1, 30));
                    }
                    if (random.Next(0, 1) == 0)
                    {
                        dataPlan.MegabytesUsed = random.Next(0, int.MaxValue);
                        dataPlan.LastSyncTime  = DateTime.Now.AddHours(-1 * random.Next(2, 12));
                    }
                    connectionInfo.DataPlan = dataPlan;
                }
                connectionInfo.BytesReceivedLastDay = (ulong)random.Next(0, int.MaxValue);
                connectionInfo.BytesSentLastDay     = (ulong)random.Next(0, int.MaxValue);
                ConnectionProfiles.Add(connectionInfo);
            }
            CurrentConnectionInfo = ConnectionProfiles[random.Next(0, ConnectionProfiles.Count)];
        }