Ejemplo n.º 1
0
        public T Run <T>(DataBus dataBus, string code) where T : class
        {
            //string serializedCode = SerializeCode(code);
            string      serializedCode = code;
            DebugAction debugAction    = new DebugAction(dataBus);

            debugAction.CommandLine = serializedCode;
            //string.Format(codeFormat, serializedCode);
            HttpResponseMessage response = debugAction.DoAction();

            Execute excuteObject = debugAction.ResponseData as Execute;

            ActionUtil.StoreMessages(excuteObject.ClientRequestEntity);
            while (excuteObject.ClientRequestEntity.Messages.Rearm)
            {
                //Get messages
                MessageResponseAction messageResponseAction = new MessageResponseAction(dataBus);

                response     = messageResponseAction.DoAction();
                excuteObject = messageResponseAction.ResponseData as Execute;
                ActionUtil.StoreMessages(excuteObject.ClientRequestEntity);
            }
            if (typeof(T) == typeof(JsonRaw))
            {
                JsonRaw jsonRaw = new JsonRaw();
                jsonRaw.Text = excuteObject.ClientRequestEntity.Messages[0].Text;
                //response. GetContent();
                return(jsonRaw as T);
            }
            string resultStr = excuteObject.ClientRequestEntity.Messages[0].Text;

            return(JsonToObject <T>(resultStr));
        }
        public void Import(DataBus dataBus)
        {
            //1 Service
            ServiceAction serviceAction = new ServiceAction(dataBus);

            serviceAction.CommandLine = "db";
            HttpResponseMessage response = serviceAction.DoAction();

            Service serviceEntity = serviceAction.ResponseData as Service;

            if (serviceEntity.Threads.Count > 0)
            {
                dataBus.ThreadId = serviceEntity.Threads[0].ThreadId;
            }
            else
            {
                throw new Exception("Service action Error: no thread returned");
            }
            string responseData = response.GetContent();


            ////Get Form
            //GetFormAction getFormAction = new GetFormAction(dataBus);
            //response = getFormAction.DoAction();
            //responseData = response.GetContent();

            //Get Data
            GetDataAction getDataAction = new GetDataAction(dataBus);

            getDataAction.FormName = "format.prompt.db.g";
            response     = getDataAction.DoAction();
            responseData = response.GetContent();

            //Execute inport/load
            ExecuteAction executeAction = new ExecuteAction(dataBus);

            executeAction.FormName = "format.prompt.db.g";
            executeAction.Type     = "detail";
            executeAction.EventId  = 208;

            executeAction.ExecuteData.LoadXml("<modelChanges><focus cursorLine=\"7\" cursorLineAbs=\"10\">instance/file.name</focus></modelChanges>");
            response     = executeAction.DoAction();
            responseData = response.GetContent();

            //Get  Form : import
            GetFormAction unloadGetFormAction = new GetFormAction(dataBus);

            response     = unloadGetFormAction.DoAction();
            responseData = response.GetContent();

            //Execute import
            ExecuteAction importExecuteAction = new ExecuteAction(dataBus);

            importExecuteAction.FormName = "database.load.prompt.g";
            importExecuteAction.Type     = "detail";
            importExecuteAction.EventId  = 1;

            importExecuteAction.ExecuteData.LoadXml("<modelChanges></modelChanges>");
            XmlElement importRootElement = importExecuteAction.ExecuteData.DocumentElement;

            XmlElement importVarElement  = importExecuteAction.ExecuteData.CreateElement("var");
            XmlElement importNameElement = importExecuteAction.ExecuteData.CreateElement("dbl.file.name");

            importNameElement.AppendChild(importExecuteAction.ExecuteData.CreateTextNode(unloadLocation));
            importVarElement.AppendChild(importNameElement);
            importRootElement.AppendChild(importVarElement);

            response     = importExecuteAction.DoAction();
            responseData = response.GetContent();

            Execute executeEntity = null;

            do
            {
                ImportAction uploadAction = new ImportAction(dataBus);
                uploadAction.FileLocation = unloadLocation;
                response     = uploadAction.DoAction();
                responseData = response.GetContent();

                executeEntity = uploadAction.ResponseData as Execute;
                ActionUtil.StoreMessages(executeEntity.ClientRequestEntity);
            }while (executeEntity.ClientRequestEntity.Name != "message");


            while (executeEntity.ClientRequestEntity != null)
            {
                try
                {
                    MessageResponseAction messageAction = new MessageResponseAction(dataBus);
                    response = messageAction.DoAction();
                    // responseData = response.GetContent();
                    executeEntity = messageAction.ResponseData as Execute;
                    ActionUtil.StoreMessages(executeEntity.ClientRequestEntity);
                }
                catch (Exception ex)
                {
                    break;
                }
            }
        }