public void SavePermission(DataConnection connection, Permission permission)
        {
            List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>();
            ScreenDataCommandParameter        p          = null;


            p = new ScreenDataCommandParameter(ParameterPermissionName, permission.Name);
            parameters.Add(p);

            p = new ScreenDataCommandParameter(ParameterCategory, permission.Category);
            parameters.Add(p);

            p = new ScreenDataCommandParameter(ParameterDescription, permission.Description);
            parameters.Add(p);

            DataCommand command = DataCommand.GetDataCommand(DataCommandPermissionSave);



            if (command == null)
            {
                throw new Exception(String.Format("DataCommand {0} could not be found in configuration", DataCommandPermissionSave));
            }
            //execute command
            sql.ExecuteCommand(null, connection, command, parameters, command.Text);
        }
Esempio n. 2
0
        private string GetDatabaseDisplayValue(string value)
        {
            string retVal = null;
            DataCommandService dataCommandDB = DataCommandService.GetInstance();

            if (String.IsNullOrEmpty(Me.PickerObject.DataCommand))
            {
                throw new ApplicationException("Picker does not have a datacommand specified in configuration");
            }

            DataCommand command = DataCommand.GetDataCommand(Me.PickerObject.DataCommand);

            if (command == null)
            {
                throw new ApplicationException(String.Format("DataCommand {0} does not exist in configuration", Me.PickerObject.DataCommand));
            }

            List<ScreenDataCommandParameter> parameters = new List<ScreenDataCommandParameter>();
            ScreenDataCommandParameter parameter = new ScreenDataCommandParameter();

            parameter.Name = command.Parameters[0].Name;
            parameter.Value = value;

            parameters.Add(parameter);

            DataTable dt = dataCommandDB.GetDataForDataCommand(command.Name, parameters);

            if (dt.Rows.Count > 0)
            {
                retVal = dt.Rows[0][Me.PickerObject.DisplayField].ToString();

            }

            return retVal;
        }
Esempio n. 3
0
        private string ExecuteDataCommand(string retVal)
        {
            DataCommandService dataCommandDB = DataCommandService.GetInstance();
            PageDB             pageDB        = new PageDB();

            DataCommand command = DataCommand.GetDataCommand(Me.DataCommand);
            List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page);
            DataTable data          = null;
            object    commandRetVal = null;

            if (command == null)
            {
                throw new ApplicationException(String.Format("DataCommand {0} could not be found in configuration", Me.DataCommand));
            }

            if (command.ReturnType == DataCommandReturnType.DataTable)
            {
                data = dataCommandDB.GetDataForDataCommand(Me.DataCommand, parameters);
            }
            else
            {
                commandRetVal = dataCommandDB.ExecuteDataCommand(Me.DataCommand, parameters);
            }

            if (command.ReturnType == DataCommandReturnType.DataTable)
            {
                if (data != null)
                {
                    if (!String.IsNullOrEmpty(Me.RedirectUrlField))
                    {
                        if (data.Rows.Count == 1)
                        {
                            retVal = data.Rows[0][Me.RedirectUrlField].ToString();
                        }
                        else
                        {
                            throw new ApplicationException("Invalid number of rows returned - " + data.Rows.Count);
                        }
                    }
                }
            }
            else
            {
                if (commandRetVal != null)
                {
                    retVal = commandRetVal.ToString();
                }
            }
            return(retVal);
        }
        public List <object> GetItems(string folder, string name)
        {
            List <object> retVal = new List <object>();

            if (String.IsNullOrEmpty(name))
            {
                retVal = new List <object>(Configuration.GetInstance().DataCommands.Cast <object>());
            }
            else
            {
                retVal.Add(DataCommand.GetDataCommand(name));
            }

            return(retVal);
        }
Esempio n. 5
0
        public object ExecuteDataCommand(DbTransaction tran, string dataCommandName, List <ScreenDataCommandParameter> parameters)
        {
            object retVal = null;

            DataCommand command = DataCommand.GetDataCommand(dataCommandName);

            if (command != null)
            {
                retVal = ExecuteCommand(tran, command, parameters, command.Text);
            }
            else
            {
                throw new ApplicationException(String.Format("Data Command could not be found in configuration - {0}", dataCommandName));
            }

            return(retVal);
        }
Esempio n. 6
0
        public async Task <object> ExecuteDataCommand(string dataCommandName, List <ScreenDataCommandParameter> parameters)
        {
            object retVal = null;

            DataCommand command = DataCommand.GetDataCommand(dataCommandName);

            if (command != null)
            {
                retVal = await ExecuteCommand(command, parameters, command.Text);
            }
            else
            {
                throw new Exception(String.Format("Data Command could not be found in configuration - {0}", dataCommandName));
            }

            return(retVal);
        }
Esempio n. 7
0
        public async Task <XDocument> GetXmlDataForDataCommand(string DataCommandName, List <ScreenDataCommandParameter> parameters)
        {
            XDocument retVal = null;

            DataCommand command = DataCommand.GetDataCommand(DataCommandName);

            if (command != null)
            {
                retVal = await GetXmlData(command, parameters, command.Text);
            }
            else
            {
                throw new Exception(String.Format("DataCommand {0} does not exist in configuration", DataCommandName));
            }

            return(retVal);
        }
Esempio n. 8
0
        public XmlDocument GetXmlDataForDataCommand(DbTransaction tran, string DataCommandName, List <ScreenDataCommandParameter> parameters)
        {
            XmlDocument retVal = null;


            DataCommand command = DataCommand.GetDataCommand(DataCommandName);

            if (command != null)
            {
                retVal = GetXmlData(tran, command, parameters, command.Text);
            }
            else
            {
                throw new ApplicationException(String.Format("DataCommand {0} does not exist in configuration", DataCommandName));
            }

            return(retVal);
        }
        private void ExecuteDataCommand(string dataCommand, List <ScreenDataCommandParameter> parameters)
        {
            if (Connection == null)
            {
                sql.ExecuteDataCommand(dataCommand, parameters);
            }
            else
            {
                DataCommand command = DataCommand.GetDataCommand(dataCommand);

                if (command == null)
                {
                    throw new Exception(String.Format("DataCommand {0} could not be found in configuration", dataCommand));
                }

                sql.ExecuteCommand(null, Connection, command, parameters, command.Text);
            }
        }
Esempio n. 10
0
        private void RefreshDataCommandParameters(ScreenDataCommand item)
        {
            //get data command
            DataCommand c = DataCommand.GetDataCommand(item.Name);

            if (c != null)
            {
                //loop through screen data command parameters
                List <ScreenDataCommandParameter> remove = new List <ScreenDataCommandParameter>();
                foreach (ScreenDataCommandParameter p in item.Parameters)
                {
                    ScreenDataCommandParameter localP = p;
                    if (!c.Parameters.Exists(x => x.Name == localP.Name))
                    {
                        remove.Add(localP);
                    }
                }

                //are there any missing from data command - if so remove
                foreach (ScreenDataCommandParameter p in remove)
                {
                    item.Parameters.Remove(p);
                }


                //loop through data command parameters
                foreach (DataCommandParameter p in c.Parameters)
                {
                    DataCommandParameter localP = p;
                    if (!item.Parameters.Exists(x => x.Name == localP.Name))
                    {
                        //are there any missing from screen command parameters - if so add with control as default

                        ScreenDataCommandParameter sp = new ScreenDataCommandParameter();

                        sp.InputType = ScreenInputType.Control;
                        sp.Name      = p.Name;
                        sp.InputKey  = p.Name.Replace("@", "").Replace("'", "").Replace(" ", "");

                        item.Parameters.Add(sp);
                    }
                }
            }
        }
        public void AddAllPermissionsToRole(DataConnection connection, string roleName)
        {
            List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>();
            ScreenDataCommandParameter        p          = null;


            p = new ScreenDataCommandParameter(ParameterRoleName, roleName);
            parameters.Add(p);

            DataCommand command = DataCommand.GetDataCommand(DataCommandRoleAddAllPermissions);



            if (command == null)
            {
                throw new Exception(String.Format("DataCommand {0} could not be found in configuration", DataCommandRoleAddAllPermissions));
            }
            //execute command
            sql.ExecuteCommand(null, connection, command, parameters, command.Text);
        }
        private DataTable GetDataForDataCommand(string dataCommand, List <ScreenDataCommandParameter> parameters)
        {
            DataTable retVal = null;

            if (Connection == null)
            {
                retVal = sql.GetDataForDataCommand(dataCommand, parameters);
            }
            else
            {
                DataCommand command = DataCommand.GetDataCommand(dataCommand);

                if (command == null)
                {
                    throw new Exception(String.Format("DataCommand {0} could not be found in configuration", dataCommand));
                }

                retVal = sql.GetData(null, Connection, command, parameters, command.Text);
            }

            return(retVal);
        }
        protected async void SaveEditForm()
        {
            DataCommandService dataCommandDB = DataCommandService.GetInstance();

            bool   SuccessIndicator = false;
            string retVal           = null;

            if (true)//Page.IsValid)
            {
                try
                {
                    object r = null;
                    List <ScreenDataCommandParameter> parameters = null;
                    switch (PageMode)
                    {
                    case FormViewMode.View:
                        CodeTorch.Core.Common.LogInfo("\r\n\r\nIn Insert Mode");

                        if (String.IsNullOrEmpty(Me.InsertCommand))
                        {
                            throw new Exception("InsertCommand is invalid");
                        }
                        CodeTorch.Core.Common.LogDebug(String.Format("InsertCommand:{0}", Me.InsertCommand));

                        parameters = Common.GetPopulatedCommandParameters(Me.InsertCommand, IPage);

                        DataCommand command = DataCommand.GetDataCommand(Me.InsertCommand);

                        switch (command.ReturnType)
                        {
                        case DataCommandReturnType.DataTable:
                            r = await dataCommandDB.GetDataForDataCommand(Me.InsertCommand, parameters);

                            break;

                        case DataCommandReturnType.Integer:
                            r = await dataCommandDB.ExecuteDataCommand(Me.InsertCommand, parameters);

                            break;

                        case DataCommandReturnType.Xml:
                            throw new NotImplementedException();
                            break;

                        case DataCommandReturnType.None:
                            break;
                        }


                        if (r != null)
                        {
                            if (!String.IsNullOrEmpty(Me.AfterInsertSettings))
                            {
                                if (r is DataTable)
                                {
                                    DataTable dt = r as DataTable;
                                    if (dt.Rows.Count > 0)
                                    {
                                        DataRow row = dt.Rows[0];
                                        Common.DataRowToSettings(row, Me.AfterInsertSettings);
                                    }
                                }
                            }
                            //if r is datatable - see if any of the values need to be stored in settings
                            //retVal = r.ToString();
                            //CodeTorch.Core.Common.LogDebug(String.Format("Output Parameter:{0}", retVal));
                        }

                        CodeTorch.Core.Common.LogDebug(String.Format("RedirectAfterInsert:{0}", Me.RedirectAfterInsert));
                        if (Me.RedirectAfterInsert)
                        {
                            if (!String.IsNullOrEmpty(Me.AfterInsertRedirectScreen))
                            {
                                Page p = MobilePage.GetPage(Me.AfterInsertRedirectScreen).GetPage();

                                Page.Navigation.PushAsync(p);
                            }
                            else
                            {
                                //TODO: do what -tell about config error
                            }

                            //string url = GetRedirectUrl(retVal);
                            //log.DebugFormat("RedirectUrl:{0}", url);
                            //Page.Response.Redirect(url,false);
                            //HttpContext.Current.ApplicationInstance.CompleteRequest();
                        }
                        else
                        {
                            Page.DisplayAlert("Alert", Me.AfterInsertConfirmationMessage, "OK");

                            //Page.DisplaySuccessAlert(String.Format(Me.AfterInsertConfirmationMessage, retVal));

                            //RefreshSections();
                        }
                        break;
                        //case FormViewMode.Edit:
                        //    log.Info("In Edit Mode");
                        //    if (String.IsNullOrEmpty(Me.UpdateCommand))
                        //    {
                        //        throw new ApplicationException("UpdateCommand is invalid");
                        //    }
                        //    log.DebugFormat("UpdateCommand:{0}", Me.UpdateCommand);

                        //    parameters = pageDB.GetPopulatedCommandParameters(Me.UpdateCommand, Page);
                        //    dataCommandDB.ExecuteDataCommand(Me.UpdateCommand, parameters);

                        //    log.DebugFormat("RedirectAfterUpdate:{0}", Me.RedirectAfterUpdate);
                        //    if (Me.RedirectAfterUpdate)
                        //    {
                        //        string url = GetRedirectUrl(Page.Request.QueryString[Me.EntityID]);
                        //        log.DebugFormat("RedirectUrl:{0}", url);
                        //        Page.Response.Redirect(url, false);
                        //        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        //    }
                        //    else
                        //    {
                        //        Page.DisplaySuccessAlert(String.Format(Me.AfterUpdateConfirmationMessage, retVal));

                        //        RefreshSections();
                        //    }
                        //    break;
                    }
                    SuccessIndicator = true;
                }
                catch (Exception ex)
                {
                    SuccessIndicator = false;

                    IPage.DisplayErrorAlert(ex.Message);



                    //log.Error(ex);
                }
            }

            //return SuccessIndicator;
        }
Esempio n. 14
0
        public static void GenerateCultureTrackingCookie()
        {
            App app = CodeTorch.Core.Configuration.GetInstance().App;

            if (app.EnableLocalization)
            {
                //get localization data command for retrieval

                DataCommandService dataCommandDB = DataCommandService.GetInstance();

                if (!String.IsNullOrEmpty(app.LocalizationCommand))
                {
                    DataCommand command = DataCommand.GetDataCommand(app.LocalizationCommand);

                    if (command == null)
                    {
                        throw new ApplicationException(String.Format("DataCommand {0} could not be found in configuration - Common.GenerateCultureTrackingCookie", app.LocalizationCommand));
                    }

                    //set any parameters needed
                    List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>();
                    ScreenDataCommandParameter        parameter  = null;

                    if (!String.IsNullOrEmpty(app.LocalizationUserNameParameter))
                    {
                        parameter = new ScreenDataCommandParameter();
                        if (app.LocalizationUserNameParameter.StartsWith("@"))
                        {
                            parameter.Name = app.LocalizationUserNameParameter;
                        }
                        else
                        {
                            parameter.Name = "@" + app.LocalizationUserNameParameter;
                        }
                        parameter.Value = Common.UserName;
                        parameters.Add(parameter);
                    }


                    //execute command

                    DataTable retVal = dataCommandDB.GetData(null, command, parameters, command.Text);


                    string culture = "en-US";
                    //get data from culture field
                    if (retVal != null)
                    {
                        if (retVal.Rows.Count > 0)
                        {
                            if (retVal.Columns.Contains(app.LocalizationCultureField))
                            {
                                if (retVal.Rows[0][app.LocalizationCultureField] != DBNull.Value)
                                {
                                    culture = retVal.Rows[0][app.LocalizationCultureField].ToString();
                                }
                            }
                        }
                    }

                    //generate culture cookie
                    HttpCookie c;

                    if (HttpContext.Current.Request.Cookies["CultureCode"] == null)
                    {
                        c = new HttpCookie("CultureCode");
                    }
                    else
                    {
                        c = HttpContext.Current.Request.Cookies["CultureCode"];
                    }

                    c.Value = culture;
                    c.Path  = "/";

                    HttpContext.Current.Response.Cookies.Add(c);
                }
            }
        }
Esempio n. 15
0
        public void ExecuteCommand()
        {
            DataCommandService dataCommandDB = DataCommandService.GetInstance();
            PageDB             pageDB        = new PageDB();

            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            try
            {
                if (Command != null)
                {
                    Me = (SetScreenObjectsDataCommand)Command;
                }


                if (String.IsNullOrEmpty(Me.DataCommand))
                {
                    throw new ApplicationException(String.Format("Command {0} - SetScreenObjects - DataCommand is invalid", Me.Name));
                }
                log.DebugFormat("DataCommand:{0}", Me.DataCommand);

                DataCommand dataCommand = DataCommand.GetDataCommand(Me.DataCommand);
                if (dataCommand == null)
                {
                    throw new ApplicationException(String.Format("SetScreenObjects Data Command - {0} - does not exist in configuration", Me.DataCommand));
                }

                if (dataCommand.ReturnType != DataCommandReturnType.DataTable)
                {
                    throw new ApplicationException(String.Format("SetScreenObjects Data Command - {0} - invalid return type - return type must be Data Table", Me.DataCommand));
                }

                List <ScreenDataCommandParameter> parameters = null;
                parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page);
                DataTable dt = dataCommandDB.GetDataForDataCommand(Me.DataCommand, parameters);

                foreach (DataRow row in dt.Rows)
                {
                    switch (row["ObjectType"].ToString().ToLower())
                    {
                    case "control":
                        SetPageControl(
                            row["Name"].ToString(),
                            row["MemberType"].ToString(),
                            row["Member"].ToString(),
                            row["Value"].ToString()
                            );
                        break;

                    case "section":
                        SetPageSection(
                            row["Name"].ToString(),
                            row["MemberType"].ToString(),
                            row["Member"].ToString(),
                            row["Value"].ToString()
                            );
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Page.DisplayErrorAlert(ex);

                log.Error(ex);
            }
        }
Esempio n. 16
0
        private CodeTorch.Core.Menu PopulateDynamicMenuItems(CodeTorch.Core.Menu menuObject)
        {
            CodeTorch.Core.Menu retVal = null;

            DataCommandService dataCommandDB             = DataCommandService.GetInstance();
            List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>();

            var items = from item in menuObject.Items
                        where item.UseCommand == true
                        select item;

            if (items.Count() > 0)
            {
                retVal          = new Core.Menu();
                retVal.Name     = menuObject.Name;
                retVal.CssClass = menuObject.CssClass;



                foreach (Core.MenuItem item in menuObject.Items)
                {
                    if (item.UseCommand == false)
                    {
                        Core.MenuItem copiedItem = ObjectCopier.Clone <Core.MenuItem>(item);
                        retVal.Items.Add(copiedItem);
                    }
                    else
                    {
                        DataCommand cmd = DataCommand.GetDataCommand(item.CommandName);

                        foreach (DataCommandParameter cmdParam in cmd.Parameters)
                        {
                            ScreenDataCommandParameter p = new ScreenDataCommandParameter();
                            //TODO: need to support context with multiple items - presently assumes one item
                            if (!String.IsNullOrEmpty(item.Context))
                            {
                                if (cmdParam.Name.ToLower().EndsWith(item.Context.ToLower()))
                                {
                                    p.Name      = cmdParam.Name;
                                    p.InputType = ScreenInputType.QueryString;
                                    p.InputKey  = item.Context;
                                    p.Value     = this.Page.Request.QueryString[item.Context];
                                }
                            }

                            if (cmdParam.Name.ToLower().EndsWith("username"))
                            {
                                p.Name      = cmdParam.Name;
                                p.InputType = ScreenInputType.Special;
                                p.InputKey  = "UserName";
                                p.Value     = Common.UserName;
                            }

                            if (cmdParam.Name.ToLower().EndsWith("hostheader"))
                            {
                                p.Name      = cmdParam.Name;
                                p.InputType = ScreenInputType.Special;
                                p.InputKey  = "HostHeader";
                                p.Value     = Common.HostHeader;
                            }

                            parameters.Add(p);
                        }


                        DataTable dt   = dataCommandDB.GetDataForDataCommand(item.CommandName, parameters);
                        DataRow[] rows = null;

                        bool containsParentID = dt.Columns.Contains("ParentID");

                        if (containsParentID)
                        {
                            rows = dt.Select("ParentID IS NULL");
                        }
                        else
                        {
                            rows = dt.Select();
                        }

                        AddMenuItems(retVal, dt, item, rows, true);
                    }
                }
            }
            else
            {
                retVal = menuObject;
            }

            return(retVal);
        }
        public async void ExecuteCommand()
        {
            if (Command != null)
            {
                Me = (ValidateUserCommand)Command;
            }
            try
            {
                DataTable          dt            = null;
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                bool IsAuthenticated             = false;

                //call data command

                //if we get datatable and row=1 store

                List <ScreenDataCommandParameter> parameters = null;
                parameters = Common.GetPopulatedCommandParameters(Me.LoginCommand, IPage);

                DataCommand command = DataCommand.GetDataCommand(Me.LoginCommand);

                switch (command.ReturnType)
                {
                case DataCommandReturnType.DataTable:
                    dt = await dataCommandDB.GetDataForDataCommand(Me.LoginCommand, parameters);

                    break;

                case DataCommandReturnType.Integer:
                    throw new NotImplementedException();
                    break;

                case DataCommandReturnType.Xml:
                    throw new NotImplementedException();
                    break;

                case DataCommandReturnType.None:
                    throw new NotImplementedException();
                    break;
                }

                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        DataRow row = dt.Rows[0];
                        Common.DataRowToSettings(row, Me.AfterLoginSettings);
                        IsAuthenticated = true;
                        if (!String.IsNullOrEmpty(Me.AfterLoginRedirectScreen))
                        {
                            Page p = MobilePage.GetPage(Me.AfterLoginRedirectScreen).GetPage();

                            Page.Navigation.PushAsync(p);
                        }
                    }
                }

                if (!IsAuthenticated)
                {
                    IPage.DisplayErrorAlert("You have entered an invalid username/password combination. Please try again.");
                }
            }
            catch (Exception ex)
            {
                IPage.DisplayErrorAlert(ex.Message);
            }
        }
Esempio n. 18
0
        public void ProcessRequest(HttpContext context)
        {
            App           app     = CodeTorch.Core.Configuration.GetInstance().App;
            StringBuilder builder = new StringBuilder();
            StringWriter  writer  = new StringWriter(builder);

            try
            {
                if (Me == null)
                {
                    if (context.Request.Path.ToLower().EndsWith("xml"))
                    {
                        Format = "xml";
                    }

                    throw new ApplicationException("No service has been configured for this path");
                }


                DataCommand command = null;
                RestServiceMethodReturnTypeEnum returnType = RestServiceMethodReturnTypeEnum.None;


                //collect parameters

                DataTable   dt  = null;
                XmlDocument doc = null;
                context.Response.TrySkipIisCustomErrors = true;

                if (Format.ToLower() == "json")
                {
                    context.Response.ContentType = "application/json";
                }
                else
                {
                    context.Response.ContentType = "text/xml";
                }

                BaseRestServiceMethod method = Me.Methods.Where(i => (i.Action.ToString() == HttpContext.Current.Request.HttpMethod)).SingleOrDefault();

                if (method != null)
                {
                    //pass parameters - minus dbcommand parameters to datacommand
                    DataCommandService dataCommandDB = DataCommandService.GetInstance();

                    if (String.IsNullOrEmpty(method.RequestDataCommand))
                    {
                        throw new ApplicationException(String.Format("Request Data Command has not been configured for this service - {0}", Me.Name));
                    }

                    command = DataCommand.GetDataCommand(method.RequestDataCommand);

                    if (command == null)
                    {
                        throw new ApplicationException(String.Format("Request Data Command - {0} - could not be found in configuration", method.RequestDataCommand));
                    }

                    List <ScreenDataCommandParameter> parameters = GetPopulatedCommandParameters(method.RequestDataCommand, method.DataCommands, null);
                    returnType = method.ReturnType;
                    //execute request datacommand and return data if applicable
                    switch (command.ReturnType)
                    {
                    case DataCommandReturnType.Integer:
                        object newID = dataCommandDB.ExecuteDataCommand(method.RequestDataCommand, parameters);

                        if (method is PostRestServiceMethod)
                        {
                            DataCommand postCommand = null;



                            PostRestServiceMethod postMethod = (PostRestServiceMethod)method;
                            returnType = postMethod.ReturnType;
                            if (!String.IsNullOrEmpty(postMethod.ResponseDataCommand))
                            {
                                postCommand = DataCommand.GetDataCommand(postMethod.ResponseDataCommand);

                                if (postCommand == null)
                                {
                                    throw new ApplicationException(String.Format("Response Data Command - {0} - could not be found in configuration", postMethod.ResponseDataCommand));
                                }

                                parameters = GetPopulatedCommandParameters(postMethod.ResponseDataCommand, method.DataCommands, newID);


                                switch (returnType)
                                {
                                case RestServiceMethodReturnTypeEnum.DataRow:
                                case RestServiceMethodReturnTypeEnum.DataTable:
                                    dt = dataCommandDB.GetDataForDataCommand(postMethod.ResponseDataCommand, parameters);
                                    break;

                                case RestServiceMethodReturnTypeEnum.Xml:
                                    doc = dataCommandDB.GetXmlDataForDataCommand(postMethod.ResponseDataCommand, parameters);
                                    break;
                                }
                            }
                        }

                        if (method is PutRestServiceMethod)
                        {
                            PutRestServiceMethod putMethod = (PutRestServiceMethod)method;
                            returnType = putMethod.ReturnType;
                            if (!String.IsNullOrEmpty(putMethod.ResponseDataCommand))
                            {
                                parameters = GetPopulatedCommandParameters(putMethod.ResponseDataCommand, method.DataCommands, newID);

                                dt = dataCommandDB.GetDataForDataCommand(putMethod.ResponseDataCommand, parameters);
                            }
                        }

                        break;

                    case DataCommandReturnType.Xml:
                        doc = dataCommandDB.GetXmlDataForDataCommand(method.RequestDataCommand, parameters);
                        break;

                    default:
                        dt = dataCommandDB.GetDataForDataCommand(method.RequestDataCommand, parameters);
                        break;
                    }

                    //in certain cases execute response datacommand
                }
                else
                {
                    throw new NotSupportedException();
                }



                //get data if any
                if (
                    ((dt != null) && (returnType == RestServiceMethodReturnTypeEnum.DataTable)) ||
                    ((dt != null) && (returnType == RestServiceMethodReturnTypeEnum.DataRow)) ||
                    ((doc != null) && (returnType == RestServiceMethodReturnTypeEnum.Xml))
                    )
                {
                    if (Format.ToLower() == "json")
                    {
                        using (JsonWriter json = new JsonTextWriter(writer))
                        {
                            DataColumnCollection columns = null;



                            switch (returnType)
                            {
                            case RestServiceMethodReturnTypeEnum.DataTable:
                                columns = dt.Columns;
                                BuildJsonArrayResponse(app, context, method, command, dt, json, columns);
                                break;

                            case RestServiceMethodReturnTypeEnum.DataRow:
                                columns = dt.Columns;
                                BuildJsonObjectResponse(app, context, method, command, dt, json, columns);
                                break;

                            case RestServiceMethodReturnTypeEnum.Xml:
                                BuildJsonXmlObjectResponse(app, method, builder, doc);
                                break;
                            }
                        }
                    }
                    else
                    {
                        //xml
                        using (XmlWriter xml = new XmlTextWriter(writer))
                        {
                            DataColumnCollection columns = null;



                            switch (method.ReturnType)
                            {
                            case RestServiceMethodReturnTypeEnum.DataTable:
                                columns = dt.Columns;
                                BuildXmlListResponse(app, context, method, command, dt, xml, columns);
                                break;

                            case RestServiceMethodReturnTypeEnum.DataRow:
                                columns = dt.Columns;
                                BuildXmlItemResponse(app, context, method, command, dt, xml, columns);
                                break;

                            case RestServiceMethodReturnTypeEnum.Xml:
                                BuildXmlObjectResponse(app, method, doc, xml);
                                break;
                            }
                        }
                    }
                }

                //perform any special post processing



                //string url = ((System.Web.Routing.Route)(RouteData.Route)).Url;
                //context.Response.Write("From the handler at " + DateTime.Now + " - " + Me.Name + " - " + url + " - " + HttpContext.Current.Request.HttpMethod);


                //context.Response.ContentType = "text/xml";
                //context.Response.Write(dt.DataSet.GetXml());


                context.Response.StatusCode = (int)HttpStatusCode.OK;

                context.Response.Write(builder.ToString());
            }
            catch (CodeTorchException cex)
            {
                builder = new StringBuilder();
                RestServiceException exception = new RestServiceException();

                exception.Status    = (int)HttpStatusCode.InternalServerError;
                exception.Message   = cex.Message;
                exception.MoreInfo  = cex.MoreInfo;
                exception.ErrorCode = cex.ErrorCode;

                context.Response.TrySkipIisCustomErrors = true;
                context.Response.StatusCode             = exception.Status;
                SerializeRestException(app, context, builder, writer, exception);
            }
            catch (Exception ex)
            {
                builder = new StringBuilder();
                RestServiceException exception = new RestServiceException();

                exception.Status  = (int)HttpStatusCode.InternalServerError;
                exception.Message = ex.Message;

                context.Response.TrySkipIisCustomErrors = true;
                context.Response.StatusCode             = exception.Status;
                SerializeRestException(app, context, builder, writer, exception);
            }
        }