Example #1
0
 public MLUiHost(MLPlugin plugin, OnContextMenuAdd callback, OnColumnItemAdd _columnAdd, GetImageDelegate _getImagecallback, OnLogDelegate _logCallback)
 {
     _getImage = _getImagecallback;
     _plugin = plugin;
     OnContextAdd = callback;
     OnColumnAdd = _columnAdd;
     logCallback = _logCallback;
 }
Example #2
0
 public MLUiHost(MLPlugin plugin, OnContextMenuAdd callback, OnColumnItemAdd _columnAdd, GetImageDelegate _getImagecallback, OnLogDelegate _logCallback)
 {
     _getImage    = _getImagecallback;
     _plugin      = plugin;
     OnContextAdd = callback;
     OnColumnAdd  = _columnAdd;
     logCallback  = _logCallback;
 }
Example #3
0
 public static void LoadCommandBars(string xmlCustomUI, GetImageDelegate getImage)
 {
     string dnaLibraryWrapper = string.Format(@"<DnaLibrary><CustomUI>{0}</CustomUI></DnaLibrary>", xmlCustomUI);
     using (StringReader sr = new StringReader(dnaLibraryWrapper))
     {
         XmlSerializer serializer = new DnaLibrarySerializer();
         // TODO: Check for and display errors....
         DnaLibrary dnaLibrary = (DnaLibrary)serializer.Deserialize(sr);
         LoadCommandBars(dnaLibrary.CustomUIs[0], getImage);
     }
 }
Example #4
0
        public static void LoadCommandBars(string xmlCustomUI, GetImageDelegate getImage)
        {
            string dnaLibraryWrapper = string.Format(@"<DnaLibrary><CustomUI>{0}</CustomUI></DnaLibrary>", xmlCustomUI);

            using (StringReader sr = new StringReader(dnaLibraryWrapper))
            {
                XmlSerializer serializer = new DnaLibrarySerializer();
                // TODO: Check for and display errors....
                DnaLibrary dnaLibrary = (DnaLibrary)serializer.Deserialize(sr);
                LoadCommandBars(dnaLibrary.CustomUIs[0], getImage);
            }
        }
        private static void TryUpdatingTexture(GetImageDelegate func, ref Bitmap bimg, ref Texture2D tex)
        {
            try {
                Bitmap temp;
                var    err = func(out temp);

                if (err == ErrorCode.None)
                {
                    if (bimg != null && temp.Timestamp <= bimg.Timestamp)
                    {
                        return;
                    }
                    bimg = temp;

                    if (bimg.Width == 0 || bimg.Height == 0)
                    {
                        return;
                    }

                    if (tex != null && (tex.width != bimg.Width || tex.height != bimg.Height))
                    {
                        Texture2D.Destroy(tex);
                        tex = null;
                    }

                    if (tex == null)
                    {
                        tex = new Texture2D(bimg.Width, bimg.Height, TextureFormat.RGB24, false);
                    }

                    tex.LoadRawTextureData(bimg.ImageData.data, (int)bimg.ImageData.length);
                    tex.Apply();
                }
                else
                {
                    //... log?
                }
            }
            catch (Exception e)
            {
                Debug.Log("Error trying to load eyes image bitmap: " + e);
            }
        }
Example #6
0
        internal static void LoadCommandBars(XmlNode xmlCustomUI, GetImageDelegate getImage)
        {
            if (xmlCustomUI.NamespaceURI != "http://schemas.excel-dna.net/office/2003/01/commandbars")
            {
                // Unsupported version ....
                // TODO: Log display ....?
                Debug.Print("Unsupported commandBars version.");
                return;
            }

            Application excelApp = new Application(ExcelDnaUtil.Application);

            loadedCustomUIs.Add(xmlCustomUI);
            try
            {
                AddCommandBarControls(excelApp, xmlCustomUI.ChildNodes, getImage);
            }
            catch (Exception e)
            {
                // Suppress exceptions
                Debug.Print("ExcelCommandBars: Error adding controls: {0}", e);
            }
        }
Example #7
0
        internal static void LoadCommandBars(XmlNode xmlCustomUI, GetImageDelegate getImage)
        {
            if (xmlCustomUI.NamespaceURI != "http://schemas.excel-dna.net/office/2003/01/commandbars")
            {
                // Unsupported version ....
                // TODO: Log display ....?
                Debug.Print("Unsupported commandBars version.");
                return;
            }

            Application excelApp = new Application(ExcelDnaUtil.Application);

            loadedCustomUIs.Add(xmlCustomUI);
            try
            {
                AddCommandBarControls(excelApp, xmlCustomUI.ChildNodes, getImage);
            }
            catch (Exception e)
            {
                // Suppress exceptions
                Debug.Print("ExcelCommandBars: Error adding controls: {0}", e);
            }
        }
Example #8
0
        private static void ApplyControlAttribute(CommandBarControl control, string attribute, string value, GetImageDelegate getImage)
        {
            switch (attribute)
            {
            case "caption":
                control.Caption = value;
                break;

            case "height":
                int height;
                if (int.TryParse(value, out height))
                {
                    control.Height = height;
                }
                else
                {
                    Debug.Print("Could not parse 'height' attribute: {0}", value);
                }
                break;

            case "onAction":
                control.OnAction = value;
                break;

            case "enabled":
                bool enabled;
                if (bool.TryParse(value, out enabled))
                {
                    control.Enabled = enabled;
                }
                else
                {
                    Debug.Print("Could not parse 'enabled' attribute: {0}", value);
                }
                break;

            case "beginGroup":
                bool beginGroup;
                if (bool.TryParse(value, out beginGroup))
                {
                    control.BeginGroup = beginGroup;
                }
                else
                {
                    Debug.Print("Could not parse 'beginGroup' attribute: {0}", value);
                }
                break;

            case "helpFile":
                control.HelpFile = value;
                break;

            case "helpContextId":
                int helpContextId;
                if (int.TryParse(value, out helpContextId))
                {
                    control.HelpContextId = helpContextId;
                }
                else
                {
                    Debug.Print("Could not parse 'helpContextId' attribute: {0}", value);
                }
                break;

            case "tag":
                control.Tag = value;
                break;

            case "tooltipText":
                control.TooltipText = value;
                break;

            case "shortcutText":
                if (control is CommandBarButton)
                {
                    (control as CommandBarButton).ShortcutText = value;
                }
                else
                {
                    Debug.Print("shortcutText only supported on Buttons");
                }
                break;

            case "faceId":
                if (control is CommandBarButton)
                {
                    int faceId;
                    if (int.TryParse(value, out faceId))
                    {
                        (control as CommandBarButton).FaceId = faceId;
                    }
                    else
                    {
                        Debug.Print("Could not parse 'faceId' attribute: {0}", value);
                    }
                }
                else
                {
                    Debug.Print("faceId only supported on Buttons");
                }
                break;

            case "image":
                if (control is CommandBarButton)
                {
                    Bitmap image = getImage(value);
                    if (image != null)
                    {
                        (control as CommandBarButton).SetButtonImage(image);
                    }
                    else
                    {
                        Debug.Print("Could not find or load image {0}", value);
                    }
                }
                else
                {
                    Debug.Print("image only supported on Buttons");
                }
                break;

            case "style":
            case "MsoButtonStyle":      // Compatible with original style code.
                if (control is CommandBarButton)
                {
                    if (Enum.IsDefined(typeof(MsoButtonStyle), value))
                    {
                        (control as CommandBarButton).Style = (MsoButtonStyle)Enum.Parse(typeof(MsoButtonStyle), value, false);
                    }
                    else
                    {
                        (control as CommandBarButton).Style = MsoButtonStyle.msoButtonAutomatic;
                    }
                }
                else
                {
                    Debug.Print("style only supported on Buttons");
                }
                break;

            default:
                Debug.Print("Unknown attribute '{0}' - ignoring.", attribute);
                break;
            }
        }
Example #9
0
 private static void ApplyControlAttributes(CommandBarControl control, XmlNode xmlNode, GetImageDelegate getImage)
 {
     foreach (XmlAttribute att in xmlNode.Attributes)
     {
         ApplyControlAttribute(control, att.Name, att.Value, getImage);
     }
 }
Example #10
0
 private static void AddControl(CommandBarControls parentControls, XmlNode xmlNode, GetImageDelegate getImage)
 {
     if (xmlNode.Name == "popup")
     {
         string          controlName = xmlNode.Attributes["caption"].Value;
         object          before      = ReadControlBeforeAttribute(xmlNode);
         CommandBarPopup newPopup    = parentControls.AddPopup(controlName, before);
         ApplyControlAttributes(newPopup, xmlNode, getImage);
         AddControls(newPopup.Controls, xmlNode.ChildNodes, getImage);
     }
     else if (xmlNode.Name == "button")
     {
         object           before    = ReadControlBeforeAttribute(xmlNode);
         CommandBarButton newButton = parentControls.AddButton(before);
         ApplyControlAttributes(newButton, xmlNode, getImage);
     }
 }
Example #11
0
 private static void AddControls(CommandBarControls parentControls, XmlNodeList xmlNodes, GetImageDelegate getImage)
 {
     foreach (XmlNode childNode in xmlNodes)
     {
         AddControl(parentControls, childNode, getImage);
     }
 }
 public override void LoadCommandBars(string xmlCustomUI, GetImageDelegate getImage)
 {
     ExcelCommandBarUtil.LoadCommandBars(xmlCustomUI, getImage);
 }
Example #13
0
 //// We cannot rely only on name to recover the proper CommandBar so we have the possibility to use the ID (which is used in priority).
 //// Indeed there are two CommandBar for "Cell" see  http://msdn.microsoft.com/en-us/library/office/gg469862(v=office.14).aspx
 //// However, at the time of the writing there is a mistake: "Application.CommandBars(Application.CommandBars("Cell").Index + 3)" is false in practice
 //private static CommandBar GetCommandBarFromIdOrName(Application excelApp,XmlAttributeCollection nodeAttributes, out string barName)
 //{
 //    var id =  nodeAttributes["id"];
 //    var name = nodeAttributes["name"];
 //    if(name ==null) throw new ArgumentException("commandBar attributes must contain name");
 //    barName = name.Value;
 //    if (id != null)
 //    {
 //        string barId = id.Value;
 //        CommandBar bar = null;
 //        for (int i = 1; i <= excelApp.CommandBars.Count; i++)
 //        {
 //            if (excelApp.CommandBars[i].Id == barId)
 //            {
 //                bar = excelApp.CommandBars[i];
 //                break;
 //            }
 //        }
 //        return bar;
 //    }
 //    else
 //    {
 //        CommandBar bar = null;
 //        for (int i = 1; i <= excelApp.CommandBars.Count; i++)
 //        {
 //            if (excelApp.CommandBars[i].Name == barName)
 //            {
 //                bar = excelApp.CommandBars[i];
 //                break;
 //            }
 //        }
 //        return bar;
 //    }
 //}
 private static void AddControls(CommandBarControls parentControls, XmlNodeList xmlNodes, GetImageDelegate getImage)
 {
     foreach (XmlNode childNode in xmlNodes)
     {
         AddControl(parentControls, childNode, getImage);
     }
 }
Example #14
0
        private static void AddCommandBarControls(Application excelApp, XmlNodeList xmlNodes, GetImageDelegate getImage)
        {
            foreach (XmlNode childNode in xmlNodes)
            {
                if (childNode.Name == "commandBar")
                {
                    string barName;
                    CommandBar bar = GetCommandBarFromIdOrName(excelApp, childNode.Attributes, out barName);
                    if (bar != null)
                    {
                        AddControls(bar.Controls, childNode.ChildNodes, getImage);
                    }
                    else
                    {
                        MsoBarPosition barPosition = MsoBarPosition.msoBarLeft;
                        XmlAttribute posAttribute = childNode.Attributes["position"];
                        if (posAttribute == null)
                        {
                            // Compatible with original patch
                            posAttribute = childNode.Attributes["MsoBarPosition"];
                        }
                        if (posAttribute != null)
                        {
                            if (Enum.IsDefined(typeof(MsoBarPosition), posAttribute.Value))
                                barPosition = (MsoBarPosition)Enum.Parse(typeof(MsoBarPosition), posAttribute.Value, false);
                        }

                        bar = excelApp.CommandBars.Add(barName, barPosition);
                        AddControls(bar.Controls, childNode.ChildNodes, getImage);
                    }

                }
            }
        }
Example #15
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
        {
            _context = context;

            ImageRequestState state = new ImageRequestState();

            string quality = "";
            string format  = "png";
            int    dotPos  = context.Request["quality_format"].IndexOf(".");

            if (dotPos != -1)
            {
                quality = context.Request["quality_format"].Substring(0, dotPos);
                format  = context.Request["quality_format"].Substring(dotPos + 1);
            }
            else
            {
                quality = context.Request["quality_format"];
            }

            if (string.IsNullOrEmpty(context.Request["identifier"]) || string.IsNullOrEmpty(context.Request["size"]) ||
                string.IsNullOrEmpty(context.Request["region"]) || string.IsNullOrEmpty(quality) ||
                string.IsNullOrEmpty(context.Request["rotation"]))
            {
                state.err = new error();

                if (string.IsNullOrEmpty(context.Request["identifier"]))
                {
                    state.err.parameter = ", identifier";
                }
                if (string.IsNullOrEmpty(context.Request["size"]))
                {
                    state.err.parameter += ", size";
                }
                if (string.IsNullOrEmpty(context.Request["region"]))
                {
                    state.err.parameter += ", region";
                }
                if (string.IsNullOrEmpty(context.Request["rotation"]))
                {
                    state.err.parameter += ", rotation";
                }
                if (string.IsNullOrEmpty(quality))
                {
                    state.err.parameter += ", quality";
                }
                if (string.IsNullOrEmpty(context.Request["format"]))
                {
                    state.err.parameter += ", format";
                }

                state.err.parameter = state.err.parameter.Substring(2);
                state.err.text      = "missing " + state.err.parameter;

                state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
            }

            string size = context.Request["size"];

            if (state.err == null && !string.IsNullOrEmpty(size))
            {
                if (size.EndsWith(","))
                {
                    state.sizeType = "resize";
                    state.width    = size.Replace(",", "");

                    if (!string.IsNullOrEmpty(state.width) && int.Parse(state.width) < 1)
                    {
                        state.err            = new error();
                        state.err.parameter  = "size";
                        state.err.text       = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else if (size.StartsWith(","))
                {
                    state.sizeType = "resize";
                    state.height   = size.Replace(",", "");

                    if (!string.IsNullOrEmpty(state.height) && int.Parse(state.height) < 1)
                    {
                        state.err            = new error();
                        state.err.parameter  = "size";
                        state.err.text       = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else if (size.Equals("full"))
                {
                    state.sizeType = "proportion";
                    state.size     = "1";
                }
                else if (size.StartsWith("pct:"))
                {
                    state.sizeType = "proportion";
                    state.size     = (double.Parse(size.Replace("pct:", "")) / 100).ToString();

                    if (!string.IsNullOrEmpty(state.size) && double.Parse(state.size) <= 0)
                    {
                        state.err            = new error();
                        state.err.parameter  = "size";
                        state.err.text       = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else if (size.StartsWith("!"))
                {
                    Regex r = new Regex(@"!(?<w>\d+),(?<h>\d+)");
                    Match m = r.Match(size);

                    state.sizeType = "best";
                    state.width    = m.Groups["w"].Value;
                    state.height   = m.Groups["h"].Value;

                    if ((!string.IsNullOrEmpty(state.width) && int.Parse(state.width) < 1) ||
                        (!string.IsNullOrEmpty(state.height) && int.Parse(state.height) < 1))
                    {
                        state.err            = new error();
                        state.err.parameter  = "size";
                        state.err.text       = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    Regex r = new Regex(@"(?<w>\d+),(?<h>\d+)");
                    Match m = r.Match(size);

                    state.sizeType = "resize";
                    state.width    = m.Groups["w"].Value;
                    state.height   = m.Groups["h"].Value;

                    if ((!string.IsNullOrEmpty(state.width) && int.Parse(state.width) < 1) ||
                        (!string.IsNullOrEmpty(state.height) && int.Parse(state.height) < 1))
                    {
                        state.err            = new error();
                        state.err.parameter  = "size";
                        state.err.text       = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }

                if (string.IsNullOrEmpty(state.sizeType) || (string.IsNullOrEmpty(state.size) && string.IsNullOrEmpty(state.height) && string.IsNullOrEmpty(state.width)))
                {
                    state.err            = new error();
                    state.err.parameter  = "size";
                    state.err.text       = "Invalid size specified";
                    state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                }
            }

            string region = context.Request["region"];

            if (state.err == null && !string.IsNullOrEmpty(region))
            {
                if (context.Request["region"].Equals("full"))
                {
                    state.region = "all";
                }
                else if (region.StartsWith("pct:"))
                {
                    Regex  r = new Regex(@"pct:(?<x>(\d+|\d+\.\d+)),(?<y>(\d+|\d+\.\d+)),(?<w>(\d+|\d+\.\d+)),(?<h>(\d+|\d+\.\d+))");
                    Match  m = r.Match(region);
                    double y = Convert.ToDouble(m.Groups["y"].Value) / 100;
                    double x = Convert.ToDouble(m.Groups["x"].Value) / 100;
                    double h = Convert.ToDouble(m.Groups["h"].Value) / 100;
                    double w = Convert.ToDouble(m.Groups["w"].Value) / 100;

                    state.region = "%" + x + "," + y + "," + w + "," + h;

                    state.regionHeight = h.ToString();
                    state.regionWidth  = w.ToString();

                    if ((!string.IsNullOrEmpty(state.regionWidth) && Convert.ToDouble(state.regionWidth) <= 0) ||
                        (!string.IsNullOrEmpty(state.regionHeight) && Convert.ToDouble(state.regionHeight) <= 0))
                    {
                        state.err            = new error();
                        state.err.parameter  = "region";
                        state.err.text       = "Invalid region specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    Regex r = new Regex(@"(?<x>\d+),(?<y>\d+),(?<w>\d+),(?<h>\d+)");
                    Match m = r.Match(region);

                    state.region       = m.Groups["x"].Value + "," + m.Groups["y"].Value + "," + m.Groups["w"].Value + "," + m.Groups["h"].Value;
                    state.regionHeight = m.Groups["h"].Value;
                    state.regionWidth  = m.Groups["w"].Value;

                    if (state.sizeType.Equals("proportion"))
                    {
                        if (!string.IsNullOrEmpty(state.regionWidth) && Convert.ToInt32(state.regionWidth) * Convert.ToDouble(state.size) < 1)
                        {
                            state.err            = new error();
                            state.err.parameter  = "region";
                            state.err.text       = "Invalid region specified";
                            state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        }
                        else if (!string.IsNullOrEmpty(state.regionHeight) && Convert.ToInt32(state.regionHeight) * Convert.ToDouble(state.size) < 1)
                        {
                            state.err            = new error();
                            state.err.parameter  = "region";
                            state.err.text       = "Invalid region specified";
                            state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        }
                    }
                    if ((!string.IsNullOrEmpty(state.regionWidth) && int.Parse(state.regionWidth) < 1) ||
                        (!string.IsNullOrEmpty(state.regionHeight) && int.Parse(state.regionHeight) < 1))
                    {
                        state.err            = new error();
                        state.err.parameter  = "region";
                        state.err.text       = "Invalid region specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }

                if (string.IsNullOrEmpty(state.region.Replace(",", "")))
                {
                    state.err            = new error();
                    state.err.parameter  = "region";
                    state.err.text       = "Invalid region specified";
                    state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                }
            }

            if (state.err == null && !string.IsNullOrEmpty(quality))
            {
                switch (quality)
                {
                case "grey": quality = "grey"; break;

                case "bitonal": quality = "bitonal"; break;

                case "color": quality = "color"; break;

                case "native": quality = "native"; break;

                default:
                    state.err            = new error();
                    state.err.parameter  = "quality";
                    state.err.text       = "only native, color, grey, bitonal supported";
                    state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    break;
                }
            }

            string rotate = context.Request["rotation"];

            if (state.err == null && !string.IsNullOrEmpty(rotate))
            {
                switch (rotate)
                {
                case "90":
                case "180":
                case "270":
                    state.rotation = rotate; break;

                default:
                    int temp = 0;
                    if (int.TryParse(rotate, out temp))
                    {
                        state.rotation = temp.ToString();
                    }
                    else
                    {
                        state.err            = new error();
                        state.err.parameter  = "rotation";
                        state.err.text       = "only 0, 90, 180, 270 are accepted rotation values";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                    break;
                }
            }

            if (state.err == null && !string.IsNullOrEmpty(format))
            {
                switch (format)
                {
                case "jpg": format = "jpg"; break;

                case "png": format = "png"; break;

                case "gif": format = "gif"; break;

                case "jp2":
                case "pdf":
                default:
                    state.err            = new error();
                    state.err.parameter  = "format";
                    state.err.text       = format + " not supported";
                    state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    break;         // no format matched
                }
            }

            state.identifier = context.Request["identifier"];
            state.rotation   = context.Request["rotation"];
            state.quality    = quality;
            state.format     = format;

            asynch = new ImageAsynchResult(cb, context, state);

            getImage = new GetImageDelegate(GetImage);
            getImage.BeginInvoke(asynch, null, state);

            return(asynch);
        }
Example #16
0
        private Image createImage()
        {
            if (!m_Async)
                return getImageFromServer();

            HasLayout = true;
            Slide currSlide = PresentationController.Instance.SelectedSlide;
            Display disp = null;
            if (currSlide != null && (disp = currSlide.DisplayList.Find(x => x.EquipmentType == m_Display.EquipmentType)) == null || disp.WindowList.Count == 0)
            {
                bool background = false;
                if (disp is ActiveDisplay) // Может не быть окон, но быть фон
                {
                    background = !string.IsNullOrEmpty(((ActiveDisplay)disp).BackgroundImage);
                }

                if (!background)
                {
                    m_Image = null;
                    HasLayout = false;
                    return m_Image;
                }
            }
            HasImage = true;
            Image retValue = null;
            GetImageDelegate gid = new GetImageDelegate(this.getImageFromServer);
            gid.BeginInvoke(new AsyncCallback(this.imageLoaded), gid);
            return retValue;
        }
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
        {
            _context = context;

            ImageRequestState state = new ImageRequestState();

            string quality = "";
            string format = "png";
            int dotPos = context.Request["quality_format"].IndexOf(".");

            if (dotPos != -1)
            {
                quality = context.Request["quality_format"].Substring(0, dotPos);
                format = context.Request["quality_format"].Substring(dotPos + 1);
            }
            else
            {
                quality = context.Request["quality_format"];
            }

            if (string.IsNullOrEmpty(context.Request["identifier"]) || string.IsNullOrEmpty(context.Request["size"]) ||
                string.IsNullOrEmpty(context.Request["region"]) || string.IsNullOrEmpty(quality) ||
                string.IsNullOrEmpty(context.Request["rotation"]))
            {
                state.err = new error();

                if (string.IsNullOrEmpty(context.Request["identifier"]))
                    state.err.parameter = ", identifier";
                if (string.IsNullOrEmpty(context.Request["size"]))
                    state.err.parameter += ", size";
                if (string.IsNullOrEmpty(context.Request["region"]))
                    state.err.parameter += ", region";
                if (string.IsNullOrEmpty(context.Request["rotation"]))
                    state.err.parameter += ", rotation";
                if (string.IsNullOrEmpty(quality))
                    state.err.parameter += ", quality";
                if (string.IsNullOrEmpty(context.Request["format"]))
                    state.err.parameter += ", format";

                state.err.parameter = state.err.parameter.Substring(2);
                state.err.text = "missing " + state.err.parameter;

                state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
            }

            string size = context.Request["size"];
            if (state.err == null && !string.IsNullOrEmpty(size))
            {
                if (size.EndsWith(","))
                {
                    state.sizeType = "resize";
                    state.width = size.Replace(",", "");

                    if (!string.IsNullOrEmpty(state.width) && int.Parse(state.width) < 1)
                    {
                        state.err = new error();
                        state.err.parameter = "size";
                        state.err.text = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else if (size.StartsWith(","))
                {
                    state.sizeType = "resize";
                    state.height = size.Replace(",", "");

                    if (!string.IsNullOrEmpty(state.height) && int.Parse(state.height) < 1)
                    {
                        state.err = new error();
                        state.err.parameter = "size";
                        state.err.text = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else if (size.Equals("full"))
                {
                    state.sizeType = "proportion";
                    state.size = "1";
                }
                else if (size.StartsWith("pct:"))
                {
                    state.sizeType = "proportion";
                    state.size = (double.Parse(size.Replace("pct:", "")) / 100).ToString();

                    if (!string.IsNullOrEmpty(state.size) && double.Parse(state.size) <= 0)
                    {
                        state.err = new error();
                        state.err.parameter = "size";
                        state.err.text = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else if (size.StartsWith("!"))
                {
                    Regex r = new Regex(@"!(?<w>\d+),(?<h>\d+)");
                    Match m = r.Match(size);

                    state.sizeType = "best";
                    state.width = m.Groups["w"].Value;
                    state.height = m.Groups["h"].Value;

                    if ((!string.IsNullOrEmpty(state.width) && int.Parse(state.width) < 1) ||
                        (!string.IsNullOrEmpty(state.height) && int.Parse(state.height) < 1))
                    {
                        state.err = new error();
                        state.err.parameter = "size";
                        state.err.text = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    Regex r = new Regex(@"(?<w>\d+),(?<h>\d+)");
                    Match m = r.Match(size);

                    state.sizeType = "resize";
                    state.width = m.Groups["w"].Value;
                    state.height = m.Groups["h"].Value;

                    if ((!string.IsNullOrEmpty(state.width) && int.Parse(state.width) < 1) ||
                        (!string.IsNullOrEmpty(state.height) && int.Parse(state.height) < 1))
                    {
                        state.err = new error();
                        state.err.parameter = "size";
                        state.err.text = "Invalid size specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }

                if (string.IsNullOrEmpty(state.sizeType) || (string.IsNullOrEmpty(state.size) && string.IsNullOrEmpty(state.height) && string.IsNullOrEmpty(state.width)))
                {
                    state.err = new error();
                    state.err.parameter = "size";
                    state.err.text = "Invalid size specified";
                    state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                }
            }

            string region = context.Request["region"];
            if (state.err == null && !string.IsNullOrEmpty(region))
            {
                if (context.Request["region"].Equals("full"))
                {
                    state.region = "all";
                }
                else if (region.StartsWith("pct:"))
                {
                    Regex r = new Regex(@"pct:(?<x>(\d+|\d+\.\d+)),(?<y>(\d+|\d+\.\d+)),(?<w>(\d+|\d+\.\d+)),(?<h>(\d+|\d+\.\d+))");
                    Match m = r.Match(region);
                    double y = Convert.ToDouble(m.Groups["y"].Value) / 100;
                    double x = Convert.ToDouble(m.Groups["x"].Value) / 100;
                    double h = Convert.ToDouble(m.Groups["h"].Value) / 100;
                    double w = Convert.ToDouble(m.Groups["w"].Value) / 100;

                    state.region = "%" + x + "," + y + "," + w + "," + h;

                    state.regionHeight = h.ToString();
                    state.regionWidth = w.ToString();

                    if ((!string.IsNullOrEmpty(state.regionWidth) && Convert.ToDouble(state.regionWidth) <= 0) ||
                        (!string.IsNullOrEmpty(state.regionHeight) && Convert.ToDouble(state.regionHeight) <= 0))
                    {
                        state.err = new error();
                        state.err.parameter = "region";
                        state.err.text = "Invalid region specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    Regex r = new Regex(@"(?<x>\d+),(?<y>\d+),(?<w>\d+),(?<h>\d+)");
                    Match m = r.Match(region);

                    state.region = m.Groups["x"].Value + "," + m.Groups["y"].Value + "," + m.Groups["w"].Value + "," + m.Groups["h"].Value;
                    state.regionHeight = m.Groups["h"].Value;
                    state.regionWidth = m.Groups["w"].Value;

                    if (state.sizeType.Equals("proportion"))
                    {
                        if (!string.IsNullOrEmpty(state.regionWidth) && Convert.ToInt32(state.regionWidth) * Convert.ToDouble(state.size) < 1)
                        {
                            state.err = new error();
                            state.err.parameter = "region";
                            state.err.text = "Invalid region specified";
                            state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        }
                        else if (!string.IsNullOrEmpty(state.regionHeight) && Convert.ToInt32(state.regionHeight) * Convert.ToDouble(state.size) < 1)
                        {
                            state.err = new error();
                            state.err.parameter = "region";
                            state.err.text = "Invalid region specified";
                            state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        }
                    }
                    if ((!string.IsNullOrEmpty(state.regionWidth) && int.Parse(state.regionWidth) < 1) ||
                        (!string.IsNullOrEmpty(state.regionHeight) && int.Parse(state.regionHeight) < 1))
                    {
                        state.err = new error();
                        state.err.parameter = "region";
                        state.err.text = "Invalid region specified";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                    }
                }

                if (string.IsNullOrEmpty(state.region.Replace(",", "")))
                {
                    state.err = new error();
                    state.err.parameter = "region";
                    state.err.text = "Invalid region specified";
                    state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                }
            }

            if (state.err == null && !string.IsNullOrEmpty(quality))
            {
                switch (quality)
                {
                    case "grey": quality = "grey"; break;
                    case "bitonal": quality = "bitonal"; break;
                    case "color": quality = "color"; break;
                    case "native": quality = "native"; break;
                    default:
                        state.err = new error();
                        state.err.parameter = "quality";
                        state.err.text = "only native, color, grey, bitonal supported";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        break;
                }
            }

            string rotate = context.Request["rotation"];
            if (state.err == null && !string.IsNullOrEmpty(rotate))
            {
                switch (rotate)
                {
                    case "90":
                    case "180":
                    case "270":
                        state.rotation = rotate; break;
                    default:
                        int temp = 0;
                        if (int.TryParse(rotate, out temp))
                        {
                            state.rotation = temp.ToString();
                        }
                        else
                        {
                            state.err = new error();
                            state.err.parameter = "rotation";
                            state.err.text = "only 0, 90, 180, 270 are accepted rotation values";
                            state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        }
                        break;
                }

            }

            if (state.err == null && !string.IsNullOrEmpty(format))
            {
                switch (format)
                {
                    case "jpg": format = "jpg"; break;
                    case "png": format = "png"; break;
                    case "gif": format = "gif"; break;
                    case "jp2":
                    case "pdf":
                    default:
                        state.err = new error();
                        state.err.parameter = "format";
                        state.err.text = format + " not supported";
                        state.err.statusCode = System.Net.HttpStatusCode.BadRequest;
                        break;     // no format matched
                }
            }

            state.identifier = context.Request["identifier"];
            state.rotation = context.Request["rotation"];
            state.quality = quality;
            state.format = format;

            asynch = new ImageAsynchResult(cb, context, state);

            getImage = new GetImageDelegate(GetImage);
            getImage.BeginInvoke(asynch, null, state);

            return asynch;
        }
Example #18
0
 private static void ApplyControlAttributes(CommandBarControl control, XmlNode xmlNode, GetImageDelegate getImage)
 {
     foreach (XmlAttribute att in xmlNode.Attributes)
     {
         ApplyControlAttribute(control, att.Name, att.Value, getImage);
     }
 }
Example #19
0
 static extern void GetImage(GetImageDelegate GetImageData);
Example #20
0
 private static void AddControl(CommandBarControls parentControls, XmlNode xmlNode, GetImageDelegate getImage)
 {
     if (xmlNode.Name == "popup")
     {
         string controlName = xmlNode.Attributes["caption"].Value;
         object before = ReadControlBeforeAttribute(xmlNode);
         CommandBarPopup newPopup = parentControls.AddPopup(controlName, before);
         ApplyControlAttributes(newPopup, xmlNode, getImage);
         AddControls(newPopup.Controls, xmlNode.ChildNodes, getImage);
     }
     else if (xmlNode.Name == "button")
     {
         object before = ReadControlBeforeAttribute(xmlNode);
         CommandBarButton newButton = parentControls.AddButton(before);
         ApplyControlAttributes(newButton, xmlNode, getImage);
     }
 }
Example #21
0
        private static void AddCommandBarControls(Application excelApp, XmlNodeList xmlNodes, GetImageDelegate getImage)
        {
            foreach (XmlNode childNode in xmlNodes)
            {
                if (childNode.Name == "commandBar")
                {
                    string     barName = childNode.Attributes["name"].Value;
                    CommandBar bar     = null;
                    for (int i = 1; i <= excelApp.CommandBars.Count; i++)
                    {
                        if (excelApp.CommandBars[i].Name == barName)
                        {
                            bar = excelApp.CommandBars[i];
                            break;
                        }
                    }
                    if (bar != null)
                    {
                        AddControls(bar.Controls, childNode.ChildNodes, getImage);
                    }
                    else
                    {
                        MsoBarPosition barPosition  = MsoBarPosition.msoBarLeft;
                        XmlAttribute   posAttribute = childNode.Attributes["position"];
                        if (posAttribute == null)
                        {
                            // Compatible with original patch
                            posAttribute = childNode.Attributes["MsoBarPosition"];
                        }
                        if (posAttribute != null)
                        {
                            if (Enum.IsDefined(typeof(MsoBarPosition), posAttribute.Value))
                            {
                                barPosition = (MsoBarPosition)Enum.Parse(typeof(MsoBarPosition), posAttribute.Value, false);
                            }
                        }

                        bar = excelApp.CommandBars.Add(barName, barPosition);
                        AddControls(bar.Controls, childNode.ChildNodes, getImage);
                    }
                }
            }
        }
Example #22
0
 private static void ApplyControlAttribute(CommandBarControl control, string attribute, string value, GetImageDelegate getImage)
 {
     switch (attribute)
     {
         case "caption":
             control.Caption = value;
             break;
         case "height":
             int height;
             if (int.TryParse(value, out height))
             {
                 control.Height = height;
             }
             else
             {
                 Debug.Print("Could not parse 'height' attribute: {0}", value);
             }
             break;
         case "onAction":
             control.OnAction = value;
             break;
         case "enabled":
             bool enabled;
             if (bool.TryParse(value, out enabled))
             {
                 control.Enabled = enabled;
             }
             else
             {
                 Debug.Print("Could not parse 'enabled' attribute: {0}", value);
             }
             break;
         case "beginGroup":
             bool beginGroup;
             if (bool.TryParse(value, out beginGroup))
             {
                 control.BeginGroup = beginGroup;
             }
             else
             {
                 Debug.Print("Could not parse 'beginGroup' attribute: {0}", value);
             }
             break;
         case "helpFile":
             control.HelpFile = value;
             break;
         case "helpContextId":
             int helpContextId;
             if (int.TryParse(value, out helpContextId))
             {
                 control.HelpContextId = helpContextId;
             }
             else
             {
                 Debug.Print("Could not parse 'helpContextId' attribute: {0}", value);
             }
             break;
         case "tag":
             control.Tag = value;
             break;
         case "tooltipText":
             control.TooltipText = value;
             break;
         case "shortcutText":
             if (control is CommandBarButton)
             {
                 (control as CommandBarButton).ShortcutText = value;
             }
             else
             {
                 Debug.Print("shortcutText only supported on Buttons");
             }
             break;
         case "faceId":
             if (control is CommandBarButton)
             {
                 int faceId;
                 if (int.TryParse(value, out faceId))
                 {
                     (control as CommandBarButton).FaceId = faceId;
                 }
                 else
                 {
                     Debug.Print("Could not parse 'faceId' attribute: {0}", value);
                 }
             }
             else
             {
                 Debug.Print("faceId only supported on Buttons");
             }
             break;
         case "image":
             if (control is CommandBarButton)
             {
                 Bitmap image = getImage(value);
                 if (image != null)
                 {
                     (control as CommandBarButton).SetButtonImage(image);
                 }
                 else
                 {
                     Debug.Print("Could not find or load image {0}", value);
                 }
             }
             else
             {
                 Debug.Print("image only supported on Buttons");
             }
             break;
         case "style":
         case "MsoButtonStyle":  // Compatible with original style code.
             if (control is CommandBarButton)
             {
                 if (Enum.IsDefined(typeof(MsoButtonStyle), value))
                     (control as CommandBarButton).Style = (MsoButtonStyle)Enum.Parse(typeof(MsoButtonStyle), value, false);
                 else
                     (control as CommandBarButton).Style = MsoButtonStyle.msoButtonAutomatic;
             }
             else
             {
                 Debug.Print("style only supported on Buttons");
             }
             break;
         default:
             Debug.Print("Unknown attribute '{0}' - ignoring.", attribute);
             break;
     }
 }
 public virtual void LoadCommandBars(string xmlCustomUI, GetImageDelegate getImage)
 {
     throw new NotImplementedException();
 }