private void WorkerAnalyzeAssets_DoWork(object sender, DoWorkEventArgs e)
        {
            Debug.WriteLine("WorkerAnalyzeAssets_DoWork");
            BackgroundWorker worker = sender as BackgroundWorker;
            Asset            asset  = null;

            var listae = _MyObservAssetV3.OrderBy(a => cacheAssetentriesV3.ContainsKey(a.Name)).ToList(); // as priority, assets not yet analyzed


            // test - let analyze only visible assets

            var visibleRowsCount       = this.DisplayedRowCount(true);
            var firstDisplayedRowIndex = (this.FirstDisplayedCell != null) ? this.FirstDisplayedCell.RowIndex : 0;
            var lastvisibleRowIndex    = (firstDisplayedRowIndex + visibleRowsCount) - 1;
            var VisibleAssets          = new List <String>();

            for (int rowIndex = firstDisplayedRowIndex; rowIndex <= lastvisibleRowIndex; rowIndex++)
            {
                var row = this.Rows[rowIndex];

                var assetname = row.Cells[this.Columns["Name"].Index].Value.ToString();
                VisibleAssets.Add(assetname);
            }

            var query   = from ae in listae join visAsset in VisibleAssets on ae.Name equals visAsset select ae;
            var listae2 = query.ToList();

            _client.RefreshTokenIfNeeded();

            foreach (AssetEntryV3 AE in listae2)
            {
                System.Threading.Thread.Sleep(1000);
                try
                {
                    asset = _client.AMSclient.Assets.Get(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName, AE.Name);

                    /*
                     * var firstPage = await MediaServicesArmClient.Assets.ListAsync(TestSettings.CustomerResourceGroup, TestSettings.CustomerAccountName);
                     *
                     * var currentPage = firstPage;
                     * while (currentPage.NextPageLink != null)
                     * {
                     *  currentPage = await MediaServicesArmClient.Assets.ListNextAsync(currentPage.NextPageLink);
                     * }
                     */

                    if (asset != null)
                    {
                        //AssetInfo myAssetInfo = new AssetInfo(asset);
                        AE.AlternateId  = asset.AlternateId;
                        AE.Description  = asset.Description;
                        AE.Created      = asset.Created.ToLocalTime().ToString("G");
                        AE.LastModified = asset.LastModified.ToLocalTime().ToString("G");
                        AE.Name         = asset.Name;
                        // AE.StorageAccountName = asset.StorageAccountName;

                        var assetBitmapAndText = DataGridViewAssets.BuildBitmapPublication(asset.Name, _client);
                        AE.Publication          = assetBitmapAndText.bitmap;
                        AE.PublicationMouseOver = assetBitmapAndText.MouseOverDesc;

                        // var assetfiles =  asset.AssetFiles.ToList();
                        var data = AssetInfo.GetAssetType(asset.Name, _client);
                        AE.Type         = data.Type;
                        AE.SizeLong     = data.Size;
                        AE.Size         = AssetInfo.FormatByteSize(AE.SizeLong);
                        AE.AssetWarning = (AE.SizeLong == 0);// || assetfiles.Any(f => f.ContentFileSize == 0));

                        assetBitmapAndText   = BuildBitmapDynEncryption(asset.Name, _client);
                        AE.DynamicEncryption = assetBitmapAndText.bitmap;
                        //AE.DynamicEncryptionMouseOver = assetBitmapAndText.MouseOverDesc;

                        if (assetBitmapAndText.Locators != null)
                        {
                            DateTime?LocDate = assetBitmapAndText.Locators.Any() ? (DateTime?)assetBitmapAndText.Locators.Min(l => l.EndTime).ToLocalTime() : null;
                            AE.LocatorExpirationDate        = LocDate.HasValue ? ((DateTime)LocDate).ToLocalTime().ToString() : null;
                            AE.LocatorExpirationDateWarning = LocDate.HasValue ? (LocDate < DateTime.Now.ToLocalTime()) : false;
                        }

                        //assetBitmapAndText = BuildBitmapAssetFilters(asset.Name, _client);
                        int?afcount = ReturnNumberAssetFilters(asset.Name, _client);
                        AE.Filters = afcount > 0 ? afcount : null;
                        //AE.FiltersMouseOver = assetBitmapAndText.MouseOverDesc;

                        cacheAssetentriesV3[asset.Name] = AE; // let's put it in cache (or update the cache)
                    }
                }
                catch // in some case, we have a timeout on Assets.Where...
                {
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
            }
            this.BeginInvoke(new Action(() => this.Refresh()), null);
        }
示例#2
0
        public async Task RefreshLiveOutputsAsync(int pagetodisplay) // all assets are refreshed
        {
            if (!_initialized)
            {
                return;
            }
            if (idsList.Count == 0)
            {
                return;
            }

            Debug.WriteLine("RefreshPrograms : start");

            this.BeginInvoke(new Action(() => this.FindForm().Cursor = Cursors.WaitCursor));

            await _client.RefreshTokenIfNeededAsync();

            IEnumerable <LiveEvent> ListEvents;

            if (_anyChannel == enumDisplayProgram.None)
            {
                ListEvents = new List <LiveEvent>();
            }
            else
            {
                ListEvents = (await _client.AMSclient.LiveEvents.ListAsync(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName))
                             .ToList()
                             .Where(l => _anyChannel == enumDisplayProgram.Any || (_anyChannel == enumDisplayProgram.Selected && LiveEventSourceNames.Contains(l.Name)));
            }


            List <Program.LiveOutputExt> LOList = new List <Program.LiveOutputExt>();

            foreach (var le in ListEvents)
            {
                var plist = (await _client.AMSclient.LiveOutputs.ListAsync(_client.credentialsEntry.ResourceGroup, _client.credentialsEntry.AccountName, le.Name))
                            .ToList();
                plist.ForEach(p => LOList.Add(new Program.LiveOutputExt()
                {
                    LiveOutputItem = p, LiveEventName = le.Name
                }));
            }

            var programquery = from c in (LOList)
                               //orderby c.LastModified descending
                               select new LiveOutputEntry
            {
                Name                = c.LiveOutputItem.Name,
                State               = c.LiveOutputItem.ResourceState,
                Description         = c.LiveOutputItem.Description,
                ArchiveWindowLength = c.LiveOutputItem.ArchiveWindowLength,
                LastModified        = c.LiveOutputItem.LastModified != null ? (DateTime?)((DateTime)c.LiveOutputItem.LastModified).ToLocalTime() : null,
                Published           = DataGridViewAssets.BuildBitmapPublication(c.LiveOutputItem.AssetName, _client).bitmap,
                LiveEventName       = c.LiveEventName
            };



            _MyObservLiveOutputs = new SortableBindingList <LiveOutputEntry>(programquery.ToList());
            this.BeginInvoke(new Action(() => this.DataSource = _MyObservLiveOutputs));
            _refreshedatleastonetime = true;

            this.BeginInvoke(new Action(() => this.FindForm().Cursor = Cursors.Default));

            Debug.WriteLine("RefreshPrograms : end");
        }