Example #1
0
        public static bool CheckMetaCompatibility(
            MgaProject project,
            ISIS.GME.Common.Interfaces.RootFolder rootFolder)
        {
            bool result = true;

            foreach (var item in rootFolder.MetaRefs)
            {
                try
                {
                    MgaMetaBase b = project.RootMeta.FindObject[item.Key];
                    if (b == null)
                    {
                        throw new Exception("Meta incompatibility");
                    }
                    else
                    {
                        // TODO: Namespaces??? this will not work
                        if (b.Name != item.Value.Name)
                        {
                            throw new Exception("Meta incompatibility");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Meta incompatibility", ex);
                }
            }

            return(result);
        }
Example #2
0
        public static T MakeConnection <T>(
            Interfaces.FCO src,
            Interfaces.FCO dst,
            Interfaces.Reference srcRef = null,
            Interfaces.Reference dstRef = null,
            Interfaces.Container parent = null,
            string roleStr = null)
            where T : Classes.Connection, new()
        {
            Contract.Requires(src != null);
            Contract.Requires(dst != null);

            IMgaFCO connection = null;

            T result = new T();

            if (parent == null)
            {
                try
                {
                    if (srcRef == null &&
                        dstRef == null)
                    {
                        // set the parent if it is null
                        if (src.ParentContainer.Impl == dst.ParentContainer.Impl)
                        {
                            parent = src.ParentContainer;
                        }
                        else if (src.ParentContainer.Impl == dst.ParentContainer.ParentContainer.Impl)
                        {
                            parent = src.ParentContainer;
                        }
                        else if (src.ParentContainer.ParentContainer.Impl == dst.ParentContainer.Impl)
                        {
                            parent = dst.ParentContainer;
                        }
                        else if (src.ParentContainer.ParentContainer.Impl == dst.ParentContainer.ParentContainer.Impl &&
                                 src.ParentContainer.Impl != dst.ParentContainer.Impl)
                        {
                            parent = src.ParentContainer.ParentContainer;
                        }
                    }
                    else if (srcRef != null &&
                             dstRef == null)
                    {
                        if (srcRef.ParentContainer.Impl == dst.ParentContainer.Impl)
                        {
                            parent = dst.ParentContainer;
                        }
                        else if (srcRef.ParentContainer.Impl == dst.ParentContainer.ParentContainer.Impl)
                        {
                            parent = srcRef.ParentContainer;
                        }
                    }
                    else if (srcRef == null &&
                             dstRef != null)
                    {
                        if (src.ParentContainer.Impl == dstRef.ParentContainer.Impl)
                        {
                            parent = src.ParentContainer;
                        }
                        else if (src.ParentContainer.ParentContainer.Impl == dstRef.ParentContainer.Impl)
                        {
                            parent = dstRef.ParentContainer;
                        }
                    }
                    else if (srcRef != null &&
                             dstRef != null)
                    {
                        if (srcRef.ParentContainer.Impl == dstRef.ParentContainer.Impl)
                        {
                            parent = srcRef.ParentContainer;
                        }
                    }
                    if (parent == null)
                    {
                        throw new Exception("Parent could not be identified based on the given parameters.");
                    }
                }
                catch (NullReferenceException ex)
                {
                    // handle exception here
                    throw ex;
                }
            }

            if (parent.Impl is MgaModel)
            {
                MgaModel    model = parent.Impl as MgaModel;
                MgaMetaRole role  = null;

                try
                {
                    if (string.IsNullOrEmpty(roleStr))
                    {
                        if (result.GetType().Name != typeof(Interfaces.Connection).Name)
                        {
                            try
                            {
                                role = (model.MetaBase as MgaMetaModel).RoleByName[result.GetType().Name];
                            }
                            catch (Exception ex)
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.AppendLine("Role was not found in the container.");
                                sb.AppendLine("Paradigm violation.");
                                sb.AppendFormat("Container type: {0} Requested role: {1}",
                                                parent.Kind,
                                                result.GetType().Name);
                                throw new Exception(sb.ToString(), ex);
                            }
                        }
                        else
                        {
                            // use default role
                            string       srcKind = src.Kind;
                            string       dstKind = dst.Kind;
                            MgaMetaRoles roles   = (model.MetaBase as MgaMetaModel).Roles;
                            foreach (MgaMetaRole item in roles)
                            {
                                MgaMetaBase metaBase = item.MetaProject.FindObject[item.Kind.MetaRef];
                                if (metaBase is MgaMetaConnection)
                                {
                                    foreach (IMgaMetaConnJoint joint in (metaBase as MgaMetaConnection).Joints)
                                    {
                                        IEnumerable <MgaMetaPointerItem> srcSpecs = joint.PointerSpecByName["src"].Items.Cast <MgaMetaPointerItem>();
                                        IEnumerable <MgaMetaPointerItem> dstSpecs = joint.PointerSpecByName["dst"].Items.Cast <MgaMetaPointerItem>();
                                        if (srcSpecs.FirstOrDefault(x => x.Desc == srcKind) != null &&
                                            dstSpecs.FirstOrDefault(x => x.Desc == dstKind) != null)
                                        {
                                            // role found (first)
                                            role = item;
                                            break;
                                        }
                                    }
                                    if (role != null)
                                    {
                                        // role is ok
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            // try to use user defined role
                            role = (model.MetaBase as MgaMetaModel).RoleByName[roleStr];
                        }
                        catch (Exception ex)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("Role was not found in the container.");
                            sb.AppendLine("Paradigm violation.");
                            sb.AppendFormat("Container type: {0} Requested role: {1}",
                                            parent.Kind,
                                            result.GetType().Name);
                            throw new Exception(sb.ToString(), ex);
                        }
                    }

                    if (role == null)
                    {
                        throw new Exception("Role not found based on the given parameters.");
                    }
                    if (srcRef == null &&
                        dstRef == null)
                    {
                        connection = model.CreateSimpleConnDisp(
                            role,
                            src.Impl as MgaFCO,
                            dst.Impl as MgaFCO,
                            null,
                            null);
                    }
                    else if (srcRef != null &&
                             dstRef == null)
                    {
                        connection = model.CreateSimpleConnDisp(
                            role,
                            src.Impl as MgaFCO,
                            dst.Impl as MgaFCO,
                            srcRef.Impl as MgaFCO,
                            null);
                    }
                    else if (srcRef == null &&
                             dstRef != null)
                    {
                        connection = model.CreateSimpleConnDisp(
                            role,
                            src.Impl as MgaFCO,
                            dst.Impl as MgaFCO,
                            null,
                            dstRef.Impl as MgaFCO);
                    }
                    else if (srcRef != null &&
                             dstRef != null)
                    {
                        connection = model.CreateSimpleConnDisp(
                            role,
                            src.Impl as MgaFCO,
                            dst.Impl as MgaFCO,
                            srcRef.Impl as MgaFCO,
                            dstRef.Impl as MgaFCO);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                throw new Exception("Parent could not be a folder.");
            }

            result.Impl = connection;

            if (result.Impl == null)
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }