Esempio n. 1
0
        private ProxyPackageInfoV1 _GetPackageWithLastEventOfType <T>(IEnumerable <ProxyPackageInfoV1> testPackages)
        {
            IEnumerable <T>             desiredTypeEvents = testPackages.GetAllLuEvents().AllSubeventsOfType <T>();
            IEnumerable <IHasTimestamp> timestampEvents   =
                testPackages.GetAllLuEvents().AllSubeventsOfType <IHasTimestamp>().OrderBy(e => e.Timestamp);

            if (desiredTypeEvents.Count() != 0 && timestampEvents.Count() != 0)
            {
                IHasTimestamp lastEventByTimestamp = timestampEvents.Last();

                foreach (T desiredTypeEvent in desiredTypeEvents)
                {
                    if (desiredTypeEvent is IHasTimestamp timestampEvent &&
                        timestampEvent == lastEventByTimestamp
                        )
                    {
                        lastEventByTimestamp = timestampEvent;
                    }
                }

                if (lastEventByTimestamp is T &&
                    lastEventByTimestamp is AbstractSdkEventV1 abstractSdkEvent
                    )
                {
                    ProxyPackageInfoV1 packageWithDesiredEvent = abstractSdkEvent.FindPackageForSubEvent(testPackages);
                    return(packageWithDesiredEvent.GetAllLuEvents().GetAllLevelSubevents().Count() == 1 ? packageWithDesiredEvent : null);
                }
            }

            return(null);
        }
        void CreateCompleted(Task <IHasTimestamp> createTask)
        {
            lock (this)
            {
                try
                {
                    Value        = createTask.Result;
                    m_handleBase = Value.HandleBase;

                    // Check if this handleBase is already present in the indexMap, and use the next index from there (else the index becomes 1)
                    int lastIndex = 0;
                    s_indexMap.TryGetValue(m_handleBase, out lastIndex);
                    m_index = lastIndex + 1;

                    // Update the indexMap with the index we used
                    s_indexMap[m_handleBase] = m_index;

                    Value.Changed += hasTimestamp_Changed;
                    m_storage.Add(this);
                    if (m_observer != null)
                    {
                        m_observer.OnNext(HandleName);
                    }
                }
                catch (Exception exception)
                {
                    if (m_observer != null)
                    {
                        m_observer.OnError(exception);
                    }
                }
            }
        }
Esempio n. 3
0
        public async Task <IBasicResult> AddOrUpdateAsync(TDomainObject domainObject)
        {
            if (domainObject.IsDirty)
            {
                var failedSpecs = await Specs.GetAddSpecs().RunSpecsAsync(domainObject);

                if (failedSpecs.Count() == 0)
                {
                    domainObject.Id = IdGenerator.Generate();

                    IHasTimestamp withTimestamp = domainObject as IHasTimestamp;

                    if (withTimestamp != null)
                    {
                        withTimestamp.DateAdded = DateTimeOffset.Now;
                    }

                    await OnAddAsync(domainObject);
                }
            }
            else
            {
                var failedSpecs = await Specs.GetUpdateSpecs().RunSpecsAsync(domainObject);

                if (failedSpecs.Count() == 0)
                {
                    await OnUpdateAsync(domainObject);
                }
            }

            return(null);
        }
        public bool TryFindObject(string handleName, out IHasTimestamp hasTimestamp)
        {
            // With some care this lookup can be made faster with a Dictionary, but remember that the HandleName can change,
            // so the dictionary would have to get update events too.
            var observable = observables.FirstOrDefault(ts => ts.HandleName == handleName);

            hasTimestamp = observable?.Value;
            return(observable != null);
        }
        public bool IsNew <T>(T model) where T : IHasTimestamp
        {
            IHasTimestamp timestampped = model;

            return(timestampped != null && (timestampped.Timestamp == null ? true : false));
        }