Example #1
0
    public void UploadNow()
    {
        //if (Time.time - lastUploadTime < timeout) {
        //	Debug.LogWarning("Don't make frequent calls to MySQL.UploadNow(), uploading is an async operation!");
        //}

        lastUploadTime = Time.time;

        if (dataTargets.Keys.Count == 0)
        {
            Debug.LogError("No logs in the upload queue. Use AddToUploadQueue() to add a logCollection to the queue before calling UploadNow().");
            return;
        }
        if (dataTargets.Keys.Count > 0)
        {
            foreach (KeyValuePair <string, DataTarget> pair in dataTargets)
            {
                DataTarget target = pair.Value;
                foreach (Dictionary <string, Dictionary <int, object> > logCollection in target.logsToUpload)
                {
                    Debug.Log("Attempting to upload logCollection with " + logCollection.Count + " rows.");
                    string  dbCols     = string.Join(sep, logCollection.Keys.ToArray());
                    string  dataString = ParseDataToString(logCollection);
                    WWWForm form       = PrepareForm(dbCols, dataString, target.credentials);

                    // Store data for later in case we need to dump them.
                    DumpedForm df = new DumpedForm();
                    df.dbName   = target.credentials.dbName;
                    df.table    = target.credentials.table;
                    df.username = target.credentials.username;
                    df.password = target.credentials.password;
                    df.dbURL    = target.credentials.dbURL;
                    df.dbSecKey = target.credentials.dbSecKey;

                    df.dbCols     = dbCols;
                    df.dataString = dataString;
                    dumpedforms.Add(df);

                    StartCoroutine(SubmitLogs(form, target.credentials.dbURL));
                }
                target.logsToUpload.Clear();
            }
        }
    }
Example #2
0
    public void UploadNow(Action callback)
    {
        //if (Time.time - lastUploadTime < timeout) {
        //	Debug.LogWarning("Don't make frequent calls to MySQL.UploadNow(), uploading is an async operation!");
        //}

        lastUploadTime = Time.time;

        if (dataTargets.Keys.Count == 0)
        {
            Debug.LogError("No logs in the upload queue. Use AddToUploadQueue() to add a LogStore to the queue before calling UploadNow().");
            return;
        }
        if (dataTargets.Keys.Count > 0)
        {
            foreach (KeyValuePair <string, DataTarget> pair in dataTargets)
            {
                DataTarget target = pair.Value;
                foreach (LogStore logStore in target.logstoreToUpload)
                {
                    Debug.Log("Attempting to upload LogStore with " + logStore.RowCount + " rows.");
                    string  dbCols     = logStore.GenerateHeaders();
                    string  dataString = logStore.ExportAll <string>();
                    WWWForm form       = PrepareForm(dbCols, dataString, target.credentials);

                    // Store data for later in case we need to dump them.
                    DumpedForm df = new DumpedForm();
                    df.dbName   = target.credentials.dbName;
                    df.table    = target.credentials.table;
                    df.username = target.credentials.username;
                    df.password = target.credentials.password;
                    df.dbURL    = target.credentials.dbURL;
                    df.dbSecKey = target.credentials.dbSecKey;

                    df.dbCols     = dbCols;
                    df.dataString = dataString;
                    dumpedforms.Add(df);
                    StartCoroutine(SubmitLogs(form, target.credentials.dbURL, callback));
                }
                target.logstoreToUpload.Clear();
            }
        }
    }
Example #3
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));
        }
    }