Example #1
0
        protected override void OnInit(EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(ScriptName))
                {
                    Exception = new InvalidEnumArgumentException("Property ScriptName is empty!");
                }
                else if (String.IsNullOrEmpty(ScriptClass))
                {
                    Exception = new InvalidEnumArgumentException("Property ScriptClass is empty!");
                }

                if (Exception != null)
                {
                    return;
                }

                //Guid hiveId = String.IsNullOrEmpty(ScriptHiveId) ? Guid.Empty : new Guid(ScriptHiveId);
                //IronRuntime ironRuntime = IronRuntime.GetIronRuntime(SPContext.Current.Site, hiveId);

                IronRuntime ironRuntime = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site);
                engine = ironRuntime.GetEngineByExtension(Path.GetExtension(ScriptName));

                if (engine != null)
                {
                    ctrl = engine.CreateDynamicInstance(ScriptClass, ScriptName) as Control;

                    var dynamicControl = ctrl as IIronControl;
                    if (dynamicControl != null)
                    {
                        dynamicControl.WebPart = null;
                        dynamicControl.Data    = null;
                        dynamicControl.Config  = Config;
                    }

                    this.Controls.Add(ctrl);
                }
            }
            catch (Exception ex)
            {
                Exception = ex;
            }

            base.OnInit(e);
        }
Example #2
0
        protected override void OnInit(EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(ScriptName))
                {
                    _exception = new InvalidEnumArgumentException("Property ScripName is empty!");
                }
                else if (String.IsNullOrEmpty(ScriptClass))
                {
                    _exception = new InvalidEnumArgumentException("Property ScripClass is empty!");
                }

                if (_exception != null)
                {
                    return;
                }

                Guid hiveId = String.IsNullOrEmpty(ScriptHiveId) ? Guid.Empty : new Guid(ScriptHiveId);

                //IronRuntime ironRuntime = IronRuntime.GetIronRuntime(SPContext.Current.Site, hiveId);
                IronRuntime ironRuntime = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site);
                engine = ironRuntime.GetEngineByExtension(Path.GetExtension(ScriptName));

                if (engine != null)
                {
                    ctrl = engine.CreateDynamicInstance(ScriptClass, ScriptName) as Control;

                    var dynamicControl = ctrl as IIronControl;
                    if (dynamicControl != null)
                    {
                        dynamicControl.WebPart = null;
                        dynamicControl.Data    = null;
                        dynamicControl.Config  = Config;
                    }

                    if (Template != null)
                    {
                        Template.InstantiateIn(ctrl);
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(TemplatePath))
                        {
                            var path = TemplatePath.Replace("~site", SPContext.Current.Site.ServerRelativeUrl)
                                       .Replace("~web", SPContext.Current.Web.ServerRelativeUrl)
                                       .Replace("~hiveSite", engine.IronRuntime.IronHive.Site.ServerRelativeUrl)
                                       .Replace("~hiveWeb", engine.IronRuntime.IronHive.Web.ServerRelativeUrl)
                                       .Replace("~hiveFolder", engine.IronRuntime.IronHive.Folder.ServerRelativeUrl);

                            Template = this.LoadTemplate(path);
                            Template.InstantiateIn(ctrl);
                        }
                    }

                    this.Controls.Add(ctrl);
                }
            }
            catch (Exception ex)
            {
                IronDiagnosticsService.Local.WriteTrace(1, IronDiagnosticsService.Local[IronCategoryDiagnosticsId.Controls], TraceSeverity.Unexpected, String.Format("Error: {0}; Stack: {1}", ex.Message, ex.StackTrace));
                _exception = ex;
            }

            base.OnInit(e);
        }