Example #1
0
        public static string GetSchemeAndHost(this Uri uri)
        {
            string requestUri = null;

            try
            {
                if (!uri.IsAbsoluteUri)
                {
                    uri = SafeUri.Get("https://" + uri.OriginalString);
                }

                requestUri = uri.TryGetSchemeAndHost();
            }
            catch (Exception)
            {
                if (Ioc.HasType <ITrackingManager>())
                {
                    Ioc.Resolve <ITrackingManager>().Event(TrackingSource.Misc, "UriHelper", string.Format("Could not parse: {0}", requestUri));
                }

                requestUri = uri.ToString();
            }

            return(requestUri);
        }
Example #2
0
        public async Task <bool> PinAsync(ITask task)
        {
            string tileId = LaunchArgumentsHelper.GetArgEditTask(task);

            var tile = new SecondaryTile(
                tileId,
                task.Title,
                tileId,
                SafeUri.Get("ms-appx:///Assets/Logo150.png"),
                TileSize.Wide310x150);

            tile.VisualElements.Wide310x150Logo = SafeUri.Get("ms-appx:///Assets/Wide310x150Logo.png");

            tile.RoamingEnabled = true;

            bool isPinned = await tile.RequestCreateForSelectionAsync(GetPlacement(), Placement.Above);

            if (isPinned)
            {
                if (this.updateTileTimer != null)
                {
                    this.updateTileTimer.Start();
                }

                this.secondaryTiles.Add(tile);
                this.notificationService?.ShowNotification(string.Format(StringResources.Notification_TaskPinnedFormat, task.Title), ToastType.Info);

                return(true);
            }

            return(false);
        }
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     if (!WinSettings.Instance.GetValue <bool>(CoreSettings.UseDarkTheme))
     {
         this.imgCloudOverview.Source = new BitmapImage(SafeUri.Get("ms-appx:///Resources/Icons/Sync/vercors-cloud-overview-dark.png", UriKind.RelativeOrAbsolute));
     }
 }
Example #4
0
        public HyperlinkPopupContent()
        {
            this.InitializeComponent();

            this.border.PointerEntered += (sender, e11) =>
            {
                Window.Current.CoreWindow.PointerCursor = handCursor;
            };
            this.border.PointerExited += (sender, e11) =>
            {
                Window.Current.CoreWindow.PointerCursor = arrowCursor;
            };
            this.border.Tapped += (s, e1) =>
            {
                try
                {
                    Uri uri = SafeUri.Get(this.Hyperlink);
                    Launcher.LaunchUriAsync(uri);
                }
                catch (Exception ex)
                {
                    TrackingManagerHelper.Exception(ex, "Exception in HyperlinkPopupContent.border.Tapped");
                }
            };
        }
Example #5
0
        protected override ExchangeInfoBuild BuildExchangeConnectionInfo()
        {
            var settings = this.Workbook.Settings;

            string plainPassword = this.CryptoService.Decrypt(settings.GetValue <byte[]>(ExchangeSettings.ExchangePassword));

            if (string.IsNullOrEmpty(plainPassword))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyPassword);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }

            var connectionInfo = new ExchangeConnectionInfo
            {
                Username             = settings.GetValue <string>(ExchangeSettings.ExchangeUsername),
                Password             = plainPassword,
                Email                = settings.GetValue <string>(ExchangeSettings.ExchangeEmail),
                Domain               = settings.GetValue <string>(ExchangeSettings.ExchangeDomain),
                TimeZoneStandardName = TimeZoneInfo.Local.StandardName,
                UtcOffset            = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalHours,
                SyncFlaggedItems     = settings.GetValue <bool>(ExchangeSettings.ExchangeSyncFlaggedItems)
            };

            if (string.IsNullOrEmpty(connectionInfo.Username))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyUsername);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }
            else if (string.IsNullOrEmpty(plainPassword))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyPassword);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }
            else if (string.IsNullOrEmpty(connectionInfo.Email))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyEmail);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }

            var uriString = settings.GetValue <string>(ExchangeSettings.ExchangeServerUri);

            if (!string.IsNullOrEmpty(uriString))
            {
                connectionInfo.ServerUri = SafeUri.Get(uriString, UriKind.RelativeOrAbsolute);
            }

            connectionInfo.Version = settings.GetValue <ExchangeServerVersion>(ExchangeSettings.ExchangeVersion);

            return(new ExchangeInfoBuild {
                IsValid = true, ConnectionInfo = connectionInfo
            });
        }
Example #6
0
        public async Task <bool> PinAsync(IAbstractFolder abstractFolder)
        {
            string tileId = LaunchArgumentsHelper.GetArgSelectFolder(abstractFolder);

            var tile = new SecondaryTile(
                tileId,
                abstractFolder.Name,
                tileId,
                SafeUri.Get("ms-appx:///Assets/Logo150.png"),
                TileSize.Wide310x150);

            tile.VisualElements.Wide310x150Logo   = SafeUri.Get("ms-appx:///Assets/Wide310x150Logo.png");
            tile.VisualElements.Square310x310Logo = SafeUri.Get("ms-appx:///Assets/Square310x310Logo.png");
            tile.VisualElements.BackgroundColor   = Colors.Transparent;

            tile.RoamingEnabled = true;

            bool isPinned = await tile.RequestCreateForSelectionAsync(GetPlacement(), Placement.Below);

            if (isPinned)
            {
                if (this.updateTileTimer != null)
                {
                    this.updateTileTimer.Start();
                }

                this.secondaryTiles.Add(tile);
                this.notificationService?.ShowNotification(string.Format(StringResources.Notification_FolderPinnedFormat, abstractFolder.Name), ToastType.Info);

                return(true);
            }

            return(false);
        }
Example #7
0
 private static Uri TryCreateUri(string uri)
 {
     try
     {
         return(SafeUri.Get(uri));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #8
0
        private async void ImageSourceChanged()
        {
            this.Children.Clear();

            string source = this.ImageSource;

            if (!string.IsNullOrEmpty(source))
            {
                this.bitmapSource = new BitmapImage();

                var image = new Image {
                    Stretch = Stretch.UniformToFill
                };
                this.bitmapSource.ImageOpened += this.ImageOnImageOpened;
                this.bitmapSource.ImageFailed += this.ImageOnImageFailed;

                try
                {
                    if (source.StartsWith("/"))
                    {
                        // embedded resource
                        this.bitmapSource.UriSource = SafeUri.Get("ms-appx://" + source, UriKind.Absolute);
                    }
                    else
                    {
                        // file stored in local app folder
                        // try to open the file
                        StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync(source);

                        using (IRandomAccessStream fileStream = await storageFile.OpenAsync(FileAccessMode.Read))
                        {
                            await this.bitmapSource.SetSourceAsync(fileStream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TrackingManagerHelper.Exception(ex, "Exception TileCanvas.ImageSourceChanged");
                }

                image.Source = this.bitmapSource;

                if (this.Children.Count == 0)
                {
                    this.Children.Add(image);
                }
            }

            if (this.opacityBorder != null)
            {
                this.opacityBorder.Opacity = 1 - this.ImageOpacity;
            }
        }
Example #9
0
        private static async void OnElementTapped(object sender, TappedRoutedEventArgs e)
        {
            string target = GetTarget((DependencyObject)sender);

            try
            {
                if (!string.IsNullOrEmpty(target))
                {
                    await Launcher.LaunchUriAsync(SafeUri.Get(target));
                }
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "Exception OpenHyperlinkOnTap.OnElementTapped");
            }
        }
Example #10
0
 public static Uri TryCreateUri(string input)
 {
     if (string.IsNullOrEmpty(input))
     {
         return(null);
     }
     else
     {
         try
         {
             return(SafeUri.Get(input.GetUriCompatibleString()));
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
Example #11
0
        public async Task <bool> PinQuickAdd()
        {
            var tile = new SecondaryTile(
                quickAddTaskTileId,
                StringResources.Tile_QuickAdd,
                LaunchArgumentsHelper.QuickAddTask,
                SafeUri.Get("ms-appx:///Assets/Square150x150LogoQuickAdd.png"),
                TileSize.Square150x150);

            bool isPinned = await tile.RequestCreateForSelectionAsync(GetPlacement(), Placement.Above);

            if (isPinned)
            {
                return(true);
            }

            return(false);
        }
Example #12
0
        public static string TryGetHyperlink(this string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(null);
            }

            Regex linkParser = new Regex(@"((https?)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\._~%]*)*", RegexOptions.IgnoreCase);
            var   match      = linkParser.Match(input);

            if (match != null && match.Success)
            {
                string parsed = match.ToString();
                if (parsed != null)
                {
                    try
                    {
                        SafeUri.Get(parsed, UriKind.RelativeOrAbsolute);

                        parsed = parsed.ToLowerInvariant();
                        if (!parsed.StartsWith("http") && !parsed.StartsWith("https") && !parsed.StartsWith("www"))
                        {
                            parsed = "www." + input;
                        }

                        return(parsed);
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
Example #13
0
        public async Task OpenWebUri(string uri)
        {
            if (string.IsNullOrEmpty(uri))
            {
                throw new ArgumentNullException("uri");
            }

            try
            {
                if (!uri.StartsWith("http", StringComparison.OrdinalIgnoreCase) &&
                    !uri.StartsWith("https", StringComparison.OrdinalIgnoreCase) &&
                    !uri.StartsWith("ms-windows-store", StringComparison.OrdinalIgnoreCase) &&
                    !uri.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
                {
                    uri = "http://" + uri;
                }

                await Launcher.LaunchUriAsync(SafeUri.Get(uri, UriKind.RelativeOrAbsolute));
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, $"Unable to open web uri: {uri}");
            }
        }
Example #14
0
        public ExchangeConnectionInfo GetConnectionInfo()
        {
            if (this.service is ExchangeSyncService)
            {
                var    stream    = Assembly.GetExecutingAssembly().GetManifestResourceStream("Chartreuse.Today.Sync.Test.ServerPublicKey.xml");
                string publicKey = new StreamReader(stream).ReadToEnd();
                byte[] password  = this.workbook.Settings.GetValue <byte[]>(ExchangeSettings.ExchangePassword);

                var connectionInfo = new ExchangeConnectionInfo
                {
                    Email             = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeEmail),
                    Username          = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeUsername),
                    Domain            = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeDomain),
                    EncryptedPassword = this.cryptoService.RsaEncrypt(publicKey, this.cryptoService.Decrypt(password)),
                    Password          = this.cryptoService.Decrypt(password),
                    Version           = this.workbook.Settings.GetValue <ExchangeServerVersion>(ExchangeSettings.ExchangeVersion),
                    DeviceId          = this.deviceId
                };

                string serverUri = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeServerUri);
                if (!string.IsNullOrEmpty(serverUri))
                {
                    connectionInfo.ServerUri = SafeUri.Get(serverUri);
                }

                return(connectionInfo);
            }
            else if (this.service is EwsSyncService)
            {
                byte[] password = this.workbook.Settings.GetValue <byte[]>(ExchangeSettings.ExchangePassword);

                var connectionInfo = new ExchangeConnectionInfo
                {
                    Email             = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeEmail),
                    Username          = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeUsername),
                    Domain            = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeDomain),
                    EncryptedPassword = password,
                    Password          = this.cryptoService.Decrypt(password),
                    Version           = this.workbook.Settings.GetValue <ExchangeServerVersion>(ExchangeSettings.ExchangeVersion),
                    DeviceId          = this.deviceId,
                    SyncFlaggedItems  = true
                };

                string serverUri = this.workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeServerUri);
                if (!string.IsNullOrEmpty(serverUri))
                {
                    connectionInfo.ServerUri = SafeUri.Get(serverUri);
                }

                return(connectionInfo);
            }
            else if (this.service is ActiveSyncService)
            {
                var connectionInfo = new ExchangeConnectionInfo
                {
                    Email             = this.workbook.Settings.GetValue <string>(ExchangeSettings.ActiveSyncEmail),
                    EncryptedPassword = this.workbook.Settings.GetValue <byte[]>(ExchangeSettings.ActiveSyncPassword),
                    Password          = this.cryptoService.Decrypt(this.workbook.Settings.GetValue <byte[]>(ExchangeSettings.ActiveSyncPassword)),
                    DeviceId          = this.deviceId,
                };

                string serverUri = this.workbook.Settings.GetValue <string>(ExchangeSettings.ActiveSyncServerUri);
                if (!string.IsNullOrEmpty(serverUri))
                {
                    connectionInfo.ServerUri = SafeUri.Get(serverUri);
                }

                return(connectionInfo);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        protected override ExchangeInfoBuild BuildExchangeConnectionInfo()
        {
            ISettings settings = this.Workbook.Settings;

            // encrypt the password using the public RSA key of the server
            Stream publicKeyStream = Assembly.Load(new AssemblyName("2Day.Exchange.Shared")).GetManifestResourceStream(PublicKeyTxtName);
            string publicKey       = new StreamReader(publicKeyStream).ReadToEnd();

            byte[] encryptedPassword = settings.GetValue <byte[]>(ExchangeSettings.ExchangePassword);
            if (encryptedPassword == null || encryptedPassword.Length == 0)
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyPassword);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }
            string plainPassword = this.CryptoService.Decrypt(encryptedPassword);

            var encryptedPasswordData = this.CryptoService.RsaEncrypt(publicKey, plainPassword);

            var connectionInfo = new ExchangeConnectionInfo
            {
                Username             = settings.GetValue <string>(ExchangeSettings.ExchangeUsername),
                EncryptedPassword    = encryptedPasswordData,
                Email                = settings.GetValue <string>(ExchangeSettings.ExchangeEmail),
                Domain               = settings.GetValue <string>(ExchangeSettings.ExchangeDomain),
                TimeZoneStandardName = TimeZoneInfo.Local.StandardName,
                UtcOffset            = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalHours,
            };

            if (string.IsNullOrEmpty(connectionInfo.Username))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyUsername);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }
            else if (string.IsNullOrEmpty(plainPassword))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyPassword);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }
            else if (string.IsNullOrEmpty(connectionInfo.Email))
            {
                this.OnSynchronizationFailed(ExchangeResources.Exchange_EmptyEmail);
                return(new ExchangeInfoBuild {
                    IsValid = false
                });
            }

            var uriString = settings.GetValue <string>(ExchangeSettings.ExchangeServerUri);

            if (!string.IsNullOrEmpty(uriString))
            {
                try
                {
                    connectionInfo.ServerUri = SafeUri.Get(uriString, UriKind.RelativeOrAbsolute);
                }
                catch (Exception)
                {
                    this.OnSynchronizationFailed(ExchangeResources.Exchange_InvalidServerUri);
                    return(new ExchangeInfoBuild {
                        IsValid = false
                    });
                }
            }

            connectionInfo.Version          = settings.GetValue <ExchangeServerVersion>(ExchangeSettings.ExchangeVersion);
            connectionInfo.IsBackgroundSync = this.Manager.IsBackground;
            connectionInfo.Source           = this.Manager.Platform;

            return(new ExchangeInfoBuild {
                IsValid = true, ConnectionInfo = connectionInfo
            });
        }
 private async void OnHelpTapped(object sender, TappedRoutedEventArgs e)
 {
     await Launcher.LaunchUriAsync(SafeUri.Get(Constants.HelpPageExchangeAddress));
 }
Example #17
0
        private async Task <ExchangeSyncResult> EnsureAutoDiscover(ExchangeConnectionInfo connectionInfo)
        {
            var success = new ExchangeSyncResult
            {
                AuthorizationResult = new ExchangeAuthorizationResult
                {
                    AuthorizationStatus = ExchangeAuthorizationStatus.OK,
                    IsOperationSuccess  = true
                },
                OperationResult = new ServiceOperationResult
                {
                    IsOperationSuccess = true
                },
            };

            // check Office 365 server uri is correct (ie. https://outlook.office365.com/EWS/Exchange.asmx)
            if (connectionInfo.ServerUri != null)
            {
                string uri = connectionInfo.ServerUri.ToString().ToLowerInvariant();
                if (uri.Contains("outlook.office365.com") && !uri.EndsWith("/ews/exchange.asmx"))
                {
                    connectionInfo.ServerUri = SafeUri.Get("https://outlook.office365.com/EWS/Exchange.asmx");
                }

                if (uri.Contains("/ews/exchange.asmx/ews/exchange.asmx"))
                {
                    connectionInfo.ServerUri = SafeUri.Get(uri.Replace("/ews/exchange.asmx/ews/exchange.asmx", "/EWS/Exchange.asmx"));
                }

                // check if the server uri looks correct, if it doesn't, run autodiscover
                var server = new EwsSyncServer(connectionInfo.CreateEwsSettings());
                try
                {
                    var identifiers = await server.GetRootFolderIdentifiersAsync(useCache : false);

                    if (identifiers != null)
                    {
                        return(success);
                    }
                }
                catch (Exception ex)
                {
                    if (connectionInfo.ServerUri != null && !connectionInfo.ServerUri.ToString().EndsWith("/ews/exchange.asmx", StringComparison.OrdinalIgnoreCase))
                    {
                        // one more try with the /ews/exchange.asmx path
                        connectionInfo.ServerUri = SafeUri.Get(uri.TrimEnd('/') + "/ews/exchange.asmx");
                        var secondResult = await this.EnsureAutoDiscover(connectionInfo);

                        if (IsExchangeSyncResultValid(secondResult))
                        {
                            return(success);
                        }
                    }
                    LogService.Log("EwsSyncService", $"Server uri is {connectionInfo.ServerUri} but GetRootFolderIds failed ({ex.Message}), fallbacking to classic autodiscover");
                }
            }

            LogService.Log("EwsSyncService", "Server uri is empty, performing auto discover");

            var engine             = new AutoDiscoverEngine();
            var autoDiscoverResult = await engine.AutoDiscoverAsync(connectionInfo.Email, connectionInfo.Username, connectionInfo.Password, connectionInfo.Version);

            if (autoDiscoverResult != null)
            {
                if (autoDiscoverResult.ServerUri != null)
                {
                    LogService.Log("EwsSyncService", "Now using server uri: " + autoDiscoverResult.ServerUri);
                    connectionInfo.ServerUri = autoDiscoverResult.ServerUri;
                }

                if (!string.IsNullOrWhiteSpace(autoDiscoverResult.RedirectEmail))
                {
                    LogService.Log("EwsSyncService", "Now using email redirect: " + autoDiscoverResult.RedirectEmail);
                    connectionInfo.Email = autoDiscoverResult.RedirectEmail;
                }
                return(success);
            }

            LogService.Log("EwsSyncService", "Auto discovery failed");

            return(new ExchangeSyncResult
            {
                AuthorizationResult = new ExchangeAuthorizationResult
                {
                    AuthorizationStatus = ExchangeAuthorizationStatus.AutodiscoveryServiceNotFound,
                    ErrorMessage = "Check credentials are valid and/or try to specify manually a valid server address"
                }
            });
        }
Example #18
0
        public async Task <ExchangeAuthorizationResult> LoginAsync(ExchangeConnectionInfo connectionInfo)
        {
            if (connectionInfo == null)
            {
                throw new ArgumentNullException("connectionInfo");
            }

            ActiveSyncServer server;

            // reset cached task folder id
            this.taskFolderId = null;

            if (connectionInfo.ServerUri == null)
            {
                LogService.Log("ActiveSyncService", "Server is empty, trying to auto discover...");
                server = CreateExchangeServer(connectionInfo);

                string discoveredUri = await server.GetAutoDiscoveredServer();

                if (string.IsNullOrEmpty(discoveredUri))
                {
                    LogService.Log("ActiveSyncService", "Didn't found a server for the email address");
                    // Wrong credentials passed to the server
                    return(new ExchangeAuthorizationResult
                    {
                        AuthorizationStatus = ExchangeAuthorizationStatus.UserCredentialsInvalid,
                        IsOperationSuccess = false,
                        ErrorMessage = ExchangeResources.ExchangeActiveSync_InvalidCredentialsMessage
                    });
                }
                connectionInfo.ServerUri = SafeUri.Get(discoveredUri);
                LogService.LogFormat("ActiveSyncService", "Server autodiscovered at '{0}'", discoveredUri);
            }

            // Try to get folders information to know if user is correct
            server = CreateExchangeServer(connectionInfo);
            FolderSyncCommandResult result;

            try
            {
                result = await server.FolderSync("0");

                connectionInfo.PolicyKey = server.PolicyKey;
            }
            catch (Exception ex)
            {
                string message = string.Empty + ex.Message;
                if (ex.InnerException != null && ex.Message != null)
                {
                    message += ", " + ex.InnerException.Message;
                }

                return(new ExchangeAuthorizationResult
                {
                    AuthorizationStatus = ExchangeAuthorizationStatus.UserCredentialsInvalid,
                    IsOperationSuccess = false,
                    ErrorMessage = message
                });
            }

            if (result.Status != StatusOk)
            {
                return(new ExchangeAuthorizationResult
                {
                    AuthorizationStatus = ExchangeAuthorizationStatus.OK,
                    IsOperationSuccess = false,
                    ErrorMessage = ActiveSyncErrorHelper.GetFolderSyncErrorMessage(result.Status)
                });
            }

            ExchangeFolder taskFolder = null;

            if (string.IsNullOrWhiteSpace(this.taskFolderId))
            {
                taskFolder = result.AddedFolders.FirstOrDefault(f => f.FolderType == DefaultTaskFolderType);
                if (taskFolder == null)
                {
                    LogService.Log("ActiveSyncService", "No default task folder found");

                    return(new ExchangeAuthorizationResult
                    {
                        AuthorizationStatus = ExchangeAuthorizationStatus.OK,
                        IsOperationSuccess = false,
                        ErrorMessage = ExchangeResources.ExchangeActiveSync_NoTasksFolder
                    });
                }
            }
            else
            {
                taskFolder = result.AddedFolders.FirstOrDefault(f => f.ServerId == this.taskFolderId);
                if (taskFolder == null)
                {
                    taskFolder = result.AddedFolders.FirstOrDefault(f => f.FolderType == DefaultTaskFolderType);
                    string taskFolderName = taskFolder != null ? taskFolder.DisplayName : "unkown";
                    string message        = $"Could not retrieve task folder with id {this.taskFolderId} (default: {taskFolderName}, all: {result.AddedFolders.Select(f => f.DisplayName).AggregateString()})";

                    LogService.LogFormat("ActiveSyncService", message);

                    return(new ExchangeAuthorizationResult
                    {
                        AuthorizationStatus = ExchangeAuthorizationStatus.OK,
                        IsOperationSuccess = false,
                        ErrorMessage = message
                    });
                }
                else
                {
                    LogService.LogFormat("ActiveSyncService", "Using task folder: {0}", taskFolder.ServerId);
                }
            }

            this.taskFolderId   = taskFolder.ServerId;
            this.taskFolderName = taskFolder.DisplayName;

            // all is Ok, update server Uri with the found Uri
            return(new ExchangeAuthorizationResult
            {
                AuthorizationStatus = ExchangeAuthorizationStatus.OK,
                IsOperationSuccess = true,
                ServerUri = connectionInfo.ServerUri
            });
        }
Example #19
0
 private void OnWebLinkTapped(object sender, TappedRoutedEventArgs e)
 {
     Launcher.LaunchUriAsync(SafeUri.Get(Constants.WebSiteAddress));
 }
Example #20
0
 private static Uri GetUri(string path)
 {
     return(SafeUri.Get(uriPrefix + path, uriKind));
 }
Example #21
0
        public void Get_scheme_7()
        {
            var result = SafeUri.Get("https://abc.contoso.com?test=true").GetSchemeAndHost();

            Assert.AreEqual("https://abc.contoso.com", result);
        }
Example #22
0
        public void Get_scheme_8()
        {
            var result = SafeUri.Get("abc.contoso.com#test", UriKind.RelativeOrAbsolute).GetSchemeAndHost();

            Assert.AreEqual("https://abc.contoso.com", result);
        }
Example #23
0
            public async Task <SystemNetHttpRequestResult> SendRequestAsync(string url, HttpMethod method, string contentType, string requestBody, byte[] requestBytes, Dictionary <string, string> headers, NetworkCredential credentials)
            {
                var filter = new HttpBaseProtocolFilter
                {
                    AutomaticDecompression = true,
                    AllowAutoRedirect      = true,
                    AllowUI = false
                };

                if (filter.IgnorableServerCertificateErrors != null)
                {
                    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
                    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
                }

                // use this to make sure we don't have weird behavior where the app caches credentials for way too long
                // the real fix seems to be using a new API introduced in 14295 but that's not the version that is targeted today
                // see: http://stackoverflow.com/questions/30731424/how-to-stop-credential-caching-on-windows-web-http-httpclient
                filter.CookieUsageBehavior = HttpCookieUsageBehavior.NoCookies;

                if (credentials != null)
                {
                    filter.ServerCredential = new PasswordCredential("2Day", credentials.UserName, credentials.Password);
                }
                else
                {
                    filter.ServerCredential = null;
                }

                var client = new HttpClient(filter);

                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        client.DefaultRequestHeaders.Add(header.Key, header.Value);
                    }
                }

                var request = new Windows.Web.Http.HttpRequestMessage(method.ToWindowsHttp(), SafeUri.Get(url));
                HttpRequestMessage systemNetRequest = request.ToSystemHttp();

                if (requestBody != null)
                {
                    if (method != HttpMethod.Post)
                    {
                        throw new NotSupportedException("Request body must use POST method");
                    }

                    var arrayContent = new HttpBufferContent(requestBytes.AsBuffer());

                    if (!string.IsNullOrWhiteSpace(contentType))
                    {
                        arrayContent.Headers.ContentType = new HttpMediaTypeHeaderValue(contentType);
                    }

                    if (method == HttpMethod.Post)
                    {
                        request.Content = arrayContent;
                    }
                }

                WebRequestBuilder.TraceRequest(systemNetRequest, requestBody);
                CancellationTokenSource timeoutCancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(30));

                Windows.Web.Http.HttpResponseMessage response = await client.SendRequestAsync(request).AsTask(timeoutCancellationToken.Token);

                client.Dispose();

                HttpResponseMessage systemNetResponse = await response.ToWindowsHttp(systemNetRequest);

                return(new SystemNetHttpRequestResult
                {
                    Request = systemNetRequest,
                    Response = systemNetResponse
                });
            }
Example #24
0
        private static string ImageTemplate(string template, string key, string imagePath, DataRequest request)
        {
            string fullPath  = "ms-appx://" + imagePath;
            string imageName = Path.GetFileName(imagePath);

            request.Data.ResourceMap[imageName] = RandomAccessStreamReference.CreateFromUri(SafeUri.Get(fullPath));

            return(template.Replace("{{" + key + "}}", imageName));
        }