Ejemplo n.º 1
0
        public static WebClient CreateWebClientWithCredentialsAndProxy(NetworkCredential credentials, ProxyOptions proxyOptions)
        {
            var proxy = proxyOptions != null?SynchronizerFactory.CreateProxy(proxyOptions) : null;

            var client = new WebClient
            {
                Credentials = credentials,
                Proxy       = proxy
            };

            return(client);
        }
        public static async Task <bool> IsOnline(ProxyOptions proxyOptionsOrNull)
        {
            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                // Use NCSI to detect network status according to https://technet.microsoft.com/en-us/library/ee126135(v=WS.10).aspx
                // try DNS first
                try
                {
                    IPHostEntry hostEntry = await Dns.GetHostEntryAsync("dns.msftncsi.com");

                    IPAddress ipAddress = Array.Find(hostEntry.AddressList, ip => ip.AddressFamily == AddressFamily.InterNetwork);
                    if (ipAddress != null && ipAddress.ToString() == "131.107.255.255")
                    {
                        return(true);
                    }
                }
                catch (Exception)
                {
                }

                // if DNS failed, try to download the ncsi.txt
                try
                {
                    string txt;
                    using (var client = new WebClient())
                    {
                        IWebProxy proxy = (proxyOptionsOrNull != null) ? SynchronizerFactory.CreateProxy(proxyOptionsOrNull) : null;
                        client.Proxy = proxy;
                        txt          = await client.DownloadStringTaskAsync(new Uri("http://www.msftncsi.com/ncsi.txt"));
                    }

                    if (txt != "Microsoft NCSI")
                    {
                        return(false);
                    }
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
 public IWebProxy GetProxyIfConfigured()
 {
     return(_networkAndProxyOptions.ProxyOptions != null?SynchronizerFactory.CreateProxy(_networkAndProxyOptions.ProxyOptions) : null);
 }
 public IWebProxy GetProxyIfConfigured()
 {
     return(SynchronizerFactory.CreateProxy(CreateProxyOptions()));
 }
Ejemplo n.º 5
0
 public IWebProxy GetProxyIfConfigured()
 {
     return(SynchronizerFactory.CreateProxy(_networkSettingsViewModel.CreateProxyOptions()));
 }
Ejemplo n.º 6
0
        public async Task <ServerResources> GetServerResources(NetworkSettingsViewModel networkSettings, GeneralOptions generalOptions)
        {
            var trimmedUrl = CalenderUrl.Trim();
            var url        = new Uri(trimmedUrl.EndsWith("/") ? trimmedUrl : trimmedUrl + "/");

            var webDavClient     = CreateWebDavClient(networkSettings, generalOptions);
            var calDavDataAccess = new CalDavDataAccess(url, webDavClient);
            var foundResources   = await calDavDataAccess.GetUserResourcesNoThrow(false);

            var foundAddressBooks = new[] { new AddressBookData(new Uri("googleApi://defaultAddressBook"), "Default AddressBook") };

            var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(EmailAddress, SynchronizerFactory.CreateProxy(networkSettings.CreateProxyOptions()));

            var taskLists = await service.Tasklists.List().ExecuteAsync();

            var taskListsData = taskLists?.Items.Select(i => new TaskListData(i.Id, i.Title)).ToArray() ?? new TaskListData[] { };

            return(new ServerResources(foundResources.CalendarResources, foundAddressBooks, taskListsData));
        }
        public async Task <ServerResources> GetServerResources()
        {
            var trimmedUrl = CalenderUrl.Trim();
            var url        = new Uri(trimmedUrl.EndsWith("/") ? trimmedUrl : trimmedUrl + "/");

            var webDavClient     = _prototypeModel.CreateWebDavClient();
            var calDavDataAccess = new CalDavDataAccess(url, webDavClient);
            var foundResources   = await calDavDataAccess.GetUserResourcesIncludingCalendarProxies(false);

            var cardDavDataAccess = new CardDavDataAccess(url, webDavClient, string.Empty, contentType => true);
            var foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(true);

            var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(EmailAddress, SynchronizerFactory.CreateProxy(_prototypeModel.CreateProxyOptions()));

            var taskLists = await service.Tasklists.List().ExecuteAsync();

            var taskListsData = taskLists?.Items.Select(i => new TaskListData(i.Id, i.Title, AccessPrivileges.All)).ToArray() ?? new TaskListData[] { };

            return(new ServerResources(foundResources.CalendarResources, foundAddressBooks, taskListsData));
        }