protected virtual void Content()
        {
            var jobs = JobsHelper.Metadata.Where(j => j.Category == category);

            foreach (var jobMetadata in jobs)
            {
                var route = $"{ManagementPage.UrlRoute}/{category}/{jobMetadata.DisplayName.Replace(" ", string.Empty)}";
                var id    = $"{jobMetadata.DisplayName.Replace(" ", string.Empty)}";

                if (jobMetadata.MethodInfo.GetParameters().Length > 1)
                {
                    string inputs = string.Empty;

                    foreach (var parameterInfo in jobMetadata.MethodInfo.GetParameters())
                    {
                        if (parameterInfo.ParameterType == typeof(PerformContext) || parameterInfo.ParameterType == typeof(IJobCancellationToken))
                        {
                            continue;
                        }

                        DisplayDataAttribute displayInfo = null;
                        if (parameterInfo.GetCustomAttributes(true).OfType <DisplayDataAttribute>().Any())
                        {
                            displayInfo = parameterInfo.GetCustomAttribute <DisplayDataAttribute>();
                        }

                        var myId = $"{id}_{parameterInfo.Name}";
                        if (parameterInfo.ParameterType == typeof(string))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name, displayInfo?.DefaultValue?.ToString());
                        }
                        else if (parameterInfo.ParameterType == typeof(int) || parameterInfo.ParameterType == typeof(int?))
                        {
                            inputs += InputNumberbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name, displayInfo?.DefaultValue?.ToString());
                        }
                        else if (parameterInfo.ParameterType == typeof(DateTime) || parameterInfo.ParameterType == typeof(DateTime?))
                        {
                            DateTime defaultDate;
                            if (displayInfo.DefaultValue == null || displayInfo.DefaultValue.ToString().Equals("today", StringComparison.CurrentCultureIgnoreCase))
                            {
                                defaultDate = DateTime.Today;
                            }
                            else
                            {
                                DateTime.TryParse(displayInfo.DefaultValue.ToString(), out defaultDate);
                            }

                            inputs += InputDatebox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name, defaultDate.ToString());
                        }
                        else if (parameterInfo.ParameterType == typeof(bool))
                        {
                            inputs += "<br/>" + InputCheckbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name, displayInfo?.DefaultValue?.ToString());
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }

                    Panel(id, jobMetadata.DisplayName, jobMetadata.Description, inputs, CreateButtons(route, "Enqueue", "enqueueing", id));
                }
                else
                {
                    Panel(id, jobMetadata.DisplayName, jobMetadata.Description, string.Empty, CreateButtons(route, "Enqueue", "enqueueing", id));
                }
            }

            WriteLiteral("\r\n<script src=\"");
            Write(Url.To($"/jsm"));
            WriteLiteral("\"></script>\r\n");
        }
Example #2
0
        protected virtual void Content()
        {
            var jobs = JobsHelper.Jobs.Where(j => j.ManagementPageSection.Contains(section)).OrderBy(job => job.Type.ToString()).ToList();

            foreach (var jobMetadata in jobs)
            {
                var route = GetRoute(jobMetadata);

                var id = GetMethodName(jobMetadata);

                if (jobMetadata.MethodInfo.GetParameters().Length > 0)
                {
                    string inputs = string.Empty;

                    foreach (var parameterInfo in jobMetadata.MethodInfo.GetParameters())
                    {
                        if (parameterInfo.ParameterType == typeof(PerformContext) || parameterInfo.ParameterType == typeof(IJobCancellationToken))
                        {
                            continue;
                        }

                        DisplayDataAttribute displayInfo = null;
                        if (parameterInfo.GetCustomAttributes(true).OfType <DisplayDataAttribute>().Any())
                        {
                            displayInfo = parameterInfo.GetCustomAttribute <DisplayDataAttribute>();
                        }

                        var myId = $"{id}_{parameterInfo.Name}";
                        if (parameterInfo.ParameterType == typeof(string))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(System.Guid))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(int))
                        {
                            inputs += InputNumberbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(DateTime))
                        {
                            inputs += InputDatebox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(DateTime?))
                        {
                            inputs += InputDatebox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(bool))
                        {
                            inputs += "<br/>" + InputCheckbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType.ToString().Contains("Enum"))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType.ToString().Contains("List"))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType.ToString().Contains("Dictionary"))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else
                        {
                            throw new NotImplementedException(parameterInfo.ParameterType.ToString() + " Converter Not Implemented");
                        }
                    }

                    Panel(id, jobMetadata.Type.Name + "." + jobMetadata.DisplayName, jobMetadata.Description, inputs, CreateButtons(route, "Enqueue", "enqueueing", id));
                }
                else
                {
                    Panel(id, jobMetadata.Type.Name + "." + jobMetadata.DisplayName, jobMetadata.Description, string.Empty, CreateButtons(route, "Enqueue", "enqueueing", id));
                }
            }

            WriteLiteral("\r\n<script src=\"");
            Write(Url.To($"/jsm"));
            WriteLiteral("\"></script>\r\n");
        }
        protected void JobWriter(string id, JobMetadata job)
        {
            string inputs = string.Empty;

            foreach (var parameterInfo in job.MethodInfo.GetParameters())
            {
                if (parameterInfo.ParameterType == typeof(PerformContext) || parameterInfo.ParameterType == typeof(IJobCancellationToken))
                {
                    continue;
                }

                DisplayDataAttribute displayInfo = null;
                if (parameterInfo.GetCustomAttributes(true).OfType <DisplayDataAttribute>().Any())
                {
                    displayInfo = parameterInfo.GetCustomAttribute <DisplayDataAttribute>();
                }

                var labelText       = displayInfo?.Label ?? parameterInfo.Name;
                var placeholderText = displayInfo?.Placeholder ?? parameterInfo.Name;
                var myId            = $"{id}_{parameterInfo.Name}";

                if (parameterInfo.ParameterType == typeof(string))
                {
                    inputs += InputTextbox(myId, displayInfo.CssClasses, labelText, placeholderText, displayInfo?.Description, displayInfo.DefaultValue, displayInfo.IsDisabled);
                }
                else if (parameterInfo.ParameterType == typeof(int))
                {
                    inputs += InputNumberbox(myId, displayInfo.CssClasses, labelText, placeholderText, displayInfo?.Description, displayInfo.DefaultValue, displayInfo.IsDisabled);
                }
                else if (parameterInfo.ParameterType == typeof(Uri))
                {
                    inputs += Input(myId, displayInfo.CssClasses, labelText, displayInfo?.Placeholder ?? labelText, displayInfo?.Description, "url", displayInfo.DefaultValue, displayInfo.IsDisabled);
                }
                else if (parameterInfo.ParameterType == typeof(DateTime))
                {
                    inputs += InputDatebox(myId, displayInfo.CssClasses, labelText, placeholderText, displayInfo?.Description, displayInfo.DefaultValue, displayInfo.IsDisabled);
                }
                else if (parameterInfo.ParameterType == typeof(bool))
                {
                    inputs += "<br/>" + InputCheckbox(myId, displayInfo.CssClasses, labelText, placeholderText, displayInfo?.Description, displayInfo.DefaultValue, displayInfo.IsDisabled);
                }
                else if (parameterInfo.ParameterType.IsEnum)
                {
                    var data = new Dictionary <string, string>();
                    foreach (int v in Enum.GetValues(parameterInfo.ParameterType))
                    {
                        data.Add(Enum.GetName(parameterInfo.ParameterType, v), v.ToString());
                    }
                    inputs += InputDataList(myId, displayInfo.CssClasses, labelText, displayInfo?.Placeholder ?? labelText, displayInfo?.Description, data, displayInfo.DefaultValue?.ToString(), displayInfo.IsDisabled);
                }
                else
                {
                    inputs += InputTextbox(myId, displayInfo.CssClasses, labelText, placeholderText, displayInfo?.Description, displayInfo.DefaultValue, displayInfo.IsDisabled);
                }
            }

            if (string.IsNullOrWhiteSpace(inputs))
            {
                inputs = "<span>This job does not require inputs</span>";
            }

            WriteLiteral($@"
				<div class=""well"">
					{inputs}
				</div>
				<div id=""{id}_error""></div>
				<div id=""{id}_success""></div>
");
        }
        protected virtual void Content()
        {
            var jobs = JobsHelper.Metadata.Where(j => j.PageTitle.Contains(pageTitle));

            foreach (var jobMetadata in jobs)
            {
                var route = $"{ManagementPage.UrlRoute}/{queue}/{jobMetadata.DisplayName?.Replace(" ", string.Empty) ?? jobMetadata.Type.Name}";
                var id    = $"{jobMetadata.DisplayName?.Replace(" ", string.Empty) ?? jobMetadata.Type.Name}";

                if (jobMetadata.MethodInfo.GetParameters().Length > 1)
                {
                    string inputs = string.Empty;

                    foreach (var parameterInfo in jobMetadata.MethodInfo.GetParameters())
                    {
                        if (parameterInfo.ParameterType == typeof(PerformContext) || parameterInfo.ParameterType == typeof(IJobCancellationToken))
                        {
                            continue;
                        }

                        DisplayDataAttribute displayInfo = null;
                        if (parameterInfo.GetCustomAttributes(true).OfType <DisplayDataAttribute>().Any())
                        {
                            displayInfo = parameterInfo.GetCustomAttribute <DisplayDataAttribute>();
                        }

                        var myId = $"{id}_{parameterInfo.Name}";
                        if (parameterInfo.ParameterType == typeof(string))
                        {
                            inputs += InputTextbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(int))
                        {
                            inputs += InputNumberbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(DateTime))
                        {
                            inputs += InputDatebox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else if (parameterInfo.ParameterType == typeof(bool))
                        {
                            inputs += "<br/>" + InputCheckbox(myId, displayInfo?.LabelText ?? parameterInfo.Name, displayInfo?.PlaceholderText ?? parameterInfo.Name);
                        }
                        else
                        {
                            Logging.LogProvider.GetCurrentClassLogger().Log(Logging.LogLevel.Warn, () => "Parameter-type is not supported.");
                            //throw new NotImplementedException();
                        }
                    }

                    Panel(id, jobMetadata.DisplayName, jobMetadata.Description, inputs, CreateButtons(route, "Enqueue", "enqueueing", id));
                }
                else
                {
                    Panel(id, jobMetadata.DisplayName, jobMetadata.Description, string.Empty, CreateButtons(route, "Enqueue", "enqueueing", id));
                }
            }

            WriteLiteral("\r\n<script src=\"");
            Write(Url.To($"/jsm"));
            WriteLiteral("\"></script>\r\n");
        }