Пример #1
0
        /// <summary>
        /// Detaches an asset tile from the API handler.
        /// </summary>
        /// <param name="assetTile">The assetTile<see cref="WpfAssetTile"/> to unsubscribe</param>
        public void DetachAssetTile(IAssetTile assetTile)
        {
            this.attachedAssetTiles.Remove(assetTile);
            IApi api = this.LoadedApis.FirstOrDefault(a => a.ApiInfo.ApiName == assetTile.AssetTileData.ApiName);

            if (api == null)
            {
                return;
            }

            // detach asset if there is no other asset tile with the same asset subscribed to this api
            bool detachAsset = !this.attachedAssetTiles.Exists(att => att.AssetTileData.ApiName == api.ApiInfo.ApiName &&
                                                               att.AssetTileData.Asset.AssetId == assetTile.AssetTileData.Asset.AssetId);

            // detach convert currency if there is no other asset tile with the same convert currency subscribed to this api
            bool detachConvertCurrency = !this.attachedAssetTiles.Exists(att => att.AssetTileData.ApiName == api.ApiInfo.ApiName &&
                                                                         att.AssetTileData.Asset.ConvertCurrency == assetTile.AssetTileData.Asset.ConvertCurrency);

            api.DetachAsset(new DetachAssetArgs()
            {
                Asset                 = assetTile.AssetTileData.Asset,
                DetachAsset           = detachAsset,
                DetachConvertCurrency = detachConvertCurrency
            });
        }
Пример #2
0
        /// <summary>
        /// Attaches an asset tile to the API handler and it's asset to the right API.
        /// </summary>
        /// <param name="assetTile">The assetTile<see cref="WpfAssetTile"/> to subscribe.</param>
        /// <param name="requestUpdate">If true, the API will request an update for this asset instantly.</param>
        public void AttachAssetTile(IAssetTile assetTile, bool requestUpdate)
        {
            // search the API to subscribe in the dictionary
            IApi api = this.LoadedApis.FirstOrDefault(a => a.ApiInfo.ApiName == assetTile.AssetTileData.ApiName);

            api.AttachAsset(assetTile.AssetTileData.Asset);

            if (api.ApiData.IsEnabled && requestUpdate)
            {
                api.RequestSingleAssetUpdateAsync(assetTile.AssetTileData.Asset);
            }

            this.attachedAssetTiles.Add(assetTile);
        }
Пример #3
0
        /// <summary>
        /// The Asstile_Closed calls the API handler to unsubscribe the asset tile,
        /// removes is from the handled asset tiles and the app data and calls the FireOnAppDataChanged method.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/> contains the closed asset tile.</param>
        /// <param name="e">The e<see cref="EventArgs"/></param>
        private void AssetTile_OnTileClosed(object sender, EventArgs e)
        {
            IAssetTile closedAssetTile = (WpfAssetTile)sender;

            this.apiHandler.DetachAssetTile(closedAssetTile);
            this.activeAssetTiles.Remove(closedAssetTile);
            this.appData.AssetTileDataSet.Remove(closedAssetTile.AssetTileData);

            this.activePortfolioTiles.ForEach(portt =>
            {
                portt.RemoveAssetTile(closedAssetTile.AssetTileData.AssetTileId);
            });

            this.FireOnAppDataChanged();
        }
Пример #4
0
        /// <summary>
        /// The Update
        /// </summary>
        /// <param name="updatedAssetTile">The updatedAsset<see cref="Asset"/></param>
        public void Update(IAssetTile updatedAssetTile)
        {
            if (this.PortfolioTileData.AssignedAssetTileIds.Any(id => id == updatedAssetTile.AssetTileData.AssetTileId))
            {
                // remove asset if the convert currency has changed
                if (this.PortfolioTileData.AssignedAssetTileIds.Count > 1)
                {
                    int otherAssignedId = this.PortfolioTileData.AssignedAssetTileIds.First(a => a != updatedAssetTile.AssetTileData.AssetTileId);

                    if (this.appData.AssetTileDataSet.First(a => a.AssetTileId == otherAssignedId).Asset.ConvertCurrency != updatedAssetTile.AssetTileData.Asset.ConvertCurrency)
                    {
                        this.PortfolioTileData.AssignedAssetTileIds.Remove(updatedAssetTile.AssetTileData.AssetTileId);
                        this.FireOnAppDataChanged();
                    }
                }

                this.UpdateTextBlocks(updatedAssetTile.AssetTileData.Asset.LastUpdated);
                this.RefreshTileStyle();
            }
        }