Exemplo n.º 1
0
        private AudioLogEntry Store(HistorySaveData saveData)
        {
            if (saveData == null)
            {
                throw new ArgumentNullException(nameof(saveData));
            }

            AudioLogEntry ale;

            using (var trans = database.BeginTrans())
            {
                ale = FindByUniqueId(saveData.Resource.UniqueId);
                if (ale == null)
                {
                    ale = CreateLogEntry(saveData);
                    if (ale == null)
                    {
                        Log.Write(Log.Level.Error, "AudioLogEntry could not be created!");
                    }
                }
                else
                {
                    LogEntryPlay(ale);
                }
                trans.Commit();
            }
            return(ale);
        }
Exemplo n.º 2
0
        private AudioLogEntry CreateLogEntry(HistorySaveData saveData)
        {
            if (string.IsNullOrWhiteSpace(saveData.Resource.ResourceTitle))
            {
                return(null);
            }

            int nextHid;

            if (historyManagerData.FillDeletedIds && unusedIds.Count > 0)
            {
                nextHid = unusedIds.First.Value;
                unusedIds.RemoveFirst();
            }
            else
            {
                nextHid = 0;
            }

            var ale = new AudioLogEntry(nextHid, saveData.Resource)
            {
                UserInvokeId = (uint)(saveData.OwnerDbId ?? 0),
                Timestamp    = Util.GetNow(),
                PlayCount    = 1,
            };

            audioLogEntries.Insert(ale);
            return(ale);
        }
Exemplo n.º 3
0
        private R <AudioLogEntry, Exception> CreateLogEntry(HistorySaveData saveData)
        {
            if (string.IsNullOrWhiteSpace(saveData.Resource.ResourceTitle))
            {
                return(new Exception("Track name is empty"));
            }

            int nextHid;

            if (config.FillDeletedIds && unusedIds.Count > 0)
            {
                nextHid = unusedIds.First.Value;
                unusedIds.RemoveFirst();
            }
            else
            {
                nextHid = 0;
            }

            var ale = new AudioLogEntry(nextHid, saveData.Resource)
            {
                UserUid   = saveData.InvokerUid,
                Timestamp = Util.GetNow(),
                PlayCount = 1,
            };

            try
            {
                audioLogEntries.Insert(ale);
                return(ale);
            }
            catch (Exception ex) { return(ex); }
        }
Exemplo n.º 4
0
        public R <AudioLogEntry> LogAudioResource(HistorySaveData saveData)
        {
            if (saveData is null)
            {
                throw new ArgumentNullException(nameof(saveData));
            }

            lock (dbLock)
            {
                var ale = FindByUniqueId(saveData.Resource.UniqueId);
                if (ale is null)
                {
                    var createResult = CreateLogEntry(saveData);
                    if (!createResult.Ok)
                    {
                        Log.Warn(createResult.Error, "AudioLogEntry could not be created!");
                        return(R.Err);
                    }
                    ale = createResult.Value;
                }
                else
                {
                    LogEntryPlay(ale);
                }

                return(ale);
            }
        }
Exemplo n.º 5
0
        private AudioLogEntry Store(HistorySaveData saveData)
        {
            if (saveData == null)
            {
                throw new ArgumentNullException(nameof(saveData));
            }

            lock (dbLock)
            {
                var ale = FindByUniqueId(saveData.Resource.UniqueId);
                if (ale == null)
                {
                    ale = CreateLogEntry(saveData);
                    if (ale == null)
                    {
                        Log.Error("AudioLogEntry could not be created!");
                    }
                }
                else
                {
                    LogEntryPlay(ale);
                }

                return(ale);
            }
        }
Exemplo n.º 6
0
        private R <AudioLogEntry, Exception> CreateLogEntry(HistorySaveData saveData)
        {
            if (string.IsNullOrWhiteSpace(saveData.Resource.ResourceTitle))
            {
                return(new Exception("Track name is empty"));
            }

            int nextHid;
            var first = unusedIds.First;

            if (config.FillDeletedIds && first != null)
            {
                nextHid = first.Value;
                unusedIds.Remove(first);
            }
            else
            {
                nextHid = 0;
            }

            var userUid = (saveData.InvokerUid ?? Uid.Anonymous).Value ?? Uid.Anonymous.Value !;
            var ale     = new AudioLogEntry(nextHid, saveData.Resource, userUid)
            {
                Timestamp = Tools.Now,
                PlayCount = 1,
            };

            try
            {
                audioLogEntries.Insert(ale);
                return(ale);
            }
            catch (Exception ex) { return(ex); }
        }
Exemplo n.º 7
0
        public R <AudioLogEntry> LogAudioResource(HistorySaveData saveData)
        {
            var entry = Store(saveData);

            if (entry != null)
            {
                return(entry);
            }
            else
            {
                return("Entry could not be stored");
            }
        }