Beispiel #1
0
        private RowAggregateData GetGroupAggregateData(string appName, AppResourceGroupInfo group, ulong totalProcessPrivateCommit)
        {
            Debug.WriteLine("GetGroupAggregateData: app: {0}, group: {1}", appName, group.InstanceId);
            ulong              commitLimit    = 0;
            ulong              totalCommit    = 0;
            ulong              privateCommit  = 0;
            ExecutionStateEx   executionState = ExecutionStateEx.Unknown;
            EnergyQuotaStateEx energyState    = EnergyQuotaStateEx.Unknown;
            int bgTaskCount = 0;

            try
            {
                AppResourceGroupMemoryReport mReport = group.GetMemoryReport();
                if (mReport != null)
                {
                    commitLimit   = mReport.CommitUsageLimit;
                    totalCommit   = mReport.TotalCommitUsage;
                    privateCommit = mReport.PrivateCommitUsage;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetMemoryReport: " + ex.ToString());
            }

            // The resource group Private Commit should always be the same (or almost the same) as the PDI Private Commit.
            Debug.WriteLine("Private Commit: ResourceGroup={0:N0} bytes ~= Total PDI={1:N0} bytes", privateCommit, totalProcessPrivateCommit);

            try
            {
                AppResourceGroupStateReport sReport = group.GetStateReport();
                if (sReport != null)
                {
                    executionState = (ExecutionStateEx)sReport.ExecutionState;
                    energyState    = (EnergyQuotaStateEx)sReport.EnergyQuotaState;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetStateReport: " + ex.ToString());
            }

            try
            {
                IList <AppResourceGroupBackgroundTaskReport> bgReports = group.GetBackgroundTaskReports();
                if (bgReports != null)
                {
                    bgTaskCount = bgReports.Count;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetBackgroundTaskReports: " + ex.ToString());
            }

            RowAggregateData groupData = new RowAggregateData(
                commitLimit, totalCommit, privateCommit, bgTaskCount, executionState, energyState);

            return(groupData);
        }
Beispiel #2
0
        public async Task Start()
        {
            if (this.IsStarted())
            {
                return;
            }


            desiredExecutionState = ExecutionStateEx.Started; // REVIEW - have a single input/output

            if (!CanStart)
            {
                return;            // TODO: Error?
            }
            StartOnMarketAvailable = true;

            // TODO:
            //DesiredExecutionState = ExecutionStateEx.Started;

            if (Account != null && Account.Started.Value)
            {
                //await Task.Run(async () => await _Start());
                await _Start().ConfigureAwait(false);
            }
            else
            {
                ExecutionStateFlags |= ExecutionStateFlags.WaitingToStart;
            }
        }
 public RowAggregateData(
     ulong limit, ulong total, ulong priv, int bg, ExecutionStateEx exState, EnergyQuotaStateEx enState)
 {
     CommitLimit    = limit;
     TotalCommit    = total;
     PrivateCommit  = priv;
     BgTaskCount    = bg;
     ExecutionState = exState;
     EnergyState    = enState;
 }
 public void Update(
     ulong limit, ulong total, ulong commit,
     ExecutionStateEx exState, EnergyQuotaStateEx enState, int bgCount)
 {
     CommitLimit         = limit;
     TotalCommit         = total;
     PrivateCommit       = commit;
     ExecutionState      = exState;
     EnergyQuotaState    = enState;
     BackgroundTaskCount = bgCount;
 }
Beispiel #5
0
        private bool AddOrUpdateApp(
            AppDiagnosticInfo app, RowAggregateData appData, ExecutionStateEx appExecutionState)
        {
            bool   result = false;
            string name   = "(unknown)";
            string appId  = string.Empty;

            if (app.AppInfo != null && app.AppInfo.DisplayInfo != null)
            {
                appId = app.AppInfo.AppUserModelId;
                name  = app.AppInfo.DisplayInfo.DisplayName;
            }

            // Check to see if this app is already in our list, and only add it if it wasn't already there.
            bool isAppFound = false;

            foreach (AppRowInfo existingRow in this)
            {
                if (appId == existingRow.Id)
                {
                    isAppFound = true;
                    break;
                }
            }

            // Don't add apps for resource groups that are not running.
            // Otherwise, for one thing, trying to get the logo would throw.
            if (!isAppFound && appExecutionState != ExecutionStateEx.NotRunning)
            {
                BitmapImage logo = GetLogoFromAppInfo(app);

                // A new app has appeared, so we add it to the list.
                AppRowInfo appRow = new AppRowInfo(
                    app,
                    appId, logo, name,
                    appData.CommitLimit, appData.TotalCommit, appData.PrivateCommit,
                    appData.ExecutionState, appData.EnergyState, appData.BgTaskCount);
                Add(appRow);
                result = true;
            }
            else
            {
                // For existing rows, we'll update the dynamic state.
                IEnumerable <AppRowInfo> appRows = this.Where(r => r.Id == appId);
                if (appRows != null && appRows.Count() > 0)
                {
                    AppRowInfo existingApp = appRows.First();
                    existingApp.Update(
                        appData.CommitLimit, appData.TotalCommit, appData.PrivateCommit,
                        appData.ExecutionState, appData.EnergyState, appData.BgTaskCount);
                }
            }
            return(result);
        }
Beispiel #6
0
        protected void SetState(ExecutionStateEx state)
        {
            var oldState = this.State;

            this.State = state;
            new MExecutionStateChanged()
            {
                Source = this, OldState = oldState, NewState = state
            }.Publish();
            OnPropertyChanged(nameof(this.State));
        }
Beispiel #7
0
 public async Task Stop()
 {
     if (this.IsStarted())
     {
         State = ExecutionStateEx.Stopping;
         if (IsTradeApiEnabled)
         {
             await Task.Run(() => Stop_TradeApi()).ConfigureAwait(false);
         }
         State = ExecutionStateEx.Stopped;
     }
 }
Beispiel #8
0
 public async Task StopAsync(CancellationToken cancellationToken = default)
 {
     if (this.IsStarted())
     {
         State = ExecutionStateEx.Stopping;
         if (IsTradeApiEnabled)
         {
             await Task.Run(() => Stop_TradeApi()).ConfigureAwait(false);
         }
         State = ExecutionStateEx.Stopped;
     }
 }
Beispiel #9
0
        public async Task Start()
        {
            State = ExecutionStateEx.Starting;
            foreach (var workspace in App.GetComponents <TradingWorkspace>())
            {
                await StartWorkspace(workspace);
            }

            RunTask = runTask();

            if (!RunTask.IsCompleted)
            {
                State = ExecutionStateEx.Started;
            }
        }
Beispiel #10
0
        public async Task StartAsync(CancellationToken cancellationToken = default)
        {
            State = ExecutionStateEx.Starting;
#if TOPORT
            foreach (var workspace in App.GetComponents <TradingWorkspace>())
            {
                await StartWorkspace(workspace);
            }
#endif

            RunTask = runTask();

            if (!RunTask.IsCompleted)
            {
                State = ExecutionStateEx.Started;
            }
        }
        public AppRowInfo(
            AppDiagnosticInfo a,
            string id,
            BitmapImage logo, string name,
            ulong limit, ulong totCommit, ulong prvCommit,
            ExecutionStateEx exState, EnergyQuotaStateEx eqState, int taskCount)
        {
            Adi  = a;
            Id   = id;
            Logo = logo;
            Name = name;

            commitLimit         = limit;
            totalCommit         = totCommit;
            privateCommit       = prvCommit;
            executionState      = exState;
            energyQuotaState    = eqState;
            backgroundTaskCount = taskCount;
        }
Beispiel #12
0
        public async Task Start()
        {
            if (this.IsStarted())
            {
                return;
            }

            lock (connectLock)
            {
                if (this.IsStarted())
                {
                    return;
                }

                State = ExecutionStateEx.Starting;
            }
            await OnStarting().ConfigureAwait(false);

            RunTask = Run();
            //RunTask = Task.Factory.StartNew(Run);
        }
Beispiel #13
0
        public bool Update()
        {
            bool result = false;

            // If we don't lock the collection, there's a race where databinding could end up with
            // additional spurious instances, especially if the polling interval is only 1-2 sec.
            lock (lockObject)
            {
                // Get a list of running apps (filtered by permission level).
                IAsyncOperation <IList <AppDiagnosticInfo> > infoOperation = AppDiagnosticInfo.RequestInfoAsync();
                Task <IList <AppDiagnosticInfo> >            infoTask      = infoOperation.AsTask();
                infoTask.Wait();
                IList <AppDiagnosticInfo> runningApps = infoTask.Result;

                // We don't recreate the list each time: instead, we remove dead rows and update existing ones,
                // only adding new rows for new apps that appear. This is slow, but typically we'd only have a small
                // number of UWP apps running (say 5-20), so it's not noticeable.
                if (runningApps != null)
                {
                    // First, remove from the list any apps that are no longer in memory.
                    RemoveDeadRows(runningApps);

                    // Find key data from the bottom-up (process and group level) for roll-up purposes.
                    foreach (AppDiagnosticInfo app in runningApps)
                    {
                        ulong              appCommitLimit    = 0;
                        ulong              appTotalCommit    = 0;
                        ulong              appPrivateCommit  = 0;
                        ExecutionStateEx   appExecutionState = ExecutionStateEx.Unknown;
                        EnergyQuotaStateEx appEnergyState    = EnergyQuotaStateEx.Unknown;
                        int appBgTaskCount = 0;

                        // Get the roll-up data from group and process level.
                        IList <AppResourceGroupInfo> groups = app.GetResourceGroups();
                        if (groups != null)
                        {
                            foreach (AppResourceGroupInfo group in groups)
                            {
                                Debug.WriteLine("app: {0}, group Id: {1}", app.AppInfo.DisplayInfo.DisplayName, group.InstanceId);

                                // Get the total private commit usage of all processes for this app.
                                ulong totalProcessPrivateCommit         = 0;
                                IList <ProcessDiagnosticInfo> processes = group.GetProcessDiagnosticInfos();
                                if (processes != null)
                                {
                                    foreach (ProcessDiagnosticInfo process in processes)
                                    {
                                        totalProcessPrivateCommit += GetProcessPrivateCommit(process);
                                    }
                                }

                                // Accumulate the aggregated totals for all resource groups for this app.
                                // We pass down the private commit for all processes for this group for comparison only.
                                RowAggregateData groupData = GetGroupAggregateData(
                                    app.AppInfo.DisplayInfo.DisplayName, group, totalProcessPrivateCommit);

                                appCommitLimit   += groupData.CommitLimit;
                                appTotalCommit   += groupData.TotalCommit;
                                appPrivateCommit += groupData.PrivateCommit;
                                appBgTaskCount   += groupData.BgTaskCount;

                                if (appExecutionState != groupData.ExecutionState)
                                {
                                    if (appExecutionState == ExecutionStateEx.Unknown)
                                    {
                                        appExecutionState = groupData.ExecutionState;
                                    }
                                    else
                                    {
                                        appExecutionState = ExecutionStateEx.Multiple;
                                    }
                                }
                                if (appEnergyState != groupData.EnergyState)
                                {
                                    if (appEnergyState == EnergyQuotaStateEx.Unknown)
                                    {
                                        appEnergyState = groupData.EnergyState;
                                    }
                                    else
                                    {
                                        appEnergyState = EnergyQuotaStateEx.Multiple;
                                    }
                                }
                            }
                        }

                        RowAggregateData appData = new RowAggregateData(
                            appCommitLimit, appTotalCommit, appPrivateCommit, appBgTaskCount, appExecutionState, appEnergyState);

                        // Now add or update the rows.
                        bool isAppAdded = AddOrUpdateApp(app, appData, appExecutionState);
                        if (isAppAdded)
                        {
                            // If any row update resulted in adding an app, we set the return value to true.
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }