コード例 #1
0
ファイル: EmmyLuaAPIMaker.cs プロジェクト: uiopsczc/Test
        public static GlobalAPI FindFahter(string fullName)
        {
            GlobalAPI aPI = null;

            if (!m_dict.TryGetValue(fullName, out aPI))
            {
                string selfName;
                string fatherFullName;
                GetFatherAndSelfName(fullName, out fatherFullName, out selfName);

                if (!string.IsNullOrEmpty(selfName))
                {
                    aPI = new GlobalAPI(selfName);
                    m_dict.Add(fullName, aPI);
                    if (string.IsNullOrEmpty(fatherFullName) && root == null)
                    {
                        root = aPI;
                    }
                }

                //not root
                if (!string.IsNullOrEmpty(fatherFullName))
                {
                    GlobalAPI fatherAPI = FindFahter(fatherFullName);
                    fatherAPI.AddChild(aPI);
                }
            }

            return(aPI);
        }
コード例 #2
0
        /// <summary>
        /// 拼接文档图片的下载地址
        /// </summary>
        /// <param name="urlPrefix">文档信息中的url前缀</param>
        /// <param name="imgType">文档转换的图片类型</param>
        /// <param name="quality">需要的图片清晰度</param>
        /// <param name="pageNum">图片页码(从1开始计算)</param>
        /// <returns></returns>
        public static string GetPageUrl(string urlPrefix, NIMDocTranscodingImageType imgType, NIMDocTranscodingQuality quality, int pageNum)
        {
            var ptr = DocTransNativeMethods.nim_doctrans_get_page_url(urlPrefix, imgType, quality, pageNum);

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

            GlobalAPI.FreeBuffer(ptr);
            return(url);
        }
コード例 #3
0
        /// <summary>
        /// 拼接文档源的下载地址
        /// </summary>
        /// <param name="urlPrefix">文档信息中的url前缀</param>
        /// <param name="fileType">文档源类型</param>
        /// <returns></returns>
        public static string GetSourceFileUrl(string urlPrefix, NIMDocTranscodingFileType fileType)
        {
            var ptr = DocTransNativeMethods.nim_doctrans_get_source_file_url(urlPrefix, fileType);

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

            GlobalAPI.FreeBuffer(ptr);
            return(url);
        }
コード例 #4
0
        /// <summary>
        /// 本地查询群信息(同步版本,堵塞NIM内部线程,谨慎使用)
        /// </summary>
        /// <param name="tid"></param>
        /// <returns></returns>
        public static NIMTeamInfo QueryCachedTeamInfo(string tid)
        {
            var ptr = TeamNativeMethods.nim_team_query_team_info_block(tid);

            if (ptr != IntPtr.Zero)
            {
                NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
                var tobj  = marshaler.MarshalNativeToManaged(ptr);
                var tinfo = NIMTeamInfo.Deserialize(tobj.ToString());
                GlobalAPI.FreeStringBuffer(ptr);
                return(tinfo);
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// 查询(单个)群成员信息(同步版本,堵塞NIM内部线程,谨慎使用)
        /// </summary>
        /// <param name="tid"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static NIMTeamMemberInfo QuerySingleMemberInfo(string tid, string uid)
        {
            NIMTeamMemberInfo info = null;
            var ptr = TeamNativeMethods.nim_team_query_team_member_block(tid, uid);

            if (ptr != IntPtr.Zero)
            {
                NimUtility.Utf8StringMarshaler marshaler = new NimUtility.Utf8StringMarshaler();
                var infoObj = marshaler.MarshalNativeToManaged(ptr);
                info = NIMTeamMemberInfo.Deserialize(infoObj.ToString());
                GlobalAPI.FreeStringBuffer(ptr);
            }
            return(info);
        }
コード例 #6
0
ファイル: EmmyLuaAPIMaker.cs プロジェクト: uiopsczc/Test
 private void AddChild(GlobalAPI child)
 {
     child.father = this;
     childList.Add(child);
 }
コード例 #7
0
ファイル: EmmyLuaAPIMaker.cs プロジェクト: uiopsczc/Test
 public static void Clear()
 {
     m_dict.Clear();
     root = null;
 }
コード例 #8
0
ファイル: EmmyLuaAPIMaker.cs プロジェクト: uiopsczc/Test
    public static void ExportLuaApi(List <Type> classList)
    {
        type_has_extension_methods = null;
        GlobalAPI.Clear();

        // add class here
        BindingFlags bindType = BindingFlags.DeclaredOnly |
                                BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public;
        List <MethodInfo> methods;

        FieldInfo[]            fields;
        PropertyInfo[]         properties;
        List <ConstructorInfo> constructors;

        ParameterInfo[] paramInfos;
        int             delta;
        string          path = m_apiDir;

        if (path == "")
        {
            return;
        }


        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        else
        {
            StdioUtil.ClearDir(path);
        }

        foreach (Type t in classList)
        {
            string name = TypeDecl(t);
            GlobalAPI.AddType(name);
            try
            {
                FileStream   fs             = new FileStream((string)(path + "/" + name.Replace(".", "_") + ".lua"), FileMode.Create);
                var          utf8WithoutBom = new System.Text.UTF8Encoding(false);
                StreamWriter sw             = new StreamWriter(fs, utf8WithoutBom);

                if (t.BaseType != null && t.BaseType != typeof(object))
                {
                    string baseName = TypeDecl(t.BaseType);
                    sw.WriteLine(string.Format("---@class {0} : {1}", (object)name, baseName));
                }
                else
                {
                    sw.WriteLine(string.Format("---@class {0}", (object)name));
                }

                #region field
                fields = t.GetFields(bindType);
                foreach (var field in fields)
                {
                    if (IsObsolete(field))
                    {
                        continue;
                    }
                    WriteField(sw, field.FieldType, field.Name);
                }

                properties = t.GetProperties(bindType);
                foreach (var property in properties)
                {
                    if (IsObsolete(property))
                    {
                        continue;
                    }
                    WriteField(sw, property.PropertyType, property.Name);
                }
                #endregion
                sw.WriteLine("");

                //string[] nameList = name.Split(new char[] { '.' });
                //string nameSpace = "";
                //for (int i = 0; i < nameList.Length - 1; i++)
                //{
                //    if (string.IsNullOrEmpty(nameSpace))
                //    {
                //        nameSpace = nameList[i];
                //    }
                //    else
                //    {
                //        nameSpace = nameSpace + "." + nameList[i];
                //    }
                //    sw.WriteLine(nameSpace + " = { }");
                //}

                sw.WriteLine(string.Format("---@type {0}", name));
                sw.WriteLine(name + " = { }");

                #region constructor
                constructors = new List <ConstructorInfo>(t.GetConstructors(bindType));
                constructors.Sort((left, right) => { return(left.GetParameters().Length - right.GetParameters().Length); });
                bool isDefineTable = false;

                if (constructors.Count > 0)
                {
                    WriteCtorComment(sw, constructors);
                    paramInfos = constructors[constructors.Count - 1].GetParameters();
                    delta      = paramInfos.Length - constructors[0].GetParameters().Length;
                    WriteFun(sw, delta, paramInfos, t, "New", name, true);
                    isDefineTable = true;
                }

                #endregion

                #region method
                methods = new List <MethodInfo>(t.GetMethods(bindType));
                var externMethod = GetExtensionMethods(t);

                foreach (var item in externMethod)
                {
                    methods.Add(item);
                }

                MethodInfo method;

                Dictionary <string, List <MethodInfo> > methodDict = new Dictionary <string, List <MethodInfo> >();

                for (int i = 0; i < methods.Count; i++)
                {
                    method = methods[i];
                    string methodName = method.Name;
                    if (IsObsolete(method))
                    {
                        continue;
                    }
                    if (method.IsGenericMethod)
                    {
                        continue;
                    }
                    if (!method.IsPublic)
                    {
                        continue;
                    }
                    if (methodName.StartsWith("get_") || methodName.StartsWith("set_"))
                    {
                        continue;
                    }

                    List <MethodInfo> list;
                    if (!methodDict.TryGetValue(methodName, out list))
                    {
                        list = new List <MethodInfo>();
                        methodDict.Add(methodName, list);
                    }
                    list.Add(method);
                }

                var itr = methodDict.GetEnumerator();
                while (itr.MoveNext())
                {
                    List <MethodInfo> list = itr.Current.Value;
                    RemoveRewriteFunHasTypeAndString(list);

                    list.Sort((left, right) =>
                    {
                        int leftLen  = left.GetParameters().Length;
                        int rightLen = right.GetParameters().Length;
                        if (left.IsDefined(typeof(ExtensionAttribute), false))
                        {
                            leftLen--;
                        }
                        if (right.IsDefined(typeof(ExtensionAttribute), false))
                        {
                            rightLen--;
                        }
                        return(leftLen - rightLen);
                    });
                    WriteFunComment(sw, list);
                    paramInfos = list[list.Count - 1].GetParameters();

                    if (list[list.Count - 1].IsDefined(typeof(ExtensionAttribute), false))
                    {
                        var newParamInfos = new List <ParameterInfo>(paramInfos);
                        newParamInfos.RemoveAt(0);
                        paramInfos = newParamInfos.ToArray();
                    }

                    delta = paramInfos.Length - list[0].GetParameters().Length;
                    WriteFun(sw, delta, paramInfos, list[0].ReturnType, list[0].Name, name, list[0].IsStatic);
                }
                itr.Dispose();

                if (methods.Count != 0 || isDefineTable)
                {
                    sw.WriteLine("return " + name);
                }
                #endregion

                //清空缓冲区
                sw.Flush();
                //关闭流
                sw.Close();
                fs.Close();
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError(name + "\n" + e.Message);
            }
        }
        string zipName = path + ".zip";
        if (File.Exists(zipName))
        {
            File.Delete(zipName);
        }
        GlobalAPI.WriteToFile();
        //ZipTool.ZipDirectory(path, zipName, 7);
        //Directory.Delete(path, true);

        Debug.Log("转换完成");
    }
コード例 #9
0
ファイル: VoiceChatApp.cs プロジェクト: lukyhruska96/VRLife
 public void Init(OpenAPI api, GlobalAPI globalAPI)
 {
     _api       = VrLifeCore.GetClosedAPI(_info);
     _globalAPI = globalAPI;
     _api.DeviceAPI.Microphone.MicrophoneData += OnMicrophoneData;
 }