Exemplo n.º 1
0
        public static ICustomReportItem CreateCustomReportItem(string type)
        {
            CustomReportItemEntry crie = null;

            try { crie = CustomReportItemEntries[type]; }
            catch // KeyNotFoundException typically
            {
                throw new Exception(string.Format("{0} is not a known CustomReportItem type", type));
            }
            if (crie.CodeModule == null)
            {
                if (crie != null && crie.ErrorMsg != null)      // error during initialization??
                {
                    throw new Exception(crie.ErrorMsg);
                }
                else
                {
                    throw new Exception(string.Format("{0} is not a known CustomReportItem type", type));
                }
            }

            Assembly asm = crie.CodeModule;
            object   o   = asm.CreateInstance(crie.ClassName, false,
                                              BindingFlags.CreateInstance, null, null, null, null);

            if (o == null)
            {
                throw new Exception(string.Format("Unable to create instance of '{0}' for CustomReportType '{1}'", crie.ClassName, type));
            }

            return(o as ICustomReportItem);
        }
        public static void DeclareNewCustomReportItem(string itemName, Type type)
        {
            if (!typeof(ICustomReportItem).IsAssignableFrom(type))
            {
                throw new ArgumentException("The type does not implement the ICustomReportItem interface: " +
                                            type == null ? "null" : type.Name);
            }

            if (CustomReportItemEntries == null)
            {
                RdlEngineConfigInit();
            }

            // Let's manage doublons, if any.
            CustomReportItemEntry item;

            if (!CustomReportItemEntries.TryGetValue(itemName, out item))
            {
                CustomReportItemEntries[itemName] = new CustomReportItemEntry(itemName, type, null);
            }
            else if (!item.Type.Equals(type))
            {
                throw new ArgumentException("A different type of CustomReportItem with the same has already been declared.");
            }
        }
Exemplo n.º 3
0
        static void GetCustomReportItem(XmlNode xNode)
        {
            string type       = null;
            string codemodule = null;
            string classname  = null;

            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                switch (xNodeLoop.Name)
                {
                case "Type":
                    type = xNodeLoop.InnerText;
                    break;

                case "CodeModule":
                    codemodule = xNodeLoop.InnerText;
                    break;

                case "ClassName":
                    classname = xNodeLoop.InnerText;
                    break;

                default:
                    break;
                }
            }
            if (type == null)
            {
                return;                 // nothing to do if no provider specified
            }
            CustomReportItemEntry crie;

            try
            {   // load the module early; saves problems with concurrency later
                string   msg = null;
                Assembly la  = null;
                if (codemodule != null && classname != null)
                {
                    la = XmlUtil.AssemblyLoadFrom(codemodule);
                    if (la == null)
                    {
                        msg = string.Format("{0} could not be loaded", codemodule);
                    }
                }
                crie = new CustomReportItemEntry(type, classname, la, msg);
                CustomReportItemEntries.Add(type, crie);
            }
            catch (Exception e)
            {           // keep exception;  if this CustomReportItem is ever used we will see the message
                crie = new CustomReportItemEntry(type, classname, null, e.Message);
                CustomReportItemEntries.Add(type, crie);
            }
        }
        public static ICustomReportItem CreateCustomReportItem(string friendlyTypeName)
        {
            CustomReportItemEntry crie = null;

            if (!CustomReportItemEntries.TryGetValue(friendlyTypeName, out crie))
            {
                throw new Exception(string.Format("{0} is not a known CustomReportItem type", friendlyTypeName));
            }
            if (crie.Type == null)
            {
                throw new Exception(crie.ErrorMsg ??
                                    string.Format("{0} is not a known CustomReportItem type", friendlyTypeName));
            }

            ICustomReportItem item = (ICustomReportItem)Activator.CreateInstance(crie.Type);

            return(item);
        }
Exemplo n.º 5
0
        public static ICustomReportItem CreateCustomReportItem(string friendlyTypeName)
        {
            CustomReportItemEntry crie = null;

            if (!CustomReportItemEntries.TryGetValue(friendlyTypeName, out crie))
            {
                throw new Exception(string.Format(Strings.RdlEngineConfig_Error_NotKnownCustomReportItemType, friendlyTypeName));
            }
            if (crie.Type == null)
            {
                throw new Exception(crie.ErrorMsg ??
                                    string.Format(Strings.RdlEngineConfig_Error_NotKnownCustomReportItemType, friendlyTypeName));
            }

            var item = (ICustomReportItem)Activator.CreateInstance(crie.Type);

            return(item);
        }
Exemplo n.º 6
0
        static void GetCustomReportItem(XmlNode xNode)
        {
            string type = null;
            string codemodule = null;
            string classname = null;
            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                    continue;
                switch (xNodeLoop.Name)
                {
                    case "Type":
                        type = xNodeLoop.InnerText;
                        break;
                    case "CodeModule":
                        codemodule = xNodeLoop.InnerText;
                        break;
                    case "ClassName":
                        classname = xNodeLoop.InnerText;
                        break;
                    default:
                        break;
                }
            }
            if (type == null)
                return;			// nothing to do if no provider specified

            CustomReportItemEntry crie;
            try
            {   // load the module early; saves problems with concurrency later
                string msg = null;
                Assembly la = null;
                if (codemodule != null && classname != null)
                {
                    la = XmlUtil.AssemblyLoadFrom(codemodule);
                    if (la == null)
                        msg = string.Format("{0} could not be loaded", codemodule);
                }
                crie = new CustomReportItemEntry(type, classname, la, msg);
                CustomReportItemEntries.Add(type, crie);
            }
            catch (Exception e)
            {		// keep exception;  if this CustomReportItem is ever used we will see the message
                crie = new CustomReportItemEntry(type, classname, null, e.Message);
                CustomReportItemEntries.Add(type, crie);
            }
        }
Exemplo n.º 7
0
        public static void DeclareNewCustomReportItem(string itemName, Type type)
        {
            if (!typeof(ICustomReportItem).IsAssignableFrom(type))
                throw new ArgumentException("The type does not implement the ICustomReportItem interface: " +
                   type == null ? "null" : type.Name);

            if (CustomReportItemEntries == null)
                RdlEngineConfigInit();

            // Let's manage doublons, if any.
            CustomReportItemEntry item;
            if (!CustomReportItemEntries.TryGetValue(itemName, out item))
                CustomReportItemEntries[itemName] = new CustomReportItemEntry(itemName, type, null);
            else if (!item.Type.Equals(type))
                throw new ArgumentException("A different type of CustomReportItem with the same has already been declared.");
        }
Exemplo n.º 8
0
        static void GetCustomReportItem(Dictionary<string, CustomReportItemEntry> crieDir, XmlNode xNode)
        {
            string friendlyTypeName = null;
            string codemodule = null;
            string classname = null;
            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                    continue;
                switch (xNodeLoop.Name)
                {
                    case "Type":
                        friendlyTypeName = xNodeLoop.InnerText;
                        break;
                    case "CodeModule":
                        codemodule = xNodeLoop.InnerText;
                        break;
                    case "ClassName":
                        classname = xNodeLoop.InnerText;
                        break;
                    default:
                        break;
                }
            }
            if (friendlyTypeName == null)
                return;         // nothing to do if no provider specified

            CustomReportItemEntry crie;
            try
            {   // load the module early; saves problems with concurrency later
                string msg = null;
                Type dotNetType = null;
                Assembly la = null;
                if (codemodule != null && classname != null)
                {
                    // Check to see if previously loaded.  Many CustomReportItems share same CodeModule.
                    Assembly[] allLoadedAss = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly ass in allLoadedAss)
                    {
                        var type = ass.GetType();
                        if( type.GetMethod("Location") != null)
                        {
                            if (ass.Location.Equals(codemodule, StringComparison.CurrentCultureIgnoreCase))
                            {
                                la = ass;
                                break;
                            }
                        }
                    }

                    if (la == null)     // not previously loaded?
                        la = XmlUtil.AssemblyLoadFrom(codemodule);
                    if (la == null)
                        msg = string.Format(Strings.RdlEngineConfig_Error_CodeModuleNotLoaded, codemodule);
                    else
                        dotNetType = la.GetType(classname);
                }

                crie = new CustomReportItemEntry(friendlyTypeName, dotNetType, msg);
                crieDir.Add(friendlyTypeName, crie);
            }
            catch (Exception e)
            {      // keep exception;  if this CustomReportItem is ever used we will see the message
                crie = new CustomReportItemEntry(friendlyTypeName, null, e.Message);
                crieDir.Add(friendlyTypeName, crie);
            }
        }
        static void GetCustomReportItem(Dictionary <string, CustomReportItemEntry> crieDir, XmlNode xNode)
        {
            string friendlyTypeName = null;
            string codemodule       = null;
            string classname        = null;

            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                switch (xNodeLoop.Name)
                {
                case "Type":
                    friendlyTypeName = xNodeLoop.InnerText;
                    break;

                case "CodeModule":
                    codemodule = xNodeLoop.InnerText;
                    break;

                case "ClassName":
                    classname = xNodeLoop.InnerText;
                    break;

                default:
                    break;
                }
            }
            if (friendlyTypeName == null)
            {
                return;         // nothing to do if no provider specified
            }
            CustomReportItemEntry crie;

            try
            {   // load the module early; saves problems with concurrency later
                string   msg        = null;
                Type     dotNetType = null;
                Assembly la         = null;
                if (codemodule != null && classname != null)
                {
                    // Check to see if previously loaded.  Many CustomReportItems share same CodeModule.
                    Assembly[] allLoadedAss = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly ass in allLoadedAss)
                    {
                        var type = ass.GetType();
                        if (type.GetMethod("Location") != null)
                        {
                            if (ass.Location.Equals(codemodule, StringComparison.CurrentCultureIgnoreCase))
                            {
                                la = ass;
                                break;
                            }
                        }
                    }

                    if (la == null)     // not previously loaded?
                    {
                        la = XmlUtil.AssemblyLoadFrom(codemodule);
                    }
                    if (la == null)
                    {
                        msg = string.Format("{0} could not be loaded", codemodule);
                    }
                    else
                    {
                        dotNetType = la.GetType(classname);
                    }
                }

                crie = new CustomReportItemEntry(friendlyTypeName, dotNetType, msg);
                crieDir.Add(friendlyTypeName, crie);
            }
            catch (Exception e)
            {      // keep exception;  if this CustomReportItem is ever used we will see the message
                crie = new CustomReportItemEntry(friendlyTypeName, null, e.Message);
                crieDir.Add(friendlyTypeName, crie);
            }
        }