Exemplo n.º 1
0
        public override clsMsg exec(clsCmd cmd)
        {
            var msg = validate(cmd);

            if (msg.Validated == false)
            {
                return(msg);
            }

            if (!func.isEmpty())
            {
                NTier.Request.iRequest oReq = _assembly.createInstance(this.AssemblyName, this.classPath) as iRequest;
                oReq.setTier(_tier);
                object[] objParams = new object[] { cmd };
                var      m         = oReq.GetType().GetMethod(func);
                msg = (clsMsg)m.Invoke(oReq, objParams);
                return(msg);
            }
            else
            {
                NTier.Request.iCommand oCmd = _assembly.createInstance(this.AssemblyName, this.classPath) as iCommand;
                oCmd.setTier(_tier);
                return(oCmd.exec(cmd));
            }
        }
        public clsMsg exec(string sPath, clsCmd cmd)
        {
            XmlNode xNode = xDoc.SelectSingleNode("//appConfig/requestData[@type='cmd']/cmd[@name='" + sPath + "']");

            if (xNode == null)
            {
                throw new Exception("Command path " + sPath + " not found !");
            }

            string sCmdType = xNode.getXmlAttributeValue("type");

            if (sCmdType != "json")
            {
                var msg = validate(xNode, cmd);
                if (msg.Validated == false)
                {
                    return(msg);
                }
            }

            //Validation
            if (xNode != null)
            {
                //Declaration
                //string sCmdType = xNode.getXmlAttributeValue("type");
                string sCRUDName = xNode.getXmlAttributeValue("crudName");

                var oCRUD = getCRUD(sCRUDName);

                if (sCmdType == "save")
                {
                    try
                    {
                        return(oCRUD.save(cmd));
                    }
                    catch (Exception ex)
                    {
                        return(g.msg_exception(ex));
                    }
                }
                else if (sCmdType == "delete")
                {
                    try
                    {
                        oCRUD.delete(cmd);
                        return(g.msg(""));
                    }
                    catch (Exception ex)
                    {
                        return(g.msg_exception(ex));
                    }
                }
                else if (sCmdType == "other")
                {
                    string sAssemblyName = xNode.getXmlAttributeValue("assemblyName");
                    string sClassPath    = xNode.getXmlAttributeValue("classPath");
                    string sFunc         = xNode.getXmlAttributeValue("func");
                    //NTier.Request.iCommand iCmd = AppDomain.CurrentDomain.CreateInstance(sAssemblyName, sClassPath).Unwrap() as iCommand;
                    NTier.Request.iCommand iCmd = oAssembly.createInstance(sAssemblyName, sClassPath) as iCommand;

                    iCmd.setTier(this);

                    if (!sFunc.isEmpty())
                    {
                        object[] objParams = new object[] { cmd };
                        var      m         = iCmd.GetType().GetMethod(sFunc);
                        clsMsg   msg       = (clsMsg)m.Invoke(iCmd, objParams);
                        return(msg);
                    }
                    else
                    {
                        return(iCmd.exec(cmd));
                    }
                }
                else if (sCmdType == "cmd")
                {
                    string q = xNode.getXmlText("sql");
                    cmd.SQL = q;
                    try
                    {
                        _adapter.exec(cmd);
                        return(g.msg(""));
                    }
                    catch (Exception ex)
                    {
                        return(g.msg_exception(ex));
                    }
                }

                else if (sCmdType == "json")
                {
                    DataTable t = Newtonsoft.Json.JsonConvert.DeserializeObject <DataTable>(cmd.getStringValue("data"));

                    //validation start
                    int i = 0;
                    foreach (DataRow r in t.Rows)
                    {
                        i++;
                        var cmd2 = new clsCmd();
                        cmd2.AddValues(r);

                        var msg = validate(xNode, cmd2);
                        if (msg.Validated == false)
                        {
                            msg.Message = string.Format(" Row Number : {0} : {1} ", i, msg.Message);
                            return(msg);
                        }
                    }

                    //updation start

                    i = 0;
                    foreach (DataRow r in t.Rows)
                    {
                        i++;
                        var cmd2 = new clsCmd();
                        cmd2.AddValues(r);

                        string q = xNode.getXmlText("sql");
                        cmd2.SQL = q;

                        try
                        {
                            _adapter.exec(cmd2);
                            return(g.msg(""));
                        }
                        catch (Exception ex)
                        {
                            var msg = g.msg_exception(ex);
                            msg.Message = string.Format(" Row Number : {0} : {1} ", i, msg.Message);
                        }
                    }
                }
            }

            return(g.msg("Path not found !"));
        }