/// <summary>
        /// Constructor
        /// </summary>
        internal AssignmentVariation(MModelPropertyDefinitor VariatingProperty, IMModelClass VariatingInstance, object VariatingValue)
        {
            this.VariatingProperty = VariatingProperty;
            this.VariatingInstance = VariatingInstance;
            this.VariatingValue    = VariatingValue;

            /*T if (VariatingProperty.TechName == UniqueElement.__GlobalId.TechName)
             *  Console.WriteLine("GlobalId"); */
        }
Example #2
0
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Registers the inverse assignment (READY TO BE UNDONE) of a supplied controlled property and its owning instance, to be undone/redone in the future.
        /// This must happen  as part of a grouping combined variation (a command being performed).
        /// Also, it will not be performed if already an undo/redo operation is running.
        /// </summary>
        internal static void RegisterInverseAssignment(MModelPropertyDefinitor SourcePropertyDef, IModelEntity Instance, object Value)
        {
            // If no engine controlling or not within command variation declaration then abandon.
            if (Instance.EditEngine == null || Instance.EditEngine.ExecutionStatus != EExecutionStatus.Running)
            {
                return;
            }

            if (!Instance.EditEngine.IsVariating)
            {
                //T Console.WriteLine("No variating at property change.");
                return;
            }

            // IMPORTANT: EDIT-ENGINES MUST MATCH FOR CHANGING VALUES.
            if (Instance.EditEngine != ActiveEntityEditor)
            {
                throw new UsageAnomaly("Active Entity-Editor differs (for assignment) from that of the changing Entity '" + Instance.ToStringAlways() + "'.");
            }

            // Stores the variation into the command being declared.
            Instance.EditEngine.StoreVariation(new AssignmentVariation(SourcePropertyDef, Instance, Value), SourcePropertyDef.ChangesExistenceStatus);
        }
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        public static void FindTextInTargetProperty(string SearchedText, IMModelClass Target, MModelPropertyDefinitor PropertyAccessor,
                                                    List <FoundObjectHint> OngoingResults, string TraveledPath,
                                                    bool IsCaseSensitive, bool IsInspectingWholeWord,
                                                    FlowDocument CurrentDocument = null, Run CurrentTextRun = null)
        {
            string Text = null;

            if (CurrentTextRun != null)
            {
                Text = CurrentTextRun.Text;
            }
            else
            {
                if (PropertyAccessor != null)
                {
                    Text = PropertyAccessor.Read(Target) as string;
                }
                else
                if (DocumentEngine.SearchProviderOfTextExtractorWithoutPropertyAccessor != null)
                {
                    Text = DocumentEngine.SearchProviderOfTextExtractorWithoutPropertyAccessor(Target);
                }

                if (Text.IsAbsent())
                {
                    return;
                }

                if (PropertyAccessor != null && PropertyAccessor.HasRichContent)
                {
                    var DocRuns = FoundObjectHint.GetTemporalDocumentRunsFor(Target, (PropertyAccessor == null
                                                                                      ? DocumentEngine.SearchProviderOfTextNameWithoutPropertyAccessor : PropertyAccessor.Name));
                    if (DocRuns == null)
                    {
                        DocRuns = FoundObjectHint.RegisterTemporalDocument(Target, PropertyAccessor.Name, Text);
                    }

                    if (DocRuns != null)
                    {
                        foreach (var DocRun in DocRuns.Item2)
                        {
                            FindTextInTargetProperty(SearchedText, Target, PropertyAccessor, OngoingResults, TraveledPath,
                                                     IsCaseSensitive, IsInspectingWholeWord, DocRuns.Item1, DocRun);
                        }
                    }

                    return;
                }
            }

            var Position     = -1;
            var CaseComparer = (IsCaseSensitive
                                ? StringComparison.Ordinal  // Must use 'ordinal' to avoid considering hyphens as part of words (culture dependant).
                                : StringComparison.OrdinalIgnoreCase);

            Position = Text.IndexOf(SearchedText, CaseComparer);

            var ToBeDisplacedOnReplace = false;    // Used when searched-text found more than once in the same property

            /*T if (Text.StartsWith("THE "))
             *  Console.WriteLine("THE "); */

            while (Position >= 0)
            {
                if (!(IsInspectingWholeWord &&
                      ((Position > 0 && (Char.IsLetterOrDigit(Text[Position - 1]) || Text[Position - 1] == '_')) ||
                       ((Position + SearchedText.Length) < Text.Length &&
                        (Char.IsLetterOrDigit(Text[Position + SearchedText.Length]) || Text[Position + SearchedText.Length] == '_')))))
                {
                    var ExcerptStart  = (Position - TEXTFOUND_EXCERPT_ADJACENTS_LEN).EnforceMinimum(0);
                    var ExcerptLength = ((Position - ExcerptStart) + SearchedText.Length + TEXTFOUND_EXCERPT_ADJACENTS_LEN).EnforceMaximum(Text.Length - ExcerptStart);
                    var Excerpt       = Text.Substring(ExcerptStart, ExcerptLength).RemoveNewLines();

                    var Result = new FoundObjectHint
                    {
                        SourceObject             = Target,
                        SourceObjectType         = (DocumentEngine.SearchProviderOfObjectTypeDetector == null ? "[Other]" : DocumentEngine.SearchProviderOfObjectTypeDetector(Target)),
                        SourceAccessor           = PropertyAccessor,
                        LocationPath             = TraveledPath.AbsentDefault("[Root]"),
                        TextExcerpt              = Excerpt,
                        TextPosition             = Position,
                        MustBeDisplacedOnReplace = ToBeDisplacedOnReplace,
                        RichDocumentRunSource    = (CurrentDocument == null || CurrentTextRun == null
                                                 ? null : Tuple.Create(CurrentDocument, CurrentTextRun))
                    };

                    OngoingResults.Add(Result);

                    ToBeDisplacedOnReplace = true;
                }

                Position = Position + SearchedText.Length;
                if (Position >= Text.Length)
                {
                    return;
                }

                Position = Text.IndexOf(SearchedText, Position, CaseComparer);
            }
        }