예제 #1
0
        public static T CreateObject <T>(
            ISIS.GME.Common.Interfaces.Container parent,
            string roleStr = null)
            where T : ISIS.GME.Common.Classes.Base, new()
        {
            Contract.Requires(parent != null);

            T      result = new T();
            string Kind   = typeof(T).Name;

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

                if (string.IsNullOrEmpty(roleStr))
                {
                    try
                    {
                        // try to use user defined role
                        role = (model.MetaBase as IMgaMetaModel).RoleByName[Kind];
                    }
                    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
                {
                    try
                    {
                        // try to use user defined role
                        role = (model.MetaBase as IMgaMetaModel).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);
                    }
                }
                try
                {
                    MgaFCO fco = model.CreateChildObject(role);
                    result.Impl = fco as IMgaObject;
                    return(result);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("New element could not be created.");
                    sb.AppendFormat("Container type: {0} Requested role: {1}",
                                    parent.Kind,
                                    result.GetType().Name);
                    throw new Exception(sb.ToString(), ex);
                }
            }
            else if (parent.Impl is MgaFolder)
            {
                if (string.IsNullOrEmpty(roleStr))
                {
                    MgaFolder folder = parent.Impl as MgaFolder;

                    foreach (MgaMetaFolder item in folder.MetaFolder.LegalChildFolders)
                    {
                        if (item.Name == Kind)
                        {
                            MgaFolder f = folder.CreateFolder(item);
                            result.Impl = f as IMgaObject;
                            return(result);
                        }
                    }
                    if (result.Impl == null)
                    {
                        foreach (MgaMetaFCO item in folder.MetaFolder.LegalRootObjects)
                        {
                            if (item.Name == Kind)
                            {
                                IMgaFCO fco = folder.CreateRootObject(item);
                                result.Impl = fco as IMgaObject;
                                return(result);
                            }
                        }
                    }
                }
                else
                {
                    MgaFolder folder = parent.Impl as MgaFolder;

                    foreach (MgaMetaFolder item in folder.MetaFolder.LegalChildFolders)
                    {
                        if (item.Name == roleStr)
                        {
                            MgaFolder f = folder.CreateFolder(item);
                            result.Impl = f as IMgaObject;
                            return(result);
                        }
                    }
                    if (result.Impl == null)
                    {
                        foreach (MgaMetaFCO item in folder.MetaFolder.LegalRootObjects)
                        {
                            if (item.Name == roleStr)
                            {
                                IMgaFCO fco = folder.CreateRootObject(item);
                                result.Impl = fco as IMgaObject;
                                return(result);
                            }
                        }
                    }
                }
            }

            return(null);
        }
예제 #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);
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parent"></param>
        /// <param name="metaRef">meta ref of the new object</param>
        /// <param name="roleMetaRef">meta ref of the role (if the parent is a model)</param>
        /// <returns></returns>
        public static T CreateObject <T>(
            ISIS.GME.Common.Interfaces.Container parent,
            int metaRef,
            int roleMetaRef = 0)
            where T : ISIS.GME.Common.Classes.Base, new()
        {
            Contract.Requires(parent != null);

            T result = new T();

            if (parent.Impl is MgaModel)
            {
                MgaModel    model = parent.Impl as MgaModel;
                MgaMetaRole role  = null;
                try
                {
                    // try to use user defined role
                    role = (model.MetaBase as MgaMetaModel).
                           Roles.
                           Cast <MgaMetaRole>().
                           FirstOrDefault(x => x.MetaRef == roleMetaRef);
                }
                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);
                }

                try
                {
                    IMgaFCO fco = model.CreateChildObject(role);
                    result.Impl = fco as IMgaObject;
                    return(result);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("New element could not be created.");
                    sb.AppendFormat("Container type: {0} Requested role: {1}",
                                    parent.Kind,
                                    result.GetType().Name);
                    throw new Exception(sb.ToString(), ex);
                }
            }
            else if (parent.Impl is MgaFolder)
            {
                try
                {
                    MgaFolder folder = parent.Impl as MgaFolder;

                    MgaMetaFolder item = folder.MetaFolder.
                                         LegalChildFolders.
                                         Cast <MgaMetaFolder>().
                                         FirstOrDefault(x => x.MetaRef == metaRef);

                    if (item != null)
                    {
                        // create new folder
                        MgaFolder f = folder.CreateFolder(item);
                        result.Impl = f as IMgaObject;
                        return(result);
                    }
                    else
                    {
                        MgaMetaFCO itemFco = folder.MetaFolder.
                                             LegalRootObjects.
                                             Cast <MgaMetaFCO>().
                                             FirstOrDefault(x => x.MetaRef == metaRef);

                        if (itemFco != null)
                        {
                            IMgaFCO f = folder.CreateRootObject(itemFco);
                            result.Impl = f as IMgaObject;
                            return(result);
                        }
                    }
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("New element could not be created in folder.");
                    sb.AppendFormat("Container type: {0} Requested child type: {1}",
                                    parent.Kind,
                                    result.GetType().Name);
                    throw new Exception(sb.ToString(), ex);
                }
            }

            return(null);
        }
예제 #4
0
 public MgaMetaRole get_RoleByMeta(MgaModel parent, MgaMetaFCO p_kind, objtype_enum objtype, MgaMetaRole p_role, MgaMetaAspect aspect)
 {
     return(delegate_.RoleByMeta[parent, p_kind, objtype, p_role, aspect]);
 }
예제 #5
0
 public MgaMetaRole GetRoleByMetaDisp(MgaModel parent, MgaMetaFCO p_kind, objtype_enum objtype, MgaMetaRole p_role, MgaMetaAspect aspect)
 {
     return(delegate_.GetRoleByMetaDisp(parent, p_kind, objtype, p_role, aspect));
 }
예제 #6
0
        /// <summary>
        /// Called when an FCO or folder changes
        /// </summary>
        /// <param name="subject">
        ///   the object the event(s) happened to
        /// </param>
        /// <param name="eventMask">
        ///   objectevent_enum values ORed together
        /// </param>
        /// <param name="param">
        ///   extra information provided for cetertain event types
        /// </param>
        public void ObjectEvent(
            MgaObject subject,
            uint eventMask,
            object param)
        {
            if (!componentEnabled)
            {
                return;
            }
            else if (isXMLImportInProgress)
            {
                return;
            }
            //else if (isProjectInTransation)
            //{
            //  return;
            //}

            if (subject.HasReadOnlyAccess() ||
                subject.IsLibObject)
            {
                return;
            }

            uint uOBJEVENT_CREATED = 0;
            uint uOBJEVENT_COPIED  = 0;

            unchecked { uOBJEVENT_CREATED = (uint)objectevent_enum.OBJEVENT_CREATED; }
            unchecked { uOBJEVENT_COPIED = (uint)objectevent_enum.OBJEVENT_COPIED; }



            if ((eventMask & uOBJEVENT_COPIED) != 0)
            {
                isCopied = true;
            }
            else if ((eventMask & uOBJEVENT_CREATED) != 0 && subject.Status == 0)
            // check Status, since object can be created and deleted in same tx
            {
                if (isCopied)
                {
                    // handle copy event
                    isCopied = false;
                }
                else
                {
                    //subject.Project.RootMeta.RootFolder.DefinedFCOByName["Task",
                    //MgaMetaBase task;
                    //if (task.MetaRef == subject.MetaBase.MetaRef)
                    {
                    }
                    // handle new object event
                    bool isBasicTask = (subject.MetaBase.Name == "Task");

                    if (subject.MetaBase.Name == "Task" || subject.MetaBase.Name == "ExecutionTask")
                    {
                        if (subject.MetaBase.Name == "Task" && string.IsNullOrEmpty((subject as MgaFCO).StrAttrByName["COMName"]) == false)
                        {
                            return;
                        }
                        if (subject.MetaBase.Name == "ExecutionTask" && string.IsNullOrEmpty((subject as MgaFCO).StrAttrByName["Invocation"]) == false)
                        {
                            return;
                        }
                        using (InterpreterSelectionForm form = new InterpreterSelectionForm())
                        {
                            form.addon = this;
                            form.Init();

                            HashSet <string> taskKinds = new HashSet <string>()
                            {
                                "ExecutionTask",
                                "Task"
                            };

                            IEnumerable <MgaAtom> taskChildren = subject.ExGetParent().
                                                                 ChildObjects.
                                                                 OfType <MgaAtom>().
                                                                 Where(x => x.ExDstFcos().Count() == 0).
                                                                 Where(x => x.ID != subject.ID).
                                                                 Where(x => taskKinds.Contains(x.Meta.Name));

                            form.lbTasks.Items.Clear();
                            foreach (var currTask in taskChildren)
                            {
                                var atomWrapper = new MgaAtomWrapper(currTask);
                                form.lbTasks.Items.Add(new MgaAtomWrapper(currTask));
                                form.lbTasks.SelectedItem = atomWrapper;
                            }

                            if (form.lbTasks.Items.Count > 0)
                            {
                                form.lbTasks.SetSelected(0, true);
                            }

                            if (!isBasicTask) // remove interpreter selection and reset positions
                            {
                                form.lbInterpreters.Items.Clear();
                                form.lbInterpreters.Visible       = false;
                                form.lblSelectInterpreter.Visible = false;
                                form.chbAutoConnect.Location      = form.label1.Location;
                                form.label1.Location  = form.lblSelectInterpreter.Location;
                                form.lbTasks.Location = form.lbInterpreters.Location;
                            }

                            DialogResult dgr = form.ShowDialog();
                            if (dgr == DialogResult.OK)
                            {
                                if (isBasicTask)
                                {
                                    ComComponent c = form.lbInterpreters.SelectedItem as ComComponent;
                                    try
                                    {
                                        if (c != null &&
                                            c.isValid)
                                        {
                                            (subject as MgaFCO).StrAttrByName["COMName"] = c.ProgId;
                                        }
                                    }
                                    catch
                                    {
                                        MessageBox.Show("Cannot save interpreter settings. 'COMName' is not a parameter of 'Task'.");
                                    }
                                }

                                //Flow
                                if (form.chbAutoConnect.Checked && (form.lbTasks.SelectedItem != null))
                                {
                                    MgaAtomWrapper selectedTask   = form.lbTasks.SelectedItem as MgaAtomWrapper;
                                    MgaAtom        lastInWorkflow = null;

                                    if (selectedTask != null)
                                    {
                                        lastInWorkflow = selectedTask.Atom;
                                    }

                                    if (lastInWorkflow != null)
                                    {
                                        MgaMetaRole role = ((subject.ExGetParent() as MgaModel).
                                                            Meta as MgaMetaModel).RoleByName["Flow"];

                                        (subject.ExGetParent() as MgaModel).CreateSimplerConnDisp(
                                            role,
                                            lastInWorkflow as MgaFCO,
                                            subject as MgaFCO);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // TODO: Handle object events (OR eventMask with the members of objectevent_enum)
            // Warning: Only those events are received that you have subscribed for by setting ComponentConfig.eventMask

            // MessageBox.Show(eventMask.ToString());
        }