/// <summary>
 /// Form groups of elements using a key selector.Transform each element.Combine the elements into a result.
 /// </summary>
 /// <typeparam name="TSource">The type of elements in the sequence</typeparam>
 /// <typeparam name="TKey">The type used as the key for grouping</typeparam>
 /// <typeparam name="TElement">The type into which each element of the sequence is transformed</typeparam>
 /// <typeparam name="TResult">The type of the final result</typeparam>
 /// <param name="source">The sequence of elements</param>
 /// <param name="keySelector">The function to extract keys from the elements</param>
 /// <param name="elementSelector">The transformation to apply to individual elements</param>
 /// <param name="resultSelector">The function to reduce the transformed elements into a final result</param>
 /// <param name="comparer">The means by which elements are compared</param>
 /// <returns>The set of result</returns>
 public static IAsyncEnumerable <TResult> GroupBy <TSource, TKey, TElement, TResult>(
     this IAsyncEnumerable <TSource> source,
     Func <TSource, TKey> keySelector
     , Func <TSource, TElement> elementSelector
     , Func <TKey, IAsyncEnumerable <TElement>, TResult> resultSelector
     , IEqualityComparer <TKey> comparer
     )
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (keySelector == null)
     {
         throw new ArgumentNullException(nameof(keySelector));
     }
     if (elementSelector == null)
     {
         throw new ArgumentNullException(nameof(elementSelector));
     }
     if (resultSelector == null)
     {
         throw new ArgumentNullException(nameof(resultSelector));
     }
     return(GroupByInternal(source, QuickFunctions.WrapValueTask(keySelector), QuickFunctions.WrapValueTask(elementSelector), QuickFunctions.WrapValueTask(resultSelector), comparer));
 }
        /// <summary>
        /// Joins two sequences based on a key and groups the results
        /// </summary>
        /// <typeparam name="TOuter">The type of elements in the outer sequence</typeparam>
        /// <typeparam name="TInner">The type of elements in the inner sequence</typeparam>
        /// <typeparam name="TKey">The type of key used for matching elements</typeparam>
        /// <typeparam name="TResult">The type of elements in the returned sequence</typeparam>
        /// <param name="outer">The outer sequence</param>
        /// <param name="inner">The inner sequence</param>
        /// <param name="outerKeySelector">The function to extract a key from an outer element</param>
        /// <param name="innerKeySelector">The function to extract a key from an inner element</param>
        /// <param name="resultSelector">The function to combine an outer item and a group of inner items</param>
        /// <returns>A new sequence of result element</returns>
        public static IAsyncEnumerable <TResult> GroupJoin <TOuter, TInner, TKey, TResult>(
            this IAsyncEnumerable <TOuter> outer,
            IAsyncEnumerable <TInner> inner,
            Func <TOuter, TKey> outerKeySelector,
            Func <TInner, TKey> innerKeySelector,
            Func <TOuter, IAsyncEnumerable <TInner>, TResult> resultSelector)
        {
            if (outer == null)
            {
                throw new ArgumentNullException(nameof(outer));
            }
            if (inner == null)
            {
                throw new ArgumentNullException(nameof(inner));
            }
            if (outerKeySelector == null)
            {
                throw new ArgumentNullException(nameof(outerKeySelector));
            }
            if (innerKeySelector == null)
            {
                throw new ArgumentNullException(nameof(innerKeySelector));
            }
            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return(GroupJoinInternal(outer, inner, QuickFunctions.WrapValueTask(outerKeySelector), QuickFunctions.WrapValueTask(innerKeySelector), QuickFunctions.WrapValueTask(resultSelector), null));
        }
示例#3
0
 public static IEnumerable <object[]> EmptyCalls()
 {
     foreach (var call in Aggregate.Seed.Tests.EmptyCalls())
     {
         call[1] = QuickFunctions.WrapTask((Func <int, int, int>)call[1]);
         yield return(call);
     }
 }
 public static IEnumerable <object[]> FactorialCalls()
 {
     foreach (var call in Aggregate.Tests.FactorialCalls())
     {
         call[1] = QuickFunctions.WrapValueTask((Func <int, int, int>)call[1]);
         yield return(call);
     }
 }
示例#5
0
        void IQraBaseNotify.Notify_LoadComplete()
        {
            var cpType = new ContentPanel().GetType();
            var cp     = (ContentPanel)QuickFunctions.GetFirstParentOfSpecifiedType(this, cpType);

            cp.SetNarrative(Narratives.CPO_Overpressure);

            pbOverpSpinner.Hide();
            InitializeInputGrid();
            InitializeInputOptionsTab();
        }
 /// <summary>
 /// Determines whether all elements in a sequence satisfy a <paramref name="predicate"/>
 /// </summary>
 /// <typeparam name="TSource">The type of elements in the sequence</typeparam>
 /// <param name="source">The sequence of elements</param>
 /// <param name="predicate">The predicate that all elements should satisfy</param>
 /// <returns>true if all elements of the sequence satisfy the predicate</returns>
 /// <remarks>Note that it is vacuously true that an empty sequence satisfies the condition</remarks>
 public static Task <bool> All <TSource>(
     this IAsyncEnumerable <TSource> source,
     Func <TSource, bool> predicate)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (predicate == null)
     {
         throw new ArgumentNullException(nameof(predicate));
     }
     return(AllInternal(source, QuickFunctions.WrapValueTask(predicate)));
 }
 /// <summary>
 /// Form groups of elements using a key selector.
 /// </summary>
 /// <typeparam name="TSource">The type of elements in the sequence</typeparam>
 /// <typeparam name="TKey">The type used as the key for grouping</typeparam>
 /// <param name="source">The sequence of elements</param>
 /// <param name="keySelector">The function to extract keys from the elements</param>
 /// <returns>The set of result</returns>
 /// <remarks>The default equality comparer for <typeparamref name="TKey"/> will be used</remarks>
 public static IAsyncEnumerable <IAsyncGrouping <TKey, TSource> > GroupBy <TSource, TKey>(
     this IAsyncEnumerable <TSource> source,
     Func <TSource, TKey> keySelector
     )
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (keySelector == null)
     {
         throw new ArgumentNullException(nameof(keySelector));
     }
     return(GroupByInternal(source, QuickFunctions.WrapValueTask(keySelector), QuickFunctions <TSource> .IdentityWrapped, null));
 }
示例#8
0
        /// <summary>
        /// Handle selection of panels to display, including updating buttons.
        /// </summary>
        /// <param name="mainForm"></param>
        /// <param name="sender"></param>
        /// <param name="containerPanel"></param>
        /// <param name="panelToActivate">New panel</param>
        /// <param name="panelNarrativeText">Text pulled from RTF to display as header</param>
        /// <param name="clickOption"></param>
        public static void ActivateActionPanel(FrmQreMain mainForm, Button sender, Panel containerPanel,
                                               UserControl panelToActivate, string panelNarrativeText,
                                               ApButtonClickOption clickOption = ApButtonClickOption.PerformClick)
        {
            mainForm.SuspendLayout();
            try
            {
                var panelThatOwnsCaller = (Panel)sender.Parent;
                containerPanel.Controls.Clear();
                if (panelThatOwnsCaller != null)
                {
                    UiStateRoutines.UnselectButtons(panelThatOwnsCaller);
                }

                UiStateRoutines.UnselectButtons(containerPanel);
                sender.ForeColor = Color.Green;

                // Clear unneeded controls
                foreach (Control thisControl in containerPanel.Controls)
                {
                    if (thisControl is Button)
                    {
                        containerPanel.Controls.Remove(thisControl);
                    }
                }

                panelToActivate.Dock = DockStyle.Fill;
                containerPanel.Controls.Add(panelToActivate);
                ActiveScreen.lblActionNarrative.Text = panelNarrativeText;
                if (clickOption == ApButtonClickOption.PerformClick)
                {
                    var firstButton = QuickFunctions.GetTopButton(panelToActivate, ChildNavOptions.NavigateChildren);
                    if (firstButton != null)
                    {
                        firstButton.PerformClick();
                    }
                    else
                    {
                        MessageBox.Show(@"Cannot perform click for the " + panelToActivate.GetType().Name +
                                        @" action panel because it contains no buttons.");
                    }
                }
            }
            finally
            {
                mainForm.ResumeLayout();
            }
        }
示例#9
0
 /// <summary>
 /// Computes an aggregate from a sequence
 /// </summary>
 /// <typeparam name="TSource">The type of elements in the source sequence</typeparam>
 /// <typeparam name="TAccumulate">The type of aggregate to compute</typeparam>
 /// <param name="source">The original sequence</param>
 /// <param name="seed">An initial value for the aggregate</param>
 /// <param name="func">A function to compute a new value of the aggregate from its existing value and a new element from the source sequence</param>
 /// <returns></returns>
 public static Task <TAccumulate> Aggregate <TSource, TAccumulate> (
     this IAsyncEnumerable <TSource> source,
     TAccumulate seed,
     Func <TAccumulate, TSource, TAccumulate> func
     )
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (func == null)
     {
         throw new ArgumentNullException(nameof(func));
     }
     return(AggregateInternal(source, new ValueTask <TAccumulate>(seed), QuickFunctions.WrapValueTask(func), QuickFunctions <TAccumulate> .IdentityWrapped));
 }
示例#10
0
        void IQraBaseNotify.Notify_LoadComplete()
        {
            pbSpinner.Hide();
            var cpType = new ContentPanel().GetType();
            var cp     = (ContentPanel)QuickFunctions.GetFirstParentOfSpecifiedType(this, cpType);

            cp.SetNarrative(Narratives.GPD_GasPlumeDispersion);

            // Set up data-bind grids
            var vdColl = new ParameterWrapperCollection(new[]
            {
                new ParameterWrapper("PlumeWrapper.XMin", "X lower limit", DistanceUnit.Meter,
                                     StockConverters.DistanceConverter),
                new ParameterWrapper("PlumeWrapper.XMax", "X upper limit", DistanceUnit.Meter,
                                     StockConverters.DistanceConverter),
                new ParameterWrapper("PlumeWrapper.YMin", "Y lower limit", DistanceUnit.Meter,
                                     StockConverters.DistanceConverter),
                new ParameterWrapper("PlumeWrapper.YMax", "Y upper limit", DistanceUnit.Meter,
                                     StockConverters.DistanceConverter),
                new ParameterWrapper("PlumeWrapper.Contours", "Contours (mole fraction)", UnitlessUnit.Unitless,
                                     StockConverters.UnitlessConverter),

                new ParameterWrapper("SysParam.ExternalPresMPA", "Ambient pressure", PressureUnit.Pa,
                                     StockConverters.PressureConverter),
                new ParameterWrapper("SysParam.ExternalTempC", "Ambient temperature", TempUnit.Kelvin,
                                     StockConverters.TemperatureConverter),
                new ParameterWrapper("FlameWrapper.d_orifice", "Orifice diameter", DistanceUnit.Meter,
                                     StockConverters.DistanceConverter),
                new ParameterWrapper("OpWrapper.Cd0", "Orifice discharge coefficient", UnitlessUnit.Unitless,
                                     StockConverters.UnitlessConverter),
                new ParameterWrapper("FlameWrapper.P_H2", "Hydrogen pressure", PressureUnit.Pa,
                                     StockConverters.PressureConverter),
                new ParameterWrapper("FlameWrapper.T_H2", "Hydrogen temperature", TempUnit.Kelvin,
                                     StockConverters.TemperatureConverter),
                new ParameterWrapper("PlumeWrapper.jet_angle", "Angle of jet", AngleUnit.Radians,
                                     StockConverters.AngleConverter)
            });

            StaticGridHelperRoutines.InitInteractiveGrid(PlumeParams, vdColl, false);

            PlumeParams.Columns[0].Width = 200;
            PlumeParams.Columns[1].Width = 200;
            PlumeParams.Columns[2].Width = 200;

            //tbPlotTitle_TextChanged(tbPlotTitle,new System.EventArgs());
        }
示例#11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string plotSavePath   = Properties.Settings.Default.plotSavePath;
                var    outputFilename = QuickFunctions.SelectSaveAsFilename("Save image", ref plotSavePath,
                                                                            "tiff", "Tiff Files(*.tiff)|*.tiff");

                if (outputFilename.Length > 0)
                {
                    pbPicture.Image.Save(outputFilename);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Action could not be performed due to error: " + ex.Message);
            }
        }
示例#12
0
        /// <summary>
        /// Switch between main analysis modes (QRA and phys)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tcNav_SelectedIndexChanged(object sender, EventArgs e)
        {
            var   activeTab   = tcNav.SelectedTab;
            Panel activePanel = null;
            var   topLevelTab = true;

            if (activeTab == tpNfpa2Mode)
            {
                activePanel = pnlNfpaNav;
            }
            else if (activeTab == tpQraMode)
            {
                activePanel = pnlQraNav;
            }

            else if (activeTab == tpPhysics)
            {
                activePanel = pnlPhysicsNav;
            }
            else
            {
                topLevelTab = false;
            }

            if (!topLevelTab)
            {
                return;
            }

            pnlActionButtons.Controls.Clear();  // Clear nav panel
            var defaultButton = QuickFunctions.GetTopButton(activePanel, ChildNavOptions.NavigateChildren);

            defaultButton.PerformClick();

            if (activeTab == tpNfpa2Mode)
            {
                var actionsNarrative = "";
                ActivateActionPanel(this, btnFire, pnlActionButtons, new ApBlank(), actionsNarrative,
                                    ApButtonClickOption.NoClick);
                var blankPanel = new CpBlank();
                ActionUtils.SetContentScreen(btnFire, blankPanel);
                ContentPanels.ContentPanel.SetNarrative(blankPanel, Narratives.PBDMode);
            }
        }
示例#13
0
        private void frmQFEMain_Load(object sender, EventArgs e)
        {
            // Delete old temp files from prev runs
            QuickFunctions.ClearOldTemporaryFiles();

            ActiveScreen = this;

            tcNav.TabPages.Remove(tpNfpa2Mode);
            tcNav.TabPages.Remove(tpTests);
            tcNav.SelectedIndex = 0;
            tcNav.SelectedTab   = null;
            tcNav.SelectedTab   = tpQraMode;

            // Populate fuel selection dropdowns.
            // One dropdown on phys UI, one on QRA. Both sync to same backend param.
            fuelTypePhys.DataSource   = QraStateContainer.Instance.FuelTypes;
            fuelTypePhys.SelectedItem = QraStateContainer.GetValue <FuelType>("FuelType");
            fuelTypeQra.DataSource    = QraStateContainer.Instance.FuelTypes;
            fuelTypeQra.SelectedItem  = QraStateContainer.GetValue <FuelType>("FuelType");
        }
示例#14
0
        public static void InitInteractiveGrid(DataGridView grid, ParameterWrapperCollection valueDefinitionObjects,
                                               bool canSort = true)
        {
            var initGridCalled = false;

            foreach (var thisVdo in valueDefinitionObjects.Values)
            {
                if (!initGridCalled)
                {
                    InitGrid(grid, new[] { "colVariable", "colValue", "colUnit" },
                             new[] { "Variable", "Value", "Unit" }, canSort);
                    initGridCalled = true;
                }

                AddLinkedValueRowToDataGrid(grid, null, thisVdo);
            }

            QuickFunctions.PreventGridColumnSorting(grid);
            grid.HandleCreated += RespondToEventAndResizeColumns;
        }
示例#15
0
 /// <summary>
 /// Computes an aggregate from a sequence
 /// </summary>
 /// <typeparam name="TSource">The type of elements in the source sequence</typeparam>
 /// <typeparam name="TAccumulate">The type of aggregate to compute</typeparam>
 /// <typeparam name="TResult">The type of the final result</typeparam>
 /// <param name="source">The original sequence</param>
 /// <param name="seed">An initial value for the aggregate</param>
 /// <param name="func">A function to compute a new value of the aggregate from its existing value and a new element from the source sequence</param>
 /// <param name="resultSelector">A transformation for the final result</param>
 /// <returns></returns>
 public static Task <TResult> Aggregate <TSource, TAccumulate, TResult> (
     this IAsyncEnumerable <TSource> source,
     TAccumulate seed,
     Func <TAccumulate, TSource, TAccumulate> func,
     Func <TAccumulate, ValueTask <TResult> > resultSelector
     )
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (func == null)
     {
         throw new ArgumentNullException(nameof(func));
     }
     if (resultSelector == null)
     {
         throw new ArgumentNullException(nameof(resultSelector));
     }
     return(AggregateInternal(source, new ValueTask <TAccumulate>(seed), QuickFunctions.WrapValueTask(func), resultSelector));
 }
示例#16
0
 private void dgRanking_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
 {
     QuickFunctions.PerformNumericSortOnGrid(sender, e);
 }
示例#17
0
        public object GetTotal(int column, string group)
        {
            object ColType = this.ColumnHeaders[column].TotalFunction;

            if (ColType == null)
            {
                return(null);
            }
            else if (ColType is QuickFunctions)
            {
                QuickFunctions TotType = (QuickFunctions)ColType;
                switch (TotType)
                {
                // Funciones varias
                case QuickFunctions.TotalName:
                    if (group == null)
                    {
                        return("TOTAL");
                    }
                    else
                    {
                        return("Subtotal " + group);
                    }

                // Funciones que cuentan
                case QuickFunctions.Count:
                    if (group == null)
                    {
                        return(this.Rows.Count);
                    }
                    else
                    {
                        decimal ResCount = 0;
                        foreach (Row Rw in this.Rows)
                        {
                            if (group == Rw.GetFormattedGroup())
                            {
                                ResCount++;
                            }
                        }
                        return(ResCount);
                    }

                // Funciones que suman
                default:
                    decimal ResSum = 0;
                    foreach (Row Rw in this.Rows)
                    {
                        if (group == null || group == Rw.GetFormattedGroup())
                        {
                            decimal CellValue = System.Convert.ToDecimal(Rw.Cells[column].Content);
                            switch (TotType)
                            {
                            case QuickFunctions.Sum:
                                ResSum += CellValue;
                                break;

                            case QuickFunctions.SumNegatives:
                                if (CellValue < 0)
                                {
                                    ResSum += CellValue;
                                }
                                break;

                            case QuickFunctions.SumPositives:
                                if (CellValue > 0)
                                {
                                    ResSum += CellValue;
                                }
                                break;
                            }
                        }
                    }
                    return(ResSum);
                }
            }
            else
            {
                return(ColType.ToString());
            }
        }
示例#18
0
 private void dgHorzLinesSpecifier_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
 {
     QuickFunctions.PerformNumericSortOnGrid(sender, e);
 }
示例#19
0
 private void dgTimePressureOptions_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
 {
     QuickFunctions.PerformNumericSortOnGrid(sender, e);
 }
示例#20
0
        public static IEnumerable <object[]> EmptyCalls()
        {
            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .Identity, null, null });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityTasked, null, null });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityWrapped, null, null });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .Identity, QuickFunctions <long> .Identity, null });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityTasked, QuickFunctions <long> .IdentityTasked, null });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityWrapped, QuickFunctions <long> .IdentityWrapped, null });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .Identity, null, (Func <long, IAsyncEnumerable <long>, long>)LongResultSelector });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityTasked, null, QuickFunctions.WrapTask <long, IAsyncEnumerable <long>, long>(LongResultSelector) });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityWrapped, null, QuickFunctions.WrapValueTask <long, IAsyncEnumerable <long>, long>(LongResultSelector) });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .Identity, QuickFunctions <long> .Identity, (Func <long, IAsyncEnumerable <long>, long>)LongResultSelector });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityTasked, QuickFunctions <long> .IdentityTasked, QuickFunctions.WrapTask <long, IAsyncEnumerable <long>, long>(LongResultSelector) });

            yield return(new object[] { AsyncEnumerable.Empty <long>(), QuickFunctions <long> .IdentityWrapped, QuickFunctions <long> .IdentityWrapped, QuickFunctions.WrapValueTask <long, IAsyncEnumerable <long>, long>(LongResultSelector) });
        }