Exemplo n.º 1
0
    async Task NormalizeAndPollAsync(CancellationToken cancel = default, bool noPoll = false)
    {
        using (await FileLock.LockWithAwait(cancel))
        {
            if (noPoll == false && this.IsCanceled == false && this.IsCleanuped == false)
            {
                if (this.Config.Callback != null)
                {
                    StatManDatabase tmp = new StatManDatabase();

                    await this.Config.Callback(Config.Param, tmp.LongValues, tmp.StrValues)._TryWaitAsync();

                    tmp.LongValues._DoForEach(x => this.AddReport(x.Key, x.Value));
                    tmp.StrValues._DoForEach(x => this.AddReport(x.Key, x.Value));
                }
            }

            StatManDatabase dataCopy;

            lock (DataLock)
            {
                dataCopy = this.Database._CloneWithJson();
            }

            await Lfs.WriteJsonToFileEncryptedAsync(this.FileNameFullPath, dataCopy, Consts.Strings.StatManEncryptKey, FileFlags.AutoCreateDirectory, cancel : cancel)._TryWaitAsync();
        }
    }