コード例 #1
0
        public static object ExeConfig(Models.Code code, WebSite site)
        {
            RenderContext context = new RenderContext();

            context.WebSite = site;
            var engine   = new Jint.Engine(JintSetting.SetOption);
            var kcontext = new k(context);

            engine.SetValue("k", kcontext);

            var k = engine.GetValue("k");

            kcontext.ReturnValues.Clear();
            try
            {
                engine.Execute(code.Config);
            }
            catch (System.Exception ex)
            {
            }

            if (kcontext.ReturnValues.Count() > 0)
            {
                return(kcontext.ReturnValues.Last());
            }
            return(null);
        }
コード例 #2
0
        public static bool FromCodeBytes(Models.Code code, byte[] DiskBytes)
        {
            string text = System.Text.Encoding.UTF8.GetString(DiskBytes);

            var linebreak = text.IndexOf(_endmark);

            var type = GetFirstLineString(text, "type");

            if (type != null && linebreak > -1)
            {
                var codebody = text.Substring(linebreak + _endmark.Length);
                if (codebody.StartsWith("\r\n"))
                {
                    codebody = codebody.Substring("\r\n".Length);
                }
                else if (codebody.StartsWith("\n"))
                {
                    codebody = codebody.Substring("\n".Length);
                }
                code.CodeType = Lib.Helper.EnumHelper.GetEnum <Kooboo.Sites.Models.CodeType>(type);
                code.Body     = codebody;
                return(true);
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// 失败,带泛型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="msg"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static ApiResult <T> ErrorResult <T>(string msg, Models.Code status = Models.Code.Error)
        {
            ApiResult <T> result = new ApiResult <T>();

            result.Code    = status;
            result.Message = msg;
            return(result);
        }
コード例 #4
0
ファイル: FillTables.cs プロジェクト: marcusjobb/Net20
        public static void fillCodes()
        {
            using (var addData = new ApartmentDB())
            {
                //Add codes to table
                var code = new Models.Code
                {
                    ID          = 1,
                    Codes       = "DI",
                    Explanation = "from the outside"
                };
                addData.Codes.Add(code);

                code = new Models.Code
                {
                    ID          = 2,
                    Codes       = "DO",
                    Explanation = "from the inside"
                };
                addData.Codes.Add(code);

                code = new Models.Code
                {
                    ID          = 3,
                    Codes       = "WDI",
                    Explanation = "wrong door in"
                };
                addData.Codes.Add(code);

                code = new Models.Code
                {
                    ID          = 4,
                    Codes       = "WDO",
                    Explanation = "wrong door out"
                };
                addData.Codes.Add(code);

                addData.SaveChanges();
                //Codes added to table
            }
        }
コード例 #5
0
ファイル: Manager.cs プロジェクト: weedkiller/Kooboo
        public static object ExeConfig(Models.Code code, WebSite site)
        {
            RenderContext context = new RenderContext();

            context.WebSite = site;
            var engine   = new Jint.Engine(JintSetting.SetOption);
            var kcontext = new k(context);

            engine.SetValue("k", kcontext);

            var k = engine.GetValue("k");

            kcontext.ReturnValues.Clear();

            try
            {
                engine.ExecuteWithErrorHandle(code.Config, new Jint.Parser.ParserOptions()
                {
                    Tolerant = true
                });
            }
            catch (System.Exception ex)
            {
                Kooboo.Data.Log.Instance.Exception.WriteException(ex);
            }

            if (kcontext.ReturnValues.Count() > 0)
            {
                return(kcontext.ReturnValues.Last());
            }
            else
            {
                var obj = EngineConfigReturnObject(engine);
                return(obj);
            }
        }
コード例 #6
0
ファイル: Manager.cs プロジェクト: weedkiller/Kooboo
        public static List <Data.Models.SimpleSetting> GetSetting(WebSite website, Models.Code code)
        {
            var config = Kooboo.Sites.Scripting.Manager.ExeConfig(code, website);

            List <Data.Models.SimpleSetting> settings = new List <SimpleSetting>();

            if (config != null)
            {
                var items = ((IEnumerable)config).Cast <object>().ToList();

                if (items != null && items.Count() > 0)
                {
                    foreach (var item in items)
                    {
                        SimpleSetting setting = new SimpleSetting();

                        var dict = item as IDictionary <string, object>;

                        object SelectionValues = null;

                        foreach (var keyvalue in dict)
                        {
                            var lowerkey = keyvalue.Key.ToLower();

                            if (lowerkey == "name")
                            {
                                setting.Name = keyvalue.Value.ToString();
                            }
                            else if (lowerkey == "tooltip")
                            {
                                setting.ToolTip = keyvalue.Value.ToString();
                            }
                            else if (lowerkey == "controltype")
                            {
                                setting.ControlType = GetControlType(keyvalue.Value.ToString());
                            }
                            else if (lowerkey == "value" || lowerkey == "defaultvalue")
                            {
                                setting.DefaultValue = keyvalue.Value;
                            }
                            else if (lowerkey == "selectionvalues" || lowerkey == "selectionvalues")
                            {
                                SelectionValues = keyvalue.Value;
                            }
                        }

                        if (setting.ControlType == Data.ControlType.Selection && SelectionValues != null)
                        {
                            var selections = SelectionValues as IDictionary <string, object>;

                            if (selections != null)
                            {
                                if (setting.SelectionValues == null)
                                {
                                    setting.SelectionValues = new Dictionary <string, string>();
                                }

                                foreach (var se in selections)
                                {
                                    setting.SelectionValues.Add(se.Key, se.Value.ToString());
                                }
                            }
                        }

                        settings.Add(setting);
                    }
                }
            }

            return(settings);
        }
コード例 #7
0
        protected void BtnAdd_Click(object sender, EventArgs e)
        {
            string language = "";

            CheckBox[] checkBoxes = new CheckBox[3] {
                chkJava, chkPython, chkCSharp
            };
            foreach (CheckBox checkBox in checkBoxes)
            {
                if (checkBox.Checked == true)
                {
                    language += checkBox.Text + ",";
                }
            }
            language = language.Substring(0, language.Length - 1);
            Models.Code code = new Models.Code()
            {
                Repository = txtRepository.Text,
                Url        = txtUrl.Text,
                Language   = language
            };
            CodeService codeService = new CodeService();
            bool        exist       = codeService.IsCodeExist(code.Repository);
            string      message     = exist ? "modify" : "add";
            bool        success;

            if (fupDemo.FileName == "")
            {
                if (exist)
                {
                    success = codeService.UpdateCode(code) == 1;
                }
                else
                {
                    success = codeService.InsertCode(code, null);
                }
            }
            else
            {
                string[] name = fupDemo.FileName.Split('.');
                if (name[name.Length - 1].ToLower() != "jpg")
                {
                    ltlMsg.Text = "<script>alert('图片必须jpg')</script>";
                    return;
                }
                if (fupDemo.FileContent.Length > 1024 * 1024)
                {
                    ltlMsg.Text = "<script>alert('不能超过1M')</script>";
                    return;
                }
                if (exist)
                {
                    success = codeService.UpdateCode(code, fupDemo.PostedFile.InputStream);
                }
                else
                {
                    success = codeService.InsertCode(code, fupDemo.PostedFile.InputStream);
                }
            }
            if (success)
            {
                Response.Redirect("~/Code/AddRepository.aspx?" + message + "=1");
            }
            else
            {
                ltlMsg.Text = "<script>alert('" + message + "异常')</script>";
            }
        }