Ejemplo n.º 1
0
 private string GetVocabDisplayString(string definitionId)
 {
     if (vdefs.ContainsKey(definitionId))
     {
         VocabularyDefinition vd = vdefs[definitionId] as VocabularyDefinition;
         return(vd.GetFormatString().Format);
     }
     else
     {
         return("");
     }
 }
Ejemplo n.º 2
0
        private string WriteTerm(Term term)
        {
            string             displayString = "";
            ArgumentCollection args          = null;

            if (term is Constant)
            {
                if (((Constant)term).Value != null)
                {
                    if (((Constant)term).Value.ToString() == string.Empty)
                    {
                        displayString = "<empty string>";
                    }
                    else
                    {
                        displayString = ((Constant)term).Value.ToString();
                    }
                }
                else
                {
                    displayString = "<null>";
                }
            }

            else if (term is UserFunction || term is ObjectReference)
            {
                Binding termBinding = null;

                if (term is UserFunction)
                {
                    termBinding = ((UserFunction)term).Binding;
                }
                else
                {
                    termBinding = ((ObjectReference)term).Binding;
                }

                if (termBinding is XMLDocumentBinding)
                {
                    XMLDocumentBinding binding = termBinding as XMLDocumentBinding;
                    displayString = binding.DocumentType;
                }
                else if (termBinding is DatabaseBinding)
                {
                    DatabaseBinding binding = termBinding as DatabaseBinding;
                    displayString = binding.DatasetName;
                }
                else if (termBinding is ClassBinding)
                {
                    ClassBinding binding = termBinding as ClassBinding;
                    displayString = binding.TypeName;
                }
                else if (termBinding is XMLDocumentFieldBinding)
                {
                    XMLDocumentFieldBinding binding = termBinding as XMLDocumentFieldBinding;
                    displayString = binding.DocumentBinding.DocumentType + ":" + binding.DocumentBinding.Selector.Alias + "/" + binding.Field.Alias;

                    if (binding.Argument != null)
                    {
                        if (binding.MemberName.ToLower() == "setstring")
                        {
                            displayString += " = {0}";
                        }

                        args = new ArgumentCollection();
                        args.Add(binding.Argument);
                    }
                }
                else if (termBinding is DatabaseColumnBinding)
                {
                    DatabaseColumnBinding binding = termBinding as DatabaseColumnBinding;
                    displayString = binding.DatabaseBinding.DatasetName + "." + binding.DatabaseBinding.TableName + "." + binding.ColumnName;

                    if (binding.Argument != null)
                    {
                        args = new ArgumentCollection();
                        args.Add(binding.Argument);
                    }
                }
                else if (termBinding is DataRowBinding)
                {
                    DataRowBinding binding = termBinding as DataRowBinding;
                    displayString = binding.DisplayName;
                }
                else if (termBinding is ClassMemberBinding)
                {
                    ClassMemberBinding binding = termBinding as ClassMemberBinding;
                    displayString = binding.ClassBinding.ImplementingType.FullName + "." + binding.MemberName;
                    args          = binding.Arguments;
                }
            }
            else if (term is ArithmeticFunction)
            {
                ArithmeticFunction f = term as ArithmeticFunction;
                args = new ArgumentCollection();
                args.Add(f.LeftArgument);
                args.Add(f.RightArgument);
            }
            else if (term is Assert)
            {
                args = new ArgumentCollection();
                args.Add(((Assert)term).Facts);
            }
            else if (term is Retract)
            {
                args = new ArgumentCollection();
                args.Add(((Retract)term).Facts);
            }
            else if (term is Update)
            {
                args = new ArgumentCollection();
                args.Add(((Update)term).Facts);
            }
            else if (term is Halt)
            {
                args = new ArgumentCollection();
                args.Add(((Halt)term).ClearAgenda);
            }

            ArrayList argsToDisplay = new ArrayList();

            if (args != null)
            {
                foreach (Term t in args)
                {
                    argsToDisplay.Add(WriteTerm(t));
                }
            }

            string format = "";

            if (term.VocabularyLink != null)
            {
                VocabularyDefinition vd = vdefs[term.VocabularyLink.DefinitionId] as VocabularyDefinition;
                format = vd.GetFormatString().Format;

                // Added to fix halt documentation CD 20140328
                if (format == "halt choices")
                {
                    format = "{0}";
                    if (displayString == "True")
                    {
                        argsToDisplay.Add("clear all rules firings");
                    }
                    else
                    {
                        argsToDisplay.Add("do not clear");
                    }
                }
            }
            else
            {
                format = displayString;
            }

            displayString = TryStringFormat(format, argsToDisplay.ToArray());

            return("<span class='TableData'>" + displayString + "</span>");
        }