Ejemplo n.º 1
0
        /// <summary>
        /// 导入已备份在云端的消息记录
        /// </summary>
        /// <param name="import_info">导入需要的参数参考NIMLogsBackupImportInfo定义</param>
        /// <returns>false 当前有导入/导出操作正在进行中</returns>
        public static bool ImportBackupFromRemote(NIMLogsBackupImportInfo import_info)
        {
            bool ret = false;

            if (import_info != null)
            {
                //这里需增长import_info的生命周期,否则import_info被gc回收掉,会导致回调出问题
                import_info_remain = import_info;

                import_info_c.UnPackageCallback_     = ImportBackupFromRemoteUnPackageCallback;
                import_info_c.RemoteDecryptCallback_ = ImportBackupFromRemoteDecryptCallback;
                import_info_c.PathRelease_           = NewPathRelease;

                import_info_c.ProgressCallback_ = ImportLogsBackupProgressCallback;
                import_info_c.CompleteCallback_ = ImportLogsBackupCompleteCallback;

                int    nSizeOfParam = Marshal.SizeOf(import_info);
                IntPtr param_ptr    = Marshal.AllocHGlobal(nSizeOfParam);
                try
                {
                    Marshal.StructureToPtr(import_info, param_ptr, false);
                    import_info_c.user_data_ = param_ptr;
                }
                catch
                {
                }
                ret = MsglogNativeMethods.nim_import_backup_from_remote(ref import_info_c);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        private static void ImportLogsBackupProgressCallback(LogsBackupRemoteOperate operate, float progress, IntPtr user_data)
        {
            NIMLogsBackupImportInfo import_info = (NIMLogsBackupImportInfo)Marshal.PtrToStructure(user_data, typeof(NIMLogsBackupImportInfo));

            if (import_info != null && import_info.ProgressCallback_ != null)
            {
                import_info.ProgressCallback_(operate, progress);
            }
        }
Ejemplo n.º 3
0
        private static void ImportLogsBackupCompleteCallback(LogsBackupRemoteOperate operate, LogsBackupRemoteState state, IntPtr user_data)
        {
            NIMLogsBackupImportInfo import_info = (NIMLogsBackupImportInfo)Marshal.PtrToStructure(user_data, typeof(NIMLogsBackupImportInfo));

            if (import_info != null && import_info.CompleteCallback_ != null)
            {
                import_info.CompleteCallback_(operate, state);
            }

            //注意,这里应释放user_data
            Marshal.FreeHGlobal(user_data);
        }
Ejemplo n.º 4
0
        private static IntPtr ImportBackupFromRemoteDecryptCallback(string file_path, string encrypt_key, IntPtr user_data)
        {
            IntPtr path = IntPtr.Zero;
            NIMLogsBackupImportInfo import_info = (NIMLogsBackupImportInfo)Marshal.PtrToStructure(user_data, typeof(NIMLogsBackupImportInfo));

            if (import_info != null && import_info.RemoteDecryptCallback_ != null)
            {
                string temp_path = import_info.RemoteDecryptCallback_(file_path, encrypt_key);
                path = Utf8StringMarshaler.GetInstance("").MarshalManagedToNative(temp_path);
            }
            return(path);
        }