예제 #1
0
    private static void CheckError_Invocation(string allInvokeWithLocationOutputPath)
    {
        if (typesImpByJs == null)
        {
            typesImpByJs      = new Dictionary <string, List <string> >();
            typesImpByJs["T"] = new List <string> {
                "T"
            };
            typesImpByJs["System.Action"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Action$1"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Action$2"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Action$3"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Action$4"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Func$1"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Func$2"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Func$3"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Func$4"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Exception"] = new List <string> {
                "ctor$$String"
            };
            typesImpByJs["System.NotImplementedException"] = new List <string> {
                "ctor"
            };
            typesImpByJs["System.Array"] = new List <string>
            {
                "length",
                "CopyTo",
                "Static_Convertall",
                "Static_Sort$1$$T$Array"
            };
            typesImpByJs["System.Collections.Generic.List$1"] = new List <string>
            {
                "ctor",
                "ctor$$IEnumerable$1",
                "ctor$$Int32",
                "RemoveRange",
                "Clear",
                "get_Item$$Int32",
                "set_Item$$Int32",
                "get_Count",
                "GetEnumerator",
                "ToArray",
                "AddRange",
                "Add",
                "Remove",
                "Contains",
                "SetItems",
                "IndexOf",
                "Exists",
                "IndexOf$$T",
                "Insert",
                "RemoveAt",
                "RemoveAll",
                //"TryRemove",
                "CopyTo",
                //"get_IsReadOnly",
                "Reverse",
                "Sort",
                "Sort$$Comparison$1",
                "ForEach",
                "Find",
                "FindIndex$$Predicate$1",
                "FindIndex$$Int32$$Predicate$1",
                "FindIndex$$Int32$$Int32$$Predicate$1",
                "FindLastIndex$$Predicate$1",
                "FindLastIndex$$Int32$$Predicate$1",
                "FindLastIndex$$Int32$$Int32$$Predicate$1",
                "FindAll",
                "GetRange",
                "InsertRange"
            };
            typesImpByJs["System.Collections.Generic.Dictionary$2"] = new List <string>
            {
                "ctor",
                "ctor$$Int32",
                "Add",
                "Remove",
                "get_Item$$TKey",
                "set_Item$$TKey",
                "ContainsKey",
                "GetEnumerator",
                "Clear",
                "TryGetValue",
                "get_Count",
                "get_Keys",
                "get_Values"
            };
            typesImpByJs["System.Collections.Generic.KeyValuePair$2"] = new List <string>
            {
                "get_Key",
                "get_Value",
                "ctor$$TKey$$TValue"
            };
            typesImpByJs["System.Collections.Generic.Dictionary.ValueCollection$2"] = new List <string> {
                "CopyTo"
            };
            // 特殊!
            typesImpByJs["System.Collections.Generic.Dictionary.KeyCollection$2"] = new List <string> {
                "CopyTo"
            };                                                                                                     // 特殊!
            typesImpByJs["System.Linq.Enumerable"] = new List <string> {
                "Static_ToArray$1"
            };
            typesImpByJs["System.Collections.Generic.HashSet$1"] = new List <string>
            {
                "ctor",
                "Add",
                "get_Count",
                "Clear",
                "Contains",
                "Remove"
            };
            typesImpByJs["System.Collections.Generic.Queue$1"] = new List <string>
            {
                "ctor",
                "ctor$$Int32",
                "Clear",
                "get_Count",
                "Enqueue",
                "Dequeue",
                "Peek",
                "Contains",
                "ToArray"
            };
            typesImpByJs["System.String"] = new List <string>
            {
                // native
                "toString",
                "length",
                "replace",
                "split",
                "indexOf",
                "substr",
                "charAt",
                /// static
                "Static_Empty",
                "Static_Format$$String$$Object",
                "Static_Format$$String$$Object$$Object",
                "Static_Format$$String$$Object$$Object$$Object",
                "Static_IsNullOrEmpty",
                "Static_Equals$$String$$String$$StringComparison",
                "Static_Join$$String$$String$Array",
                // instance
                "ctor$$Char$Array",
                "ctor$$Char$Array$$Int32$$Int32",
                "Insert",
                "Substring$$Int32",
                "Substring$$Int32$$Int32",
                "Substring",
                "ToLower",
                "toLowerCase",
                "ToUpper",
                "toUpperCase",
                "getItem",
                "IndexOf$$String",
                "IndexOf$$Char",
                "LastIndexOf",
                "LastIndexOf$$Char",
                "LastIndexOf$$String",
                "Remove$$Int32",
                "Remove$$Int32$$Int32",
                "StartsWith$$String",
                "EndsWith$$String",
                "Contains",
                "get_Length",
                "Split$$Char$Array",
                "trim",
                "Trim",
                "ltrim",
                "rtrim",
                "Static_Format$$String$$Object$Array",
                "Replace$$String$$String",
                "Replace$$Char$$Char",
                "PadLeft$$Int32$$Char",
                "PadRight$$Int32$$Char",
                "ToCharArray"
            };
            typesImpByJs["System.Char"] = new List <string> {
                "toString", "Static_IsNumber$$Char"
            };
            typesImpByJs["System.Int32"] = new List <string>
            {
                "toString",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Int32",
                "ToString$$String",
                "CompareTo$$Int32"
            };
            typesImpByJs["System.UInt64"] = new List <string>
            {
                "toString",
                "Static_Parse$$String",
                "Static_TryParse$$String$$UInt64"
            };
            typesImpByJs["System.Int64"] = new List <string>
            {
                "toString",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Int64",
                "ToString$$String",
                "CompareTo$$Int64"
            };
            typesImpByJs["System.Boolean"] = new List <string>
            {
                "toString",
                "CompareTo$$Boolean"
            };
            typesImpByJs["System.Double"] = new List <string>
            {
                "toString",
                "ToString$$String",
                "CompareTo$$Double",
                "Static_tryParse",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Double"
            };
            typesImpByJs["System.Single"] = new List <string>
            {
                "toString",
                "ToString$$String",
                "CompareTo$$Single",
                "Static_tryParse",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Single"
            };
            //			typesImpByJs["System.Int32"] = new List<string> { "toString", "Static_Parse$$String",  };
            typesImpByJs["System.Enum"] = new List <string> {
                "toString"
            };
            typesImpByJs["System.MulticastDelegate"] = new List <string>();
        }


        string allExportedMembersFile = GetAllExportedMembersFile();

        var allInvoked  = LoadAllInvoked(allInvokeWithLocationOutputPath);
        var allExported = LoadAllExported(allExportedMembersFile);

        foreach (var KV in typesImpByJs)
        {
            HashSet <string> HS = null;
            if (!allExported.TryGetValue(KV.Key, out HS))
            {
                HS = new HashSet <string>();
                allExported.Add(KV.Key, HS);
            }
            if (KV.Value == null)
            {
                continue;
            }

            foreach (string m in KV.Value)
            {
                if (!HS.Contains(m))
                {
                    HS.Add(m);
                }
            }
        }

        var sbError = new StringBuilder();

        int errCount = 0;

        foreach (var KV in allInvoked)
        {
            string           typeName = KV.Key;
            HashSet <string> hsExported;
            var DInvoked = KV.Value;

            // 类有导出吗?
            if (!allExported.TryGetValue(typeName, out hsExported))
            {
                errCount++;
                sbError.AppendFormat("[{0}] not exported.", typeName);
                sbError.AppendLine();
                foreach (var KV2 in DInvoked)
                {
                    string methodName = KV2.Key;
                    sbError.AppendFormat("      {0}", methodName);
                    sbError.AppendLine();

                    foreach (var loc in KV2.Value)
                    {
                        sbError.AppendFormat("        {0} {1}", loc.FileName, loc.Line);
                        sbError.AppendLine();
                    }
                }
            }
            else
            {
                foreach (var KV2 in DInvoked)
                {
                    string methodName = KV2.Key;
                    // 函数可用/有导出吗
                    if (hsExported == null || !hsExported.Contains(methodName))
                    {
                        errCount++;
                        sbError.AppendFormat("[{0}].{1} not valid.", typeName, methodName);
                        sbError.AppendLine();

                        foreach (var loc in KV2.Value)
                        {
                            sbError.AppendFormat("        {0} {1}", loc.FileName, loc.Line);
                            sbError.AppendLine();
                        }
                    }
                }
            }
        }

        string fullpath = GetTempFileNameFullPath("CompilerCheckErrorResult.txt");

        File.Delete(fullpath);

        if (errCount > 0)
        {
            File.WriteAllText(fullpath, sbError.ToString());

            string relPath = fullpath.Replace("\\", "/").Substring(fullpath.IndexOf("Assets/"));
            var    context = AssetDatabase.LoadAssetAtPath <Object>(relPath);
            Debug.LogError("Check invocation error result: (" + errCount + " errors) (点击此条可定位文件)", context);
            Debug.LogError(sbError);
        }
        else
        {
            Debug.Log("Check invocation error result: 0 error");
        }
    }
        /// <summary>
        /// Read a data file downloaded from the FCC Univeral License System advanced search and fill the collection with its data.
        /// </summary>
        /// <param name="filename">Path to downloaded file.</param>
        public void ReadFile(String filename)
        {
            var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);

            using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        string[] tokens = line.Split(new char[] { '|' }, StringSplitOptions.None);
                        if (tokens != null && tokens.Length > 4)
                        {
                            string typeToken = tokens[0];
                            string callSign  = "";
                            if (!String.IsNullOrEmpty(typeToken))
                            {
                                if (typeToken.Equals("HD"))
                                {
                                    callSign = tokens[4];
                                    if (!HD.ContainsKey(callSign))
                                    {
                                        HD.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("EN"))
                                {
                                    callSign = tokens[4];
                                    if (!EN.ContainsKey(callSign))
                                    {
                                        EN.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("HS"))
                                {
                                    callSign = tokens[3];
                                    Tuple <HistoryRecordAction, String> actionType = GetHistoryActionType(tokens[5]);
                                    HistoryRecord rec = new HistoryRecord()
                                    {
                                        CallSign          = callSign,
                                        LicenseKey        = tokens[1],
                                        Date              = DateTime.ParseExact(tokens[4], "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                        Action            = actionType.Item1,
                                        ActionDescription = actionType.Item2
                                    };
                                    if (!HS.ContainsKey(callSign))
                                    {
                                        List <HistoryRecord> recList = new List <HistoryRecord>();
                                        recList.Add(rec);
                                        HS.Add(callSign, recList);
                                    }
                                    else
                                    {
                                        HS[callSign].Add(rec);
                                    }
                                }
                                else if (typeToken.Equals("AM"))
                                {
                                    callSign = tokens[4];
                                    if (!AM.ContainsKey(callSign))
                                    {
                                        AM.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("SC"))
                                {
                                    callSign = tokens[4];
                                    if (!SC.ContainsKey(callSign))
                                    {
                                        SC.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("CO"))
                                {
                                    callSign = tokens[4];
                                    if (!CO.ContainsKey(callSign))
                                    {
                                        CO.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("LM"))
                                {
                                    callSign = tokens[4];
                                    if (!LM.ContainsKey(callSign))
                                    {
                                        LM.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ExtractOperatorRecords();
        }