Example #1
0
        /// <summary>Called by the control's OnDoubleClick()</summary>
        /// <param name="e">A DiagramPointEventArgs that contains event data.</param>
        public override void OnDoubleClick(DiagramPointEventArgs e)
        {
            base.OnDoubleClick(e);

            if (OpenCodeFile != null)
            {
                ModelClass modelClass = (ModelClass)ModelElement;

                if (OpenCodeFile(modelClass))
                {
                    return;
                }

                if (ExecCodeGeneration != null && QuestionDisplay.Show($"Can't open generated file for {modelClass.Name}. It may not have been generated yet. Do you want to generate the code now?") == true)
                {
                    ExecCodeGeneration();

                    if (OpenCodeFile(modelClass))
                    {
                        return;
                    }
                }

                ErrorDisplay.Show($"Can't open generated file for {modelClass.Name}");
            }
        }
        /// <inheritdoc />
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            base.ElementDeleting(e);

            Generalization element = (Generalization)e.ModelElement;
            Store          store   = element.Store;
            Transaction    current = store.TransactionManager.CurrentTransaction;

            if (current.IsSerializing)
            {
                return;
            }

            if (element.Superclass.IsDeleting)
            {
                return;
            }

            ModelClass         superclass   = element.Superclass;
            ModelClass         subclass     = element.Subclass;
            List <Association> associations = store.ElementDirectory.AllElements.OfType <Association>().Where(a => a.Source == superclass || a.Target == superclass).ToList();

            if (!superclass.AllAttributes.Any() && !associations.Any())
            {
                return;
            }

            if (!subclass.IsDeleting && QuestionDisplay.Show($"Push {superclass.Name} attributes and associations down to {subclass.Name}?") == true)
            {
                superclass.PushDown(subclass);
            }
        }
Example #3
0
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            base.ElementDeleting(e);

            ModelClass  element = (ModelClass)e.ModelElement;
            Store       store   = element.Store;
            Transaction current = store.TransactionManager.CurrentTransaction;

            if (current.IsSerializing)
            {
                return;
            }

            List <Generalization> generalizations = store.ElementDirectory.AllElements.OfType <Generalization>().Where(g => g.Superclass == element).ToList();

            if (generalizations.Any())
            {
                string question = generalizations.Count == 1
                                 ? $"Push {element.Name} attributes and associations down its to its subclass?"
                                 : $"Push {element.Name} attributes and associations down its to {generalizations.Count} subclasses?";

                if (QuestionDisplay.Show(question) == true)
                {
                    foreach (ModelClass subclass in generalizations.Select(g => g.Subclass))
                    {
                        element.PushDown(subclass);
                    }
                }
            }
        }
Example #4
0
    private IEnumerator displayQuestionWithDelay(int pQuestionIndex)
    {
        yield return(new WaitUntil(() => FindObjectOfType <QuestionDisplay>() != null));

        QuestionDisplay qd = FindObjectOfType <QuestionDisplay>();

        if (qd != null)
        {
            qd.DisplayQuestion(pQuestionIndex);
        }
    }
    //internal static void GetTriviaQuestion(Tile currentTile)
    //{
    //    var color = currentTile.color;
    //    Category category = (Category)Enum.Parse(typeof(Category), color, true);

    //    Question newQuestion = _qdb.GetQuestion(Category.RED).Prompt;
    //}

    public void GetAndDisplayNewTriviaQuestion(string color)
    {
        Debug.Log($"RuleController asks QuestionDB to display trivia question and answer choices.");
        var questionDisplay = new QuestionDisplay();

        _currentQuestion = questionDisplay.GetNewQuestion(color, _qdb);

        //activate the group first or the DisplayQuestion method wont be able to find the GameObjects
        SetAndActivateTimer();
        ActivateQuestionAnswerGroup(true);

        questionDisplay.DisplayQuestion(_currentQuestion);
    }
Example #6
0
    void Start()
    {
        vocaList      = FindObjectOfType <QuestionParser>();
        randomIntList = new Queue <int>();

        for (int i = 0; i < CAPACITY; i++)
        {
            randomIntList.Enqueue(Random.Range(0, vocaList.voca.Count));
        }
        display = FindObjectOfType <QuestionDisplay>();

        StartCoroutine(AssignQuestions());
    }
Example #7
0
        private void RoundList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            QuestionList.Items.Clear();
            QuestionDisplay l;

            foreach (BeeQuestion question in Bee.Rounds.RoundByIndex(RoundList.SelectedIndex).Questions)
            {
                l = new QuestionDisplay()
                {
                    DataContext = question
                };
                QuestionList.Items.Add(l);
            }
        }
Example #8
0
        private ModelClass ProcessClass([NotNull] ClassDeclarationSyntax classDecl, NamespaceDeclarationSyntax namespaceDecl = null)
        {
            ModelClass result = null;

            if (classDecl == null)
            {
                throw new ArgumentNullException(nameof(classDecl));
            }

            ModelRoot modelRoot = Store.ModelRoot();
            string    className = classDecl.Identifier.Text;

            if (namespaceDecl == null && classDecl.Parent is NamespaceDeclarationSyntax classDeclParent)
            {
                namespaceDecl = classDeclParent;
            }

            if (Store.Get <ModelEnum>().Any(c => c.Name == className))
            {
                ErrorDisplay.Show($"'{className}' already exists in model as an Enum.");

                // ReSharper disable once ExpressionIsAlwaysNull
                return(result);
            }

            if (classDecl.TypeParameterList != null)
            {
                ErrorDisplay.Show($"Can't add generic class '{className}'.");

                // ReSharper disable once ExpressionIsAlwaysNull
                return(result);
            }

            Transaction tx = Store.TransactionManager.CurrentTransaction == null
                             ? Store.TransactionManager.BeginTransaction()
                             : null;

            List <string> customInterfaces = new List <string>();

            try
            {
                ModelClass superClass = null;
                result = Store.Get <ModelClass>().FirstOrDefault(c => c.Name == className);

                // Base classes and interfaces
                // Check these first. If we need to add new models, we want the base class already in the store
                if (classDecl.BaseList != null)
                {
                    foreach (BaseTypeSyntax type in classDecl.BaseList.Types)
                    {
                        string baseName = type.ToString();

                        // Do we know this is an interface?
                        if (KnownInterfaces.Contains(baseName) || superClass != null || result?.Superclass != null)
                        {
                            customInterfaces.Add(baseName);
                            if (!KnownInterfaces.Contains(baseName))
                            {
                                KnownInterfaces.Add(baseName);
                            }

                            continue;
                        }

                        // is it inheritance or an interface?
                        superClass = modelRoot.Classes.FirstOrDefault(c => c.Name == baseName);

                        // if it's not in the model, we just don't know. Ask the user
                        if (superClass == null && (KnownClasses.Contains(baseName) || QuestionDisplay.Show($"For class {className}, is {baseName} the base class?") == true))
                        {
                            superClass = new ModelClass(Store, new PropertyAssignment(ModelClass.NameDomainPropertyId, baseName));
                            modelRoot.Classes.Add(superClass);
                        }
                        else
                        {
                            customInterfaces.Add(baseName);
                            KnownInterfaces.Add(baseName);
                        }
                    }
                }

                if (result == null)
                {
                    result = new ModelClass(Store, new PropertyAssignment(ModelClass.NameDomainPropertyId, className))
                    {
                        Namespace  = namespaceDecl?.Name?.ToString() ?? modelRoot.Namespace,
                        IsAbstract = classDecl.DescendantNodes().Any(n => n.Kind() == SyntaxKind.AbstractKeyword)
                    };

                    modelRoot.Classes.Add(result);
                }

                if (superClass != null)
                {
                    result.Superclass = superClass;
                }

                if (result.CustomInterfaces != null)
                {
                    customInterfaces.AddRange(result.CustomInterfaces
                                              .Split(',')
                                              .Where(i => !String.IsNullOrEmpty(i))
                                              .Select(i => i.Trim()));
                }

                if (customInterfaces.Contains("INotifyPropertyChanged"))
                {
                    result.ImplementNotify = true;
                    customInterfaces.Remove("INotifyPropertyChanged");
                }

                if (result.Superclass != null && customInterfaces.Contains(result.Superclass.Name))
                {
                    customInterfaces.Remove(result.Superclass.Name);
                }

                result.CustomInterfaces = customInterfaces.Any()
                                         ? String.Join(",", customInterfaces.Distinct())
                                         : null;


                XMLDocumentation xmlDocumentation = new XMLDocumentation(classDecl);
                result.Summary     = xmlDocumentation.Summary;
                result.Description = xmlDocumentation.Description;
            }
            catch
            {
                tx = null;

                throw;
            }
            finally
            {
                tx?.Commit();
            }

            return(result);
        }
Example #9
0
        private ModelClass ProcessClass([NotNull] ClassDeclarationSyntax classDecl, NamespaceDeclarationSyntax namespaceDecl = null)
        {
            ModelClass result;

            if (classDecl == null)
            {
                throw new ArgumentNullException(nameof(classDecl));
            }

            ModelRoot modelRoot = Store.ModelRoot();
            string    className = classDecl.Identifier.Text.Split(':').LastOrDefault();

            if (!ValidateInput())
            {
                return(null);
            }

            Transaction tx = Store.TransactionManager.CurrentTransaction == null
                             ? Store.TransactionManager.BeginTransaction()
                             : null;

            List <string> customInterfaces = new List <string>();

            try
            {
                result = Store.Get <ModelClass>().FirstOrDefault(c => c.Name == className);

                if (result == null)
                {
                    result = new ModelClass(Store
                                            , new PropertyAssignment(ModelClass.NameDomainPropertyId, className)
                                            , new PropertyAssignment(ModelClass.NamespaceDomainPropertyId, namespaceDecl?.Name?.ToString() ?? modelRoot.Namespace)
                                            , new PropertyAssignment(ModelClass.IsAbstractDomainPropertyId, classDecl.DescendantNodes().Any(n => n.Kind() == SyntaxKind.AbstractKeyword)));

                    modelRoot.Classes.Add(result);
                }

                ModelClass superClass = FindSuperClass();

                if (superClass != null)
                {
                    result.Superclass = superClass;
                }

                if (result.CustomInterfaces != null)
                {
                    customInterfaces.AddRange(result.CustomInterfaces
                                              .Split(',')
                                              .Where(i => !string.IsNullOrEmpty(i))
                                              .Select(i => i.Trim()));
                }

                if (customInterfaces.Contains("INotifyPropertyChanged"))
                {
                    result.ImplementNotify = true;
                    customInterfaces.Remove("INotifyPropertyChanged");
                }

                if (result.Superclass != null && customInterfaces.Contains(result.Superclass.Name))
                {
                    customInterfaces.Remove(result.Superclass.Name);
                }

                result.CustomInterfaces = customInterfaces.Any()
                                         ? string.Join(",", customInterfaces.Distinct())
                                         : null;

                AttributeSyntax tableAttribute = classDecl.GetAttribute("Table");

                if (tableAttribute != null)
                {
                    result.TableName = tableAttribute.GetAttributeArguments().First().Expression.ToString().Trim('"');

                    string schemaName = tableAttribute.GetNamedArgumentValue("Schema");
                    if (schemaName != null)
                    {
                        result.DatabaseSchema = schemaName;
                    }
                }

                XMLDocumentation xmlDocumentation = new XMLDocumentation(classDecl);
                result.Summary     = xmlDocumentation.Summary;
                result.Description = xmlDocumentation.Description;
                tx?.Commit();
            }
            catch
            {
                tx?.Rollback();
                throw;
            }

            return(result);

            ModelClass FindSuperClass()
            {
                ModelClass superClass = null;

                // Base classes and interfaces
                // Check these first. If we need to add new models, we want the base class already in the store
                IEnumerable <BaseTypeSyntax> baseTypes = (classDecl.BaseList?.Types ?? Enumerable.Empty <BaseTypeSyntax>());

                foreach (string baseName in baseTypes.Select(type => type.ToString().Split(':').Last()))
                {
                    // Do we know this is an interface?
                    if (KnownInterfaces.Contains(baseName) || superClass != null || result.Superclass != null)
                    {
                        customInterfaces.Add(baseName);

                        if (!KnownInterfaces.Contains(baseName))
                        {
                            KnownInterfaces.Add(baseName);
                        }

                        continue;
                    }

                    // is it inheritance or an interface?
                    superClass = modelRoot.Classes.FirstOrDefault(c => c.Name == baseName);

                    // if it's not in the model, we just don't know. Ask the user
                    if (superClass == null && (KnownClasses.Contains(baseName) || QuestionDisplay.Show($"For class {className}, is {baseName} the base class?") == true))
                    {
                        string[] nameparts = baseName.Split('.');

                        superClass = nameparts.Length == 1
                                  ? new ModelClass(Store, new PropertyAssignment(ModelClass.NameDomainPropertyId, nameparts.Last()))
                                  : new ModelClass(Store
                                                   , new PropertyAssignment(ModelClass.NameDomainPropertyId, nameparts.Last())
                                                   , new PropertyAssignment(ModelClass.NamespaceDomainPropertyId, string.Join(".", nameparts.Take(nameparts.Length - 1))));

                        modelRoot.Classes.Add(superClass);
                    }
                    else
                    {
                        customInterfaces.Add(baseName);
                        KnownInterfaces.Add(baseName);
                    }
                }

                return(superClass);
            }

            bool ValidateInput()
            {
                if (className == null)
                {
                    ErrorDisplay.Show("Can't find class name");

                    return(false);
                }

                if (namespaceDecl == null && classDecl.Parent is NamespaceDeclarationSyntax classDeclParent)
                {
                    namespaceDecl = classDeclParent;
                }

                if (Store.Get <ModelEnum>().Any(c => c.Name == className))
                {
                    ErrorDisplay.Show($"'{className}' already exists in model as an Enum.");

                    return(false);
                }

                if (classDecl.TypeParameterList != null)
                {
                    ErrorDisplay.Show($"Can't add generic class '{className}'.");

                    return(false);
                }

                return(true);
            }
        }
Example #10
0
        private static void ProcessClass([NotNull] Store store, [NotNull] ClassDeclarationSyntax classDecl, NamespaceDeclarationSyntax namespaceDecl = null)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }

            if (classDecl == null)
            {
                throw new ArgumentNullException(nameof(classDecl));
            }

            ModelRoot modelRoot = store.ElementDirectory.AllElements.OfType <ModelRoot>().FirstOrDefault();
            string    className = classDecl.Identifier.Text;

            if (namespaceDecl == null && classDecl.Parent is NamespaceDeclarationSyntax classDeclParent)
            {
                namespaceDecl = classDeclParent;
            }

            if (store.ElementDirectory.AllElements.OfType <ModelEnum>().Any(c => c.Name == className))
            {
                ErrorDisplay.Show($"'{className}' already exists in model as an Enum.");

                return;
            }

            if (classDecl.TypeParameterList != null)
            {
                ErrorDisplay.Show($"Can't add generic class '{className}'.");

                return;
            }

            Transaction tx = store.TransactionManager.CurrentTransaction == null
                             ? store.TransactionManager.BeginTransaction()
                             : null;

            try
            {
                ModelClass    superClass       = null;
                List <string> customInterfaces = new List <string>();
                ModelClass    modelClass       = store.ElementDirectory.AllElements.OfType <ModelClass>().FirstOrDefault(c => c.Name == className);

                // Base classes and interfaces
                // Check these first. If we need to add new models, we want the base class already in the store
                if (classDecl.BaseList != null)
                {
                    foreach (BaseTypeSyntax type in classDecl.BaseList.Types)
                    {
                        string baseName = type.ToString();

                        // INotifyPropertyChanged is special. We know it's an interface, and it'll turn into a class property later
                        if (baseName == "INotifyPropertyChanged" || superClass != null || modelClass?.Superclass != null)
                        {
                            customInterfaces.Add(baseName);

                            continue;
                        }

                        // is it inheritance or an interface?
                        superClass = modelRoot.Types.OfType <ModelClass>().FirstOrDefault(c => c.Name == baseName);

                        // if it's not in the model, we just don't know. Ask the user
                        if (superClass == null && QuestionDisplay.Show($"For class {className}, is {baseName} the base class?") == true)
                        {
                            superClass = new ModelClass(store, new PropertyAssignment(ModelClass.NameDomainPropertyId, baseName));
                            modelRoot.Types.Add(superClass);
                        }
                        else
                        {
                            customInterfaces.Add(baseName);
                        }
                    }
                }

                if (modelClass == null)
                {
                    modelClass = new ModelClass(store, new PropertyAssignment(ModelClass.NameDomainPropertyId, className))
                    {
                        Namespace    = namespaceDecl?.Name?.ToString() ?? modelRoot.Namespace
                        , IsAbstract = classDecl.DescendantNodes().Any(n => n.Kind() == SyntaxKind.AbstractKeyword)
                    };

                    modelRoot.Types.Add(modelClass);
                }

                if (superClass != null)
                {
                    modelClass.Superclass = superClass;
                }

                if (modelClass.CustomInterfaces != null)
                {
                    customInterfaces.AddRange(modelClass.CustomInterfaces
                                              .Split(',')
                                              .Where(i => !string.IsNullOrEmpty(i))
                                              .Select(i => i.Trim()));
                }

                if (customInterfaces.Contains("INotifyPropertyChanged"))
                {
                    modelClass.ImplementNotify = true;
                    customInterfaces.Remove("INotifyPropertyChanged");
                }

                if (modelClass.Superclass != null && customInterfaces.Contains(modelClass.Superclass.Name))
                {
                    customInterfaces.Remove(modelClass.Superclass.Name);
                }

                modelClass.CustomInterfaces = customInterfaces.Any()
                                             ? string.Join(",", customInterfaces.Distinct())
                                             : null;


                XMLDocumentation xmlDocumentation = new XMLDocumentation(classDecl);
                modelClass.Summary     = xmlDocumentation.Summary;
                modelClass.Description = xmlDocumentation.Description;
            }
            catch
            {
                tx = null;

                throw;
            }
            finally
            {
                tx?.Commit();
            }
        }