Beispiel #1
0
        public virtual object DropSet(string tid)
        {
            if (!SetVersion <T> .CanModify())
            {
                throw new AuthenticationException("User is not a Set Version Operator.");
            }

            var probe = SetVersion <T> .Get(tid);

            if (probe == null)
            {
                throw new InvalidDataException("Invalid ID.");
            }

            var sw = new Stopwatch();

            try
            {
                sw.Start();
                probe.Remove();
                sw.Stop();

                Log.Add <T>($"SetVersion: DropSet [{tid}] OK ({sw.ElapsedMilliseconds} ms)");

                return(probe);
            } catch (Exception e)
            {
                sw.Stop();
                Log.Add <T>(e, $"SetVersion: DropSet [{tid}] ERR ({sw.ElapsedMilliseconds} ms): {e.Message}");
                throw;
            }
        }
Beispiel #2
0
        public virtual object GetById(string id)
        {
            if (!SetVersion <T> .CanBrowse())
            {
                throw new AuthenticationException("User is not authorized to download.");
            }

            var sw = new Stopwatch();

            try
            {
                sw.Start();
                var preRet = SetVersion <T> .Get(id);

                sw.Stop();

                Log.Add <T>($"SetVersion : GetById [{id}] OK ({sw.ElapsedMilliseconds} ms)");
                return(preRet);
            } catch (Exception e)
            {
                sw.Stop();
                Log.Add <T>(e, $"SetVersion: GetById [{id}] ERR ({sw.ElapsedMilliseconds} ms)");
                throw;
            }
        }
Beispiel #3
0
        public virtual object PostItem(SetVersion <T> item)
        {
            var sw = new Stopwatch();

            if (!SetVersion <T> .CanModify())
            {
                throw new AuthenticationException("User is not a Set Version Operator.");
            }

            try
            {
                sw.Start();
                var preRet = SetVersion <T> .Get(item.Save().Id);

                sw.Stop();

                Log.Add <T>("SetVersion PostItem OK (" + sw.ElapsedMilliseconds + " ms)");
                return(preRet);
            } catch (Exception e)
            {
                sw.Stop();
                Log.Add <T>(e, "SetVersion PostItem ERR (" + sw.ElapsedMilliseconds + " ms): " + e.Message);
                throw;
            }
        }
Beispiel #4
0
        public virtual object SetCurrent(string id)
        {
            if (!SetVersion <T> .CanBrowse())
            {
                throw new AuthenticationException("User is not authorized.");
            }

            var sw = new Stopwatch();

            try
            {
                sw.Start();

                var probe = SetVersion <T> .Get(id);

                if (probe == null)
                {
                    throw new InvalidDataException("Invalid ID.");
                }

                if (probe.IsCurrent)
                {
                    return(probe);
                }

                var allCurrentSets = SetVersion <T> .Where(i => i.IsCurrent);

                foreach (var setVersion in allCurrentSets)
                {
                    if (!setVersion.IsCurrent)
                    {
                        continue;
                    }

                    setVersion.IsCurrent = false;
                    setVersion.Save();
                }

                probe.IsCurrent = true;
                probe           = SetVersion <T> .Get(probe.Save().Id);

                sw.Stop();

                Log.Add <T>($"SetVersion : SetCurrent [{id}] OK ({sw.ElapsedMilliseconds} ms)");

                return(probe);
            } catch (Exception e)
            {
                sw.Stop();
                Log.Add <T>(e, $"SetVersion: SetCurrent [{id}] ERR ({sw.ElapsedMilliseconds} ms): {e.Message}");
                throw;
            }
        }