Exemple #1
0
        private static bool IsDTToSelf(DataRow dr)
        {
            int?StratumIdSource    = null;
            int StateClassIdSource = 0;
            int?StratumIdDest      = null;
            int?StateClassIdDest   = null;

            DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest);

            if (!StateClassIdDest.HasValue)
            {
                return(true);
            }

            if (StateClassIdSource == StateClassIdDest.Value)
            {
                if (!StratumIdDest.HasValue)
                {
                    return(true);
                }
                else
                {
                    return(NullableUtilities.NullableIdsEqual(StratumIdSource, StratumIdDest));
                }
            }

            return(false);
        }
        private void VALIDATE_DETERMINISTIC_TRANSITIONS()
        {
            DataTable  dtdata   = this.GetData();
            DTAnalyzer Analyzer = new DTAnalyzer(dtdata, this.Project);

            foreach (DataRow dr in dtdata.Rows)
            {
                if (dr.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                int?StratumIdSource    = null;
                int StateClassIdSource = 0;
                int?StratumIdDest      = null;
                int?StateClassIdDest   = null;

                DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest);

                if (StateClassIdDest.HasValue)
                {
                    Debug.Assert(Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value));
                }
            }
        }
        /// <summary>
        /// Overrides Validate
        /// </summary>
        /// <param name="data"></param>
        /// <param name="transferMethod"></param>
        /// <returns></returns>
        /// <remarks>
        /// While the incoming state class Ids can themselves be valid, they must also be valid within the context of the union of the
        /// incoming data and the existing data.  In other words, each destination state class must point to a source state class within
        /// the same stratum.
        /// </remarks>
        public override void Validate(System.Data.DataTable proposedData, DataTransferMethod transferMethod)
        {
            base.Validate(proposedData, transferMethod);

            DataTable  dtdata           = this.GetData();
            DTAnalyzer AnalyzerExisting = new DTAnalyzer(dtdata, this.Project);
            DTAnalyzer AnalyzerProposed = new DTAnalyzer(proposedData, this.Project);

            foreach (DataRow ProposedRow in proposedData.Rows)
            {
                int?StratumIdSource    = null;
                int StateClassIdSource = 0;
                int?StratumIdDest      = null;
                int?StateClassIdDest   = null;

                DTAnalyzer.GetDTFieldValues(ProposedRow, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest);

                if (!StateClassIdDest.HasValue)
                {
                    return;
                }

                //If the state class is not part of the incoming data then we need to see if it is part of the existing data, and
                //if it isn't then we can't continue.  Note that if the import option is 'Overwrite' then the state class
                //will not appear in the existing data!

                bool ClassInClip     = AnalyzerProposed.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value);
                bool ClassInExisting = AnalyzerExisting.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value);
                bool IsOverwrite     = (transferMethod == SyncroSim.Core.DataTransferMethod.Overwrite);

                if (!ClassInClip)
                {
                    if (IsOverwrite || (!ClassInExisting))
                    {
                        AnalyzerExisting.ThrowDataException(StateClassIdDest.Value, true);
                    }
                }

                //Also validate the location

                if (!DTAnalyzer.IsValidLocation(ProposedRow[Strings.DATASHEET_DT_LOCATION_COLUMN_NAME]))
                {
                    throw new DataException(MessageStrings.ERROR_INVALID_CELL_ADDRESS);
                }
            }
        }
        private bool ResolveProbabilisticTransitions(DTAnalyzer analyzer)
        {
            bool      HasChanges = false;
            DataTable dt         = this.GetDataSheet(Strings.DATASHEET_PT_NAME).GetData();

            for (int Index = dt.Rows.Count - 1; Index >= 0; Index--)
            {
                DataRow dr = dt.Rows[Index];

                if (dr.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                int?StratumIdSource    = null;
                int StateClassIdSource = 0;
                int?StratumIdDest      = null;
                int?StateClassIdDest   = null;

                DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest);

                if (!analyzer.StateClassExists(StratumIdSource, StateClassIdSource))
                {
                    DataTableUtilities.DeleteTableRow(dt, dr);
                    HasChanges = true;

                    continue;
                }

                if (!StateClassIdDest.HasValue)
                {
                    continue;
                }

                if (!analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value))
                {
                    DataTableUtilities.DeleteTableRow(dt, dr);
                    HasChanges = true;
                }
            }

            return(HasChanges);
        }
        private bool ResolveDeterministicTransitions(DTAnalyzer analyzer)
        {
            bool      HasChanges = false;
            DataTable dt         = this.GetData();

            for (int Index = dt.Rows.Count - 1; Index >= 0; Index--)
            {
                DataRow dr = dt.Rows[Index];

                if (dr.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                int?StratumIdSource    = null;
                int StateClassIdSource = 0;
                int?StratumIdDest      = null;
                int?StateClassIdDest   = null;

                DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest);

                if (!StateClassIdDest.HasValue)
                {
                    continue;
                }

                if (!analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value))
                {
                    dr[Strings.DATASHEET_DT_STRATUMIDDEST_COLUMN_NAME]    = DBNull.Value;
                    dr[Strings.DATASHEET_DT_STATECLASSIDDEST_COLUMN_NAME] = DBNull.Value;

                    HasChanges = true;
                }
            }

            return(HasChanges);
        }
        public override void Validate(DataRow proposedRow, DataTransferMethod transferMethod)
        {
            base.Validate(proposedRow, transferMethod);

            int?StratumIdSource    = null;
            int StateClassIdSource = 0;
            int?StratumIdDest      = null;
            int?StateClassIdDest   = null;

            DTAnalyzer.GetDTFieldValues(proposedRow, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest);

            if (!StateClassIdDest.HasValue)
            {
                return;
            }

            if (StateClassIdDest.Value == StateClassIdSource)
            {
                if (!StratumIdDest.HasValue)
                {
                    return;
                }

                if (NullableUtilities.NullableIdsEqual(StratumIdSource, StratumIdDest))
                {
                    return;
                }
            }

            DTAnalyzer Analyzer = new DTAnalyzer(this.GetData(), this.Project);

            if (!Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value))
            {
                Analyzer.ThrowDataException(StateClassIdDest.Value, true);
            }
        }