Esempio n. 1
0
        public async Task RemoveAsync(FocusItem evt)
        {
            var item = await digitServiceContext.FocusItems.Where(v => v.Id == evt.Id).SingleOrDefaultAsync();

            digitServiceContext.FocusItems.Remove(item);
            await digitServiceContext.SaveChangesAsync();
        }
Esempio n. 2
0
        private List <FocusItem> AddDataToCollection(
            FocusData data, List <FocusItem> allData)
        {
            if (allData.Any(x => x.ItemId == data.ItemId))
            {
                allData.First(x => x.ItemId == data.ItemId).AddAndCombineItem(data);
            }
            else
            {
                var focusItem = new FocusItem(data.ItemId);
                focusItem.AddAndCombineItem(data);
                allData.Add(focusItem);
            }

            return(allData);
        }
Esempio n. 3
0
        private async Task <TransitDirections> GetFreshDirections(string userId, Event evt, FocusItem item, Location location)
        {
            string directionsKey = null;
            var    address       = await ResolveAddress(userId, evt);

            if (null != address && null != location)
            {
                try
                {
                    var start = new Coordinate()
                    {
                        Lat = location.Latitude,
                        Lng = location.Longitude
                    };
                    DateTimeOffset directionRequestTime = DateTimeOffset.Now;
                    if (item.DirectionsMetadata?.TravelStatus == TravelStatus.OnJourney)
                    {
                        directionRequestTime = location.Timestamp;
                    }
                    bool             requestWithNow   = evt.Start <= directionRequestTime;
                    DirectionsResult directionsResult = null;
                    const int        preferredRoute   = 0;
                    if (!requestWithNow)
                    {
                        directionsResult = await travelServiceClient.Users[userId].Directions.Transit.Get(start, address, evt.Start);
                        if (null != directionsResult.NotFound ||
                            directionsResult.TransitDirections.Routes[preferredRoute].DepatureTime < directionRequestTime)
                        {
                            requestWithNow = true;
                        }
                    }
                    if (requestWithNow)
                    {
                        directionsResult = await travelServiceClient.Users[userId].Directions.Transit.Get(start, address, null, directionRequestTime);
                    }
                    directionsKey = directionsResult?.CacheKey;
                    await focusStore.UpdateDirections(item.Id, directionsResult,
                                                      null != directionsResult.NotFound?null : (int?)preferredRoute);

                    item.DirectionsMetadata = new DirectionsMetadata()
                    {
                        Error         = directionsResult.NotFound?.Reason,
                        Key           = directionsResult.CacheKey,
                        PeferredRoute = preferredRoute
                    };
                    if (null == directionsResult.NotFound)
                    {
                        await travelServiceClient.Directions[directionsResult.CacheKey]
                        .Subscribe(new Uri(_options.DirectionsCallbackUri));
                    }
                    return(directionsResult.TransitDirections);
                }
                catch (TravelServiceException ex)
                {
                    await logger.LogForFocusItem(userId, item.Id, $"Error while retrieving directions for {evt.Subject}: {ex.Message}",
                                                 logLevel : LogLevel.Error);
                }
            }
            // TODO maybe clear directions with focusStore.UpdateDirections
            return(null);
        }
Esempio n. 4
0
        private async Task <DirectionsUpdateResult> GetCachedDirectionsOrNew(string userId, Event evt, FocusItem item, Location location)
        {
            var directionsResult = await travelServiceClient.Directions[item.DirectionsMetadata.Key].GetAsync();

            if (null != directionsResult)
            {
                if (!await RouteUpdateRequired(userId,
                                               directionsResult,
                                               item,
                                               location,
                                               DateTimeOffset.Now))
                {
                    return(new DirectionsUpdateResult()
                    {
                        Directions = directionsResult.TransitDirections,
                        IsNew = false
                    });
                }
            }
            return(new DirectionsUpdateResult()
            {
                Directions = await GetFreshDirections(userId, evt, item, location),
                IsNew = true
            });
        }
Esempio n. 5
0
        private async Task <bool> RouteUpdateRequired(string userId, DirectionsResult res, FocusItem item,
                                                      Location location, DateTimeOffset now)
        {
            if (item.DirectionsMetadata.TravelStatus == TravelStatus.Finished)
            {
                return(false);
            }
            if (null == location)
            {
                return(false);
            }
            var traceMeasures = await travelServiceClient
                                .Directions[res.CacheKey]
                                .Itineraries[item.DirectionsMetadata.PeferredRoute]
                                .Trace(new TraceLocation()
            {
                Accuracy = new TraceLocationAccuracy()
                {
                    Confidence = 0.68,
                    Radius     = location.Accuracy
                },
                Coordinate = new Coordinate(location.Latitude, location.Longitude),
                Timestamp  = location.Timestamp
            });
            await logger.LogForFocusItem(userId, item.Id, $"Traced {Math.Round(traceMeasures.ConfidenceOnRoute * 100)}% on route at accuracy of " +
                                         $"{location.Accuracy}, " +
                                         $" with delay of {traceMeasures.PositionOnRoute.Delay}", DigitTraceAction.TraceOnRoute,
                                         new Dictionary <string, object>() {
                { "lng", location.Longitude },
                { "lat", location.Latitude }
            });

            if (traceMeasures.ConfidenceOnRoute > 0.3)
            {
                if (traceMeasures.PositionOnRoute.Delay < FocusConstants.MaxAllowedDelay &&
                    (-FocusConstants.MaxAllowedEarly) < traceMeasures.PositionOnRoute.Delay)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 6
0
 public static void MapFromFocusItem(this StoredFocusItem storedFocusItem, FocusItem focusItem)
 {
 }
Esempio n. 7
0
    /// <summary>
    /// 更新列表
    /// </summary>
    public void UpdateList()
    {
        m_IsDirty = false;

        bool isFocusing = false;

        UIPanelFocus CurrentPanel     = UIPanelFocus.Current;
        GameObject   CurrentSelection = CurrentPanel != null?CurrentPanel.GetSelection() : null;

        ScrollRect scroller = GetComponent <ScrollRect>();

        //如果模板改变了,销毁所有单元格
        if (m_TemplateChanged)
        {
            m_TemplateChanged = false;

            for (int i = 0; i < scroller.content.childCount; i += 2)
            {
                Transform titleBox = scroller.content.GetChild(i);
                for (int j = titleBox.childCount - 1; j >= 0; j--)
                {
                    RecycleTitle(titleBox.GetChild(j));
                }
                Transform itemBox = scroller.content.GetChild(i + 1);
                for (int j = itemBox.childCount - 1; j >= 0; j--)
                {
                    if (itemBox.GetChild(j).gameObject == CurrentSelection)
                    {
                        isFocusing = true;
                    }

                    RecycleItem(itemBox.GetChild(j));
                }
            }

            Transform titlePool = GetTitlePool();
            titlePool.SetParent(null);
            Object.Destroy(titlePool.gameObject);

            Transform itemPool = GetItemPool();
            itemPool.SetParent(null);
            Object.Destroy(itemPool.gameObject);

            m_Index2ItemA.Clear();
        }

        //如果数据改变了,回收所有单元格
        if (m_DataChanged)
        {
            m_DataChanged = false;
            foreach (RectTransform transform in m_Index2ItemA.Values)
            {
                if (transform.gameObject == CurrentSelection)
                {
                    isFocusing = true;
                }

                RecycleItem(transform);
            }
            m_Index2ItemA.Clear();
        }

        int selectedTableIndex = Mathf.Max(0, Mathf.Min(m_CurrentSelect.x, m_GroupDatas.Count - 1));
        int selectedArrayIndex = m_CurrentSelect.y;

        if (m_GroupDatas.Count > 0)
        {
            selectedArrayIndex = Mathf.Max(0, Mathf.Min(selectedArrayIndex, m_GroupDatas[selectedTableIndex].ItemDataList.Count - 1));
        }
        else
        {
            selectedArrayIndex = 0;
        }

        m_CurrentSelect = new Vector2Int(selectedTableIndex, selectedArrayIndex);

        VisibleItems.Clear();

        int   index  = 0;
        float beginY = 0;

        for (int i = 0; i < m_GroupDatas.Count; i++)
        {
            beginY += i > 0 ? m_ContentSpacing : 0;

            beginY += LayoutHead(i, m_GroupDatas[i], scroller, GetOrCreateBox(scroller.content, index), beginY);
            index++;

            beginY += m_ContentSpacing;

            beginY += LayoutList(i, m_GroupDatas[i], scroller, GetOrCreateBox(scroller.content, index), beginY, VisibleItems);
            index++;
        }

        //回收多余的标题
        for (int i = index; i < scroller.content.childCount; i++)
        {
            Transform box = scroller.content.GetChild(i);

            LayoutElement viewElement = box.GetComponent <LayoutElement>();
            viewElement.preferredWidth  = viewElement.minWidth = 0;
            viewElement.preferredHeight = viewElement.minHeight = 0;

            if (i % 2 == 0)
            {
                for (int j = box.childCount - 1; j >= 0; j--)
                {
                    RecycleTitle(box.GetChild(j));
                }
            }
        }

        //回收不可见的单元格
        StringKeys.Clear();
        StringKeys.AddRange(m_Index2ItemA.Keys);
        foreach (string key in StringKeys)
        {
            if (!VisibleItems.ContainsKey(key))
            {
                RecycleItem(m_Index2ItemA[key]);
                m_Index2ItemA.Remove(key);
            }
        }
        StringKeys.Clear();

        //布局可见的单元格
        //bool selectChanged = !m_LastSelect.Equals(m_CurrentSelect);
        foreach (ItemInfo info in VisibleItems.Values)
        {
            string key = info.DataIndex.x + "_" + info.DataIndex.y;

            RectTransform item = m_Index2ItemA.ContainsKey(key) ? m_Index2ItemA[key] : CreateItem(info.ItemBox);
            item.anchoredPosition = new Vector2(info.ItemPosition.x, -info.ItemPosition.y);
            item.sizeDelta        = m_CellSize;
            item.SetSiblingIndex(info.ItemDepth);

            if (isFocusing && info.DataIndex.Equals(m_CurrentSelect) && CurrentPanel != null)
            {
                CurrentPanel.SetSelection(item.gameObject);
            }

            if (m_Index2ItemA.ContainsKey(key))
            {
                m_Index2ItemA.Remove(key);
                if (/*selectChanged && (*/ info.DataIndex.Equals(m_LastSelect) || info.DataIndex.Equals(m_CurrentSelect))//)
                {
                    RenderItem?.Invoke(info.DataIndex, info.Data, item, info.DataIndex.x == m_CurrentSelect.x && info.DataIndex.y == m_CurrentSelect.y);
                }
            }
            else
            {
                RenderItem?.Invoke(info.DataIndex, info.Data, item, info.DataIndex.x == m_CurrentSelect.x && info.DataIndex.y == m_CurrentSelect.y);
            }

            FocusItem focus = item.GetComponent <FocusItem>() ?? item.gameObject.AddComponent <FocusItem>();
            focus.Viewer = this;
            focus.Index  = info.DataIndex;

            AutoSelectOnGotFocus autoFocus = item.GetComponent <AutoSelectOnGotFocus>() ?? item.gameObject.AddComponent <AutoSelectOnGotFocus>();
            autoFocus.autoSelect = AutoSelectOnGotFocus;

            if (!m_Index2ItemB.ContainsKey(key))
            {
                m_Index2ItemB.Add(key, item);
            }
        }
        VisibleItems.Clear();

        Dictionary <string, RectTransform> tmp = m_Index2ItemA;

        m_Index2ItemA = m_Index2ItemB;
        m_Index2ItemB = tmp;
        m_Index2ItemB.Clear();

        m_LastSelect = m_CurrentSelect;

        VerticalLayoutGroup scrollerLayout = scroller.content.GetComponent <VerticalLayoutGroup>();

        if (!scrollerLayout)
        {
            scrollerLayout = scroller.content.gameObject.AddComponent <VerticalLayoutGroup>();
        }
        scrollerLayout.childControlWidth      = true;
        scrollerLayout.childControlHeight     = true;
        scrollerLayout.childForceExpandWidth  = true;
        scrollerLayout.childForceExpandHeight = true;

        RectOffset offset = scrollerLayout.padding;

        offset.left   = m_ContentPadding.left;
        offset.right  = m_ContentPadding.right;
        offset.top    = m_ContentPadding.top;
        offset.bottom = m_ContentPadding.bottom;

        scrollerLayout.padding = m_ContentPadding;
        scrollerLayout.padding = offset;
        scrollerLayout.spacing = m_ContentSpacing;

        ContentSizeFitter scrollerSize = scroller.content.GetComponent <ContentSizeFitter>();

        if (!scrollerSize)
        {
            scrollerSize = scroller.content.gameObject.AddComponent <ContentSizeFitter>();
        }
        scrollerSize.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
        scrollerSize.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

        Canvas.ForceUpdateCanvases();

        //Debug.Log("Updateing");
    }
Esempio n. 8
0
 public void HighlightItem(FocusItem item)
 {
     m_items[m_current].Unhighlight();
     m_current = System.Array.IndexOf(m_items, item);
     m_items[m_current].Highlight();
 }