Ejemplo n.º 1
0
        public static void UnregisterComponentsInGMERegistry()
        {
            MgaRegistrar registrar = new MgaRegistrar();
            CheckGMEInterfaceVersion(registrar);

            registrar.UnregisterComponent(ComponentConfig.progID, ComponentConfig.registrationMode);
        }
Ejemplo n.º 2
0
        public static void UnregisterComponentsInGMERegistry()
        {
            MgaRegistrar registrar = new MgaRegistrar();

            CheckGMEInterfaceVersion(registrar);

            registrar.UnregisterComponent(ComponentConfig.progID, ComponentConfig.registrationMode);
        }
Ejemplo n.º 3
0
 private static void CheckGMEInterfaceVersion(MgaRegistrar registrar)
 {
     if ((int)GMEInterfaceVersion_enum.GMEInterfaceVersion_Current != (int)((IGMEVersionInfo)registrar).version)
     {
         throw new RegistrationException("GMEInterfaceVersion mismatch: this assembly is using " +
                                         (int)GMEInterfaceVersion_enum.GMEInterfaceVersion_Current +
                                         " but the GME interface version is " + (int)((IGMEVersionInfo)registrar).version +
                                         "\n\nPlease install a compatible GME version or update the interop dlls.");
     }
 }
Ejemplo n.º 4
0
 private static void CheckGMEInterfaceVersion(MgaRegistrar registrar)
 {
     if ((int)GMEInterfaceVersion_enum.GMEInterfaceVersion_Current != (int)((IGMEVersionInfo)registrar).version)
     {
         throw new RegistrationException("GMEInterfaceVersion mismatch: this assembly is using " +
             (int)GMEInterfaceVersion_enum.GMEInterfaceVersion_Current +
             " but the GME interface version is " + (int)((IGMEVersionInfo)registrar).version +
             "\n\nPlease install a compatible GME version or update the interop dlls.");
     }
 }
Ejemplo n.º 5
0
        private void LoadInterpreters()
        {
            List<ComComponent> ComComponents = new List<ComComponent>();

            MgaRegistrar registrar = new MgaRegistrar();
            regaccessmode_enum r = regaccessmode_enum.REGACCESS_BOTH;
            IEnumerable components = (IEnumerable)(object)registrar.GetComponentsDisp(r);

            string paradigm = "CyPhyML";

            foreach (string comProgId in components)
            {
                try
                {
                    bool isAssociated;
                    bool canAssociate;

                    registrar.IsAssociated(comProgId, paradigm, out isAssociated, out canAssociate, r);
                    string DllPath = registrar.LocalDllPath[comProgId];

                    componenttype_enum Type;
                    string desc;
                    registrar.QueryComponent(
                        comProgId,
                        out Type,
                        out desc,
                        regaccessmode_enum.REGACCESS_BOTH);

                    bool isInterpreter = false;
                    isInterpreter = (Type == componenttype_enum.COMPONENTTYPE_INTERPRETER);

                    if (canAssociate &&
                        File.Exists(DllPath) &&
                        isInterpreter)
                    {
                        ComComponent component = new ComComponent(comProgId);
                        if (component.isValid)
                        {
                            ComComponents.Add(component);
                        }
                    }
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    // don't add to list
                }
            }

            lbInterpreters.Items.Clear();
            ComComponents.Sort((Comparison<ComComponent>)((a, b) => a.ToString().CompareTo(b.ToString())));
            foreach (ComComponent c in ComComponents)
            {
                lbInterpreters.Items.Add(c);
            }
        }
Ejemplo n.º 6
0
        private void LoadInterpreters()
        {
            List <ComComponent> ComComponents = new List <ComComponent>();

            MgaRegistrar       registrar  = new MgaRegistrar();
            regaccessmode_enum r          = regaccessmode_enum.REGACCESS_BOTH;
            IEnumerable        components = (IEnumerable)(object)registrar.GetComponentsDisp(r);

            string paradigm = "CyPhyML";

            foreach (string comProgId in components)
            {
                try
                {
                    bool isAssociated;
                    bool canAssociate;

                    registrar.IsAssociated(comProgId, paradigm, out isAssociated, out canAssociate, r);
                    string DllPath = registrar.LocalDllPath[comProgId];

                    componenttype_enum Type;
                    string             desc;
                    registrar.QueryComponent(
                        comProgId,
                        out Type,
                        out desc,
                        regaccessmode_enum.REGACCESS_BOTH);

                    bool isInterpreter = false;
                    isInterpreter = (Type == componenttype_enum.COMPONENTTYPE_INTERPRETER);

                    if (canAssociate &&
                        File.Exists(DllPath) &&
                        isInterpreter)
                    {
                        ComComponent component = new ComComponent(comProgId);
                        if (component.isValid)
                        {
                            ComComponents.Add(component);
                        }
                    }
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    // don't add to list
                }
            }

            lbInterpreters.Items.Clear();
            ComComponents.Sort((Comparison <ComComponent>)((a, b) => a.ToString().CompareTo(b.ToString())));
            foreach (ComComponent c in ComComponents)
            {
                lbInterpreters.Items.Add(c);
            }
        }
Ejemplo n.º 7
0
        public static void RegisterComponentsInGMERegistry()
        {
            MgaRegistrar registrar = new MgaRegistrar();
            CheckGMEInterfaceVersion(registrar);
            registrar.RegisterComponent(ComponentConfig.progID, ComponentConfig.componentType, ComponentConfig.componentName, ComponentConfig.registrationMode);

            if (!ComponentConfig.paradigmName.Equals("*"))
            {
                registrar.Associate(
                   ComponentConfig.progID,
                    ComponentConfig.paradigmName,
                    ComponentConfig.registrationMode);
            }
        }
Ejemplo n.º 8
0
        public static void RegisterComponentsInGMERegistry()
        {
            MgaRegistrar registrar = new MgaRegistrar();

            CheckGMEInterfaceVersion(registrar);
            registrar.RegisterComponent(ComponentConfig.progID, ComponentConfig.componentType, ComponentConfig.componentName, ComponentConfig.registrationMode);

            if (!ComponentConfig.paradigmName.Equals("*"))
            {
                registrar.Associate(
                    ComponentConfig.progID,
                    ComponentConfig.paradigmName,
                    ComponentConfig.registrationMode);
            }
        }
Ejemplo n.º 9
0
        protected void InitializeIconPaths(MgaFCO task)
        {
            string allIconPaths = new MgaRegistrar().get_IconPath(regaccessmode_enum.REGACCESS_BOTH);
            string projectDir   = GetDirectoryFromConnStr(task.Project.ProjectConnStr);
            string paradigmDir  = GetDirectoryFromConnStr(task.Project.ParadigmConnStr);

            if (!string.IsNullOrWhiteSpace(allIconPaths) &&
                !string.IsNullOrWhiteSpace(projectDir) &&
                !string.IsNullOrWhiteSpace(paradigmDir))
            {
                allIconPaths   = allIconPaths.Replace("$PROJECTDIR", projectDir);
                allIconPaths   = allIconPaths.Replace("$PARADIGMDIR", paradigmDir);
                this.iconPaths = allIconPaths.Split(';').ToList();
            }
        }
Ejemplo n.º 10
0
		public static void RegisterComponentsInGMERegistry()
		{
			if (ComponentConfig.iconPath == null)
			{
				ComponentConfig.iconPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + '\\' + ComponentConfig.iconName;
			}

			MgaRegistrar registrar = new MgaRegistrar();
			CheckGMEInterfaceVersion(registrar);
			registrar.RegisterComponent(ComponentConfig.progID, ComponentConfig.componentType, ComponentConfig.componentName, ComponentConfig.registrationMode);
			registrar.set_ComponentExtraInfo(ComponentConfig.registrationMode, ComponentConfig.progID, "Icon", ComponentConfig.iconPath);

			if (!ComponentConfig.paradigmName.Equals("*"))
			{
				registrar.Associate(
					 ComponentConfig.progID,
						ComponentConfig.paradigmName,
						ComponentConfig.registrationMode);
			}
		}
Ejemplo n.º 11
0
        public static void RegisterComponentsInGMERegistry()
        {
            if (ComponentConfig.iconPath == null)
            {
                ComponentConfig.iconPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + '\\' + ComponentConfig.iconName;
            }

            MgaRegistrar registrar = new MgaRegistrar();

            CheckGMEInterfaceVersion(registrar);
            registrar.RegisterComponent(ComponentConfig.progID, ComponentConfig.componentType, ComponentConfig.componentName, ComponentConfig.registrationMode);
            registrar.set_ComponentExtraInfo(ComponentConfig.registrationMode, ComponentConfig.progID, "Icon", ComponentConfig.iconPath);
            registrar.set_ComponentExtraInfo(ComponentConfig.registrationMode, ComponentConfig.progID, "Tooltip", ComponentConfig.componentName);

            if (!ComponentConfig.paradigmName.Equals("*"))
            {
                registrar.Associate(
                    ComponentConfig.progID,
                    ComponentConfig.paradigmName,
                    ComponentConfig.registrationMode);
            }
        }
Ejemplo n.º 12
0
        public void Draw(uint hdc)
        {
            // VERY important to cast to int
            System.IntPtr hdcptr;
            unchecked { hdcptr = (System.IntPtr)(int)hdc; }

            // Create graphics object
            Graphics g = Graphics.FromHdc(hdcptr);

            // Set up string format for the label
            StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            // Drawing style
            Pen pen = new Pen(color);
            Brush brush = new SolidBrush(color);
#if DEBUG
            // Draw the place
            g.DrawRectangle(pen, x, y, w, h);
#endif
            Color contentColor = Color.Black;
            string Content = "";
            //if (myobj == null)
            //{
            //  g.Dispose();
            //  return;
            //}
            if (LastMetaKind == "Task")
            {
                Icon icon = null;
                if (interpreters[TaskProgId].isValid)
                {
                    contentColor = Color.Blue;
                    Content = interpreters[TaskProgId].ToolTip;
                    if (string.IsNullOrWhiteSpace(Content))
                    {
                        Content = interpreters[TaskProgId].Name;
                    }
                    if (Content.StartsWith("MGA.Interpreter.", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Content = Content.Substring("MGA.Interpreter.".Length);
                    }
                    MgaRegistrar registrar = new MgaRegistrar();
                    string DllFileName = registrar.LocalDllPath[TaskProgId];
                    try
                    {
                        // TODO: we should read this from the registry...
                        // if the value is ,IDI_COMPICON get the icon from the dll
                        string iconFileNameGuess = Path.ChangeExtension(DllFileName, ".ico");
                        var temp = registrar.get_IconPath(regaccessmode_enum.REGACCESS_USER);

                        if (File.Exists(iconFileNameGuess))
                        {
                            icon = Icon.ExtractAssociatedIcon(iconFileNameGuess);
                        }
                        else
                        {
                            icon = Icon.ExtractAssociatedIcon(DllFileName);
                        }
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    contentColor = Color.Red;
                    Content = "INVALID" + Environment.NewLine + TaskProgId;
                    icon = InvalidTask;
                }
                using (Icon icon2 = new Icon(icon, IconWidth, IconHeight))
                    g.DrawIcon(icon2, new Rectangle(x, y, IconWidth, IconHeight));

                g.DrawString(
                    Content,
                    SystemFonts.DefaultFont,
                    new SolidBrush(contentColor),
                    new RectangleF(
                        x,
                        y + h + 15,
                        g.MeasureString(Content, SystemFonts.DefaultFont).Width,
                        g.MeasureString(Content, SystemFonts.DefaultFont).Height),
                    sf);

                /*
                g.DrawString(
                    Parameters,
                    SystemFonts.DefaultFont,
                    new SolidBrush(Color.DarkGreen),
                    new RectangleF(
                        x,
                        y + h + 25,
                        g.MeasureString(Parameters, SystemFonts.DefaultFont).Width,
                        g.MeasureString(Parameters, SystemFonts.DefaultFont).Height),
                    sf);
                 */
            }
            else if (LastMetaKind == "WorkflowRef")
            {
                int i = 0;
                Icon icon = null;

                foreach (TaskInfo taskInfo in workflow)
                {
                    if (taskInfo.IsComComponent)
                    {
                        var comComponent = new ComComponent(taskInfo.COMName);
                        if (comComponent.isValid)
                        {
                            MgaRegistrar registrar = new MgaRegistrar();
                            string DllFileName = registrar.LocalDllPath[comComponent.ProgId];
                            try
                            {
                                // TODO: we should read this from the registry...
                                // if the value is ,IDI_COMPICON get the icon from the dll
                                string iconFileNameGuess = Path.ChangeExtension(DllFileName, ".ico");

                                if (File.Exists(iconFileNameGuess))
                                {
                                    icon = Icon.ExtractAssociatedIcon(iconFileNameGuess);
                                }
                                else
                                {
                                    icon = Icon.ExtractAssociatedIcon(DllFileName);
                                }
                            }
                            catch (ArgumentException)
                            {
                            }
                        }
                        else
                        {
                            // draw error image
                            icon = InvalidTask;
                        }
                    }
                    else
                    {
                        string iconFileName = taskInfo.IconName;
                        if (!string.IsNullOrWhiteSpace(iconFileName) &&
                            File.Exists(iconFileName))
                        {
                            Bitmap bitmap = (Bitmap)Image.FromFile(iconFileName);
                            icon = Icon.FromHandle(bitmap.GetHicon());
                        }
                        else
                        {
                            icon = InvalidTask;
                        }
                    }

                    try
                    {
                        int IconStartX = x + (IconWidth + TaskPadding) * i;
                        g.DrawIcon(new Icon(icon, IconWidth, IconHeight),
                            new Rectangle(IconStartX, y, IconWidth, IconHeight));

                        if (taskInfo != workflow.Reverse().FirstOrDefault())
                        {
                            Pen p = new Pen(Color.Black, LineWidth);
                            p.StartCap = LineStartCap;
                            p.EndCap = LineEndCap;
                            int LineStartX = IconStartX + IconWidth;
                            g.DrawLine(p,
                                new Point(
                                    LineStartX + LineStartPadding,
                                    y + IconHeight / 2),
                                new Point(
                                    LineStartX + TaskPadding - LineEndPadding,
                                    y + IconHeight / 2));
                        }
                        i++;
                    }
                    catch (ArgumentException)
                    {
                    }

                }
                if (workflow != null)
                {
                    if (workflow.Count == 0 ||
                        icon == null)
                    {
                        icon = UndefinedWorkFlow;
                        g.DrawIcon(
                            new Icon(icon, IconWidth, IconHeight),
                            new Rectangle(x, y, IconWidth, IconHeight));
                    }
                }
            }

            // Draw the label
            g.DrawString(name, SystemFonts.DefaultFont, new SolidBrush(labelColor), 
                new RectangleF(x + w / 2 - LabelSize.Width / 2, y + h + 5, LabelSize.Width, 10), sf);

            sf.Dispose();
            g.Dispose();
        }
Ejemplo n.º 13
0
        protected void InitializeIconPaths(MgaFCO task)
        {
            string allIconPaths = new MgaRegistrar().get_IconPath(regaccessmode_enum.REGACCESS_BOTH);
            string projectDir = GetDirectoryFromConnStr(task.Project.ProjectConnStr);
            string paradigmDir = GetDirectoryFromConnStr(task.Project.ParadigmConnStr);

            if (!string.IsNullOrWhiteSpace(allIconPaths) &&
                !string.IsNullOrWhiteSpace(projectDir) &&
                !string.IsNullOrWhiteSpace(paradigmDir))
            {
                allIconPaths = allIconPaths.Replace("$PROJECTDIR", projectDir);
                allIconPaths = allIconPaths.Replace("$PARADIGMDIR", paradigmDir);
                this.iconPaths = allIconPaths.Split(';').ToList();
            }
        }
Ejemplo n.º 14
0
        public void Draw(uint hdc)
        {
            // VERY important to cast to int
            System.IntPtr hdcptr;
            unchecked { hdcptr = (System.IntPtr)(int) hdc; }

            // Create graphics object
            Graphics g = Graphics.FromHdc(hdcptr);

            // Set up string format for the label
            StringFormat sf = new StringFormat(StringFormatFlags.NoClip);

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            // Drawing style
            // n.b. GME decorators are based on pixels and shouldn't be scaled by DPI changes
            Font  font  = new Font("Arial", 12f, GraphicsUnit.Pixel);
            Pen   pen   = new Pen(color);
            Brush brush = new SolidBrush(color);

#if DEBUG
            // Draw the place
            g.DrawRectangle(pen, x, y, w, h);
#endif
            Color  contentColor = Color.Black;
            string Content      = "";
            //if (myobj == null)
            //{
            //  g.Dispose();
            //  return;
            //}
            if (FCOKind == "Task")
            {
                Icon icon = null;
                if (interpreters[TaskProgId].isValid)
                {
                    contentColor = Color.Blue;
                    Content      = interpreters[TaskProgId].ToolTip;
                    if (string.IsNullOrWhiteSpace(Content))
                    {
                        Content = interpreters[TaskProgId].Name;
                    }
                    if (Content.StartsWith("MGA.Interpreter.", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Content = Content.Substring("MGA.Interpreter.".Length);
                    }
                    MgaRegistrar registrar   = new MgaRegistrar();
                    string       DllFileName = registrar.LocalDllPath[TaskProgId];
                    try
                    {
                        // if the value is ,IDI_COMPICON get the icon from the dll
                        string iconFileNameGuess = Path.ChangeExtension(DllFileName, ".ico");
                        string iconPath          = null;
                        try
                        {
                            iconPath = registrar.ComponentExtraInfo[regaccessmode_enum.REGACCESS_BOTH, TaskProgId, "Icon"];
                        }
                        catch (COMException)
                        {
                        }

                        if (File.Exists(iconFileNameGuess))
                        {
                            icon = Icon.ExtractAssociatedIcon(iconFileNameGuess);
                        }
                        else if (iconPath != null && File.Exists(iconPath))
                        {
                            icon = Icon.ExtractAssociatedIcon(iconPath);
                        }
                        else
                        {
                            icon = Icon.ExtractAssociatedIcon(DllFileName);
                        }
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    contentColor = Color.Red;
                    Content      = "INVALID" + Environment.NewLine + TaskProgId;
                    icon         = InvalidTask;
                }
                using (Icon icon2 = new Icon(icon, IconWidth, IconHeight))
                    g.DrawIcon(icon2, new Rectangle(x, y, IconWidth, IconHeight));

                g.DrawString(
                    Content,
                    font,
                    new SolidBrush(contentColor),
                    x + w / 2.0f,
                    y + h + LabelSize.Height * 1.2f, sf);
            }
            else if (FCOKind == "WorkflowRef")
            {
                int  i    = 0;
                Icon icon = null;

                foreach (TaskInfo taskInfo in workflow)
                {
                    Bitmap bitmap = null;
                    if (taskInfo.IsComComponent)
                    {
                        var comComponent = new ComComponent(taskInfo.COMName);
                        // FIXME cache this per-process for performance
                        if (comComponent.isValid)
                        {
                            MgaRegistrar registrar   = new MgaRegistrar();
                            string       DllFileName = registrar.LocalDllPath[comComponent.ProgId];
                            try
                            {
                                // if the value is ,IDI_COMPICON get the icon from the dll
                                string iconFileNameGuess = Path.ChangeExtension(DllFileName, ".ico");
                                string iconPath          = null;
                                try
                                {
                                    iconPath = registrar.ComponentExtraInfo[regaccessmode_enum.REGACCESS_BOTH, taskInfo.COMName, "Icon"];
                                }
                                catch (COMException)
                                {
                                }

                                if (File.Exists(iconFileNameGuess))
                                {
                                    icon = Icon.ExtractAssociatedIcon(iconFileNameGuess);
                                }
                                else if (iconPath != null && File.Exists(iconPath))
                                {
                                    icon = Icon.ExtractAssociatedIcon(iconPath);
                                }
                                else
                                {
                                    icon = Icon.ExtractAssociatedIcon(DllFileName);
                                }
                            }
                            catch (ArgumentException)
                            {
                            }
                        }
                        else
                        {
                            // draw error image
                            icon = new Icon(InvalidTask, InvalidTask.Size);
                        }
                    }
                    else
                    {
                        string iconFileName = taskInfo.IconName;
                        if (!string.IsNullOrWhiteSpace(iconFileName) &&
                            File.Exists(iconFileName))
                        {
                            bitmap = (Bitmap)Image.FromFile(iconFileName);
                            icon   = Icon.FromHandle(bitmap.GetHicon());
                        }
                        else
                        {
                            icon = new Icon(InvalidTask, InvalidTask.Size);
                        }
                    }

                    try
                    {
                        int IconStartX = x + (IconWidth + TaskPadding) * i;
                        var placedIcon = new Icon(icon, IconWidth, IconHeight);
                        using (placedIcon)
                        {
                            g.DrawIcon(placedIcon, new Rectangle(IconStartX, y, IconWidth, IconHeight));
                        }

                        if (taskInfo != workflow.Last())
                        {
                            Pen p = new Pen(Color.Black, LineWidth * g.DpiX / 96);
                            using (p)
                            {
                                p.StartCap = LineStartCap;
                                p.EndCap   = LineEndCap;
                                int LineStartX = IconStartX + IconWidth;
                                g.DrawLine(p,
                                           new Point(
                                               LineStartX + LineStartPadding,
                                               y + IconHeight / 2),
                                           new Point(
                                               LineStartX + TaskPadding - LineEndPadding,
                                               y + IconHeight / 2));
                            }
                        }
                        i++;
                    }
                    catch (ArgumentException)
                    {
                    }
                    finally
                    {
                        if (bitmap != null)
                        {
                            bitmap.Dispose();
                            bitmap = null;
                        }
                        if (icon != null)
                        {
                            icon.Dispose();
                            icon = null;
                        }
                    }
                }
                if (workflow.Count == 0)
                {
                    icon = UndefinedWorkFlow;
                    g.DrawIcon(
                        icon, // new Icon(icon, IconWidth, IconHeight),
                        new Rectangle(x, y, IconWidth, IconHeight));
                }
            }
            if (this.MetaKind == "MetricConstraint")
            {
                string symbol = ">";
                if (MetricConstraint_TargetType == "Must Exceed")
                {
                    symbol = ">";
                }
                else if (MetricConstraint_TargetType == "Must Not Exceed")
                {
                    symbol = "\u2264";
                }
                else if (MetricConstraint_TargetType == "Must Equal")
                {
                    symbol = "=";
                }
                using (Font symbolFont = new Font(SystemFonts.DefaultFont.FontFamily, 40f, GraphicsUnit.Pixel))
                    using (StringFormat symbolFormat = new StringFormat(StringFormatFlags.NoClip))
                    {
                        g.TextRenderingHint        = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        symbolFormat.Alignment     = StringAlignment.Center;
                        symbolFormat.LineAlignment = StringAlignment.Center;

                        g.DrawString(symbol, symbolFont, new SolidBrush(labelColor), new PointF(x + w / 2.0f, y + h / 2.0f), symbolFormat);
                    }
            }

            // Draw the label
            g.DrawString(name, font, new SolidBrush(labelColor),
                         new RectangleF(x + w / 2.0f - LabelSize.Width / 2.0f, y + h, LabelSize.Width, LabelSize.Height), sf);

            font.Dispose();
            sf.Dispose();
            g.Dispose();
        }
Ejemplo n.º 15
0
        private void DrawWorkflowRef(Graphics g)
        {
            int  i    = 0;
            Icon icon = null;

            foreach (TaskInfo taskInfo in workflow)
            {
                IntPtr hIcon  = IntPtr.Zero;
                Bitmap bitmap = null;
                if (taskInfo.IsComComponent)
                {
                    var comComponent = new ComComponent(taskInfo.COMName);
                    // FIXME cache this per-process for performance
                    if (comComponent.isValid)
                    {
                        MgaRegistrar registrar   = new MgaRegistrar();
                        string       DllFileName = registrar.LocalDllPath[comComponent.ProgId];
                        try
                        {
                            // if the value is ,IDI_COMPICON get the icon from the dll
                            string iconFileNameGuess = Path.ChangeExtension(DllFileName, ".ico");
                            string iconPath          = null;
                            try
                            {
                                iconPath = registrar.ComponentExtraInfo[regaccessmode_enum.REGACCESS_BOTH, taskInfo.COMName, "Icon"];
                            }
                            catch (COMException)
                            {
                            }

                            if (File.Exists(iconFileNameGuess))
                            {
                                icon = Icon.ExtractAssociatedIcon(iconFileNameGuess);
                            }
                            else if (iconPath != null && File.Exists(iconPath))
                            {
                                icon = Icon.ExtractAssociatedIcon(iconPath);
                            }
                            else
                            {
                                icon = Icon.ExtractAssociatedIcon(DllFileName);
                            }
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                    else
                    {
                        // draw error image
                        icon = new Icon(InvalidTask, InvalidTask.Size);
                    }
                }
                else
                {
                    string iconFileName = taskInfo.IconName;
                    if (!string.IsNullOrWhiteSpace(iconFileName) &&
                        File.Exists(iconFileName))
                    {
                        bitmap = (Bitmap)Image.FromFile(iconFileName);
                        hIcon  = bitmap.GetHicon();
                        icon   = Icon.FromHandle(hIcon);
                    }
                    else
                    {
                        icon = new Icon(InvalidTask, InvalidTask.Size);
                    }
                }

                try
                {
                    int IconStartX = x + (IconWidth + TaskPadding) * i;
                    var placedIcon = new Icon(icon, IconWidth, IconHeight);
                    using (placedIcon)
                    {
                        g.DrawIcon(placedIcon, new Rectangle(IconStartX, y, IconWidth, IconHeight));
                    }

                    if (taskInfo != workflow.Last())
                    {
                        Pen p = new Pen(Color.Black, LineWidth * g.DpiX / 96);
                        using (p)
                        {
                            p.StartCap = LineStartCap;
                            p.EndCap   = LineEndCap;
                            int LineStartX = IconStartX + IconWidth;
                            g.DrawLine(p,
                                       new Point(
                                           LineStartX + LineStartPadding,
                                           y + IconHeight / 2),
                                       new Point(
                                           LineStartX + TaskPadding - LineEndPadding,
                                           y + IconHeight / 2));
                        }
                    }
                    i++;
                }
                catch (ArgumentException)
                {
                }
                finally
                {
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                        bitmap = null;
                    }
                    if (icon != null)
                    {
                        icon.Dispose();
                        icon = null;
                    }
                    if (hIcon != IntPtr.Zero)
                    {
                        if (DestroyIcon(hIcon) == false)
                        {
                            throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
                        }
                    }
                }
            }
            if (workflow.Count == 0)
            {
                icon = UndefinedWorkFlow;
                g.DrawIcon(
                    icon, // new Icon(icon, IconWidth, IconHeight),
                    new Rectangle(x, y, IconWidth, IconHeight));
            }
        }
Ejemplo n.º 16
0
        public void Draw(uint hdc)
        {
            // VERY important to cast to int
            System.IntPtr hdcptr;
            unchecked { hdcptr = (System.IntPtr)(int) hdc; }

            // Create graphics object
            Graphics g = Graphics.FromHdc(hdcptr);

            // Set up string format for the label
            StringFormat sf = new StringFormat(StringFormatFlags.NoClip);

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            // Drawing style
            // n.b. GME decorators are based on pixels and shouldn't be scaled by DPI changes
            Font font = new Font("Arial", 12f, GraphicsUnit.Pixel);

#if DEBUG
            Pen pen = new Pen(color);
            // Draw the place
            using (pen) {
                g.DrawRectangle(pen, x, y, w, h);
            }
#endif
            Color  contentColor = Color.Black;
            string Content      = "";
            //if (myobj == null)
            //{
            //  g.Dispose();
            //  return;
            //}
            if (FCOKind == "Task")
            {
                Icon icon = null;
                if (interpreters[TaskProgId].isValid)
                {
                    contentColor = Color.Blue;
                    Content      = interpreters[TaskProgId].ToolTip;
                    if (string.IsNullOrWhiteSpace(Content))
                    {
                        Content = interpreters[TaskProgId].Name;
                    }
                    if (Content.StartsWith("MGA.Interpreter.", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Content = Content.Substring("MGA.Interpreter.".Length);
                    }
                    MgaRegistrar registrar   = new MgaRegistrar();
                    string       DllFileName = registrar.LocalDllPath[TaskProgId];
                    try
                    {
                        // if the value is ,IDI_COMPICON get the icon from the dll
                        string iconFileNameGuess = Path.ChangeExtension(DllFileName, ".ico");
                        string iconPath          = null;
                        try
                        {
                            iconPath = registrar.ComponentExtraInfo[regaccessmode_enum.REGACCESS_BOTH, TaskProgId, "Icon"];
                        }
                        catch (COMException)
                        {
                        }

                        if (File.Exists(iconFileNameGuess))
                        {
                            icon = Icon.ExtractAssociatedIcon(iconFileNameGuess);
                        }
                        else if (iconPath != null && File.Exists(iconPath))
                        {
                            icon = Icon.ExtractAssociatedIcon(iconPath);
                        }
                        else
                        {
                            icon = Icon.ExtractAssociatedIcon(DllFileName);
                        }
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    contentColor = Color.Red;
                    Content      = "INVALID" + Environment.NewLine + TaskProgId;
                    icon         = InvalidTask;
                }
                using (Icon icon2 = new Icon(icon, IconWidth, IconHeight))
                    g.DrawIcon(icon2, new Rectangle(x, y, IconWidth, IconHeight));

                g.DrawString(
                    Content,
                    font,
                    new SolidBrush(contentColor),
                    x + w / 2.0f,
                    y + h + LabelSize.Height * 1.2f, sf);
            }
            else if (FCOKind == "WorkflowRef")
            {
                DrawWorkflowRef(g);
            }
            if (this.MetaKind == "MetricConstraint")
            {
                string symbol = ">";
                if (MetricConstraint_TargetType == "Must Exceed")
                {
                    symbol = ">";
                }
                else if (MetricConstraint_TargetType == "Must Not Exceed")
                {
                    symbol = "\u2264";
                }
                else if (MetricConstraint_TargetType == "Must Equal")
                {
                    symbol = "=";
                }
                using (Font symbolFont = new Font(SystemFonts.DefaultFont.FontFamily, 40f, GraphicsUnit.Pixel))
                    using (StringFormat symbolFormat = new StringFormat(StringFormatFlags.NoClip))
                    {
                        g.TextRenderingHint        = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        symbolFormat.Alignment     = StringAlignment.Center;
                        symbolFormat.LineAlignment = StringAlignment.Center;

                        using (var brush = new SolidBrush(labelColor))
                        {
                            g.DrawString(symbol, symbolFont, brush, new PointF(x + w / 2.0f, y + h / 2.0f), symbolFormat);
                        }
                    }
            }

            // Draw the label
            using (var brush = new SolidBrush(labelColor))
            {
                g.DrawString(name, font, brush,
                             new RectangleF(x + w / 2.0f - LabelSize.Width / 2.0f, y + h, LabelSize.Width, LabelSize.Height), sf);
            }

            font.Dispose();
            sf.Dispose();
            g.Dispose();
        }
        public DefaultBitmapDecorator(GenericDecorator decorator,
            IntPtr parentHwnd, MgaFCO fco, MgaMetaFCO metafco, MgaProject project, IBackroundDraw backgrounddraw, Type formType = null)
            : base(parentHwnd, fco, project, formType != null)
        {
            string iconName;
            decorator.GetPreference(out iconName, "icon");
            string defaultIconName = iconName;

            if (fco != null)
            {
                string kind = fco.Meta.Name;
                if (kind == "ParkingSign")
                {
                    iconName = GetParkingSignIcon(fco);
                }
                else if (kind == "FloodSign")
                {
                    iconName = GetFloodSignIcon(fco);
                }
                else if (kind == "StreetSign")
                {
                    iconName = GetStreetSignIcon(fco);
                }
                // else fall through to the default icon
            }

            this.backgrounddraw = backgrounddraw;

            this.formType = formType;

            string projectDir = Path.GetDirectoryName(project.ProjectConnStr.Substring(4));
            string paradigmDir = Path.GetDirectoryName(project.ParadigmConnStr.Substring(4));

            MgaRegistrar registrar = new MgaRegistrar();
            StringBuilder iconPath = new StringBuilder(registrar.IconPath[regaccessmode_enum.REGACCESS_BOTH]);

            iconPath.Replace("$PROJECTDIR", projectDir);
            iconPath.Replace("$PARADIGMDIR", paradigmDir);

            search_paths = iconPath.ToString().Split(';');

            foreach (string path in search_paths)
            {
                string fileName = Path.Combine(path, iconName);
                if (File.Exists(fileName))
                {
                    image = Image.FromFile(fileName);
                    break;
                }
            }

            if (image == null) // look at the default
            {
                foreach (string path in search_paths)
                {
                    string fileName = Path.Combine(path, defaultIconName);
                    if (File.Exists(fileName))
                    {
                        image = Image.FromFile(fileName);
                        break;
                    }
                }
            }

            if (image == null)
            {
                image = LoadImage(defaultIconStr);
                default_image = image;
            }

            if (fco != null)
            {
                fcoName = fco.Name;
                //fcoName = String.IsNullOrEmpty(metafco.DisplayedName) ? metafco.Name : metafco.DisplayedName;

                if (fco.ObjType == objtype_enum.OBJTYPE_REFERENCE)
                {

                    MgaReference reference = fco as MgaReference;
                    if (reference.Referred == null)
                    {
                        Embellish = EmbellishType.NullReference;
                    }
                    else
                    {
                        Embellish = EmbellishType.Reference;
                    }

                } else  if (fco.IsInstance)
                {
                    // instance

                    Embellish = EmbellishType.Instance;
                }
                else if (fco.DerivedFrom != null)
                {
                    // Subtype
                    Embellish = EmbellishType.SubType;
                }
                else if (fco.DerivedObjects.Count != 0)
                {
                    Embellish = EmbellishType.Type;
                }
                else
                {
                    Embellish = EmbellishType.None;
                }
            }
            else
            {
                fcoName = String.IsNullOrEmpty(metafco.DisplayedName) ? metafco.Name : metafco.DisplayedName;
            }
        }