コード例 #1
0
ファイル: Composers.cs プロジェクト: bharanijayasuri/umbraco8
        private static void EnableDisableComposers(ICollection <Type> types)
        {
            var enabled = new Dictionary <Type, EnableInfo>();

            // process the enable/disable attributes
            // these two attributes are *not* inherited and apply to *classes* only (not interfaces).
            // remote declarations (when a composer enables/disables *another* composer)
            // have priority over local declarations (when a composer disables itself) so that
            // ppl can enable composers that, by default, are disabled.
            // what happens in case of conflicting remote declarations is unspecified. more
            // precisely, the last declaration to be processed wins, but the order of the
            // declarations depends on the type finder and is unspecified.
            foreach (var composerType in types)
            {
                foreach (var attr in composerType.GetCustomAttributes <EnableAttribute>())
                {
                    var type = attr.EnabledType ?? composerType;
                    if (enabled.TryGetValue(type, out var enableInfo) == false)
                    {
                        enableInfo = enabled[type] = new EnableInfo();
                    }
                    var weight = type == composerType ? 1 : 2;
                    if (enableInfo.Weight > weight)
                    {
                        continue;
                    }

                    enableInfo.Enabled = true;
                    enableInfo.Weight  = weight;
                }
                foreach (var attr in composerType.GetCustomAttributes <DisableAttribute>())
                {
                    var type = attr.DisabledType ?? composerType;
                    if (enabled.TryGetValue(type, out var enableInfo) == false)
                    {
                        enableInfo = enabled[type] = new EnableInfo();
                    }
                    var weight = type == composerType ? 1 : 2;
                    if (enableInfo.Weight > weight)
                    {
                        continue;
                    }

                    enableInfo.Enabled = false;
                    enableInfo.Weight  = weight;
                }
            }

            // remove composers that end up being disabled
            foreach (var kvp in enabled.Where(x => x.Value.Enabled == false))
            {
                types.Remove(kvp.Key);
            }
        }
コード例 #2
0
        private void draw_enabled(TaskVarOp t, Graphics g, int col, int row, Point pt)
        {
            //int exec = focus + 1;
            //int thread = col + 1;
            EnableInfo info = EnableInfo.Error;

            lock (t.entry)
            {
                info = t.entry.enableinfo[col];
            }
            int left   = pt.X + col * col_sz;
            int top    = pt.Y + 1 + row * row_sz;
            int right  = left + col_sz;
            int bottom = top + row_sz - 1;
            int mid    = bottom - (bottom - top) / 4;

            if (info == EnableInfo.Disabled)
            {
                g.FillRectangle(new SolidBrush(disabledcolor),
                                left, top, right - left, bottom - top);
            }
            else if (info == EnableInfo.Enabled)
            {
                g.FillRectangle(new SolidBrush(enabledcolor),
                                left, top, right - left, bottom - top);
            }
            else if (info == EnableInfo.Enable)
            {
                // ALT 1 : smooth
                //Brush b = new LinearGradientBrush(new Point(left, top), new Point(left, bottom),
                //                                                      disabledcolor, enabledcolor);
                //g.FillRectangle(b,
                //   left, top, right-left, bottom-top);

                // ALT2 : triangles
                //g.FillPolygon(disabledbrush, new Point[] {
                //    new Point(left, top), new Point (right, top), new Point(left, bottom)
                //});
                //g.FillPolygon(enabledbrush, new Point[] {
                //    new Point(left, bottom), new Point (right, top), new Point(right, bottom)
                //});

                // ALT3 : middle
                g.FillRectangle(new SolidBrush(disabledcolor),
                                left, top, right - left, mid - top);
                g.FillRectangle(Brushes.DarkGray,
                                left, mid, right - left, bottom - mid);
            }
            else if (info == EnableInfo.Disable)
            {
                g.FillRectangle(new SolidBrush(enabledcolor),
                                left, top, right - left, mid - top);
                g.FillRectangle(Brushes.DarkGray,
                                left, mid, right - left, bottom - mid);
            }
            else if (info == EnableInfo.Error)
            {
                g.FillRectangle(Brushes.Crimson,
                                left, top, right - left, bottom - top);
            }
        }