private void BuildGraph(object state)
        {
            try
            {
                using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                {
                    IDomainObject currentObject = modelService.GetDomainObject(ContaindDomainObjectIdAndType.Key, ContaindDomainObjectIdAndType.Value);
                    FindDependencies(currentObject, null);
                }

                if (!abort)
                {
                    Invoke(new System.Action(() =>
                    {
                        RenderGraph();
                    }));
                }
            }
            finally
            {
                waitEvent.Set();

                if (!abort)
                {
                    Invoke(new System.Action(() =>
                    {
                        this.Cursor = Cursors.Default;
                    }));
                }
            }
        }
Пример #2
0
        private void PropertyMapForm2_Load(object sender, EventArgs e)
        {
            using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
            {
                viewActionDao = ctx["ViewActionDao"] as IViewActionDao;

                ViewAction = viewActionDao.FindById(ViewAction.Id);

                List <IMappableProperty> targetProperties = new List <IMappableProperty>(ViewAction.ViewNode.View.ResponseMap.MappedProperties.Cast <IMappableProperty>());

                IUXSessionDao sessionDao = ctx["UXSessionDao"] as IUXSessionDao;

                foreach (UXSessionProperty property in sessionDao.FindByApplicationId(FrontendApplication.Id).Properties)
                {
                    targetProperties.Add(property);
                }

                if (ViewAction.ViewToActionMap != null)
                {
                    IPropertyMapDao propertyMapDao = ctx["PropertyMapDao"] as IPropertyMapDao;
                    propertyMapControl.PropertyMap = propertyMapDao.FindById(ViewAction.ViewToActionMap.Id);
                }

                propertyMapControl.SourceProperties = ViewAction.Action.RequestMap.MappedProperties.Cast <IMappableProperty>();
                propertyMapControl.TargetProperties = targetProperties;
                propertyMapControl.Map();
            }
        }
        private void searchBtn_Click(object sender, EventArgs e)
        {
            Config.Backend.LastSelectedServiceInFindServiceMethod = serviceTbx.Text;
            Config.Save();

            try
            {
                this.Cursor = Cursors.WaitCursor;

                using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                {
                    IServiceMethodDao serviceMethodDao = ctx["ServiceMethodDao"] as IServiceMethodDao;

                    IList <Cdc.MetaManager.DataAccess.Domain.ServiceMethod> serviceMethods = serviceMethodDao.FindByApplicationIdNameAndService(BackendApplication.Id, string.IsNullOrEmpty(nameTbx.Text) ? "%" : nameTbx.Text, string.IsNullOrEmpty(serviceTbx.Text) ? "%" : serviceTbx.Text);

                    entityListView.BeginUpdate();

                    entityListView.Items.Clear();

                    foreach (Cdc.MetaManager.DataAccess.Domain.ServiceMethod serviceMethod in serviceMethods)
                    {
                        ListViewItem item = entityListView.Items.Add(serviceMethod.Id.ToString());
                        item.SubItems.Add(serviceMethod.Name);
                        item.SubItems.Add(serviceMethod.Service.Name);
                        item.Tag = serviceMethod;
                    }

                    entityListView.EndUpdate();
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Пример #4
0
        private void ReadViewBeforeExiting()
        {
            using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
            {
                View = dialogService.GetViewById(View.Id);

                NHibernateUtil.Initialize(View.Application);
                NHibernateUtil.Initialize(View.RequestMap);
                NHibernateUtil.Initialize(View.ResponseMap);
            }
        }
        private bool AddQueryInfo()
        {
            bool propertiesAdded = true;

            queryControl.CompileQuery();

            if (queryControl.IsQueryCompiled)
            {
                if (!NamingGuidance.CheckQueryName(queryControl.QueryName, true))
                {
                    return(false);
                }

                if (Action.Query.Id != Guid.Empty)
                {
                    using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                    {
                        // Get a fresh copy from database (original)
                        Query dbQuery = modelService.GetInitializedDomainObject <Query>(Action.Query.Id);

                        // Syncronize the new one with the one in the database
                        //if (!MetaManagerServices.Helpers.QueryHelper.SyncProperties(Action.Query, dbQuery, HandleDeletedQueryProperties, out propertiesAdded))
                        if (!MetaManagerServices.Helpers.QueryHelper.SyncProperties(queryControl.Query, dbQuery, HandleDeletedQueryProperties, out propertiesAdded))
                        {
                            return(false);
                        }

                        foreach (QueryProperty qp in queryPropertyToDelete)
                        {
                            dbQuery.Properties.Remove(qp);
                        }

                        Action.Query = dbQuery;
                    }
                }

                Action.Query.Name   = queryControl.QueryName.Trim();
                Action.Query.Schema = schema;

                return(true);
            }
            else
            {
                MessageBox.Show("You must compile the query first.");
                return(false);
            }
        }
 private void UpdateTableName(IList <BusinessEntity> allExistingEntities)
 {
     using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Auto, true))
     {
         foreach (BusinessEntity businessEntity in allExistingEntities)
         {
             if (string.IsNullOrEmpty(businessEntity.TableName))
             {
                 if (businessEntity.Properties.Count > 0 &&
                     businessEntity.Properties[0].StorageInfo != null &&
                     !string.IsNullOrEmpty(businessEntity.Properties[0].StorageInfo.TableName))
                 {
                     businessEntity.TableName = businessEntity.Properties[0].StorageInfo.TableName;
                     modelService.SaveDomainObject(businessEntity);
                 }
             }
         }
     }
 }
Пример #7
0
        private void searchBtn_Click(object sender, EventArgs e)
        {
            using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
            {
                FindViewTypes findViewType = FindViewTypes.All;

                if (rbCustomOnly.Checked)
                {
                    findViewType = FindViewTypes.Custom;
                }
                else if (rbDrilldowns.Checked)
                {
                    findViewType = FindViewTypes.Drilldowns;
                }

                // Find the views
                IList <Cdc.MetaManager.DataAccess.Domain.View> views = dialogService.GetViews(tbEntity.Text, tbName.Text, tbTitle.Text, findViewType, FrontendApplication.Id);

                lvResult.BeginUpdate();

                lvResult.Items.Clear();

                if (views != null && views.Count > 0)
                {
                    foreach (Cdc.MetaManager.DataAccess.Domain.View view in views)
                    {
                        ListViewItem item = lvResult.Items.Add(view.Id.ToString());
                        item.SubItems.Add(view.Name);
                        item.SubItems.Add(view.Title);
                        item.SubItems.Add(view.Type.ToString());
                        item.SubItems.Add(view.BusinessEntity.Name);
                        item.Tag = view;
                    }
                }

                lvResult.EndUpdate();
            }

            EnableDisableButtons();
        }
        private bool SyncProperties(StoredProcedure dbStoredProc, StoredProcedure newProc)
        {
            using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
            {
                procedurePropertiesToDelete.Clear();
                List <ProcedureProperty> addList    = new List <ProcedureProperty>();
                List <ProcedureProperty> changeList = new List <ProcedureProperty>();
                List <ProcedureProperty> deleteList = new List <ProcedureProperty>(dbStoredProc.Properties);

                // Compare new query properties to old ones
                // determine cause of action, i.e. Add new Properties, Delete removed Properties
                // or update data type
                foreach (ProcedureProperty newPp in newProc.Properties)
                {
                    ProcedureProperty original = FindPropertyByName(newPp.Name, newPp.PropertyType, deleteList);

                    if (original != null)
                    {
                        if (!ProcedureProperty.IsEqual(newPp, original))
                        {
                            // Datatype changed
                            changeList.Add(newPp);
                        }
                        else
                        {
                            // Set sequence
                            original.Sequence = newPp.Sequence;
                        }

                        // Mark as treated
                        deleteList.Remove(original);
                    }
                    else
                    {
                        // Totally new
                        addList.Add(newPp);
                    }
                }

                // What is left in deleteList should be removed
                if (deleteList.Count > 0)
                {
                    Dictionary <string, object> searchKey = new Dictionary <string, object>();
                    searchKey.Add("ProcedureProperty.Id", deleteList[0].Id);
                    IList <MappedProperty> mappedProperties = modelService.GetAllDomainObjectsByPropertyValues <MappedProperty>(searchKey);

                    foreach (ProcedureProperty deleteProp in deleteList)
                    {
                        procedurePropertiesToDelete.Add(deleteProp);
                        dbStoredProc.Properties.Remove(deleteProp);
                    }
                }

                if (addList.Count > 0)
                {
                    foreach (ProcedureProperty addProp in addList)
                    {
                        addProp.StoredProcedure = dbStoredProc;
                        dbStoredProc.Properties.Add(addProp);
                    }
                }

                if (changeList.Count > 0)
                {
                    foreach (ProcedureProperty changeProp in changeList)
                    {
                        ProcedureProperty dbPp = FindPropertyByName(changeProp.Name, changeProp.PropertyType, dbStoredProc.Properties);

                        if (dbPp != null)
                        {
                            dbPp.DbDatatype     = changeProp.DbDatatype;
                            dbPp.Length         = changeProp.Length;
                            dbPp.Precision      = changeProp.Precision;
                            dbPp.Scale          = changeProp.Scale;
                            dbPp.OriginalColumn = changeProp.OriginalColumn;
                            dbPp.OriginalTable  = changeProp.OriginalTable;
                            dbPp.Text           = changeProp.Text;
                            dbPp.Sequence       = changeProp.Sequence;
                        }
                    }
                }

                return(true);
            }
        }
        private void searchServiceBtn_Click(object sender, EventArgs e)
        {
            if (serviceMethodCb.SelectedValue != null)
            {
                using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                {
                    List <Property>       properties       = new List <Property>();
                    List <MappedProperty> mappedProperties = new List <MappedProperty>();

                    // Populate servicemethodlist
                    ServiceMethod serviceMethod = modelService.GetInitializedDomainObject <ServiceMethod>((Guid)serviceMethodCb.SelectedValue);

                    PropertyMap propertyMap = null;

                    if (serviceMethod != null)
                    {
                        // Get the correct map
                        if (rbResponseMap.Checked)
                        {
                            propertyMap = serviceMethod.ResponseMap;
                        }
                        else if (rbRequestMap.Checked)
                        {
                            propertyMap = serviceMethod.RequestMap;
                        }

                        foreach (MappedProperty mappedProp in propertyMap.MappedProperties)
                        {
                            if (mappedProp.Target is Property)
                            {
                                // Remove custom properties if they shouldn't be shown
                                if (!CanShowCustomProperties && (mappedProp.Target as Property).StorageInfo == null)
                                {
                                    continue;
                                }

                                properties.Add((Property)mappedProp.Target);
                                mappedProperties.Add(mappedProp);
                            }
                        }
                    }

                    if (CanMultiSelectProperties)
                    {
                        gbSelect.Text = "Select Mapped Properties (Multiselect Enabled)";
                    }
                    else
                    {
                        gbSelect.Text = "Select Mapped Property (Multiselect Disabled)";
                    }

                    propertyListView.BeginUpdate();

                    propertyListView.Items.Clear();

                    countLbl.Text = "";

                    if (properties != null)
                    {
                        countLbl.Text = properties.Count.ToString();

                        foreach (MappedProperty property in mappedProperties)
                        {
                            ListViewItem item = propertyListView.Items.Add(property.Id.ToString());
                            item.SubItems.Add(property.Name);
                            item.SubItems.Add(property.Target.Id.ToString());
                            item.SubItems.Add(property.Target.Name);
                            item.SubItems.Add(property.Target.Type.ToString());
                            item.Tag = property;

                            if (((Property)property.Target).StorageInfo != null)
                            {
                                item.SubItems.Add(((Property)property.Target).StorageInfo.TableName);
                                item.SubItems.Add(((Property)property.Target).StorageInfo.ColumnName);
                            }
                            else
                            {
                                item.SubItems.Add("");
                                item.SubItems.Add("");
                            }

                            if (((Property)property.Target).BusinessEntity != null)
                            {
                                item.SubItems.Add(((Property)property.Target).BusinessEntity.Name);
                            }
                            else
                            {
                                item.SubItems.Add("");
                            }
                        }
                    }

                    propertyListView.EndUpdate();

                    // Always select first row if anything is found
                    if (propertyListView.Items.Count > 0)
                    {
                        propertyListView.Items[0].Selected = true;
                        propertyGrid.SelectedObject        = propertyListView.Items[0].Tag;
                    }
                    else
                    {
                        propertyGrid.SelectedObject = null;
                    }

                    CheckEnableDisableButtons();
                }
            }
        }
Пример #10
0
        private void searchBtn_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
            {
                IList <Property> properties = null;

                Dictionary <string, object> propKeys = new Dictionary <string, object>();

                if (BusinessEntity != null)
                {
                    propKeys.Add("BusinessEntity.Id", BusinessEntity.Id);
                }
                else if (!string.IsNullOrEmpty(beTbx.Text.Trim()))
                {
                    propKeys.Add("BusinessEntity.Name", beTbx.Text.Trim());
                    propKeys.Add("BusinessEntity.Application.Id", BackendApplication.Id);
                }
                else
                {
                    propKeys.Add("BusinessEntity.Application.Id", BackendApplication.Id);
                }

                if (!string.IsNullOrEmpty(nameTbx.Text.Trim()))
                {
                    propKeys.Add("Name", nameTbx.Text.Trim());
                }

                if (!string.IsNullOrEmpty(tableTbx.Text.Trim()))
                {
                    propKeys.Add("StorageInfo.TableName", tableTbx.Text.Trim());
                }

                if (!string.IsNullOrEmpty(columnTbx.Text.Trim()))
                {
                    propKeys.Add("StorageInfo.ColumnName", columnTbx.Text.Trim());
                }

                if (!CanShowCustomProperties)
                {
                    propKeys.Add("StorageInfo.Schema.Id", Schema.Id);
                }

                properties = modelService.GetAllDomainObjectsByPropertyValues <Property>(propKeys, false, true);

                //if (CanShowCustomProperties)
                //{
                //    properties = appService.GetAllPropertiesByNameSchemaTableAndColumn(nameTbx.Text, Schema.Id, tableTbx.Text, columnTbx.Text, beTbx.Text, BackendApplication.Id);
                //}
                //else
                //{
                //    properties = appService.GetAllExistingPropertiesByNameSchemaTableAndColumn(nameTbx.Text, Schema.Id, tableTbx.Text, columnTbx.Text, beTbx.Text);
                //}

                if (CanMultiSelectProperties)
                {
                    gbSelect.Text = "Select Properties (Multiselect Enabled)";
                }
                else
                {
                    gbSelect.Text = "Select Property (Multiselect Disabled)";
                }

                propertyListView.BeginUpdate();

                propertyListView.Items.Clear();

                countLbl.Text = "";

                ListViewItem foundTableItem = null;

                if (properties != null)
                {
                    countLbl.Text = properties.Count.ToString();

                    int c = 0;

                    foreach (Property property in properties)
                    {
                        c++;
                        ListViewItem item = propertyListView.Items.Add(property.Id.ToString());
                        item.SubItems.Add(property.Name);

                        if (property.Type != null)
                        {
                            item.SubItems.Add(property.Type.ToString());
                        }
                        else
                        {
                            item.SubItems.Add("Unknown");
                        }

                        item.Tag = property;

                        if (property.StorageInfo != null)
                        {
                            item.SubItems.Add(property.StorageInfo.TableName);
                            item.SubItems.Add(property.StorageInfo.ColumnName);

                            if (!string.IsNullOrEmpty(AutoSelectTableForFoundColumn) &&
                                property.StorageInfo.TableName.ToUpper() == AutoSelectTableForFoundColumn.ToUpper())
                            {
                                foundTableItem = item;
                            }
                        }
                        else
                        {
                            item.SubItems.Add("");
                            item.SubItems.Add("");
                        }

                        if (property.BusinessEntity != null)
                        {
                            item.SubItems.Add(property.BusinessEntity.Name);
                        }
                        else
                        {
                            item.SubItems.Add("");
                        }

                        if (property.Hint != null)
                        {
                            string d = property.Hint.Text;
                        }

                        if (c == 1000)
                        {
                            break;
                        }
                    }

                    propertyListView.SortByColumn(1, SortOrder.Ascending, false);
                }

                propertyListView.EndUpdate();

                // Always select first row if anything is found and AutoSelectTableForFoundColumn is not set
                if (propertyListView.Items.Count > 0)
                {
                    if (foundTableItem != null)
                    {
                        foundTableItem.Selected = true;
                    }

                    // If still nothing is selected just select first row
                    if (propertyListView.SelectedItems.Count == 0)
                    {
                        propertyListView.Items[0].Selected = true;
                        propertyGrid.SelectedObject        = propertyListView.Items[0].Tag;
                    }

                    propertyListView.Focus();
                }
                else
                {
                    propertyGrid.SelectedObject = null;
                }

                CheckEnableDisableButtons();
            }

            Cursor = Cursors.Default;
        }
Пример #11
0
        private void ThreadWork(object state)
        {
            try
            {
                try
                {
                    using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                    {
                        ((DataAccess.DomainInterceptor)MetaManagerServices.GetDomainInterceptor()).GetDataFromConfigurationManagement = true;

                        generateStartTime = DateTime.Now;

                        var selectedServices = (from id in (List <string>) state
                                                select modelService.GetDomainObject <Service>(Guid.Parse(id))).ToList();

                        // Get which business entities we need to generate depending on the selected services.
                        Dictionary <Guid, BusinessEntity> entityDictionary = new Dictionary <Guid, BusinessEntity>();

                        //Dictionary<Guid, IDomainObject> loadedObjects = new Dictionary<Guid, IDomainObject>();
                        List <Service> loadedServices = new List <Service>();

                        foreach (Service service in selectedServices)
                        {
                            //Service loadedService = (Service)loadedObjects[service.Id];
                            Service loadedService = modelService.GetDomainObject <Service>(service.Id);

                            loadedServices.Add(loadedService);

                            foreach (ServiceMethod method in loadedService.ServiceMethods)
                            {
                                if (method != null)
                                {
                                    if (!entityDictionary.ContainsKey(method.MappedToAction.BusinessEntity.Id))
                                    {
                                        entityDictionary.Add(method.MappedToAction.BusinessEntity.Id, method.MappedToAction.BusinessEntity);
                                    }
                                }
                            }
                        }

                        ApplicationTemplate template = new ApplicationTemplate();
                        template.entities           = entityDictionary.Values.ToList <BusinessEntity>();
                        template.services           = loadedServices;
                        template.solutionFileName   = Path.Combine(solutionPathTbx.Text, solutionNameTbx.Text + ".sln");
                        template.referenceDirectory = referencePathTbx.Text;
                        template.templateCallback   = CodeSmithTemplateCallback;

                        template.Render(TextWriter.Null);

                        UpdateStatusAndTime("Done!", 0, 0, 0);
                    }

                    string info = string.Format("Code generation complete.\r\n{0} files generated, {1} files written to disk", FileCacheManager.GetWrites(), FileCacheManager.GetWritesToDisk());


                    if (this.InvokeRequired)
                    {
                        this.Invoke(new System.Action(() =>
                        {
                            ShowGenerationResult.Show(this, "Generation Result", info, "Files written to disk", FileCacheManager.GetWrittenFilesToDisk());
                        })
                                    );
                    }
                    else
                    {
                        ShowGenerationResult.Show(this, "Generation Result", info, "Files written to disk", FileCacheManager.GetWrittenFilesToDisk());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error in Codegeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                ((DataAccess.DomainInterceptor)MetaManagerServices.GetDomainInterceptor()).GetDataFromConfigurationManagement = false;

                if (this.InvokeRequired)
                {
                    this.Invoke(new System.Action(() =>
                    {
                        Cursor.Current    = Cursors.Default;
                        pProgress.Visible = false;
                        EnableDisableButtons();
                    })
                                );
                }
                else
                {
                    Cursor.Current    = Cursors.Default;
                    pProgress.Visible = false;
                    EnableDisableButtons();
                }
            }
        }
        private void PopulateTables()
        {
            using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
            {
                // Save all unique dictionmary entries
                Dictionary <string, string> uniqueEntityExistingDict = new Dictionary <string, string>();
                Dictionary <string, string> uniqueEntityNewDict      = new Dictionary <string, string>();

                // Fetch all businessentities to match
                IList <BusinessEntity> allExistingEntities = modelService.GetAllDomainObjectsByApplicationId <BusinessEntity>(BackendApplication.Id);

                // Try to update tablename if not set
                UpdateTableName(allExistingEntities);

                // Fetch the list of tables
                IList <DataModelTableInfo> tableList = DataModelImporter.GetAllTablesInSchema(currentSchema);

                lvTables.Items.Clear();
                lvTables.BeginUpdate();

                foreach (DataModelTableInfo table in tableList)
                {
                    LocalTableItem localTable = new LocalTableItem();
                    localTable.RemoteTable         = table;
                    localTable.LocalBusinessEntity = null;
                    localTable.Syncable            = true;

                    IList <BusinessEntity> findBusinessEntities = allExistingEntities.Where(e => e.TableName == table.TableName).ToList();

                    bool exists = findBusinessEntities.Count == 1;

                    if (exists)
                    {
                        localTable.LocalBusinessEntity = findBusinessEntities[0];

                        // Remove the businessentity from the list so we know which we have left afterwards
                        allExistingEntities.Remove(localTable.LocalBusinessEntity);
                    }

                    ListViewItem item = new ListViewItem(table.TableName);

                    string entityName = DataModelImporter.GetCaptionFromComment(table.TableComment);
                    if (string.IsNullOrEmpty(entityName))
                    {
                        entityName = table.TableName;
                    }

                    if (exists)
                    {
                        item.SubItems.Add(localTable.LocalBusinessEntity.Name);
                    }
                    else
                    {
                        item.SubItems.Add(entityName);
                    }

                    item.SubItems.Add(table.TableCreated.ToShortDateString());
                    item.SubItems.Add(exists ? "Existing" : "New");
                    item.SubItems.Add(table.TableComment.TrimEnd(new char[] { '\n', ' ' }).Replace("\n", " - "));

                    item.Tag = localTable;

                    if (!exists)
                    {
                        item.ForeColor = Color.Green;
                    }

                    lvTables.Items.Add(item);

                    if (exists)
                    {
                        if (!uniqueEntityExistingDict.ContainsKey(entityName))
                        {
                            uniqueEntityExistingDict[entityName] = table.TableName;
                        }
                        else
                        {
                            // Error, same entity name found again.
                            string tablename = uniqueEntityExistingDict[entityName];

                            AddToProgressText(string.Format("ERROR:\tTable {0} will have the same business entity name as table {1} after updating.\n" +
                                                            "\tIt will not be possible to update until the table comment is changed.\n",
                                                            table.TableName, tablename));

                            item.BackColor = Color.LightSalmon;

                            localTable.Syncable = false;

                            // Find the other table and set the color and set to uncheckable
                            ListViewItem otherTableItem = lvTables.FindItemWithText(tablename);

                            if (otherTableItem != null)
                            {
                                otherTableItem.BackColor = Color.LightSalmon;

                                LocalTableItem otherLocalTableItem = (LocalTableItem)otherTableItem.Tag;
                                otherLocalTableItem.Syncable = false;
                            }
                        }
                    }
                    else
                    {
                        // First check if the new table is ok with the other new tables namewise.
                        if (!uniqueEntityNewDict.ContainsKey(entityName))
                        {
                            uniqueEntityNewDict[entityName] = table.TableName;
                        }
                        else
                        {
                            // Error, same entity name found again.
                            string tablename = uniqueEntityNewDict[entityName];

                            AddToProgressText(string.Format("ERROR:\tThe new table {0} will have the same business entity name as the table {1} after updating.\n" +
                                                            "\tIt will not be possible to import this table until the table comment is changed.\n",
                                                            table.TableName, tablename));

                            item.BackColor = Color.LightSalmon;

                            localTable.Syncable = false;

                            // Find the other table and set the color and set to uncheckable
                            ListViewItem otherTableItem = lvTables.FindItemWithText(tablename);

                            if (otherTableItem != null)
                            {
                                otherTableItem.BackColor = Color.LightSalmon;

                                LocalTableItem otherLocalTableItem = (LocalTableItem)otherTableItem.Tag;
                                otherLocalTableItem.Syncable = false;
                            }
                        }

                        // Now check if the entityname is ok with the existing businessentities namewise
                        // If not then only set the new table to uncheckable.
                        if (uniqueEntityExistingDict.ContainsKey(entityName))
                        {
                            // Error, entity name found
                            string tablename = uniqueEntityExistingDict[entityName];

                            AddToProgressText(string.Format("ERROR:\tThe new table {0} will have the same business entity name as the existing table {1} after updating.\n" +
                                                            "\tIt will not be possible to import this table until the table comment is changed.\n",
                                                            table.TableName, tablename));

                            item.BackColor = Color.LightSalmon;

                            localTable.Syncable = false;
                        }
                    }
                }

                // List all businessentities left in list. These must have been removed.
                foreach (BusinessEntity entity in allExistingEntities)
                {
                    // Do not show any entities that doesn't have a tablename defined.
                    // These are used internally like CustomProperties
                    if (string.IsNullOrEmpty(entity.TableName))
                    {
                        continue;
                    }

                    LocalTableItem localTable = new LocalTableItem();
                    localTable.RemoteTable         = null;
                    localTable.LocalBusinessEntity = entity;
                    localTable.Syncable            = true;

                    ListViewItem item = new ListViewItem(entity.TableName);

                    item.SubItems.Add(entity.Name);
                    item.SubItems.Add(string.Empty);
                    item.SubItems.Add("Removed");
                    item.SubItems.Add(string.Empty);

                    item.Tag = localTable;

                    item.ForeColor = Color.Red;

                    lvTables.Items.Add(item);
                }

                lvTables.EndUpdate();
            }
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            List <string> tableNames = new List <string>();

            CallbackService callbackService = new CallbackService();

            callbackService.SetCallback(DoCallback);
            callbackService.Initialize(lvTables.CheckedItems.Count);

            tbProgress.Clear();

            foreach (ListViewItem item in lvTables.CheckedItems)
            {
                LocalTableItem tableItem = (LocalTableItem)item.Tag;

                if (tableItem.RemoteTable != null)
                {
                    tableNames.Add(tableItem.RemoteTable.TableName);
                }
            }


            bool changesMade = false;

            if (tableNames.Count > 0)
            {
                IList <BusinessEntity> businessEntities         = null;
                DataModelChanges       detectedChanges          = null;
                IList <BusinessEntity> existingBusinessEntities = null;

                try
                {
                    this.Cursor      = Cursors.WaitCursor;
                    btnClose.Enabled = false;

                    using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                    {
                        businessEntities         = DataModelImporter.AnalyzeTables(currentSchema, tableNames, false);
                        existingBusinessEntities = modelService.GetAllDomainObjectsByApplicationId <BusinessEntity>(BackendApplication.Id);

                        AddToProgressText("\nAnalyzing fetched data compared to MetaManager database... ");

                        detectedChanges = DataModelImporter.CompareEntities(businessEntities, existingBusinessEntities);

                        AddToProgressText("done!\n");
                    }
                }
                catch (Exception ex)
                {
                    // Exception caught. Do nothing further!
                    MessageBox.Show(string.Format("Error caught when retreiving information from database!\r\nFix the problem and try again!\r\nError:\r\n\t{0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                finally
                {
                    this.Cursor      = Cursors.Default;
                    btnClose.Enabled = true;
                }

                if (detectedChanges != null &&
                    detectedChanges.Count > 0)
                {
                    AddToProgressText("\nShowing changes to user to decide what changes to apply...\n");

                    using (ShowDataModelChanges form = new ShowDataModelChanges())
                    {
                        form.BackendApplication  = BackendApplication;
                        form.FrontendApplication = FrontendApplication;

                        form.DetectedChanges = detectedChanges;

                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            AddToProgressText("\nSaving new and changed properties and business entities... ");
                            // Update detected changes depending on user input from dialog.
                            DataModelImporter.CompareEntities(businessEntities, existingBusinessEntities, detectedChanges);

                            try
                            {
                                MetaManagerServices.Helpers.ApplicationHelper.UpdateBackendDataModel(detectedChanges, BackendApplication);
                                changesMade = true;
                            }
                            catch (ModelAggregatedException ex)
                            {
                                string mess = ex.Message;
                                string ids  = string.Empty;
                                foreach (string id in ((ModelAggregatedException)ex).Ids)
                                {
                                    ids += id + "\r\n";
                                }

                                Clipboard.SetText(ids);
                                mess += "\r\n\r\nThe Ids has been copied to the clipboard";
                                AddToProgressText("\r\n");
                                AddToProgressText("\r\n");
                                AddToProgressText(mess);
                                AddToProgressText("\r\n");
                            }
                            catch (Exception ex)
                            {
                                AddToProgressText("\n\n");
                                AddToProgressText(ex.Message);
                                AddToProgressText("\n");
                            }
                        }
                        else
                        {
                            AddToProgressText("\nUser canceled!\n");
                        }
                    }
                }
                else
                {
                    AddToProgressText("\nNo changes found!\n");
                }
            }

            if (changesMade)
            {
                AddToProgressText("\nFetching all tables to repopulate the list...\n");
                PopulateTables();
                AddToProgressText("Done!\n");
            }
        }
Пример #14
0
        private void okBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckPaths())
                {
                    return;
                }

                okBtn.Enabled             = false;
                cancelBtn.Enabled         = false;
                btnStopGeneration.Enabled = true;
                doBreak = false;

                Cursor.Current = Cursors.WaitCursor;

                // Save to config file
                Config.Backend.XMLSchemaFolder    = tbXMLSchemaFolder.Text;
                Config.Backend.PLSQLPackageFolder = tbPLSQLPackageFolder.Text;
                Config.Save();

                try
                {
                    // Reset progressbar and make the panel visible
                    progressBar.Value   = 0;
                    pProgress.Visible   = true;
                    lblTimeElapsed.Text = string.Empty;

                    lblProgressText.Text = "Extracting Data from Database...";
                    System.Windows.Forms.Application.DoEvents();

                    using (new SessionScope(MetaManagerServices.GetSessionFactory(), MetaManagerServices.GetDomainInterceptor(), true, FlushMode.Never, true))
                    {
                        IList <Report> reports = new List <Report>();

                        List <IDomainObject> selectedReports = modelService.GetAllDomainObjectsByApplicationId <Report>(BackendApplication.Id).OrderBy(r => (r.Name)).ToList <IDomainObject>();

                        foreach (Report report in selectedReports)
                        {
                            Report readReport = modelService.GetDomainObject <Report>(report.Id);
                            reports.Add(readReport);
                        }

                        ReportTemplate template = new ReportTemplate();

                        // Create the plsql body and spec directories if they don't exist
                        string plsqlBodyDirectory = Path.Combine(tbPLSQLPackageFolder.Text.Trim(), "body");
                        string plsqlSpecDirectory = Path.Combine(tbPLSQLPackageFolder.Text.Trim(), "spec");

                        if (!Directory.Exists(plsqlBodyDirectory))
                        {
                            Directory.CreateDirectory(plsqlBodyDirectory);
                        }

                        if (!Directory.Exists(plsqlSpecDirectory))
                        {
                            Directory.CreateDirectory(plsqlSpecDirectory);
                        }

                        template.reports                  = reports;
                        template.xsdDirectory             = tbXMLSchemaFolder.Text.Trim();
                        template.plsqlBodyDirectory       = plsqlBodyDirectory;
                        template.plsqlSpecDirectory       = plsqlSpecDirectory;
                        template.printDocumentPackageName = "PrintDocument"; // Name of package for printing document
                        template.templateCallback         = CodeSmithTemplateCallback;

                        generateStartTime = DateTime.Now;

                        template.Render(TextWriter.Null);

                        UpdateTime();
                    }

                    if (FileCacheManager.GetFilesNotSaved().Count > 0)
                    {
                        string notSavedFiles = FileCacheManager.GetFilesNotSaved().Aggregate((current, next) => current + Environment.NewLine + '\t' + next);

                        string txt = "There were one or more files that couldn't be saved.\r\n" +
                                     "Probable cause is that the file is located in a dynamic Clearcase view and is not checked out.\r\n" +
                                     "Check out the file(s) and generate again.";

                        ShowGenerationResult.Show(this, "Generation Result: Not saved files", txt, "Files not saved", FileCacheManager.GetFilesNotSaved());
                    }

                    string text = string.Format("Code generation complete.\r\n{0} files generated, {1} files written to disk.",
                                                FileCacheManager.GetWrites(),
                                                FileCacheManager.GetWritesToDisk());

                    ShowGenerationResult.Show(this, "Generation Result", text, "Files written to disk", FileCacheManager.GetWrittenFilesToDisk());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error in Codegeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                Cursor.Current    = Cursors.Default;
                pProgress.Visible = false;
                EnableDisableButtons();
            }
        }