Пример #1
0
        internal void SetDataObject(object data)
        {
            if (data == null)
            {
                return;
            }

            if (!ObjectDescriptor.TryCreate(data.GetType(), out var objectDescriptor))
            {
                throw new HandlebarsRuntimeException($"Cannot resolve object descriptor for type `{data.GetType()}`");
            }

            var objectAccessor = new ObjectAccessor(data, objectDescriptor);

            foreach (var property in objectAccessor.Properties)
            {
                var value = objectAccessor[property];
                if (property.WellKnownVariable == WellKnownVariable.None)
                {
                    ContextDataObject.AddOrReplace(property, value, out _);
                }
                else
                {
                    ContextDataObject.AddOrReplace(property, value, out WellKnownVariables[(int)property.WellKnownVariable]);
                }
            }
        }
Пример #2
0
        public ScriptResponse Execute(ContextDataObject context, Entity document)
        {
            //PREPARE XML FILE FROM DOCUMENT
            Customer customer = new Customer();

            customer.Code          = document.Code;
            customer.Name          = document.Name;
            customer.Description   = document.Description;
            customer.Address       = document.Attributes.Address;
            customer.ContractStart = document.Attributes.ContractStart.ToShortDateString();
            customer.ContractEnd   = document.Attributes.ContractEnd.ToShortDateString();
            customer.FinancialID   = document.Attributes.FinancialID;

            string path = context.Parameters["FilePath"].ToString();

            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(customer.GetType());
            using (StringWriter textWriter = new StringWriter())
            {
                //OUTPUT HTML FROM XML
                x.Serialize(textWriter, customer);

                var html = TransformXMLToHTML(textWriter.ToString(), xsltString);
                File.WriteAllText(path + $"{document.Code}.html", html);
                Console.WriteLine("HTML at: " + path + $"{document.Code}.html");
            }

            var message = "Successful!";

            return(new ScriptResponse
            {
                Message = message
            });
        }
Пример #3
0
        public ScriptResponse Execute(ContextDataObject context, string query)
        {
            ErpBS bsERP = new ErpBS();

            if (!context.Parameters.ContainsKey("TipoPlataforma"))
            {
                throw new Exception("TipoPlataforma inválido");
            }

            EnumTipoPlataforma tipoPlataforma;

            if (!Enum.TryParse <EnumTipoPlataforma>((string)context.Parameters["TipoPlataforma"], out tipoPlataforma))
            {
                throw new Exception("TipoPlataforma inválido");
            }

            try
            {
                bsERP.AbreEmpresaTrabalho(tipoPlataforma, context.Company, context.Username, context.Password);
            }
            catch (Exception e)
            {
                throw new Exception("Erro a abrir a empresa no ERP: " + e.Message);
            }

            StdBELista queryResults = bsERP.Consulta(query);

            int numLinhas  = queryResults.NumLinhas();
            int numColunas = queryResults.NumColunas();

            string[] headers = new string[numColunas];
            for (short i = 0; i < numColunas; i++)
            {
                headers[i] = queryResults.Nome(i);
            }

            object[,] data = new object[numLinhas, numColunas];
            for (short i = 0; i < numLinhas; i++)
            {
                for (short j = 0; j < numColunas; j++)
                {
                    var nome = headers[j];
                    data[i, j] = queryResults.Valor(nome);
                }
                queryResults.Seguinte();
            }

            QueryResult response = new QueryResult()
            {
                Headers = headers,
                Data    = data
            };

            bsERP.FechaEmpresaTrabalho();

            return(new ScriptResponse
            {
                Object = response
            });
        }
Пример #4
0
        public object Execute(ContextDataObject context, Entity document)
        {
            /* **************************************** */
            /* **************************************** */
            /*          ADD YOUR CODE HERE              */
            ErpBS bsERP = new ErpBS();

            try {
                if (!context.Parameters.ContainsKey("TipoPlataforma"))
                {
                    throw new Exception("TipoPlataforma inválido");
                }

                EnumTipoPlataforma tipoPlataforma;
                if (!Enum.TryParse <EnumTipoPlataforma>((string)context.Parameters["TipoPlataforma"], out tipoPlataforma))
                {
                    throw new Exception("TipoPlataforma inválido");
                }

                try
                {
                    bsERP.AbreEmpresaTrabalho(tipoPlataforma, context.Company, context.Username, context.Password);
                }
                catch (Exception e)
                {
                    throw new Exception("Erro a abrir a empresa no ERP: " + e.Message);
                }
                GcpBEDocumentoCompra purchaseOrder = new GcpBEDocumentoCompra();
                purchaseOrder.set_Tipodoc("ECF");
                purchaseOrder.set_Serie("A");
                purchaseOrder.set_TipoEntidade("F");
                purchaseOrder.set_Entidade(document.Attributes.Supplier);
                purchaseOrder.set_NumDocExterno("0");
                purchaseOrder.set_Observacoes("Documento gerado no portal OMNIA: Pedido de Encomenda " + document.NumberSerieCode + "/" + document.Number);
                purchaseOrder.set_DataCarga(document.DateCreated.ToShortDateString());
                purchaseOrder.set_DataDescarga(document.DateCreated.ToShortDateString());

                bsERP.Comercial.Compras.PreencheDadosRelacionados(purchaseOrder);
                foreach (var line in document.Commitments.GoodsPurchaseRequest)
                {
                    bsERP.Comercial.Compras.AdicionaLinha(purchaseOrder, line.Resource, line.Quantity, "A1", "", line.Amount);
                }

                bsERP.Comercial.Compras.Actualiza(purchaseOrder);

                bsERP.FechaEmpresaTrabalho();

                return(new ScriptResponse {
                    Message = "Integrado documento " + purchaseOrder.get_Tipodoc() + " " + purchaseOrder.get_Serie() + "/" + purchaseOrder.get_NumDoc()
                });
            } catch (Exception ex) {
                bsERP.FechaEmpresaTrabalho();

                throw ex;
            }
        }
Пример #5
0
        internal bool TryGetContextVariable(ChainSegment segment, out object value)
        {
            if (segment.WellKnownVariable != WellKnownVariable.None)
            {
                var wellKnownVariable = WellKnownVariables[(int)segment.WellKnownVariable];
                return(BlockParamsObject.TryGetValue(segment, out value) ||
                       ContextDataObject.TryGetValue(wellKnownVariable, out value));
            }

            return(BlockParamsObject.TryGetValue(segment, out value) ||
                   ContextDataObject.TryGetValue(segment, out value));
        }
Пример #6
0
        public ScriptResponse Execute(ContextDataObject context, string query)
        {
            //BUILD CONNECTION
            var connectionString = new SqlConnectionStringBuilder();

            connectionString.DataSource     = context.Parameters["SqlServer"].ToString();
            connectionString.UserID         = context.Username;
            connectionString.Password       = context.Password;
            connectionString.InitialCatalog = context.Parameters["SqlDb"].ToString();
            var connection = new SqlConnection(connectionString.ToString());

            //EXECUTE QUERY
            DataTable table = new DataTable();

            using (SqlCommand cmd = new SqlCommand(
                       query, new SqlConnection(connectionString.ToString())))
            {
                cmd.Connection.Open();
                table.Load(cmd.ExecuteReader());
                cmd.Connection.Close();
            }

            string[] headers = new string[table.Columns.Count];
            object[,] data = new object[table.Rows.Count, table.Columns.Count];

            for (short i = 0; i < table.Columns.Count; i++)
            {
                headers[i] = table.Columns[i].ColumnName;
            }
            for (short j = 0; j < table.Rows.Count; j++)
            {
                for (short k = 0; k < table.Columns.Count; k++)
                {
                    data[j, k] = table.Rows[j][k];
                }
            }

            //RETURN OBJECT
            QueryResult response = new QueryResult()
            {
                Headers = headers,
                Data    = data
            };

            return(new ScriptResponse
            {
                Object = response
            });
        }
Пример #7
0
        public ScriptResponse Execute(ContextDataObject context, Entity document)
        {
            //BUILD CONNECTION
            var connectionString = new SqlConnectionStringBuilder();

            connectionString.DataSource     = context.Parameters["SqlServer"].ToString();
            connectionString.UserID         = context.Username;
            connectionString.Password       = context.Password;
            connectionString.InitialCatalog = context.Parameters["SqlDb"].ToString();
            var connection = new SqlConnection(connectionString.ToString());

            //EXECUTE QUERY
            var sqlString = string.Format(@"
DECLARE @Project INT

SELECT @Project = ID
FROM [dbo].[Project]
WHERE [Code] = '{0}'

INSERT INTO [dbo].[Task]
([ProjectID],[Description],[Completed])
VALUES 
(@Project,'{1}',{2})
", document.Attributes.Project, document.Attributes.Description, Convert.ToInt16(document.Attributes.Completed));

            DataTable table = new DataTable();

            using (SqlCommand cmd = new SqlCommand(
                       sqlString, new SqlConnection(connectionString.ToString())))
            {
                cmd.Connection.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows == 0)
                {
                    throw new Exception("No data integrated");
                }
                cmd.Connection.Close();
            }

            var message = "Integration Successful!";

            return(new ScriptResponse
            {
                Message = message
            });
        }
Пример #8
0
        private void Initialize()
        {
            Root = ParentContext?.Root ?? this;

            if (!ReferenceEquals(Root, this))
            {
                Root.RootDataObject.CopyTo(ContextDataObject);
            }
            ContextDataObject.AddOrReplace(ChainSegment.Root, Root.Value, out WellKnownVariables[(int)WellKnownVariable.Root]);

            if (ParentContext == null)
            {
                ContextDataObject.AddOrReplace(
                    ChainSegment.Parent,
                    UndefinedBindingResult.Create(ChainSegment.Parent),
                    out WellKnownVariables[(int)WellKnownVariable.Parent]
                    );

                return;
            }

            ContextDataObject.AddOrReplace(
                ChainSegment.Parent,
                ParentContext.Value,
                out WellKnownVariables[(int)WellKnownVariable.Parent]
                );

            ParentContext.BlockParamsObject.CopyTo(BlockParamsObject);

            TemplatePath = ParentContext.TemplatePath ?? TemplatePath;

            //Inline partials cannot use the Handlebars.RegisteredTemplate method
            //because it pollutes the static dictionary and creates collisions
            //where the same partial name might exist in multiple templates.
            //To avoid collisions, pass around a dictionary of compiled partials
            //in the context
            InlinePartialTemplates.Outer = ParentContext.InlinePartialTemplates;

            if (!(Value is HashParameterDictionary dictionary) || ParentContext.Value == null || ReferenceEquals(Value, ParentContext.Value))
            {
                return;
            }

            // Populate value with parent context
            PopulateHash(dictionary, ParentContext.Value, Configuration);
        }
Пример #9
0
        internal void SetDataObject(object data)
        {
            if (data == null)
            {
                return;
            }

            var objectDescriptor = ObjectDescriptor.Create(data, Configuration);
            var objectAccessor   = new ObjectAccessor(data, objectDescriptor);

            foreach (var property in objectAccessor.Properties)
            {
                var value = objectAccessor[property];
                RootDataObject.AddOrReplace(property, value, out _);
                ContextDataObject.AddOrReplace(property, value, out _);
            }
        }
Пример #10
0
        internal void SetDataObject(object data)
        {
            if (data == null)
            {
                return;
            }

            if (!Configuration.ObjectDescriptorProvider.TryGetDescriptor(data.GetType(), out var objectDescriptor))
            {
                throw new HandlebarsRuntimeException($"Cannot resolve object descriptor for type `{data.GetType()}`");
            }

            var objectAccessor = new ObjectAccessor(data, objectDescriptor);

            foreach (var property in objectAccessor.Properties)
            {
                var value = objectAccessor[property];
                RootDataObject.AddOrReplace(property, value, out _);
                ContextDataObject.AddOrReplace(property, value, out _);
            }
        }