예제 #1
0
        private static SrmDocument CopyPaste(SrmDocument sourceDoc, IEnumerable <DocNode> nodes, SrmDocument targetDoc, IdentityPath to)
        {
            SetDefaultModifications(targetDoc);
            if (nodes != null)
            {
                sourceDoc = sourceDoc.RemoveAllBut(nodes);
            }

            var stringWriter = new XmlStringWriter();

            using (var writer = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            })
            {
                XmlSerializer ser = new XmlSerializer(typeof(SrmDocument));
                ser.Serialize(writer, sourceDoc);
            }
            IdentityPath newPath, nextAdd;

            targetDoc = targetDoc.ImportDocumentXml(new StringReader(stringWriter.ToString()),
                                                    null,
                                                    MeasuredResults.MergeAction.remove,
                                                    false,
                                                    null,
                                                    Settings.Default.StaticModList,
                                                    Settings.Default.HeavyModList,
                                                    to,
                                                    out newPath,
                                                    out nextAdd,
                                                    false);
            return(targetDoc);
        }
        public static XmlProgramRenamerResult RenameProgram(
            string programCode, string newProgramName)
        {
            try
            {
                var document = XDocument.Load(new StringReader(programCode));
                document.Declaration = new XDeclaration("1.0", "UTF-8", "yes");

                var program     = document.Element("program");
                var header      = program.Element("header");
                var programName = header.Element("programName");
                programName.SetValue(newProgramName);

                var writer = new XmlStringWriter();
                document.Save(writer, SaveOptions.None);
                var newProgramCode = writer.ToString();

                return(new XmlProgramRenamerResult
                {
                    Status = XmlRenameStatus.Success,
                    NewProgramCode = newProgramCode
                });
            }
            catch (Exception)
            {
                return(new XmlProgramRenamerResult
                {
                    Status = XmlRenameStatus.Error,
                    NewProgramCode = null
                });
            }
        }
예제 #3
0
        //-----------------------------------------------------------------------------------------------

        //Gets the XML representing a job
        private static string XmlFromJob(GJob job)
        {
            XmlStringWriter xsw = new XmlStringWriter();

            xsw.Writer.WriteStartElement("job");
            xsw.Writer.WriteAttributeString("id", job.Id.ToString());
            xsw.Writer.WriteStartElement("input");
            xsw.Writer.WriteFullEndElement(); // close input
            xsw.Writer.WriteStartElement("work");
            xsw.Writer.WriteFullEndElement(); // close work
            xsw.Writer.WriteStartElement("output");

            foreach (EmbeddedFileDependency fileDep in job.OutputFiles)
            {
                xsw.Writer.WriteStartElement("embedded_file");
                xsw.Writer.WriteAttributeString("name", fileDep.FileName);
                xsw.Writer.WriteString(fileDep.Base64EncodedContents);
                xsw.Writer.WriteFullEndElement(); // close embedded_file element
            }

            xsw.Writer.WriteEndElement(); // close output
            xsw.Writer.WriteEndElement(); // close task

            return(xsw.GetXmlString());
        }
예제 #4
0
        public string ExecuteXmlString()
        {
            var xmlWriter = new XmlStringWriter(WriterMode.Managed);

            ExecuteXmlWriter(xmlWriter.XmlWriter);
            return(xmlWriter.XmlString);
        }
예제 #5
0
        /*
         * XML
         * Los datos son utilizados para almacenar la transacción en la base de datos
         * tanto local como central.
         */
        public override void SerializeToDB(XmlStringWriter writer)
        {
            writer.WriteStartElement("trans_bes_debito_credito");
            writer.WriteField("shop_id", shop_id);
            writer.WriteField("till_id", till_id);
            writer.WriteField("trans_num", trans_num);
            writer.WriteField("last_digits", last_digits);
            writer.WriteField("codigo_comercio", codigo_comercio);
            writer.WriteField("terminal_id", terminal_id);
            writer.WriteField("code_auth", code_auth);
            writer.WriteField("monto", monto);
            writer.WriteField("cuotas", cuotas);
            writer.WriteField("nro_operacion", nro_operacion);
            writer.WriteField("abrev_tipo_tarjeta", abrev_tipo_tarjeta);
            //writer.WriteField("fecha_contable", fecha_contable);
            writer.WriteField("abrev_marca_tarjeta", abrev_marca_tarjeta);
            writer.WriteField("fecha", fecha);

            /*
             * if (shopMulti != null)
             * writer.WriteField("shops_multi_id", shopMulti.ID);
             * writer.WriteField("shops_multi_points", shopMultiPoints);
             */
            writer.WriteEndElement();
            base.SerializeToDB(writer);
        }
예제 #6
0
        private void btnTransform_Click(object sender, EventArgs e)
        {
            try
            {
                // temporary to copy from clipboard when pressing
                // the button instead of using the text in the textbox
                //txtStylesheet.Text = Clipboard.GetText();

                XmlDocument Stylesheet = new XmlDocument();
                Stylesheet.InnerXml = txtStylesheet.Text;

                XslCompiledTransform XCT = new XslCompiledTransform(true);
                XCT.Load(Stylesheet);

                XmlDocument InputDocument = new XmlDocument();
                InputDocument.InnerXml = txtInputXML.Text;

                XmlStringWriter OutputWriter = XmlStringWriter.Create();

                XCT.Transform(InputDocument, OutputWriter);

                txtOutputXML.Text = OutputWriter.ToString();
            }

            catch (Exception Ex)
            {
                txtOutputXML.Text = Ex.Message;
            }
        }
        //public async Task Save(string path = null)
        //{
        //    // TODO XML: move to IDE.Core

        //    if (path == null)
        //    {
        //        path = BasePath + "/" + StorageConstants.ProgramCodePath;
        //    }

        //    if (Debugger.IsAttached)
        //    {
        //        await SaveInternal(path);
        //    }
        //    else
        //    {
        //        try
        //        {
        //            await SaveInternal(path);
        //        }
        //        catch (Exception ex)
        //        {
        //            throw new Exception("Cannot write Project", ex);
        //        }
        //    }
        //}

        //private async Task SaveInternal(string path)
        //{
        //    // TODO XML: move to IDE.Core

        //    using (var storage = StorageSystem.GetStorage())
        //    {
        //        var writer = new XmlStringWriter();
        //        var document = CreateXml();
        //        document.Save(writer, SaveOptions.None);

        //        var xml = writer.GetStringBuilder().ToString();
        //        await storage.WriteTextFileAsync(path, xml);
        //    }
        //}


        public string ToXmlString()
        {
            var writer   = new XmlStringWriter();
            var document = CreateXml();

            document.Save(writer, SaveOptions.None);
            return(writer.ToString());
        }
 void PM_OnSerializeToDbTransItemInElement(XmlStringWriter writer, TransItem item)
 {
     /*
      * if (item is TransPayment)
      * {
      *  TransPayment transaction = item as TransPayment;
      *  string propina = (10 * BL.CurrentTransaction.Total / 100).ToString();
      *  writer.WriteField("propina", propina);
      * }
      */
 }
예제 #9
0
        /// <summary>
        /// Executes the given xml command and returns the result as an xml string.
        /// </summary>
        /// <param name="rootPrefix">The namespace prefix of the root element.</param>
        /// <param name="rootLocalName">The local name of the root element.</param>
        /// <param name="rootNs">The namespace URI to associate with the root element.</param>
        /// <returns>The resulting xml.</returns>
        public string ExecuteXmlString(string rootPrefix, string rootLocalName, string rootNs)
        {
            var xmlWriter = new XmlStringWriter(WriterMode.Managed);

            xmlWriter.XmlWriter.WriteStartElement(rootPrefix, rootLocalName, rootNs);

            ExecuteXmlWriter(xmlWriter.XmlWriter);

            xmlWriter.XmlWriter.WriteEndElement();
            return(xmlWriter.XmlString);
        }
예제 #10
0
 public override void SerializeToDB(XmlStringWriter writer)
 {
     writer.WriteStartElement("trans_bes_debito");
     writer.WriteField("shop_id", shop_id);
     writer.WriteField("till_id", till_id);
     writer.WriteField("trans_num", trans_num);
     writer.WriteField("last_digits", last_digits);
     writer.WriteField("nro_operacion", nro_operacion);
     writer.WriteField("monto", monto);
     writer.WriteField("code_auth", code_auth);
     writer.WriteEndElement();
     base.SerializeToDB(writer);
 }
예제 #11
0
        //Gets the XML representing a job
        private static string XmlFromJob(GJob job)
        {
            XmlStringWriter xsw = new XmlStringWriter();

            xsw.Writer.WriteStartElement("job");
            xsw.Writer.WriteAttributeString("id", job.Id.ToString());
            xsw.Writer.WriteStartElement("input");
            xsw.Writer.WriteFullEndElement(); // close input
            xsw.Writer.WriteStartElement("work");
            xsw.Writer.WriteFullEndElement(); // close work
            xsw.Writer.WriteStartElement("output");

            foreach (EmbeddedFileDependency fileDep in job.OutputFiles)
            {
                xsw.Writer.WriteStartElement("embedded_file");
                xsw.Writer.WriteAttributeString("name", fileDep.FileName);
                xsw.Writer.WriteString(fileDep.Base64EncodedContents);
                xsw.Writer.WriteFullEndElement(); // close embedded_file element
            }

            /*
             * //in the new API for GJob, the stderr, stdout are properties.
             * //put them into XML as output elements
             */
            //stdout
            xsw.Writer.WriteStartElement("embedded_file");
            xsw.Writer.WriteAttributeString("name", "stdout.txt");
            xsw.Writer.WriteString(Utils.EncodeBase64(job.Stdout));
            xsw.Writer.WriteFullEndElement(); // close embedded_file element
            logger.Debug("Stdout " + job.Stdout);

            //stderr
            xsw.Writer.WriteStartElement("embedded_file");
            xsw.Writer.WriteAttributeString("name", "stderr.txt");
            xsw.Writer.WriteString(Utils.EncodeBase64(job.Stderr));
            xsw.Writer.WriteFullEndElement(); // close embedded_file element
            logger.Debug("Stderr " + job.Stderr);

            //log
            xsw.Writer.WriteStartElement("embedded_file");
            xsw.Writer.WriteAttributeString("name", "log.txt");
            xsw.Writer.WriteString(Utils.EncodeBase64(job.Log));
            xsw.Writer.WriteFullEndElement(); // close embedded_file element
            logger.Debug("Log " + job.Log);

            xsw.Writer.WriteEndElement(); // close output
            xsw.Writer.WriteEndElement(); // close task

            return(xsw.GetXmlString());
        }
        void PM_OnSerializeToPrinterTransItemInElement(XmlStringWriter writer, TransItem item)
        {
            //throw new NotImplementedException();
            if (item is Transaction)
            {
                Transaction transaction = item as Transaction;
                string      foliosii    = transaction.GetCustomField("bes_folio_num").ToString();
                writer.WriteField("folionum", foliosii);

                string webserviceChileSignature = transaction.GetCustomField("webservice_bes_signature").ToString();
                writer.WriteField("dte_firma", webserviceChileSignature);

                string nombreTipoDocumento = transaction.GetCustomField("tipo_documento").ToString();
                writer.WriteField("tipodoc", nombreTipoDocumento);
            }
        }
        //GRABA EN DB
        void PM_OnSerializeToDbTransItemInElement(XmlStringWriter writer, TransItem item)
        {
            //throw new NotImplementedException();
            if (item is Transaction)
            {
                Transaction transaction = item as Transaction;
                string      webserviceChileSignature = transaction.GetCustomField("webservice_bes_signature").ToString();
                writer.WriteField("dte_firma", webserviceChileSignature);

                //webservice_bes_folionum
                string webserviceChileFolioNUM = transaction.GetCustomField("webservice_bes_folionum").ToString();
                writer.WriteField("bes_folio_num", webserviceChileFolioNUM);

                string doctypeBES = transaction.GetCustomField("dte_doc_type").ToString();
                writer.WriteField("doc_type", doctypeBES);
            }
        }//FINISH PM_OnSerializeToDbTransItemInElement
예제 #14
0
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the finished jobs as an xml string
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sc">security credentials used to perform this operation</param>
        /// <param name="taskId"></param>
        /// <returns>XML string representing the job</returns>
        public static string GetFinishedJobs(IManager manager, SecurityCredentials sc, string taskId)
        {
            byte[][] FinishedThreads = manager.Owner_GetFinishedThreads(sc, taskId);

            XmlStringWriter xsw = new XmlStringWriter();

            xsw.Writer.WriteStartElement("task");
            xsw.Writer.WriteAttributeString("id", taskId);

            for (int i = 0; i < FinishedThreads.Length; i++)
            {
                GJob job = (GJob)Utils.DeserializeFromByteArray(FinishedThreads[i]);
                xsw.Writer.WriteRaw("\n" + CrossPlatformHelper.XmlFromJob(job) + "\n");
                logger.Debug("Writing thread:" + job.Id);
            }
            xsw.Writer.WriteEndElement(); // close job

            return(xsw.GetXmlString());
        }
예제 #15
0
        /// <summary>
        /// オブジェクトをXML形式でシリアル化する
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string Serialize <T>(T data, XmlWriterSettings?settings = null)
        {
            var serializer = new XmlSerializer(typeof(T));

            if (settings is null)
            {
                settings = new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                };
            }
            var emptyns = new XmlSerializerNamespaces();

            emptyns.Add(string.Empty, string.Empty);
            var stringWriter = new XmlStringWriter();
            var writer       = XmlWriter.Create(stringWriter, settings);

            serializer.Serialize(writer, data, emptyns);

            return(stringWriter.ToString());
        }
        /*
         * XML
         * Los datos son utilizados para almacenar la transacción en la base de datos
         * tanto local como central.
         */
        public override void SerializeToDB(XmlStringWriter writer)
        {
            writer.WriteStartElement("trans_bes_cheque");
            writer.WriteField("shop_id", shop_id);
            writer.WriteField("till_id", till_id);
            writer.WriteField("trans_num", trans_num);
            writer.WriteField("bank_id", bank_id);
            writer.WriteField("rut_cheque", rut_cheque);
            writer.WriteField("nro_cta_corriente", nro_cta_corriente);
            writer.WriteField("nro_cheque", nro_cheque);
            writer.WriteField("monto", monto);
            writer.WriteField("code_auth", code_auth);
            writer.WriteField("nombre_completo", nombre_completo);
            writer.WriteField("tasas", tasas);
            writer.WriteField("fecha", fecha);

            /*
             * if (shopMulti != null)
             * writer.WriteField("shops_multi_id", shopMulti.ID);
             * writer.WriteField("shops_multi_points", shopMultiPoints);
             */
            writer.WriteEndElement();
            base.SerializeToDB(writer);
        }
        }//FINISH PM_OnSerializeToDbTransItemInElement

        //ANTES DEL CIERRE DE LA TRANSACCION
        void PM_OnBeforeCloseTransaction(Transaction transaction, ref bool abort)
        {
            //throw new NotImplementedException();
            // ARROJA ERROR SI EL SERVICIO NO ESTA DISPONIBLE


            if (webservice == null)
            {
                abort = true;
                BL.MsgError("WEBSERVICE NO COMUNICATION");
                return;
            }
            else
            {
                string printoutType = "";
                if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.KeepDefault || transaction.ManualPrintoutSelected == DbPayment.PrintoutType.NoPrintout)
                {
                    printoutType = "39";
                }
                if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.Invoice)
                {
                    printoutType = "33";
                }
                if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.Bill)
                {
                    printoutType = "39";
                }
                if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.Invoice && transaction.Customer == null)
                {
                    BL.MsgError("WE NEED A CUSTOMER");
                    abort = true;
                    return;
                }
                //string xmlData = "";
                //string documentType = "";

                DbCustomer receptorDTE = new DbCustomer();
                receptorDTE = customer;

                XmlStringWriter writer = new XmlStringWriter(BL.DB);
                writer.WriteRaw(@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>");

                if (printoutType == "33")//FACTURA
                {
                    //INICIO DTE
                    writer.WriteStartElement("DTE");
                    writer.WriteAttribute("version", "1.0");
                    writer.WriteAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
                    writer.WriteAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
                    writer.WriteAttribute("xmlns", "http://www.sii.cl/SiiDte");
                    //FIN DTE
                }
                else//BOLETA
                {
                    //INICIO EnvioBOLETA
                    writer.WriteStartElement("EnvioBOLETA");
                    writer.WriteAttribute("version", "1.0");
                    writer.WriteAttribute("xmlns", "http://www.sii.cl/SiiDte");
                    writer.WriteAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
                    writer.WriteAttribute("xsi:schemaLocation", "http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd");
                    //FIN EnvioBoleta
                }

                //RUT RECEPTOR
                string rrecep;
                rrecep = getRutReceptorDTE();
                //RUT RECEPTOR

                if (printoutType == "39")//BOLETA
                {
                    //ONLY BOLETA
                    writer.WriteStartElement("SetDTE");
                    writer.WriteAttribute("ID", string.Format("ENVBOL-{0}", transaction.TransDate.ToString("yyyyMMddHHmmss")));
                    writer.WriteStartElement("Caratula");
                    writer.WriteAttribute("version", "1.0");
                    //string shopRut = BL.DB.Shop["rut"].ToString();
                    //string shopRut = "76328464-6";
                    string shopRut = dataEmisor.RutBoleta;
                    writer.WriteElement("RutEmisor", shopRut);
                    //string RutEnvia = BL.DB.Shop["RutEnvia"].ToString();
                    //string RutEnvia = "8833649-6";
                    string RutEnvia = dataEmisor.RutRepLegal;
                    writer.WriteElement("RutEnvia", RutEnvia);
                    //string RutReceptor = BL.DB.Shop["RutReceptor"].ToString();
                    //string RutReceptor = "66666666-6";
                    writer.WriteElement("RutReceptor", rrecep);
                    //DateTime FchResol = Convert.ToDateTime(BL.DB.Shop["FchResol"]);
                    //DateTime FchResol = new DateTime(2014, 04, 22);
                    DateTime FchResol = (dataEmisor.ResolDate);
                    writer.WriteElement("FchResol", FchResol.ToString("yyyy-MM-dd"));
                    //writer.WriteElement("NroResol", 0);
                    writer.WriteElement("NroResol", dataEmisor.NumResol);
                    writer.WriteElement("TmstFirmaEnv", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));
                    writer.WriteStartElement("SubTotDTE");
                    writer.WriteElement("TpoDTE", printoutType);
                    writer.WriteElement("NroDTE", 1);
                    writer.WriteEndElement();
                    writer.WriteEndElement();

                    writer.WriteStartElement("DTE");
                    writer.WriteAttribute("version", "1.0");
                    //END ONLY BOLETA
                }
                //string besRut = "76054473-6"; //MANAGE THIS FROM DB ON FRONTEND dataEmisor.Rut
                //
                string besRut = dataEmisor.Rut;
                if (printoutType == "39")
                {
                    //ONLY BOLETA
                    writer.WriteStartElement("Documento");
                    //string besRut = myClassPAramData["besRUT"].ToString();
                    string besRutBoletaE = dataEmisor.RutBoleta;
                    solicitarFolio = webservice.Solicitar_Folio(besRutBoletaE, 39);
                    writer.WriteAttribute("ID", string.Format("R{0}T{1}F{2}", besRutBoletaE, printoutType, solicitarFolio.Folio));
                    //END ONLY BOLETA
                }
                else
                {
                    solicitarFolio = webservice.Solicitar_Folio(besRut, 33);
                    writer.WriteStartElement("Documento");
                }

                writer.WriteStartElement("Encabezado");
                writer.WriteStartElement("IdDoc");
                writer.WriteElement("TipoDTE", printoutType);
                writer.WriteElement("Folio", solicitarFolio.Folio);
                writer.WriteElement("FchEmis", DateTime.Now.ToString("yyyy-MM-dd"));

                if (printoutType == "39")
                {
                    //SOLO BOLETA
                    writer.WriteElement("IndServicio", 3);
                    //SOLO BOLETA
                }
                else
                {
                    //TermPagoGlosa
                    //FchVenc
                    writer.WriteElement("TermPagoGlosa", "30 dias Precio Contado"); ///////////////////////////////////////////ASK 4 THIS FIELD
                    writer.WriteElement("FchVenc", "2016-06-30");                   /////////////////////////////////////////////////////////////ASK 4 THIS FIELD
                }

                writer.WriteEndElement(); //IdDoc

                //FIN DATOS EMISOR

                if (printoutType == "39")
                {
                    writer.WriteStartElement("Emisor");
                    writer.WriteElement("RUTEmisor", dataEmisor.Rut);
                    writer.WriteElement("RznSocEmisor", dataEmisor.RazonEmisor);
                    writer.WriteElement("GiroEmisor", dataEmisor.GiroEmisor);
                    writer.WriteElement("CdgSIISucur", dataEmisor.CodigoSII);
                    writer.WriteElement("DirOrigen", dataEmisor.DireccionEm);
                    writer.WriteElement("CmnaOrigen", dataEmisor.ComunaEm);
                    writer.WriteElement("CiudadOrigen", dataEmisor.CiudadEm);
                    writer.WriteEndElement(); //Emisor
                }
                else
                {
                    writer.WriteStartElement("Emisor");
                    //<Acteco>602300</Acteco>
                    writer.WriteElement("Acteco", dataEmisor.ActEco);
                    writer.WriteElement("RUTEmisor", dataEmisor.Rut);
                    writer.WriteElement("RznSoc", dataEmisor.RazonEmisor);
                    writer.WriteElement("GiroEmis", dataEmisor.GiroEmisor);
                    writer.WriteElement("DirOrigen", dataEmisor.DireccionEm);
                    writer.WriteElement("CmnaOrigen", dataEmisor.ComunaEm);
                    writer.WriteElement("CiudadOrigen", dataEmisor.CiudadEm);
                    writer.WriteElement("CdgVendedor", BL.CurrentOperator.Code);
                    writer.WriteEndElement(); //Emisor
                }

                //OBJETO RECEPTOR
                DbCustomer receptorC = BL.DB.GetCustomerByCardNum((rrecep.Replace("-", "")), false);

                //OBJETO RECEPTOR

                writer.WriteStartElement("Receptor");
                writer.WriteElement("RUTRecep", rrecep);


                if (printoutType == "33")//FACTURA
                {
                    //<CdgIntRecep>76124037C</CdgIntRecep>
                    writer.WriteElement("CdgIntRecep", getCodeIntRecep(rrecep));
                    writer.WriteElement("RznSocRecep", receptorC.C_o);
                    //<GiroRecep>VENTA AL POR MAYOR DE OTROS PRODUCTOS N.</GiroRecep>
                    writer.WriteElement("GiroRecep", receptorC.C_o);
                    writer.WriteElement("DirRecep", receptorC.Street);
                    writer.WriteElement("CmnaRecep", receptorC.Notes1);
                    writer.WriteElement("CiudadRecep", receptorC.City);
                    writer.WriteEndElement(); //Receptor
                }
                else//BOLETA
                {
                    writer.WriteElement("RznSocRecep", null);
                    writer.WriteElement("Contacto", null);//ASK NUM TELEFONO
                    writer.WriteElement("DirRecep", null);
                    writer.WriteElement("CmnaRecep", null);
                    writer.WriteElement("CiudadRecep", null);
                    writer.WriteElement("DirPostal", null);
                    writer.WriteElement("CmnaPostal", null);
                    writer.WriteElement("CiudadPostal", null);
                    writer.WriteEndElement(); //Receptor
                }

                writer.WriteStartElement("Totales");

                if (printoutType == "33")//FACTURA
                {
                    double monto, neto, iva;
                    string netoS, ivaS;
                    monto = SafeConvert.ToInt32(transaction.Total);
                    neto  = monto * 0.81;
                    iva   = monto - neto;
                    netoS = SafeConvert.ToString(neto);
                    ivaS  = SafeConvert.ToString(iva);

                    writer.WriteElement("TpoMoneda", "PESO CL");
                    writer.WriteElement("MntNeto", netoS);
                    writer.WriteElement("TasaIVA", "19.00");
                    writer.WriteElement("IVA", ivaS);
                }
                writer.WriteElement("MntTotal", SafeConvert.ToInt32(transaction.Total));
                writer.WriteEndElement(); //Totales

                writer.WriteEndElement(); //Encabezado

                int position = 1;
                foreach (TransArticle art in transaction.GetItems <TransArticle>())
                {
                    writer.WriteStartElement("Detalle");
                    writer.WriteElement("NroLinDet", position);
                    writer.WriteStartElement("CdgItem");
                    writer.WriteElement("TpoCodigo", "Interna");
                    writer.WriteElement("VlrCodigo", art.Data.Code);
                    writer.WriteEndElement(); //CdgItem
                    writer.WriteElement("NmbItem", art.Data.Description);

                    if (printoutType == "33")
                    {
                        writer.WriteElement("DscItem", art.Data.Description);
                    }

                    writer.WriteElement("QtyItem", art.Data.MeasureUnit == DbArticle.Units.Pieces ? art.Quantity : 1);
                    //writer.WriteElement("QtyItem", 1);
                    writer.WriteElement("UnmdItem", null);
                    writer.WriteElement("PrcItem", art.UnitPrice);
                    //writer.WriteElement("MontoItem", art.TotalPrice);
                    string totalprice = art.TotalPrice.ToString();
                    totalprice = totalprice.Replace(".00", "");
                    writer.WriteElement("MontoItem", totalprice);
                    writer.WriteEndElement(); //Detalle
                    position++;
                }

                writer.WriteEndElement(); //Documento
                writer.WriteEndElement(); //DTE

                if (printoutType == "39")
                {
                    writer.WriteEndElement(); //SetDTE
                    writer.WriteEndElement(); //EnvioBOLETA || DTE
                }

                string xmlString = writer.ToString();


                if (printoutType == "33")
                {
                    resultProcesarTXTDTE = webservice.Carga_TXTDTE(xmlString, "XML");
                }
                else
                {
                    resultProcesarTXTBoleta = webservice.Carga_TXTBoleta(xmlString, "XML");
                }
                string fob;
                if (printoutType == "33")
                {
                    fob = "Factura";
                }
                else
                {
                    fob = "Boleta";
                }

                if (dataEmisor.SaveXML == 1)
                {
                    //SAVE TO FILE XML
                    string path = Path.GetPathRoot(Environment.SystemDirectory);
                    System.IO.Directory.CreateDirectory("C:\\xmlTCPOS");
                    //System.IO.File.WriteAllText(@"C:\xmlTCPOS\" + fob + "" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xml", xmlString);
                    System.IO.File.WriteAllText(@"" + path + "xmlTCPOS\\" + fob + "" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xml", xmlString);
                    //END SAVE TO FILE XML
                }

                if (printoutType == "33")
                {
                    if (resultProcesarTXTDTE.XML != "")
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(resultProcesarTXTDTE.XML);
                        XmlElement root = doc.DocumentElement;
                        if (root == null)
                        {
                            abort = true;
                            throw new Exception("XML BAD FORMAT");
                        }
                        XmlNodeList SignatureValue = root.GetElementsByTagName("TED");
                        string      signature      = "";
                        foreach (XmlNode tableNode in SignatureValue)
                        {
                            signature = tableNode.InnerXml;
                        }
                        if (signature != "")
                        {
                            signature = string.Format("<TED version=\"1.0\">" + signature + "</TED>");
                        }
                        transaction.SetCustomField("webservice_bes_signature", signature);
                        transaction.SetCustomField("dte_doc_type", printoutType);

                        XmlNodeList folioNUMValue = root.GetElementsByTagName("F");
                        string      folioNUM      = "";
                        foreach (XmlNode tableNode in folioNUMValue)
                        {
                            folioNUM = tableNode.InnerXml;
                        }

                        if (folioNUM != "")
                        {
                            folioNUM = string.Format("" + folioNUM + "");
                        }


                        transaction.SetCustomField("webservice_bes_folionum", folioNUM);
                        //GUARDA FOLIO 2 PRINT
                        if (folioNUM != "")
                        {
                            transaction.SetCustomField("bes_folio_num", folioNUM);
                        }
                        //END GUARDA FOLIO 2 PRINT
                        //PRINT TIPO DOC
                        transaction.SetCustomField("tipo_documento", "FACTURA ELECTRONICA");
                        //END PRINT TIPO DOC
                    }
                    else
                    {
                        abort = true;
                        BL.MsgError("No answer from webservice,\nelectronic invoice cannot be accepted\nPlease use another type of document");
                    }
                }
                else
                {
                    //if response from webservice read xml response and get the signature, save it into transaction and print signature
                    if (resultProcesarTXTBoleta.XML != "")
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(resultProcesarTXTBoleta.XML);
                        XmlElement root = doc.DocumentElement;
                        if (root == null)
                        {
                            abort = true;
                            throw new Exception("XML BAD FORMAT");
                        }

                        //OBTENER TED Y GUARDAR
                        XmlNodeList SignatureValue = root.GetElementsByTagName("TED");
                        string      signature      = "";
                        foreach (XmlNode tableNode in SignatureValue)
                        {
                            signature = tableNode.InnerXml;
                        }

                        if (signature != "")
                        {
                            signature = string.Format("<TED version=\"1.0\">" + signature + "</TED>");
                        }

                        transaction.SetCustomField("webservice_bes_signature", signature);
                        transaction.SetCustomField("dte_doc_type", printoutType);
                        //FIN OBTENER TED Y GUARDAR

                        //OBTENER FOLIONUM Y GUARDAR
                        XmlNodeList folioNUMValue = root.GetElementsByTagName("F");
                        string      folioNUM      = "";
                        foreach (XmlNode tableNode in folioNUMValue)
                        {
                            folioNUM = tableNode.InnerXml;
                        }

                        if (folioNUM != "")
                        {
                            folioNUM = string.Format("" + folioNUM + "");
                        }


                        transaction.SetCustomField("webservice_bes_folionum", folioNUM);
                        //FIN FOLIONUM Y GUARDAR
                        //GUARDA FOLIO 2 PRINT
                        if (folioNUM != "")
                        {
                            transaction.SetCustomField("bes_folio_num", folioNUM);
                        }
                        //END GUARDA FOLIO 2 PRINT
                        transaction.SetCustomField("tipo_documento", "BOLETA ELECTRONICA");
                    }
                    else
                    {
                        abort = true;
                        BL.MsgError("No answer from webservice,\nelectronic invoice cannot be accepted\nPlease use another type of document");
                    }
                }
            }
        }//FINISH PM_OnBeforeCloseTransaction
예제 #18
0
        private static SrmDocument CopyPaste(SrmDocument sourceDoc, IEnumerable<DocNode> nodes, SrmDocument targetDoc, IdentityPath to)
        {
            SetDefaultModifications(targetDoc);
            if(nodes != null)
                sourceDoc = sourceDoc.RemoveAllBut(nodes);

            var stringWriter = new XmlStringWriter();
            using (var writer = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented })
            {
                XmlSerializer ser = new XmlSerializer(typeof(SrmDocument));
                ser.Serialize(writer, sourceDoc);
            }
            IdentityPath newPath, nextAdd;
            targetDoc = targetDoc.ImportDocumentXml(new StringReader(stringWriter.ToString()),
                                                    null,
                                                    MeasuredResults.MergeAction.remove,
                                                    false,
                                                    null,
                                                    Settings.Default.StaticModList,
                                                    Settings.Default.HeavyModList,
                                                    to,
                                                    out newPath,
                                                    out nextAdd,
                                                    false);
            return targetDoc;
        }
예제 #19
0
파일: Project.cs 프로젝트: msachs/TestRepo2
        public void Save()
        {
            XDocument xDocument = CreateXML();
              string path = BasePath + "/" + ProjectCodePath;

              using (IStorage storage = StorageSystem.GetStorage())
              {
            try
            {
              var writer = new XmlStringWriter();
              document.Save(writer, SaveOptions.None);

              string xml = writer.GetStringBuilder().ToString();
              storage.WriteTextFile(BasePath + "/" + ProjectCodePath, xml);
            }
            catch
            {
              throw new Exception("Cannot write Project");
            }
              }
        }
예제 #20
0
        private void ShareMinimal(ZipFile zip)
        {
            TemporaryDirectory tempDir = null;

            try
            {
                var docOriginal = Document;
                if (Document.Settings.HasBackgroundProteome)
                {
                    // Remove any background proteome reference
                    Document = Document.ChangeSettings(Document.Settings.ChangePeptideSettings(
                                                           set => set.ChangeBackgroundProteome(BackgroundProteome.NONE)));
                }
                if (Document.Settings.HasRTCalcPersisted)
                {
                    // Minimize any persistable retention time calculator
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.PeptideSettings.Prediction.RetentionTime
                                        .Calculator.PersistMinimized(tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath, string.Empty);
                    }
                }
                if (Document.Settings.HasOptimizationLibraryPersisted)
                {
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.TransitionSettings.Prediction.OptimizedLibrary.PersistMinimized(
                        tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath, string.Empty);
                    }
                }
                if (Document.Settings.HasIonMobilityLibraryPersisted)
                {
                    // Minimize any persistable drift time predictor
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.PeptideSettings.Prediction.DriftTimePredictor
                                        .IonMobilityLibrary.PersistMinimized(tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath, string.Empty);
                    }
                }
                if (Document.Settings.HasLibraries)
                {
                    // Minimize all libraries in a temporary directory, and add them
                    if (tempDir == null)
                    {
                        tempDir = new TemporaryDirectory();
                    }
                    Document = BlibDb.MinimizeLibraries(Document, tempDir.DirPath,
                                                        Path.GetFileNameWithoutExtension(DocumentPath),
                                                        ProgressMonitor);
                    if (ProgressMonitor != null && ProgressMonitor.IsCanceled)
                    {
                        return;
                    }

                    foreach (var librarySpec in Document.Settings.PeptideSettings.Libraries.LibrarySpecs)
                    {
                        var tempLibPath = Path.Combine(tempDir.DirPath, Path.GetFileName(librarySpec.FilePath) ?? string.Empty);
                        zip.AddFile(tempLibPath, string.Empty);

                        // If there is a .redundant.blib file that corresponds to a .blib file
                        // in the temp temporary directory, add that as well
                        IncludeRedundantBlib(librarySpec, zip, tempLibPath);
                    }
                }

                ShareDataAndView(zip);
                if (ReferenceEquals(docOriginal, Document))
                {
                    zip.AddFile(DocumentPath, string.Empty);
                }
                else
                {
                    // If minimizing changed the document, then serialize and archive the new document
                    var stringWriter = new XmlStringWriter();
                    using (var writer = new XmlTextWriter(stringWriter)
                    {
                        Formatting = Formatting.Indented
                    })
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(SrmDocument));
                        ser.Serialize(writer, Document);
                        zip.AddEntry(Path.GetFileName(DocumentPath), stringWriter.ToString(), Encoding.UTF8);
                    }
                }
                Save(zip);
            }
            finally
            {
                if (tempDir != null)
                {
                    try
                    {
                        tempDir.Dispose();
                    }
                    catch (IOException x)
                    {
                        var message = TextUtil.LineSeparate(string.Format(Resources.SrmDocumentSharing_ShareMinimal_Failure_removing_temporary_directory__0__,
                                                                          tempDir.DirPath),
                                                            x.Message);
                        throw new IOException(message);
                    }
                }
            }
        }
예제 #21
0
        private void ShareMinimal(ZipFile zip)
        {
            TemporaryDirectory tempDir = null;
            try
            {
                var docOriginal = Document;
                if (Document.Settings.HasBackgroundProteome)
                {
                    // Remove any background proteome reference
                    Document = Document.ChangeSettings(Document.Settings.ChangePeptideSettings(
                        set => set.ChangeBackgroundProteome(BackgroundProteome.NONE)));
                }
                if (Document.Settings.HasRTCalcPersisted)
                {
                    // Minimize any persistable retention time calculator
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.PeptideSettings.Prediction.RetentionTime
                        .Calculator.PersistMinimized(tempDir.DirPath, Document);
                    if (tempDbPath != null)
                        zip.AddFile(tempDbPath, string.Empty);
                }
                if (Document.Settings.HasOptimizationLibraryPersisted)
                {
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.TransitionSettings.Prediction.OptimizedLibrary.PersistMinimized(
                            tempDir.DirPath, Document);
                    if (tempDbPath != null)
                        zip.AddFile(tempDbPath, string.Empty);
                }
                if (Document.Settings.HasIonMobilityLibraryPersisted)
                {
                    // Minimize any persistable drift time predictor
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.PeptideSettings.Prediction.DriftTimePredictor
                        .IonMobilityLibrary.PersistMinimized(tempDir.DirPath, Document);
                    if (tempDbPath != null)
                        zip.AddFile(tempDbPath, string.Empty);
                }
                if (Document.Settings.HasLibraries)
                {
                    // Minimize all libraries in a temporary directory, and add them
                    if (tempDir == null)
                        tempDir = new TemporaryDirectory();
                    Document = BlibDb.MinimizeLibraries(Document, tempDir.DirPath,
                                                        Path.GetFileNameWithoutExtension(DocumentPath),
                                                        ProgressMonitor);
                    if (ProgressMonitor != null && ProgressMonitor.IsCanceled)
                        return;

                    foreach (var librarySpec in Document.Settings.PeptideSettings.Libraries.LibrarySpecs)
                    {
                        var tempLibPath = Path.Combine(tempDir.DirPath, Path.GetFileName(librarySpec.FilePath) ?? string.Empty);
                        zip.AddFile(tempLibPath, string.Empty);

                        // If there is a .redundant.blib file that corresponds to a .blib file
                        // in the temp temporary directory, add that as well
                        IncludeRedundantBlib(librarySpec, zip, tempLibPath);
                    }
                }

                ShareDataAndView(zip);
                if (ReferenceEquals(docOriginal, Document))
                    zip.AddFile(DocumentPath, string.Empty);
                else
                {
                    // If minimizing changed the document, then serialize and archive the new document
                    var stringWriter = new XmlStringWriter();
                    using (var writer = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented })
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(SrmDocument));
                        ser.Serialize(writer, Document);
                        zip.AddEntry(Path.GetFileName(DocumentPath), stringWriter.ToString(), Encoding.UTF8);
                    }
                }
                Save(zip);
            }
            finally
            {
                if (tempDir != null)
                {
                    try
                    {
                        tempDir.Dispose();
                    }
                    catch (IOException x)
                    {
                        var message = TextUtil.LineSeparate(string.Format(Resources.SrmDocumentSharing_ShareMinimal_Failure_removing_temporary_directory__0__,
                                                                          tempDir.DirPath),
                                                            x.Message);
                        throw new IOException(message);
                    }
                }
            }
        }
예제 #22
0
        public static async Task <VersionConverterResult> ConvertToXmlVersion(
            string projectCode, string targetVersion)
        {
            // TODO XML: move to IDE.Core
            VersionConverterStatus error;
            var xml = "";

            if (!string.IsNullOrEmpty(projectCode))
            {
                //string projectCode;

                //using (var storage = StorageSystem.GetStorage())
                //{
                //    projectCode = await storage.ReadTextFileAsync(projectCodePath);
                //}

                if (projectCode != null)
                {
                    var document = XDocument.Load(new StringReader(projectCode));
                    document.Declaration = new XDeclaration("1.0", "UTF-8", "yes");

                    var inputVersion = GetInputVersion(document);

                    if (XmlConstants.SupportedXMLVersions.Contains(inputVersion))
                    {
                        return(new VersionConverterResult
                        {
                            Error = VersionConverterStatus.NoError,
                            Xml = projectCode
                        });
                    }

                    if (double.Parse(inputVersion) < XmlConstants.MinimumCodeVersion)
                    {
                        return(new VersionConverterResult
                        {
                            Error = VersionConverterStatus.VersionTooOld,
                            Xml = null
                        });
                    }

                    error = ConvertVersions(inputVersion, targetVersion, document);

                    if (error == VersionConverterStatus.NoError)
                    {
                        var writer = new XmlStringWriter();
                        document.Save(writer, SaveOptions.None);
                        xml = writer.GetStringBuilder().ToString();


                        //if (overwriteProject)
                        //{
                        //    using (var storage = StorageSystem.GetStorage())
                        //    {
                        //        try
                        //        {
                        //            await storage.WriteTextFileAsync(projectCodePath, xml);
                        //        }
                        //        catch
                        //        {
                        //            error = VersionConverterStatus.ProgramDamaged;
                        //        }
                        //    }
                        //}
                    }
                    else
                    {
                        error = VersionConverterStatus.ProgramDamaged;
                    }
                }
                else
                {
                    error = VersionConverterStatus.ProgramDamaged;
                }
            }
            else
            {
                error = VersionConverterStatus.ProgramDamaged;
            }

            return(new VersionConverterResult {
                Xml = xml, Error = error
            });
        }