Пример #1
0
        private static void RefreshAccessTokenCallback(IntPtr sessionHandlePtr)
        {
            var handle  = new SessionHandle(sessionHandlePtr);
            var session = new Session(handle);

            AuthenticationHelper.RefreshAccessTokenAsync(session).ContinueWith(_ => session.CloseHandle());
        }
Пример #2
0
        private static unsafe void HandleSessionError(IntPtr sessionHandlePtr, ErrorCode errorCode, byte *messageBuffer, IntPtr messageLength, IntPtr userInfoPairs, int userInfoPairsLength, bool isClientReset)
        {
            try
            {
                var handle  = new SessionHandle(sessionHandlePtr);
                var session = new Session(handle);
                var message = Encoding.UTF8.GetString(messageBuffer, (int)messageLength);

                SessionException exception;

                if (isClientReset)
                {
                    var userInfo = StringStringPair.UnmarshalDictionary(userInfoPairs, userInfoPairsLength);
                    exception = new ClientResetException(session.User.App, message, userInfo);
                }
                else if (errorCode == ErrorCode.PermissionDenied)
                {
                    var userInfo = StringStringPair.UnmarshalDictionary(userInfoPairs, userInfoPairsLength);
                    exception = new PermissionDeniedException(session.User.App, message, userInfo);
                }
                else
                {
                    exception = new SessionException(message, errorCode);
                }

                Session.RaiseError(session, exception);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        private static unsafe void HandleSessionError(IntPtr sessionHandlePtr, ErrorCode errorCode, byte *messageBuffer, IntPtr messageLength, IntPtr userInfoPairs, int userInfoPairsLength)
        {
            var handle  = new SessionHandle(sessionHandlePtr);
            var session = new Session(handle);
            var message = Encoding.UTF8.GetString(messageBuffer, (int)messageLength);

            SessionException exception;

            if (errorCode.IsClientResetError())
            {
                var userInfo = MarshalErrorUserInfo(userInfoPairs, userInfoPairsLength);
                exception = new ClientResetException(message, userInfo);
            }
            else if (errorCode == ErrorCode.PermissionDenied)
            {
                var userInfo = MarshalErrorUserInfo(userInfoPairs, userInfoPairsLength);
                exception = new PermissionDeniedException(message, userInfo);
            }
            else
            {
                exception = new SessionException(message, errorCode);
            }

            Session.RaiseError(session, exception);
        }
        private static unsafe void RefreshAccessTokenCallback(IntPtr userHandlePtr, IntPtr sessionHandlePtr, sbyte *urlBuffer, IntPtr urlLength)
        {
            var userHandle = new SyncUserHandle();

            userHandle.SetHandle(userHandlePtr);
            var user = new User(userHandle);

            var sessionHandle = new SessionHandle();

            sessionHandle.SetHandle(sessionHandlePtr);

            var realmUri = new Uri(new string(urlBuffer, 0, (int)urlLength, System.Text.Encoding.UTF8));

            user.RefreshAccessToken(realmUri.AbsolutePath)
            .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    // TODO: raise error event on the session
                }
                else
                {
                    sessionHandle.RefreshAccessToken(t.Result.Item1, t.Result.Item2);
                }
            });
        }
Пример #5
0
        internal static Session Create(IntPtr sessionPtr)
        {
            if (sessionPtr == IntPtr.Zero)
            {
                return(null);
            }

            var handle = new SessionHandle();

            handle.SetHandle(sessionPtr);

            return(new Session(handle));
        }
        public static SessionHandle GetSession(string path, Native.SyncConfiguration configuration, byte[] encryptionKey)
        {
            DoInitialFileSystemConfiguration();

            var result = NativeMethods.get_session(path, (IntPtr)path.Length, configuration, encryptionKey, out var nativeException);

            nativeException.ThrowIfNecessary();

            var handle = new SessionHandle();

            handle.SetHandle(result);
            return(handle);
        }
Пример #7
0
        static unsafe AppHandle()
        {
            NativeCommon.Initialize();
            SessionHandle.InstallCallbacks();

            NativeMethods.LogMessageCallback logMessage   = HandleLogMessage;
            NativeMethods.UserCallback       userLogin    = HandleUserCallback;
            NativeMethods.VoidTaskCallback   taskCallback = HandleTaskCompletion;
            NativeMethods.BsonCallback       bsonCallback = HandleBsonCallback;

            GCHandle.Alloc(logMessage);
            GCHandle.Alloc(userLogin);
            GCHandle.Alloc(taskCallback);
            GCHandle.Alloc(bsonCallback);

            //// This is a hack due to a mixup of what OS uses as platform/SDK and what is displayed in the UI.
            //// The original code is below:
            ////
            //// string platform;
            //// string platformVersion;
            //// var platformRegex = new Regex("^(?<platform>[^0-9]*) (?<version>[^ ]*)", RegexOptions.Compiled);
            //// var osDescription = platformRegex.Match(RuntimeInformation.OSDescription);
            //// if (osDescription.Success)
            //// {
            ////     platform = osDescription.Groups["platform"].Value;
            ////     platformVersion = osDescription.Groups["version"].Value;
            //// }
            //// else
            //// {
            ////     platform = Environment.OSVersion.Platform.ToString();
            ////     platformVersion = Environment.OSVersion.VersionString;
            //// }

            var platform        = "Realm .NET";
            var platformVersion = RuntimeInformation.OSDescription;

            // var sdkVersion = typeof(AppHandle).GetTypeInfo().Assembly.GetName().Version.ToString(3);

            // TODO: temporarily add -beta.X suffix to the SDK
            var sdkVersion = "10.0.0-beta.6";

            NativeMethods.initialize(
                platform, (IntPtr)platform.Length,
                platformVersion, (IntPtr)platformVersion.Length,
                sdkVersion, (IntPtr)sdkVersion.Length,
                userLogin, taskCallback, bsonCallback, logMessage);

            HttpClientTransport.Install();
        }
Пример #8
0
        public bool TryGetSession(string path, out SessionHandle handle)
        {
            var result = NativeMethods.get_session(this, path, (IntPtr)path.Length, out var ex);

            ex.ThrowIfNecessary();

            if (result == IntPtr.Zero)
            {
                handle = null;

                return(false);
            }

            handle = new SessionHandle(result);
            return(true);
        }
Пример #9
0
        static unsafe AppHandle()
        {
            NativeCommon.Initialize();
            SessionHandle.InstallCallbacks();

            NativeMethods.LogMessageCallback logMessage   = HandleLogMessage;
            NativeMethods.UserCallback       userLogin    = HandleUserCallback;
            NativeMethods.VoidTaskCallback   taskCallback = HandleTaskCompletion;
            NativeMethods.BsonCallback       bsonCallback = HandleBsonCallback;

            GCHandle.Alloc(logMessage);
            GCHandle.Alloc(userLogin);
            GCHandle.Alloc(taskCallback);
            GCHandle.Alloc(bsonCallback);

            //// This is a hack due to a mixup of what OS uses as platform/SDK and what is displayed in the UI.
            //// The original code is below:
            ////
            //// string platform;
            //// string platformVersion;
            //// var platformRegex = new Regex("^(?<platform>[^0-9]*) (?<version>[^ ]*)", RegexOptions.Compiled);
            //// var osDescription = platformRegex.Match(RuntimeInformation.OSDescription);
            //// if (osDescription.Success)
            //// {
            ////     platform = osDescription.Groups["platform"].Value;
            ////     platformVersion = osDescription.Groups["version"].Value;
            //// }
            //// else
            //// {
            ////     platform = Environment.OSVersion.Platform.ToString();
            ////     platformVersion = Environment.OSVersion.VersionString;
            //// }

            var platform        = InteropConfig.Platform;
            var platformVersion = RuntimeInformation.OSDescription;

            // TODO: temp - remove that once we're out of beta
            var sdkVersion = "10.2.0-beta.2"; // InteropConfig.SDKVersion.ToString(3);

            NativeMethods.initialize(
                platform, platform.IntPtrLength(),
                platformVersion, platformVersion.IntPtrLength(),
                sdkVersion, sdkVersion.IntPtrLength(),
                userLogin, taskCallback, bsonCallback, logMessage);

            HttpClientTransport.Install();
        }
Пример #10
0
 public static extern void refresh_access_token(SessionHandle session,
                                                [MarshalAs(UnmanagedType.LPWStr)] string access_token, IntPtr access_token_len,
                                                [MarshalAs(UnmanagedType.LPWStr)] string server_path, IntPtr server_path_len,
                                                out NativeException ex);
Пример #11
0
 public static extern void shutdown_and_wait(SessionHandle session, out NativeException ex);
Пример #12
0
 public static extern void start(SessionHandle session, out NativeException ex);
Пример #13
0
 internal Session(SessionHandle handle)
 {
     Handle = handle;
 }
Пример #14
0
 public static extern void report_error_for_testing(SessionHandle session, int error_code, [MarshalAs(UnmanagedType.LPWStr)] string message, IntPtr message_len, [MarshalAs(UnmanagedType.U1)] bool is_fatal);
Пример #15
0
 public static extern ulong register_progress_notifier(SessionHandle session,
                                                       IntPtr token_ptr,
                                                       ProgressDirection direction,
                                                       [MarshalAs(UnmanagedType.U1)] bool is_streaming,
                                                       out NativeException ex);
Пример #16
0
 internal static Session Create(string path)
 {
     return(Create(SessionHandle.SessionForPath(path)));
 }
Пример #17
0
 public static extern void set_multiplex_identifier(SessionHandle session, [MarshalAs(UnmanagedType.LPWStr)] string identifier, IntPtr identifier_len, out NativeException ex);
Пример #18
0
 public static extern IntPtr get_raw_pointer(SessionHandle session);
Пример #19
0
 public static extern SessionState get_state(SessionHandle session, out NativeException ex);
Пример #20
0
 public static extern IntPtr get_user(SessionHandle session);
Пример #21
0
 public static extern void report_progress_for_testing(SessionHandle session, ulong downloaded, ulong downloadable, ulong uploaded, ulong uploadable);
Пример #22
0
 private Session(SessionHandle handle)
 {
     Handle = handle;
 }
Пример #23
0
 public static extern void unregister_progress_notifier(SessionHandle session, ulong token, out NativeException ex);
Пример #24
0
 public static extern void set_url_prefix(SessionHandle session, [MarshalAs(UnmanagedType.LPWStr)] string prefix, IntPtr prefix_len, out NativeException ex);
Пример #25
0
 public static extern void wait(SessionHandle session, IntPtr task_completion_source, ProgressDirection direction, out NativeException ex);
Пример #26
0
 public static extern IntPtr get_path(SessionHandle session, IntPtr buffer, IntPtr buffer_length, out NativeException ex);
Пример #27
0
 internal Session(string path) : this(SessionHandle.GetSessionForPath(path))
 {
 }