Exemplo n.º 1
0
    private void DetectDumpedLogs()
    {
        // If no credentials are available, we skip dumplog detection.
        if (dataTargets.Keys.Count == 0)
        {
            Debug.LogWarning("No credentials loaded, aborting logdump detection..");
            return;
        }

        var fileDumps = Directory.GetFiles(directory, "logdump*");

        if (fileDumps == null)
        {
            return;
        }

        List <DumpedForm> forms = new List <DumpedForm>();

        foreach (string filename in fileDumps)
        {
            // determine whether  file is empty.
            var fi = new FileInfo(filename);
            if (fi.Length == 0)
            {
                Debug.LogWarning("empty logdump " + filename + ", deleting coldump and logdump..");
                File.Delete(filename);
                continue;
            }

            string line;
            string json = "";

            DumpedForm form = new DumpedForm();

            using (StreamReader reader = new StreamReader(filename)) {
                while ((line = reader.ReadLine()) != null)
                {
                    json += line;
                }
            }

            JsonUtility.FromJsonOverwrite(json, form);


            File.Delete(filename);

            // determine whether filestrings are empty.
            if (String.IsNullOrEmpty(json.Trim()))
            {
                Debug.LogWarning("malformed dump " + filename + ", deleting coldump and logdump..");
                continue;
            }

            Debug.Log("Dumped Logs Detected.");
            forms.Add(form);
        }

        foreach (DumpedForm dumpform in forms)
        {
            TargetCredentials creds = new TargetCredentials()
            {
                dbName   = dumpform.dbName,
                table    = dumpform.table,
                username = dumpform.username,
                password = dumpform.password,
                dbURL    = dumpform.dbURL,
                dbSecKey = dumpform.dbSecKey
            };
            var form = PrepareForm(dumpform.dbCols, dumpform.dataString, creds);
            StartCoroutine(SubmitLogs(form, dumpform.dbURL));
        }
    }