コード例 #1
0
        private static void AddEmptyTreeItems()
        {
            #region Add the build items to the project - this generates UI for them
            // We need a project to be loaded so that we can investigate it for
            // what is a Screen/Entity in case there is no generated code already
            // present.
            // Update - I don't think this matters anymore, we should base it off of the
            // glux below

            Section.GetAndStartContextAndTime("Screens");
            foreach (ScreenSave screen in ProjectManager.GlueProjectSave.Screens)
            {
                ElementViewWindow.AddScreen(screen);;
            }
            Section.EndContextAndTime();
            Section.GetAndStartContextAndTime("Entities");
            foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            {
                ElementViewWindow.AddEntity(entity, generateCode: false);
            }
            ElementViewWindow.ResumeLayout();
            Section.EndContextAndTime();
            #endregion
        }
コード例 #2
0
        private void CreateEntityTreeNodes()
        {
            //ProjectManager.GlueProjectSave.Entities[78].NamedObjects[9].UpdateCustomProperties();


            // Let's make this faster.
            //foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            // Actually, the contained functions may show popups, and if 2 simultaneous popups
            // are shown, one can cancel the other out and this can cause Glue to freeze. This means
            // we can't parallel foreah it
            //Parallel.ForEach(ProjectManager.GlueProjectSave.Entities, (entity) =>
            foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            {
                entity.UpdateCustomProperties();
                entity.UpdateFromBaseType();
            }

            for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
            {
                EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i];
                // This is so fast that we no longer need to show the
                // user details - and not doing it will make things even faster
                //SetInitWindowText("Creating Entity: " + entitySave.Name);

                EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode(entitySave.Name);

                #region If there is no EntityTreeNode

                if (entityTreeNode == null)
                {
                    // See if the file exists
                    string fileToSearchFor = FileManager.RelativeDirectory + entitySave.Name + ".cs";

                    if (System.IO.File.Exists(fileToSearchFor))
                    {
                        // If we got here that means there's probably not a build item for this file
                        MessageBox.Show("The Glue project has the following Entity:\n" + entitySave.Name + "\n" +
                                        "but this file is not part of Visual Studio.  This file may have been removed manually or " +
                                        "there may have been some saving error.  You should close Glue, manually add this and the Generated file " +
                                        "to Visual Studio, then restart Glue.");
                        MainGlueWindow.Self.HasErrorOccurred = true;
                    }
                    else
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                        mbmb.MessageText = "Could not find the file name\n\n" + fileToSearchFor + "\n\nwhich is used by the entity\n\n" + entitySave.Name + "\n\n" +
                                           "What would you like to do?";


                        mbmb.AddButton("Create a new custom code file", DialogResult.Yes);
                        mbmb.AddButton("Delete this Entity", DialogResult.No);
                        mbmb.AddButton("Do nothing.  The Entity will not show up in Glue until this problem is fixed.", DialogResult.Cancel);

                        DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self);

                        switch (result)
                        {
                        case DialogResult.Yes:
                            if (entityTreeNode == null)
                            {
                                entityTreeNode = ElementViewWindow.AddEntity(entitySave);
                            }

                            CodeWriter.GenerateAndAddElementCustomCode(entitySave);

                            //entityTreeNode.GenerateCode(ProjectManager.EntityTemplateCode);

                            break;

                        case DialogResult.No:
                            ProjectManager.GlueProjectSave.Entities.RemoveAt(i);
                            i--;
                            continue;

                        //break;
                        case DialogResult.Cancel:
                            // do nothing
                            continue;

                            //break;
                        }

                        System.Windows.Forms.MessageBox.Show("Could not create the EntitySave for " + entitySave.Name +
                                                             " because the following file doesn't exist\n\n" + fileToSearchFor);
                    }
                    //mGlueProjectSave.Entities.RemoveAt(i);
                    //i--;
                }

                #endregion


                entityTreeNode.EntitySave = entitySave;

                CheckForMissingCustomFile(entityTreeNode);


                entityTreeNode.UpdateReferencedTreeNodes();

                // moved above
                //entityTreeNode.EntitySave.UpdateCustomProperties();
                //entityTreeNode.EntitySave.UpdateFromBaseType();
            }
        }
コード例 #3
0
        public void AddEntity(EntitySave entitySave, bool suppressAlreadyExistingFileMessage)
        {
            string fileName = entitySave.Name + ".cs";

            entitySave.Tags.Add("GLUE");
            entitySave.Source = "GLUE";

            var glueProject = GlueState.Self.CurrentGlueProject;

            glueProject.Entities.Add(entitySave);

            glueProject.Entities.SortByName();

            #region Create the Entity (not the generated version)

            var newItem = GlueCommands.Self.ProjectCommands.CreateAndAddCodeFile(fileName, false);

            string projectNamespace = GlueState.Self.ProjectNamespace;


            string directory = FileManager.GetDirectory(entitySave.Name);
            if (!directory.ToLower().EndsWith(projectNamespace.ToLower() + "/entities/"))
            {
                GlueCommands.Self.GenerateCodeCommands.GetNamespaceForElement(entitySave);
                // test this on doubly-embedded Entities.
                projectNamespace = GlueCommands.Self.GenerateCodeCommands.GetNamespaceForElement(entitySave);
                // += (".Entities." + FileManager.RemovePath(directory)).Replace("/", "");
            }

            StringBuilder stringBuilder = new StringBuilder(CodeWriter.EntityTemplateCode);

            CodeWriter.SetClassNameAndNamespace(
                projectNamespace,
                entitySave.ClassName,
                stringBuilder);

            string modifiedTemplate = stringBuilder.ToString();

            string nonGeneratedFileName = FileManager.RelativeDirectory + fileName;

            if (newItem == null)
            {
                if (!suppressAlreadyExistingFileMessage)
                {
                    MessageBox.Show("There is already a file named\n\n" + nonGeneratedFileName + "\n\nThis file will be used instead of creating a new one just in case you have code that you want to keep there.");
                }
            }
            else
            {
                FileManager.SaveText(modifiedTemplate, nonGeneratedFileName);
            }
            #endregion

            #region Create <EntityName>.Generated.cs

            string generatedFileName = FileManager.MakeRelative(directory).Replace("/", "\\") + entitySave.ClassName + ".Generated.cs";

            ProjectManager.CodeProjectHelper.CreateAndAddPartialCodeFile(generatedFileName, true);

            #endregion

            ElementViewWindow.AddEntity(entitySave);

            GlueCommands.Self.GenerateCodeCommands.GenerateElementCodeTask(entitySave);

            ProjectManager.SaveProjects();

            GluxCommands.Self.SaveGlux();
        }