示例#1
0
        public override void ParseParameters()
        {
            Upper           = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Upper Bound").Value);
            Lower           = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Lower Bound").Value);
            Target          = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Target").Value);
            MinRewarded     = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Min % Rewarded").Value);
            MaxRewarded     = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Max % Rewarded").Value);
            MinNumOfTrials  = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Min Num of Trials").Value);
            pTarget         = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "% Target").Value);
            JSPressState    = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Joystick Pressed State").Value);
            JSPressSubFSM   = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Joystick Pressed Sub FSM").Value);
            RewardState     = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Reward State").Value);
            RewardSubFSM    = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Reward Sub FSM").Value);
            Shaping         = bool.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Shape?").Value);
            TargetEdgeDist  = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Edge Distance").Value);
            MinJumpDist     = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Min Jump Distance").Value);
            BoundThreshJump = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Bound Threshold for Jump").Value);


            // inputs of the random reward scheme
            RandomReward  = bool.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Random Reward?").Value);
            defNormTrials = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Normal Trials").Value);
            defProbTrials = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Prob Trials").Value);
            BlockJitter   = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Block Jitter").Value);
            RewardProb1   = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Reward Prob 1").Value);
            RewardProb2   = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Reward Prob 2").Value);
            RewardProb3   = double.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Reward Prob 3").Value);
            numBlocks     = int.Parse(ScriptParameters.First(a => a.ScriptParameter.Name == "Blocks in Cycle").Value);
        }
示例#2
0
        public static IEnumerable SqlQuery(string query, ScriptParameters parameters)
        {
            var command = ReadOnlyCommand(CommandType.Text);

            if (parameters != null)
            {
                foreach (KeyValuePair <object, object> kvp in parameters)
                {
                    if (query.Contains("@" + kvp.Key.ToString()))
                    {
                        command.Param(kvp.Key.ToString(), kvp.Value.ToString() == "null", DBNull.Value, kvp.Value);
                    }
                }
            }

            DataTable dt = command.FillDataTable(query);
            IList <IDictionary <object, object> > result = new List <IDictionary <object, object> >();

            foreach (DataRow dr in dt.Rows)
            {
                IDictionary <object, object> dict = new Dictionary <object, object>();
                foreach (DataColumn dc in dt.Columns)
                {
                    dict.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                result.Add(dict);
            }

            return(result);
        }
示例#3
0
 public ScriptCompilerOptions(ScriptParameters parameters)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters");
     }
     _parameters = parameters;
 }
示例#4
0
        public DataFeedResult GetDataFeedResult(string alias, string key, IDictionary <object, object> parameters = null)
        {
            var feed = Session.Query <DataFeed>().FirstOrDefault(x => x.FeedAlias == alias);

            DataFeedResult result = null;

            if (feed != null)
            {
                result = new DataFeedResult
                {
                    ID          = feed.FeedID,
                    GUID        = feed.FeedGUID,
                    Alias       = feed.FeedAlias,
                    Name        = feed.FeedName,
                    Description = feed.FeedDescription,
                    Private     = feed.Private,
                    Active      = feed.Active,
                    Deleted     = feed.Deleted,
                    Data        = null
                };

                if (result.Deleted)
                {
                    return(result);
                }

                if (parameters == null)
                {
                    parameters = new Dictionary <object, object>();
                }

                feed.ApplyDefaultParameters(parameters);

                DataSet ds = ExecuteQuery(feed, ScriptParameters.Create(parameters));
                result.Name = ds.DataSetName;
                result.Data = new DataFeedResultSet();

                IList <DataTable> tables = GetTables(ds, key);

                foreach (DataTable dt in tables)
                {
                    var items = new DataFeedResultItemCollection();
                    foreach (DataRow dr in dt.Rows)
                    {
                        var item = new DataFeedResultItem();
                        foreach (DataColumn dc in dt.Columns)
                        {
                            item[dc.ColumnName] = dr[dc.ColumnName].ToString();
                        }
                        items.Add(item);
                    }

                    result.Data[dt.TableName] = items;
                }
            }

            return(result);
        }
示例#5
0
        private ScriptParameters GetParameters(DataFeed feed)
        {
            var dict = new Dictionary <object, object>();

            Merge(dict, Request.QueryString);
            Merge(dict, Request.Form);
            feed.ApplyDefaultParameters(dict);

            var result = ScriptParameters.Create(dict);

            return(result);
        }
示例#6
0
        public ScriptResult Run(string script, ScriptParameters parameters = null)
        {
            if (string.IsNullOrEmpty(script))
            {
                throw new Exception("No script was provided");
            }

            Engine eng = ScriptingContext.Engine;

            eng.Run(script, parameters);

            return(eng.Result);
        }
示例#7
0
        public DataSet ExecuteQuery(DataFeed feed, HttpRequestBase request)
        {
            var parameters = new Dictionary <object, object>();

            foreach (var key in request.QueryString.AllKeys)
            {
                parameters.Add(key, request.QueryString[key]);
            }

            var util = new DataFeedUtility(Provider);

            feed.ApplyDefaultParameters(parameters);
            return(util.ExecuteQuery(feed, ScriptParameters.Create(parameters)));
        }
示例#8
0
        public ActionResult Ajax(FeedModel model)
        {
            model.Provider = Provider;

            if (model.Command == "run-script")
            {
                string    query  = string.Empty;
                string    error  = string.Empty;
                string    buffer = string.Empty;
                string    html   = string.Empty;
                Hashtable data   = new Hashtable();

                if (model.FeedType == DataFeedType.Python)
                {
                    query = model.Query;
                }
                else
                {
                    query = string.Format("data(sqlquery(\"{0}\"))", model.Query.Replace("\n", " ").Replace("\"", @"\""").Trim());
                }

                var dict = new Dictionary <object, object>();
                DataFeedItem.ApplyDefaultParameters(model.DefaultParameters, dict);

                var parameters = ScriptParameters.Create(dict);

                var result = _engine.Run(query, parameters);

                if (result.Exception != null)
                {
                    error = result.Exception.Message;
                }

                buffer = result.Buffer.ToString();
                html   = result.Html.ToString();
                if (result.DataSet.Count > 0)
                {
                    foreach (KeyValuePair <string, ScriptData> kvp in result.DataSet)
                    {
                        data.Add(kvp.Key, new { Headers = kvp.Value.GetHeaders().Select(x => x.DisplayText).ToArray(), Items = kvp.Value.GetItems() });
                    }
                }

                return(Json(new { Success = true, Message = "", Error = error, Buffer = buffer, Html = html, Data = data, Parameters = parameters.ToString() }));
            }
            else
            {
                return(Json(new { Success = false, Message = "Invalid command" }));
            }
        }
示例#9
0
        private DataSet ExecuteQuery(DataFeed feed, ScriptParameters parameters)
        {
            DataSet   ds = new DataSet();
            DataTable dt = null;

            string sql  = feed.FeedQuery;
            string name = feed.FeedName;

            if (parameters != null)
            {
                name = parameters.Replace(name);
            }

            ds.DataSetName = name;

            if (feed.FeedType == DataFeedType.SQL)
            {
                var command = ReadOnlyDataCommand.Create(CommandType.Text);

                if (parameters != null)
                {
                    sql = parameters.Replace(sql);
                    command.Param(parameters);
                }

                command.FillDataSet(ds, sql);

                if (ds.Tables.Count > 0)
                {
                    ds.Tables[0].TableName = "default";
                }
            }
            else
            {
                ScriptResult result = ScriptEngine.Run(feed.FeedQuery, parameters);
                if (result.Exception != null)
                {
                    throw result.Exception;
                }
                foreach (var kvp in result.DataSet)
                {
                    dt           = kvp.Value.AsDataTable();
                    dt.TableName = kvp.Key;
                    ds.Tables.Add(dt);
                }
            }

            return(ds);
        }
    private void OnGUI()
    {
        if (coreData == null)
        {
            foreach (string guid in AssetDatabase.FindAssets("t: CoreData"))
            {
                coreData = AssetDatabase.LoadAssetAtPath <CoreData>(AssetDatabase.GUIDToAssetPath(guid));
            }
        }
        scrollView = GUILayout.BeginScrollView(scrollView);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Script Index : " + currentScriptIndex.ToString());
        currentScriptIndex = EditorGUILayout.Popup(currentScriptIndex, coreData.GetScriptNames());
        if (GUILayout.Button("New Character Script"))
        {
            coreData.characterScripts.Add(new CharacterScript());
            currentScriptIndex = coreData.characterScripts.Count - 1;
        }
        EditorGUILayout.EndHorizontal();
        CharacterScript currentScript = coreData.characterScripts[currentScriptIndex];

        currentScript.name = EditorGUILayout.TextField("Name : ", currentScript.name);
        int deleteParam = -1;

        for (int p = 0; p < currentScript.parameters.Count; p++)
        {
            ScriptParameters currentParam = currentScript.parameters[p];
            EditorGUILayout.BeginHorizontal();

            currentParam.name = EditorGUILayout.TextField("Parameter Name : ", currentParam.name);
            if (GUILayout.Button("x", GUILayout.Width(25)))
            {
                deleteParam = p;
            }

            EditorGUILayout.EndHorizontal();
            currentParam.val = EditorGUILayout.FloatField("Default Value : ", currentParam.val);
        }
        if (deleteParam > -1)
        {
            currentScript.parameters.RemoveAt(deleteParam);
        }
        if (GUILayout.Button("+", GUILayout.Width(25)))
        {
            currentScript.parameters.Add(new ScriptParameters());
        }
        GUILayout.EndScrollView();
        EditorUtility.SetDirty(coreData);
    }
示例#11
0
        public static IList <IDictionary> Query(string query, ScriptParameters parameters)
        {
            IList <IDictionary> result = null;

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnSselData"].ConnectionString))
                using (var cmd = new SqlCommand(query, conn))
                    using (var adap = new SqlDataAdapter(cmd))
                    {
                        ApplyParameters(cmd, parameters);
                        var dt = new DataTable();
                        adap.Fill(dt);
                        result = DataTableToList(dt);
                        conn.Close();
                    }

            return(result);
        }
示例#12
0
        public static void ApplyParameters(SqlCommand cmd, ScriptParameters parameters)
        {
            foreach (var kvp in parameters)
            {
                var p = cmd.CreateParameter();

                p.ParameterName = kvp.Key.ToString();

                if (kvp.Value == null)
                {
                    p.Value = DBNull.Value;
                }
                else
                {
                    p.Value = kvp.Value;
                }

                cmd.Parameters.Add(p);
            }
        }
        public void Method1(ScriptParameters sp)
        {
            string pattern   = @"\|";
            string parameter = sp.InputVariables["[Facture.InstanceID]"].ToString();

            using (Process process = new Process())
            {
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.FileName  = "java";
                process.StartInfo.Arguments = @"-jar C:\\jars\\application.jar " + parameter;
                process.Start();
                StreamReader reader = process.StandardOutput;
                string       output = reader.ReadToEnd();
                process.WaitForExit();
                string[] results = Regex.Split(output, pattern, RegexOptions.IgnoreCase);
                sp.OutputVariables["responseCode"] = results[0];
                sp.OutputVariables["statusCode"]   = results[1];
            }
        }
示例#14
0
 public virtual ScriptResult Run(string script, ScriptParameters parameters = null)
 {
     throw new NotImplementedException();
 }
示例#15
0
        public void Inititialize(IList <Include> includes, StringBuilder initScript = null, ScriptParameters parameters = null)
        {
            Includes = includes;

            Parameters.Merge(parameters);

            Result = new ScriptResult();
            engine = Python.CreateEngine();
            scope  = engine.Runtime.CreateScope();

            StringBuilder sb = DefaultInitScript();

            if (initScript != null)
            {
                sb = sb.Append(initScript.ToString());
            }

            try
            {
                engine.CreateScriptSourceFromString(sb.ToString(), SourceCodeKind.Statements).Execute(scope);
            }
            catch (Exception ex)
            {
                LastException = ex;
                return;
            }

            if (Includes != null)
            {
                ICollection <string> paths = engine.GetSearchPaths();
                foreach (Include inc in Includes)
                {
                    string dir = Path.GetDirectoryName(inc.File.FullName);
                    if (!paths.Contains(dir))
                    {
                        paths.Add(dir);
                    }
                }

                engine.SetSearchPaths(paths);

                foreach (Include inc in Includes)
                {
                    if (!string.IsNullOrEmpty(inc.ClassName))
                    {
                        engine.CreateScriptSourceFromString(string.Format("import {0}", inc.ClassName), SourceCodeKind.SingleStatement).Execute(scope);
                    }
                }
            }

            try
            {
                SetVariable("query", new QueryDelegate(Query));
                SetVariable("sqlquery", new SqlQueryDelegate(SqlQuery));
                SetVariable("tools", new Tools());
                SetVariable("echo", new EchoDelegate(Echo));
                SetVariable("html", new SetHtmlDelegate(SetHtml));
                SetVariable("tag", new CreateTagDelegate(CreateTag));
                SetVariable("data", new SetDataDelegate(SetData));
                SetVariable("feed", new ExecuteFeedDelegate(ExecuteFeed));
                SetVariable("header", new SetHeaderDelegate(SetHeader));
                SetVariable("mail", new SendMailDelegate(SendMail));
                SetVariable("title", new EchoDelegate(SetTitle));
                SetVariable("err", new EchoDelegate(SetError));
                SetVariable("param", new GetParameterValueDelegate(GetParameterValue));
                SetVariable("nl", Environment.NewLine);
            }
            catch (Exception ex)
            {
                LastException = ex;
                return;
            }
        }