예제 #1
0
        /// <summary>
        /// 获取安装目录(SDK DLL所在的当前目录)
        /// </summary>
        /// <returns>返回的目录路径</returns>
        public static string GetCurModuleDir()
        {
            IntPtr outStrPtr = nim_tool_get_cur_module_dir();
            string ret       = Marshal.PtrToStringAuto(outStrPtr);

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #2
0
        /// <summary>
        /// 获取本地存储路径
        /// </summary>
        /// <returns>返回的目录路径</returns>
        public static string GetLocalAppDataDir()
        {
            IntPtr outStrPtr = nim_tool_get_local_appdata_dir();
            string ret       = Marshal.PtrToStringAuto(outStrPtr);

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #3
0
        /// <summary>
        /// 获取SDK里app account对应的具体类型的app data目录(如图片消息文件存放目录,语音消息文件存放目录等)
        /// </summary>
        /// <param name="appAccount">APP account。如果传入空字符串,则返回结果为空</param>
        /// <param name="appdataType">具体类型的app data。见NIMAppDataType定义</param>
        /// <returns>返回的目录路径(目录可能未生成,需要app自行判断是否已生成)</returns>
        public static string GetUserSpecificAppDataDir(string appAccount, NIMAppDataType appdataType)
        {
            IntPtr outStrPtr = nim_tool_get_user_specific_appdata_dir(appAccount, appdataType);
            string ret       = Marshal.PtrToStringAuto(outStrPtr);

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #4
0
        /// <summary>
        /// 生成UUID
        /// </summary>
        /// <returns>返回的UUID</returns>
        public static string GetUuid()
        {
            IntPtr outStrPtr = nim_tool_get_uuid();
            string ret       = Marshal.PtrToStringAnsi(outStrPtr);

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #5
0
        /// <summary>
        /// 计算文件的md5
        /// </summary>
        /// <param name="filePath">文件完整路径</param>
        /// <returns>返回的md5</returns>
        public static string GetFileMd5(string filePath)
        {
            IntPtr outStrPtr = nim_tool_get_file_md5(filePath);
            string ret       = Marshal.PtrToStringAnsi(outStrPtr);

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #6
0
        /// <summary>
        /// 计算md5
        /// </summary>
        /// <param name="input">需要计算md5的内容</param>
        /// <returns>返回的md5</returns>
        public static string GetMd5(string input)
        {
            IntPtr outStrPtr = nim_tool_get_md5(input);
            string ret       = Marshal.PtrToStringAnsi(outStrPtr);

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #7
0
        /// <summary>
        /// 替换在词库中匹配的字符串
        /// </summary>
        /// <param name="text">目标文本</param>
        /// <param name="replace">替换字符串</param>
        /// <param name="libName">词库名称</param>
        /// <returns>替换后的字符串(WIN32平台 返回字符串为"2"时表明含有敏感词不允许发送;"3"表明需要将内容设置在消息结构的反垃圾字段里,由服务器过滤;其他内容可以作为消息正常发送)</returns>
        public static string ReplaceTextMatchedKeywords(string text, string replace, string libName)
        {
            var ptr = nim_tool_replace_text_matched_keywords(text, replace, libName);
            Utf8StringMarshaler marshaler = new Utf8StringMarshaler();
            var result = marshaler.MarshalNativeToManaged(ptr) as string;

            GlobalAPI.FreeBuffer(ptr);
            return(result);
        }
예제 #8
0
        /// <summary>
        ///     计算md5
        /// </summary>
        /// <param name="input">需要计算md5的内容</param>
        /// <returns>返回的md5</returns>
        public static string GetMd5(string input)
        {
            var outStrPtr = nim_tool_get_md5(input);

            NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
            var ret = marshaler.MarshalNativeToManaged(outStrPtr) as string;

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #9
0
        /// <summary>
        ///     获取安装目录(SDK DLL所在的当前目录)
        /// </summary>
        /// <returns>返回的目录路径</returns>
        public static string GetCurModuleDir()
        {
            var outStrPtr = nim_tool_get_cur_module_dir();

            NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
            var ret = marshaler.MarshalNativeToManaged(outStrPtr) as string;

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #10
0
        /// <summary>
        ///     获取本地存储路径
        /// </summary>
        /// <returns>返回的目录路径</returns>
        public static string GetLocalAppDataDir()
        {
            var outStrPtr = nim_tool_get_local_appdata_dir();

            NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
            var ret = marshaler.MarshalNativeToManaged(outStrPtr) as string;

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #11
0
        /// <summary>
        ///     获取SDK里app account对应的具体类型的app data目录(如图片消息文件存放目录,语音消息文件存放目录等)
        /// </summary>
        /// <param name="appAccount">APP account。如果传入空字符串,则返回结果为空</param>
        /// <param name="appdataType">具体类型的app data。见NIMAppDataType定义</param>
        /// <returns>返回的目录路径(目录可能未生成,需要app自行判断是否已生成)</returns>
        public static string GetUserSpecificAppDataDir(string appAccount, NIMAppDataType appdataType)
        {
            var outStrPtr = nim_tool_get_user_specific_appdata_dir(appAccount, appdataType);

            NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
            var ret = marshaler.MarshalNativeToManaged(outStrPtr) as string;

            GlobalAPI.FreeStringBuffer(outStrPtr);
            return(ret);
        }
예제 #12
0
        /// <summary>
        /// 从消息的中获取附件(图片、语音、视频等)的本地路径
        /// </summary>
        /// <param name="msg">消息对象</param>
        /// <returns>消息如果有附件,不管是否已下载,返回附件的本地路径;消息如果没有附件,返回空字符串""</returns>
        public static string GetAttachmentPathFromMsg(NIMIMMessage msg)
        {
            var jsonMsg = msg.Serialize();
            var ptr     = TalkNativeMethods.nim_talk_get_attachment_path_from_msg(jsonMsg);

            NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
            var path = marshaler.MarshalNativeToManaged(ptr) as string;

            GlobalAPI.FreeBuffer(ptr);
            return(path);
        }
예제 #13
0
        /// <summary>
        /// 由其他消息生成转发消息
        /// </summary>
        /// <param name="srcMsg">原始消息</param>
        /// <param name="msgSetting">新的消息属性</param>
        /// <param name="msgId">新的客户端消息id</param>
        /// <param name="sessionId">转发目标</param>
        /// <param name="sessionType">转发目标会话类型</param>
        /// <param name="timetag">消息时间</param>
        /// <returns></returns>
        public static NIMIMMessage CreateRetweetMessage(NIMIMMessage srcMsg, NIMMessageSetting msgSetting, string msgId, string sessionId, Session.NIMSessionType sessionType, long timetag)
        {
            string srcMsgJson  = srcMsg.Serialize();
            string settingJson = string.Empty;

            if (msgSetting != null)
            {
                settingJson = msgSetting.Serialize();
            }
            var newMsgPtr = TalkNativeMethods.nim_talk_create_retweet_msg(srcMsgJson, msgId, sessionType, sessionId, settingJson, timetag);

            if (newMsgPtr != IntPtr.Zero)
            {
                NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
                var newMsg     = marshaler.MarshalNativeToManaged(newMsgPtr);
                var newMsgJson = newMsg.ToString();
                var dstMsg     = MessageFactory.CreateMessage(newMsgJson);
                GlobalAPI.FreeStringBuffer(newMsgPtr);
                return(dstMsg);
            }
            return(null);
        }