/// <summary>
        /// Nice helper function that tallies up compounds for a set of streams
        /// </summary>
        /// <param name="streams"></param>
        /// <returns></returns>
        protected virtual Dictionary <string, StreamComponent> TallyCompounds(IEnumerable <AbstractStream> streams)
        {
            Dictionary <string, StreamComponent> compounds = new Dictionary <string, StreamComponent>(5);

            //tally up flow rates for each compound
            foreach (AbstractStream stream in streams)
            {
                // TODO: Get the commented-out part working again
                throw new NotImplementedException();
                ITableAdapter tableAdapter = null;// TableAdapterFactory.CreateTableAdapter(stream.Table);

                //start at index value = 1 as we're assuming that 1 is the header row, which we don't
                //check in this particular rule (see CheckOverallFlowRate())
                for (int i = 1; i < tableAdapter.GetRowCount(); i++)
                {
                    string compound = tableAdapter.GetCompoundAtRow(i);
                    string quantity = tableAdapter.GetQuantityAtRow(i);
                    string units    = tableAdapter.GetUnitAtRow(i);

                    if (compound != null)
                    {
                        if (!compounds.ContainsKey(compound))
                        {
                            compounds[compound]      = new StreamComponent();
                            compounds[compound].Name = compound;
                        }
                        compounds[compound].AddValue(quantity, units);
                    }
                }
            }
            return(compounds);
        }
        /// <summary>
        /// Returns the overall flow rate for a set of streams
        /// </summary>
        /// <param name="streams">This is a list of streams whos Overall will be add together</param>
        /// <returns>Returns a StreamComponent which contains the results</returns>
        private StreamComponent TallyOverallFlowRate(IEnumerable <AbstractStream> streams)
        {
            StreamComponent component = new StreamComponent();

            //tally up flow rates coming into this compound
            foreach (AbstractStream stream in streams)
            {
                // TODO: Get the commented-out part working again
                throw new NotImplementedException();
                ITableAdapter tableAdapter = null;// TableAdapterFactory.CreateTableAdapter(stream.Table);
                if (tableAdapter.GetTableType() == TableType.Chemcial)
                {
                    component.AddValue(tableAdapter.GetQuantityAtRow(0));
                }
            }
            return(component);
        }
        protected ValidationResult sumOfPartsEqualsTotalQuantity(ITableAdapter tableAdapter)
        {
            float overalQuantity;

            if (tableAdapter.GetRowCount() == 1)
            {
                //Only one row so it must be true;
                return(ValidationResult.Empty);
            }

            //? is wildcard for percent here cheating a little
            if (tableAdapter.GetUnitAtRow(0) == "?")
            {
                //using percents so the sum must at up to 100 (100%)
                overalQuantity = 100;
            }
            else
            {
                try
                {
                    overalQuantity = float.Parse(tableAdapter.GetQuantityAtRow(0));
                }
                catch
                {
                    //Not a number and the only thing the table accepts that isn't a number is ?
                    //since we do not know the total we cannot see if the sum equals the total so assume true
                    return(ValidationResult.Empty);
                }
                //So didn't return so overalQuantity must be equal to the overal Quantity
            }

            //at this point overalQuantity could equal 100 or the overal Quantity but we dont care the sume of the parts must
            //equal whatever number it is.

            bool  gotQuestionMark  = false;
            float sumPartsQuantity = 0;
            int   i = 1;

            //the adapter gets rid of the extra row
            while (i < tableAdapter.GetRowCount())
            {
                try
                {
                    sumPartsQuantity += float.Parse(tableAdapter.GetQuantityAtRow(i));
                }
                catch
                {
                    //the only thing that would make the parse fail is a questionMark
                    gotQuestionMark = true;
                }
                i++;
            }

            //Fails if either the sum is gerater than the overal or if sum does not equal overal and questionMark was not found
            if ((sumPartsQuantity > overalQuantity) || (gotQuestionMark == false && sumPartsQuantity != overalQuantity))
            {
                return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Sum_Does_Not_Equal_Total_Quantity)));
            }

            return(ValidationResult.Empty);
        }
示例#4
0
        /// <summary>
        /// This is called when we want to check the tables validity.  Then it calls buildFeedbackMessage so that,
        /// a a new EveryoneDict can be made with the new data.
        /// </summary>
        /// <param name="tables">This is a list of PropertiesWindow to be checked typically all of them</param>
        private void CheckChemicalStreamPropertiesWindowFeedback(IEnumerable <IPfdElement> tables)
        {
            IRule rule = new TableRule();

            List <string>            nonUniqueNames = new List <string>();
            List <IPropertiesWindow> listOfTables   = new List <IPropertiesWindow>();

            foreach (IPropertiesWindow table in tables)
            {
                rule.Target = table;
                rule.CheckRule();

                // TODO: fix (eventually)
                throw new NotImplementedException("Rule manager is broken");
                ITableAdapter tableAdapter = null;
                //ITableAdapter tableAdapter = TableAdapterFactory.CreateTableAdapter(table);
                int       i     = 0;
                int       items = tableAdapter.GetRowCount();
                TableType tableType;
                string    label, units, quantity, compound, temp;

                while (i < items)
                {
                    tableType = tableAdapter.GetTableType();
                    label     = tableAdapter.GetLabelAtRow(i);
                    units     = tableAdapter.GetUnitAtRow(i);
                    quantity  = tableAdapter.GetQuantityAtRow(i);
                    compound  = tableAdapter.GetCompoundAtRow(i);

                    if (currentDifficultySetting == OptionDifficultySetting.MaterialAndEnergyBalance)
                    {
                        temp = tableAdapter.GetTemperature();
                    }
                    else
                    {
                        //we dont need temp to just zero it out
                        temp = "0";
                    }

                    if (!tableDict.Keys.Contains(label))
                    {
                        tableDict.Add(label, new GenericTableData(table, tableType, label, units, quantity, compound, temp));
                    }
                    else
                    {
                        if (!nonUniqueNames.Contains(label))
                        {
                            nonUniqueNames.Add(label);
                        }
                        listOfTables.Add(table);
                    }
                    i++;
                }

                foreach (ValidationResult vr in rule.ValidationResults)
                {
                    if (!EveryoneDict.ContainsKey(vr.Target))
                    {
                        EveryoneDict.Add(vr.Target, new List <string>());
                    }
                    EveryoneDict[vr.Target].Add("[" + ruleNumber + "]\n-" + vr.Message + "\n");
                    ruleNumber++;
                }
            }
            if (nonUniqueNames.Count > 0)
            {
                ValidationResult vr = (new ValidationResult(listOfTables, ErrorMessageGenerator.GenerateMesssage(Validation.ErrorMessages.NonUniqueNames, nonUniqueNames.ToArray())));
                if (!EveryoneDict.ContainsKey(vr.Target))
                {
                    EveryoneDict.Add(vr.Target, new List <string>());
                }
                EveryoneDict[vr.Target].Add("[" + ruleNumber + "]\n-" + vr.Message + "\n");
                ruleNumber++;
            }
        }