Exemple #1
0
        private static IEnumerable <SetVersion <T> > InternalGetAllItems()
        {
            var preRet = new List <SetVersion <T> >();

            if (App.Current.Orchestrator?.Person?.Locator == null)
            {
                return(preRet);
            }

            if (SetVersion <T> .CanBrowse())
            {
                preRet = SetVersion <T> .All().ToList();

                if (SetVersion <T> .CanModify())
                {
                    preRet.Add(new SetVersion <T>
                    {
                        Code      = Constants.CURRENT_LIVE_WORKSET_TAG,
                        Id        = Constants.CURRENT_LIVE_WORKSET_TAG,
                        Name      = "Workset",
                        IsPublic  = true,
                        IsLocked  = false,
                        IsCurrent = !preRet.Any(i => i.IsCurrent)
                    });
                }
            }
            else
            {
                preRet = SetVersion <T> .Where(i => i.IsPublic).ToList();
            }

            preRet = preRet.OrderBy(i => i.TimeStamp).Reverse().ToList();

            return(preRet);
        }
Exemple #2
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;
            }
        }
Exemple #3
0
        private static long Count()
        {
            var dataSetVersion = (SetVersioningPrimitiveAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(SetVersioningPrimitiveAttribute));

            if (App.Current.Orchestrator?.Person?.Locator == null)
            {
                return(0);
            }

            long preRet;

            if (dataSetVersion.CanBrowse())
            {
                preRet = SetVersion <T> .Count();
            }
            else
            {
                var personLocator = App.Current.Orchestrator?.Person?.Locator;

                preRet = SetVersion <T> .Where(i => i.OperatorLocator == personLocator).Count();
            }

            return(preRet);
        }