コード例 #1
0
ファイル: CodeFilters.cs プロジェクト: mbsky/kub-engine
    public static object GetData(StageParams config)
    {
        string[] parts = config.map.Split( new char[]{':'}, 3 );
        if ( parts.Length > 2 ) config.map = parts[2];

        string key = parts[0] + parts[1];
        StageAction action = null;

        lock ( loaded )
        {
            if ( loaded.ContainsKey( key ) ) action = loaded[key];
        }

        if ( action == null )
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            Type filters = asm.GetType(parts[0]);
            MethodInfo filter = filters.GetMethod(parts[1]);

            action = delegate( StageParams conf )
            {
                return filter.Invoke(null, new object[] { conf });
            };

            lock (loaded)
            {
                loaded.Add(key, action);
            }
        }

        return action(config);
    }
コード例 #2
0
    /*
     *  direct time output
     */
    public static object output_time(StageParams config)
    {
        XmlDocument input = Util.Validate <XmlDocument>(config.data, "output_time");

        config.context.Response.Write(input.FirstChild.ChildNodes[1].FirstChild.FirstChild.FirstChild.Value.ToString());
        return(null);
    }
コード例 #3
0
ファイル: XSLTFilter.cs プロジェクト: mbsky/kub-engine
    public static object GetData(StageParams config)
    {
        XmlDocument input = Util.Validate<XmlDocument>( config.data, "XSLTStage" );

        string xslPath = config.context.Server.MapPath( config.map );
        if (!File.Exists(xslPath))
            throw new FileLoadException(String.Format("Style sheet {0} is not found", xslPath));

        XslCompiledTransform transform = new XslCompiledTransform();
        transform.Load(xslPath, new XsltSettings(false, true), new XmlUrlResolver());

        XsltArgumentList al = new XsltArgumentList();

        int index = 0;
        foreach (XmlNode node in config.stage)
            if ( node.Attributes["type"] != null )
                al.AddParam( node.Name, "", config.allParams[index++]);

        if (!config.last)
        {
            MemoryStream output = new MemoryStream();
            transform.Transform(input, al, output);
            return output;
        }
        else
        {
            transform.Transform(input, al, config.outputStream);
            return null;
        }
    }
コード例 #4
0
        public override bool RunScriptCommand()
        {
            BattleStateManager current = BattleStateManager.current;
            bool result;

            if (current != null)
            {
                result = true;
                StageParams stageParams = current.hierarchyData.stageParams;
                ClassSingleton <AdventureSceneData> .Instance.stage = stageParams.gameObject;
                LightColorChanger lightColorChanger = ClassSingleton <AdventureSceneData> .Instance.adventureLight.GetComponent <LightColorChanger>();

                if (lightColorChanger == null)
                {
                    lightColorChanger = ClassSingleton <AdventureSceneData> .Instance.adventureLight.gameObject.AddComponent <LightColorChanger>();
                }
                BattleCameraObject battleCameraObject = stageParams.gameObject.AddComponent <BattleCameraObject>();
                battleCameraObject.sunLight             = ClassSingleton <AdventureSceneData> .Instance.adventureLight;
                battleCameraObject.camera3D             = ClassSingleton <AdventureSceneData> .Instance.adventureCamera.camera3D;
                battleCameraObject.sunLightColorChanger = lightColorChanger;
                stageParams.SetHierarchyEnviroments(battleCameraObject);
                base.ResumeScriptEngine();
            }
            else
            {
                result = false;
            }
            return(result);
        }
コード例 #5
0
    /*
     *  Convert current stream output to XMLDocument output
     */
    public static object stream_to_xml_document(StageParams config)
    {
        Stream      input = Util.Validate <Stream>(config.data, "myfilter:stream_to_xml_document");
        XmlDocument doc   = new XmlDocument();

        doc.Load(input);
        input.Close();
        return(doc);
    }
コード例 #6
0
    /*
     *  log current output
     */
    public static object log_output(StageParams config)
    {
        //MemoryStream stream = new MemoryStream();
        //Types.WriteOutput( config.data, stream );
        //byte[] temp = new byte[ stream.Length ];
        //stream.Seek( 0, SeekOrigin.Begin );
        //stream.Read( temp, 0, (int)stream.Length );

        //Log.Error("log_output", System.Text.Encoding.UTF8.GetString(temp), config.context);
        return(config.data);
    }
コード例 #7
0
ファイル: MyFilters.cs プロジェクト: mbsky/kub-engine
    /*
        log current output
    */
    public static object log_output(StageParams config)
    {
        //MemoryStream stream = new MemoryStream();
        //Types.WriteOutput( config.data, stream );
        //byte[] temp = new byte[ stream.Length ];
        //stream.Seek( 0, SeekOrigin.Begin );
        //stream.Read( temp, 0, (int)stream.Length );

        //Log.Error("log_output", System.Text.Encoding.UTF8.GetString(temp), config.context);
        return config.data;
    }
コード例 #8
0
ファイル: MyFilters.cs プロジェクト: mbsky/kub-engine
    /*
        This filter an example of using code filters.
        It's add column to XmlDocument table with number of row value.
        Now this done actually via xslt position() function now - but I left this code for reference.

        <stage map="code:myfilters:add_line_numbers">
          <start_number type="int" input_index="1"/>
        </stage>
    */
    public static object add_line_numbers(StageParams config)
    {
        XmlDocument input = Util.Validate<XmlDocument>( config.data, "myfilter:add_line_numbers" );

        Util.AddNodedText(input.FirstChild.ChildNodes[0], "column", "", true);

        XmlNode body = input.FirstChild.ChildNodes[1];
        for (int i = 0; i < body.ChildNodes.Count; ++i) Util.AddNodedText(body.ChildNodes[i], "value",
            ( (int)config.allParams[0] + i + 1).ToString(), true);

        return input;
    }
コード例 #9
0
ファイル: StageProcessor.cs プロジェクト: mbsky/kub-engine
 public static object Dispatch(StageParams config, Dictionary<string, StageAction> mapping)
 {
     string[] subMapping = config.map.Split(new char[] { ':' }, 2);
     
     config.map = subMapping[1];
     
     string key = subMapping[0];
     
     if (mapping.ContainsKey(key)) return mapping[key](config);
     
     throw new Exception("Unknow mapping key: " + key);
 }
コード例 #10
0
ファイル: MyFilters.cs プロジェクト: mbsky/kub-engine
    /*
        This filter change xml table structure from
        <root>
        <head><column>cn</column></head>
        <body><row><value>123</value></row></body>
        </root>

        to

        <root>
        <head><column>cn</column></head>
        <body><row><cn>123</cn></row></body>
        </root>
    */
    public static object set_values_column_name(StageParams config)
    {
        XmlDocument input = Util.Validate<XmlDocument>(config.data, "myfilter:set_values_column_name");

        XmlNode head = input.FirstChild.ChildNodes[0];
        XmlNode body = input.FirstChild.ChildNodes[1];

        foreach (XmlNode row in body.ChildNodes)
            for (int i = 0; i < row.ChildNodes.Count; ++i)
                row.ReplaceChild(Util.ChangeName(row.ChildNodes[i], head.ChildNodes[i].FirstChild.Value), row.ChildNodes[i] );

        return input;
    }
コード例 #11
0
ファイル: StageProcessor.cs プロジェクト: mbsky/kub-engine
    public static object Dispatch(StageParams config, Dictionary <string, StageAction> mapping)
    {
        string[] subMapping = config.map.Split(new char[] { ':' }, 2);

        config.map = subMapping[1];

        string key = subMapping[0];

        if (mapping.ContainsKey(key))
        {
            return(mapping[key](config));
        }

        throw new Exception("Unknow mapping key: " + key);
    }
コード例 #12
0
    /*
     *  This filter an example of using code filters.
     *  It's add column to XmlDocument table with number of row value.
     *  Now this done actually via xslt position() function now - but I left this code for reference.
     *
     *  <stage map="code:myfilters:add_line_numbers">
     *    <start_number type="int" input_index="1"/>
     *  </stage>
     */
    public static object add_line_numbers(StageParams config)
    {
        XmlDocument input = Util.Validate <XmlDocument>(config.data, "myfilter:add_line_numbers");

        Util.AddNodedText(input.FirstChild.ChildNodes[0], "column", "", true);

        XmlNode body = input.FirstChild.ChildNodes[1];

        for (int i = 0; i < body.ChildNodes.Count; ++i)
        {
            Util.AddNodedText(body.ChildNodes[i], "value",
                              ((int)config.allParams[0] + i + 1).ToString(), true);
        }

        return(input);
    }
コード例 #13
0
    /*
     *  This filter change xml table structure from
     *  <root>
     *  <head><column>cn</column></head>
     *  <body><row><value>123</value></row></body>
     *  </root>
     *
     *  to
     *
     *  <root>
     *  <head><column>cn</column></head>
     *  <body><row><cn>123</cn></row></body>
     *  </root>
     */
    public static object set_values_column_name(StageParams config)
    {
        XmlDocument input = Util.Validate <XmlDocument>(config.data, "myfilter:set_values_column_name");

        XmlNode head = input.FirstChild.ChildNodes[0];
        XmlNode body = input.FirstChild.ChildNodes[1];

        foreach (XmlNode row in body.ChildNodes)
        {
            for (int i = 0; i < row.ChildNodes.Count; ++i)
            {
                row.ReplaceChild(Util.ChangeName(row.ChildNodes[i], head.ChildNodes[i].FirstChild.Value), row.ChildNodes[i]);
            }
        }

        return(input);
    }
コード例 #14
0
    public static object GetData(StageParams config)
    {
        XmlDocument input = Util.Validate <XmlDocument>(config.data, "XSLTStage");

        string xslPath = config.context.Server.MapPath(config.map);

        if (!File.Exists(xslPath))
        {
            throw new FileLoadException(String.Format("Style sheet {0} is not found", xslPath));
        }

        XslCompiledTransform transform = new XslCompiledTransform();

        transform.Load(xslPath, new XsltSettings(false, true), new XmlUrlResolver());

        XsltArgumentList al = new XsltArgumentList();

        int index = 0;

        foreach (XmlNode node in config.stage)
        {
            if (node.Attributes["type"] != null)
            {
                al.AddParam(node.Name, "", config.allParams[index++]);
            }
        }

        if (!config.last)
        {
            MemoryStream output = new MemoryStream();
            transform.Transform(input, al, output);
            return(output);
        }
        else
        {
            transform.Transform(input, al, config.outputStream);
            return(null);
        }
    }
コード例 #15
0
ファイル: CodeFilters.cs プロジェクト: mbsky/kub-engine
    public static object GetData(StageParams config)
    {
        string[] parts = config.map.Split(new char[] { ':' }, 3);
        if (parts.Length > 2)
        {
            config.map = parts[2];
        }

        string      key    = parts[0] + parts[1];
        StageAction action = null;

        lock ( loaded )
        {
            if (loaded.ContainsKey(key))
            {
                action = loaded[key];
            }
        }

        if (action == null)
        {
            Assembly   asm     = Assembly.GetExecutingAssembly();
            Type       filters = asm.GetType(parts[0]);
            MethodInfo filter  = filters.GetMethod(parts[1]);

            action = delegate(StageParams conf)
            {
                return(filter.Invoke(null, new object[] { conf }));
            };

            lock (loaded)
            {
                loaded.Add(key, action);
            }
        }

        return(action(config));
    }
コード例 #16
0
        public override bool RunScriptCommand()
        {
            bool       result = true;
            string     stagePrefabPathByAttackEffectId = CommonResourcesDataMng.Instance().GetStagePrefabPathByAttackEffectId(this.stageFileName);
            GameObject original   = AssetDataMng.Instance().LoadObject(stagePrefabPathByAttackEffectId, null, true) as GameObject;
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(original);

            ClassSingleton <AdventureSceneData> .Instance.stage = gameObject;
            gameObject.name             = "Stage";
            gameObject.transform.parent = ClassSingleton <AdventureSceneData> .Instance.scriptObjectRoot.transform;
            LightColorChanger sunLightColorChanger = ClassSingleton <AdventureSceneData> .Instance.adventureLight.gameObject.AddComponent <LightColorChanger>();

            BattleCameraObject battleCameraObject = gameObject.AddComponent <BattleCameraObject>();

            battleCameraObject.sunLight             = ClassSingleton <AdventureSceneData> .Instance.adventureLight;
            battleCameraObject.camera3D             = ClassSingleton <AdventureSceneData> .Instance.adventureCamera.camera3D;
            battleCameraObject.sunLightColorChanger = sunLightColorChanger;
            StageParams component = gameObject.GetComponent <StageParams>();

            component.SetHierarchyEnviroments(battleCameraObject);
            base.ResumeScriptEngine();
            return(result);
        }
コード例 #17
0
ファイル: MysqlSource.cs プロジェクト: mbsky/kub-engine
    public static object GetData( StageParams config )
    {
        if (settings == null) settings = Util.GetByName(Engine.GetConfig(), "mysql");

        using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection())
        {
            conn.ConnectionString = settings.Attributes["connectionString"].Value;
            conn.Open();

            using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand())
            {
                cmd.Connection = conn;

                object result = null;

                /*
                    mysql map details
                    [code/storeprocedure]:[table/scalar/nonquery]:[text/procedure name]
                */

                string[] resultMap = config.map.Split(new char[] { ':' }, 3);

                string ct = resultMap[0]; // call type
                string rt = resultMap[1]; // return type
                string mp = resultMap[2]; // mapping ( sql text or store procedure name )

                if (!Validate(ct, validCodeTypes)) throw new Exception("Mysql bad call type: " + ct);
                if (!Validate(rt, validResultTypes)) throw new Exception("Mysql bad result type: " + rt);

                // command text
                cmd.CommandText = mp;

                // command type
                if (ct == "code")
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Prepare();
                }
                else cmd.CommandType = CommandType.StoredProcedure;

                List<string> output_params = new List<string>();

                // named parameters
                for (int i = 0; i < config.stage.ChildNodes.Count; ++i)
                {
                    XmlNode paramNode = config.stage.ChildNodes[i];
                    if (!Util.GetAttr(paramNode, "inplace", false))
                        if (Util.GetAttr(paramNode, "output", false))
                        {
                            cmd.Parameters.Add(paramNode.Name, Convert(paramNode.Attributes["type"].Value));
                            cmd.Parameters[paramNode.Name].Direction = ParameterDirection.Output;
                            output_params.Add(paramNode.Name);
                        }
                        else Add(cmd, "@" + paramNode.Name, config.allParams[i]);
                }

                if (rt == "table")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "Root", ""));

                    MySqlDataReader reader = cmd.ExecuteReader();
                    DataToXML.Write(doc, reader);
                    reader.Close();

                    if (cmd.CommandText.StartsWith("select SQL_CALC_FOUND_ROWS"))
                    {
                        cmd.CommandText = "SELECT FOUND_ROWS()";
                        cmd.Parameters.Clear();
                        reader = cmd.ExecuteReader();
                        reader.Read();
                        doc.FirstChild.Attributes.Append(doc.CreateAttribute("found_rows")).Value = reader.GetInt32(0).ToString();
                        reader.Close();
                    }

                    result = doc;
                }
                else if (rt == "list")
                {
                    MySqlDataReader reader = cmd.ExecuteReader();
                    MemoryStream output = new MemoryStream();
                    DataToList.Write(output, reader);
                    reader.Close();

                    result = output;
                }
                else if (rt == "scalar")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "Root", ""));

                    object callresult = cmd.ExecuteScalar();
                    doc.FirstChild.AppendChild(doc.CreateNode(XmlNodeType.Text, "", ""));
                    doc.FirstChild.FirstChild.Value = callresult.ToString();

                    result = doc;
                }
                else if (rt == "nonquery")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "Root", ""));

                    int affected = cmd.ExecuteNonQuery();
                    doc.FirstChild.Attributes.Append(doc.CreateAttribute("affected")).Value = affected.ToString();

                    result = doc;
                }

                foreach (string param in output_params)
                {
                    XmlDocument doc = Util.Validate<XmlDocument>(result, "Output params for this request not supported");
                    doc.FirstChild.Attributes.Append(
                        doc.CreateAttribute(param)).Value = cmd.Parameters[param].Value.ToString();
                }

                return result;
            }
        }
    }
コード例 #18
0
ファイル: MysqlSource.cs プロジェクト: mbsky/kub-engine
    public static object GetData(StageParams config)
    {
        if (settings == null)
        {
            settings = Util.GetByName(Engine.GetConfig(), "mysql");
        }

        using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection())
        {
            conn.ConnectionString = settings.Attributes["connectionString"].Value;
            conn.Open();

            using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand())
            {
                cmd.Connection = conn;

                object result = null;

                /*
                 *  mysql map details
                 *  [code/storeprocedure]:[table/scalar/nonquery]:[text/procedure name]
                 */

                string[] resultMap = config.map.Split(new char[] { ':' }, 3);

                string ct = resultMap[0]; // call type
                string rt = resultMap[1]; // return type
                string mp = resultMap[2]; // mapping ( sql text or store procedure name )

                if (!Validate(ct, validCodeTypes))
                {
                    throw new Exception("Mysql bad call type: " + ct);
                }
                if (!Validate(rt, validResultTypes))
                {
                    throw new Exception("Mysql bad result type: " + rt);
                }

                // command text
                cmd.CommandText = mp;

                // command type
                if (ct == "code")
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Prepare();
                }
                else
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                }

                List <string> output_params = new List <string>();

                // named parameters
                for (int i = 0; i < config.stage.ChildNodes.Count; ++i)
                {
                    XmlNode paramNode = config.stage.ChildNodes[i];
                    if (!Util.GetAttr(paramNode, "inplace", false))
                    {
                        if (Util.GetAttr(paramNode, "output", false))
                        {
                            cmd.Parameters.Add(paramNode.Name, Convert(paramNode.Attributes["type"].Value));
                            cmd.Parameters[paramNode.Name].Direction = ParameterDirection.Output;
                            output_params.Add(paramNode.Name);
                        }
                        else
                        {
                            Add(cmd, "@" + paramNode.Name, config.allParams[i]);
                        }
                    }
                }

                if (rt == "table")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "Root", ""));

                    MySqlDataReader reader = cmd.ExecuteReader();
                    DataToXML.Write(doc, reader);
                    reader.Close();

                    if (cmd.CommandText.StartsWith("select SQL_CALC_FOUND_ROWS"))
                    {
                        cmd.CommandText = "SELECT FOUND_ROWS()";
                        cmd.Parameters.Clear();
                        reader = cmd.ExecuteReader();
                        reader.Read();
                        doc.FirstChild.Attributes.Append(doc.CreateAttribute("found_rows")).Value = reader.GetInt32(0).ToString();
                        reader.Close();
                    }

                    result = doc;
                }
                else if (rt == "list")
                {
                    MySqlDataReader reader = cmd.ExecuteReader();
                    MemoryStream    output = new MemoryStream();
                    DataToList.Write(output, reader);
                    reader.Close();

                    result = output;
                }
                else if (rt == "scalar")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "Root", ""));

                    object callresult = cmd.ExecuteScalar();
                    doc.FirstChild.AppendChild(doc.CreateNode(XmlNodeType.Text, "", ""));
                    doc.FirstChild.FirstChild.Value = callresult.ToString();

                    result = doc;
                }
                else if (rt == "nonquery")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.AppendChild(doc.CreateNode(XmlNodeType.Element, "Root", ""));

                    int affected = cmd.ExecuteNonQuery();
                    doc.FirstChild.Attributes.Append(doc.CreateAttribute("affected")).Value = affected.ToString();

                    result = doc;
                }

                foreach (string param in output_params)
                {
                    XmlDocument doc = Util.Validate <XmlDocument>(result, "Output params for this request not supported");
                    doc.FirstChild.Attributes.Append(
                        doc.CreateAttribute(param)).Value = cmd.Parameters[param].Value.ToString();
                }

                return(result);
            }
        }
    }
コード例 #19
0
ファイル: FileSource.cs プロジェクト: mbsky/kub-engine
 public static object GetData( StageParams config )
 {
     FileStream stream = new FileStream( config.context.Server.MapPath( config.map ), FileMode.Open, FileAccess.Read);
     return stream;
 }
コード例 #20
0
ファイル: Engine.cs プロジェクト: mbsky/kub-engine
    private void Process(string url, HttpContext context)
    {
        string[] urlParts = url.Split('/');

        string fullActionName = String.Join("-", new string[] { urlParts[2], urlParts[1], urlParts[0] });

        // get service description
        if (!serverActions.ContainsKey(fullActionName))
            throw new Exception( String.Format("Action {0} ( sysname: {1} ) is not defined", url, fullActionName));

        XmlNode service = serverActions[fullActionName];
        Stream  outputStream = null;

        //  ---------- cashe case ----------------------------------------------------------------------------

        bool noinfo = Util.GetAttr(service, "noinfo", false);
        bool nocache = Util.GetAttr(service, "nocache", false ) || System.Configuration.ConfigurationManager.AppSettings["nocache"] == "true";

        if (!nocache)
        {
            // have cached values?
            object saved = context.Cache.Get(url);
            if (saved != null)
            {
                Log.Info(String.Format("KUCE_use_cache: {0}", url), context);
                Types.WriteOutput(saved, context.Response.OutputStream, false);
                return;
            }

            outputStream = new MemoryStream(0x5000);
        }
        else outputStream = context.Response.OutputStream;

        //   ----------------------------------------------------------------------------

        // log action start
        int start = Environment.TickCount;

        if ( !noinfo )
            Log.Info(String.Format("KUCE_process {0}, current active: {1}", url, activeHandles.ToString()), context);

        // prepare all service params
        string[] allValues = new string[urlParts.Length - 3];
        Array.Copy(urlParts, 3, allValues, 0, allValues.Length);

        // the process
        List<object> output = new List<object>();
        object data = null;
        int    currentParamIndex = 0; // specify how params was used from input

        // action must be locked?

        if (service.Attributes["locked"] != null) Monitor.Enter(service);
        try
        {
            foreach (XmlNode stage in service.ChildNodes)
            {
                if (stage.Name == "stage")
                {
                    bool lastStage = false;

                    if (stage.NextSibling == null || Util.GetAttr(stage.NextSibling, "flush", false) )
                        lastStage = true;

                    if ( Util.GetAttr(stage, "flush", false) && data != null ) output.Add(data);

                    object[] stageParams = Types.GetParamsForStage(stage, allValues, ref currentParamIndex, context);

                    /*
                        inplace параметры применяются к mapping ещё до того как стейдж начинается парситься,
                        что позволяет очень гибко настраивать стейд через параметры
                    */
                    List<object> inplace = new List<object>();
                    for (int i = 0; i < stage.ChildNodes.Count; ++i)
                    {
                        XmlNode paramNode = stage.ChildNodes[i];
                        if (Util.GetAttr(paramNode, "inplace", false ) ) inplace.Add(stageParams[i]);
                    }

                    string stageMapping = String.Format(stage.Attributes["map"].Value, inplace.ToArray());

                    StageParams config = new StageParams(data, stage, stageParams, context, stageMapping, lastStage, outputStream);

                    data = StageParams.Dispatch(config, StageProcessor.actions);
                }
            }
        }
        catch (Exception ex)
        {
            HandleError(ex, context);
        }
        finally
        {
            if (service.Attributes["locked"] != null) Monitor.Exit(service);
        }

        if (data != null) output.Add(data);

        foreach (object result in output) Types.WriteOutput(result, outputStream, true);

        Types.WriteOutput(outputStream, context.Response.OutputStream, false);

        // -------- caching issues ----------------------------------------------------------------

        if (!nocache)
        {
            // cache is filled and ready
            context.Cache.Insert(url, outputStream, Dependency.Get( String.Join("/", new string[] { urlParts[0], urlParts[1] } ) ),
                    System.Web.Caching.Cache.NoAbsoluteExpiration,
                    System.Web.Caching.Cache.NoSlidingExpiration );
        }

        if (Util.GetAttr(service, "noclientcache", false ))
        {
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Cache.SetNoStore();
        }
        else
        {
            context.Response.Cache.SetMaxAge(TimeSpan.FromMinutes(60));
            context.Response.Cache.SetProxyMaxAge(TimeSpan.FromMinutes(60));
        }

        if ( service.Attributes["flushcache"] != null) Dependency.Update(service.Attributes["flushcache"].Value);

        // ----------------------------------------------------------------------------------------

        if ( !noinfo )
            Log.Info(String.Format("KUCE_end {0}, time: {1}", url, Environment.TickCount - start ), context);
    }
コード例 #21
0
    private void Process(string url, HttpContext context)
    {
        string[] urlParts = url.Split('/');


        string fullActionName = String.Join("-", new string[] { urlParts[2], urlParts[1], urlParts[0] });

        // get service description
        if (!serverActions.ContainsKey(fullActionName))
        {
            throw new Exception(String.Format("Action {0} ( sysname: {1} ) is not defined", url, fullActionName));
        }

        XmlNode service      = serverActions[fullActionName];
        Stream  outputStream = null;

        //  ---------- cashe case ----------------------------------------------------------------------------

        bool noinfo  = Util.GetAttr(service, "noinfo", false);
        bool nocache = Util.GetAttr(service, "nocache", false) || System.Configuration.ConfigurationManager.AppSettings["nocache"] == "true";

        if (!nocache)
        {
            // have cached values?
            object saved = context.Cache.Get(url);
            if (saved != null)
            {
                Log.Info(String.Format("KUCE_use_cache: {0}", url), context);
                Types.WriteOutput(saved, context.Response.OutputStream, false);
                return;
            }

            outputStream = new MemoryStream(0x5000);
        }
        else
        {
            outputStream = context.Response.OutputStream;
        }

        //   ----------------------------------------------------------------------------

        // log action start
        int start = Environment.TickCount;

        if (!noinfo)
        {
            Log.Info(String.Format("KUCE_process {0}, current active: {1}", url, activeHandles.ToString()), context);
        }

        // prepare all service params
        string[] allValues = new string[urlParts.Length - 3];
        Array.Copy(urlParts, 3, allValues, 0, allValues.Length);

        // the process
        List <object> output            = new List <object>();
        object        data              = null;
        int           currentParamIndex = 0; // specify how params was used from input

        // action must be locked?

        if (service.Attributes["locked"] != null)
        {
            Monitor.Enter(service);
        }
        try
        {
            foreach (XmlNode stage in service.ChildNodes)
            {
                if (stage.Name == "stage")
                {
                    bool lastStage = false;

                    if (stage.NextSibling == null || Util.GetAttr(stage.NextSibling, "flush", false))
                    {
                        lastStage = true;
                    }

                    if (Util.GetAttr(stage, "flush", false) && data != null)
                    {
                        output.Add(data);
                    }

                    object[] stageParams = Types.GetParamsForStage(stage, allValues, ref currentParamIndex, context);

                    /*
                     *  inplace параметры применяются к mapping ещё до того как стейдж начинается парситься,
                     *  что позволяет очень гибко настраивать стейд через параметры
                     */
                    List <object> inplace = new List <object>();
                    for (int i = 0; i < stage.ChildNodes.Count; ++i)
                    {
                        XmlNode paramNode = stage.ChildNodes[i];
                        if (Util.GetAttr(paramNode, "inplace", false))
                        {
                            inplace.Add(stageParams[i]);
                        }
                    }

                    string stageMapping = String.Format(stage.Attributes["map"].Value, inplace.ToArray());

                    StageParams config = new StageParams(data, stage, stageParams, context, stageMapping, lastStage, outputStream);

                    data = StageParams.Dispatch(config, StageProcessor.actions);
                }
            }
        }
        catch (Exception ex)
        {
            HandleError(ex, context);
        }
        finally
        {
            if (service.Attributes["locked"] != null)
            {
                Monitor.Exit(service);
            }
        }

        if (data != null)
        {
            output.Add(data);
        }

        foreach (object result in output)
        {
            Types.WriteOutput(result, outputStream, true);
        }

        Types.WriteOutput(outputStream, context.Response.OutputStream, false);

        // -------- caching issues ----------------------------------------------------------------

        if (!nocache)
        {
            // cache is filled and ready
            context.Cache.Insert(url, outputStream, Dependency.Get(String.Join("/", new string[] { urlParts[0], urlParts[1] })),
                                 System.Web.Caching.Cache.NoAbsoluteExpiration,
                                 System.Web.Caching.Cache.NoSlidingExpiration);
        }

        if (Util.GetAttr(service, "noclientcache", false))
        {
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Cache.SetNoStore();
        }
        else
        {
            context.Response.Cache.SetMaxAge(TimeSpan.FromMinutes(60));
            context.Response.Cache.SetProxyMaxAge(TimeSpan.FromMinutes(60));
        }

        if (service.Attributes["flushcache"] != null)
        {
            Dependency.Update(service.Attributes["flushcache"].Value);
        }

        // ----------------------------------------------------------------------------------------

        if (!noinfo)
        {
            Log.Info(String.Format("KUCE_end {0}, time: {1}", url, Environment.TickCount - start), context);
        }
    }
コード例 #22
0
ファイル: MyFilters.cs プロジェクト: mbsky/kub-engine
 /*
     direct time output
 */
 public static object output_time(StageParams config)
 {
     XmlDocument input = Util.Validate<XmlDocument>(config.data, "output_time");
     config.context.Response.Write(input.FirstChild.ChildNodes[1].FirstChild.FirstChild.FirstChild.Value.ToString());
     return null;
 }
コード例 #23
0
ファイル: MyFilters.cs プロジェクト: mbsky/kub-engine
 /*
     Convert current stream output to XMLDocument output
 */
 public static object stream_to_xml_document(StageParams config)
 {
     Stream input = Util.Validate<Stream>(config.data, "myfilter:stream_to_xml_document");
     XmlDocument doc = new XmlDocument();
     doc.Load(input);
     input.Close();
     return doc;
 }
コード例 #24
0
ファイル: FileSource.cs プロジェクト: mbsky/kub-engine
    public static object GetData(StageParams config)
    {
        FileStream stream = new FileStream(config.context.Server.MapPath(config.map), FileMode.Open, FileAccess.Read);

        return(stream);
    }