Buscar contenidos

viernes, 1 de noviembre de 2019

Deserialize JSON into C# dynamic object


https://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object



dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

                string name = stuff.Name;

                string address = stuff.Address.City;



-----



Simple "string JSON data" to object without any third-party DLL file:
WebClient client = new WebClient();
string getString = client.DownloadString("https://graph.facebook.com/zuck");

JavaScriptSerializer serializer = new JavaScriptSerializer();
dynamic item = serializer.Deserialize<object>(getString);
string name = item["name"];

//note: JavaScriptSerializer in this namespaces
//System.Web.Script.Serialization.JavaScriptSerializer
Note: You can also using your custom object.
Personel item = serializer.Deserialize<Personel>(getString);

jueves, 31 de octubre de 2019

Import .ispac file or deployed project back into a Visual Studio Project

 Link: https://sqlnotesfromtheunderground.wordpress.com/2015/06/17/import-ispac-file-or-deployed-project-back-into-a-visual-studio-project/

Import .ispac into Visual Studio Project

Open Visual Studio
File -> New -> Project (Business Intelligence -> Integrations Serices)
Select “Integration Services Import Project Wizard”
ispacToSolution
Click next from the Import Project wizard
ispacToSolution02
Select “Project deployment file” and then select Browse and point it to your .ispac.
ispacToSolution03
It will now validate the pack and if you have set a password on the project, be asked to enter that.
ispacToSolution04
Review and select “Import”
ispacToSolution05
Hopefully should see a nice selection of Result Passed now to confirm the wizard work correctly Close and you are in your Project.
ispacToSolution06

Import Project from SSISDB into Visual Studio Project

Is very similar in its steps, where we just change the the Select Source from a file to a Integration Services Catalog
Where you Select the Server you want to import the project from (I have select the localhost via =.) and then choose the project to Import from the instance.
ispacToSolution07
ispacToSolution08
You then just follow the confirmation steps to complete the process

viernes, 11 de octubre de 2019

datatables.net - seleccionar todos checkbox - paginación virtual


http://jsfiddle.net/05xnxzbd/


--Seleccionar CheckBox que resultan de la Busqueda

$("[id*='id_seleccionar_todos']").click(function () {
            var flag_estado_seleccionar = $("[id*='id_seleccionar_todos']").is(":checked");
           
            var oTable = $('#tblCombos').dataTable();
            var rowcollection = oTable.$("tr", { "page": "all" });
            rowcollection.each(function () {

var nombreCombo = $(this).find('td:eq(1)').text().toUpperCase();

var criterio = $("#id_buscar_filtrar").val().toUpperCase();
 
if(nombreCombo.indexOf(criterio) !== -1){
$(this).find(":checkbox").prop("checked", flag_estado_seleccionar);  
}
   
            });
 
        });




   $("[id*='id_seleccionar_todos']").click(function () {
            var flag_estado_seleccionar = $("[id*='id_seleccionar_todos']").is(":checked");
            var contador = 0;
            //$("input[type=checkbox]").each(function () {
            //    $(this).prop("checked", flag_estado_seleccionar);
            //    contador++;
            //    //console.log(contador);
            //});
         
            var oTable = $('#tblCombos').dataTable();
            var rowcollection = oTable.$("input[type=checkbox]", { "page": "all" });
            rowcollection.each(function () {
                $(this).prop("checked", flag_estado_seleccionar);               
            });

        });


HTML

<!DOCTYPE html><html><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script><link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css"><body><h1>Guia para seleccionar todos los controles CheckBox</h1><h3>Esto es una copia del codigo de la pantlla de Combos, que al no tener ambiente, se replicó el escenario</h3><input id="id_seleccionar_todos" type="checkbox" name="" value="" /> <span style='font-size:14px;color:#424242;'>SELECCIONAR/TODOS</span> (<span style='font-size:13px;color:#07728E;'>Para habilitar esta opción debe seleccionar la página <b style=''>Ver todos</b></span>)<hr><table id="tblCombos" class="table table-striped table-hover dt-responsive dataTable no-footer DTTT_selectable dtr-column collapsed" cellspacing="0" role="grid" aria-describedby="tblCombos_info" style="width: 1565px;"><thead> <tr role="row" style="height: 0px;"><th class="all sorting_asc" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 155px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="IdCombo: Activar para ordenar la columna de manera descendente" aria-sort="ascending"><div class="dataTables_sizing" style="height:0;overflow:hidden;">IdCombo</div></th><th class="all sorting" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 342px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="Nombre Combo: Activar para ordenar la columna de manera ascendente"><div class="dataTables_sizing" style="height:0;overflow:hidden;">Nombre Combo</div></th><th class="all sorting" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 203px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="Fecha Inicial: Activar para ordenar la columna de manera ascendente"><div class="dataTables_sizing" style="height:0;overflow:hidden;">Fecha Inicial</div></th><th class="all sorting" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 190px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="Fecha Final: Activar para ordenar la columna de manera ascendente"><div class="dataTables_sizing" style="height:0;overflow:hidden;">Fecha Final</div></th><th class="all sorting" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 137px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="Estatus: Activar para ordenar la columna de manera ascendente"><div class="dataTables_sizing" style="height:0;overflow:hidden;">Estatus</div></th><th class="all sorting" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 193px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="Seleccionar: Activar para ordenar la columna de manera ascendente"><div class="dataTables_sizing" style="height:0;overflow:hidden;">Seleccionar</div></th><th class="all sorting" aria-controls="tblCombos" rowspan="1" colspan="1" style="width: 156px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;" aria-label="Consulta: Activar para ordenar la columna de manera ascendente"><div class="dataTables_sizing" style="height:0;overflow:hidden;">Consulta</div></th></tr> </thead> <tbody><tr role="row" class="odd"><td class="sorting_1">493</td><td>COMBOS PRUEBA UAT 2 CELSTEL CEL 4G SAMSUNG J4 CORE NEG</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(493)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="even"><td class="sorting_1">494</td><td>COMBOS PRUEBA UAT VALES UNISUPERTEL CEL 4G HUAWEI Y5 8GB 2018 DOR + VALE DE Q100 UNISUPER REGALIA</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(494)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="odd"><td class="sorting_1">495</td><td>COMBOS PRUEBA UAT RECARGA 1500 TEL CEL 4G SAMSUNG J4 CORE NEG + RECARGA ELECTRONICA MOVISTAR</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(495)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="even"><td class="sorting_1">496</td><td>COMBOS PRUEBA UAT RECARGA 500 TEL CEL 4G HUAWEI P30 AZ + RECARGA ELECTRONICA TIGO</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(496)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="odd"><td class="sorting_1">497</td><td>COMBOS PRUEBA UAT 2 CELS TEL CEL 4G SAMSUNG J4 CORE NEG </td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(497)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="even"><td class="sorting_1">498</td><td>COMBOS PRUEBA UAT 1 REGALIA TV LED 60" LG 60UM7270PSA SMART 4K + TECLADO MICROSOFT C/SOPORTE COMBO</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(498)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="odd"><td class="sorting_1">499</td><td>COMBOS PRUEBA UAT 2 REGALIAS SET COL OLYMPIA SALUD KING 200X200 + LICUADORA OSTER BRLY07R00 VID 3 V</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(499)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="even"><td class="sorting_1">500</td><td>COMBOS PRUEBA UAT 3 REGALIAS REF AUTO WHIRLP LWT1615Q 16CF 473L BLC + HORNO MIC WHIRLP WM1211D 1.1CF SILVER</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(500)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="odd"><td class="sorting_1">501</td><td>COMBOS PRUEBA UAT 4 REGALIAS MOTO SERPENTO ASPID 150 ROJ 2020 + AUDIF PAST KLIP EXTREME KHS633BL BT</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(501)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr><tr role="row" class="even"><td class="sorting_1">502</td><td>COMBOS PRUEBA UAT PRODS CON DESC MAQ COSER BROTHER XM2701 + OLLA PRES SANKEY K11 11L</td><td>01/08/2019</td><td>30/11/2019</td><td>Activo</td><td><input type="checkbox"></td><td><button type="button" onclick="modalBusquedaCombo.fnCargarPantallaModal(502)" class="btn btn-success btn-busqueda-combo"><i class="fa fa-search"></i></button></td></tr></tbody> </table> </body></html>


JAVASCRIPT

$( document ).ready(function() {

 $("[id*='id_seleccionar_todos']").attr("disabled", true);
   
 $('#tblCombos').dataTable( {  
   "lengthMenu": [[5, 10, 50, -1], [5, 10, 50, "Ver todos"]],
   "searching": false,    
         "language": {
         "lengthMenu": "Mostrar _MENU_ registros por página",
         "info": "Mostrando _START_ a _END_ de _TOTAL_ resultados",   
           "zeroRecords": "No se encontraron resultados :( ",         
            "infoEmpty": "No se encontraron resultados :( ",
            "infoFiltered": "(filtered from _MAX_ total records)",
            "sSearch": "Buscar: ",         
            paginate: {
            next: 'Siguiente', // or '→' &#8594;
            previous: 'Anterior' // or '←' &#8592;
    }
  }
        
} );

$("[id*='id_seleccionar_todos']").click(function(){
    var flag_estado_seleccionar = $("[id*='id_seleccionar_todos']").is (":checked");
    var contador = 0;
    $("input[type=checkbox]").each(function(){         
      $(this).prop("checked", flag_estado_seleccionar);
      contador++;
      //console.log(contador);
    });                    
 });

  setInterval(function(){
    $( "select option:selected" ).each(function() {      
     $("[id*='id_seleccionar_todos']").attr("disabled", true);     
      if($(this).val() == "-1")
      {
        //true habilitar checkbox seleccionar todos                       
        $("[id*='id_seleccionar_todos']").removeAttr("disabled");
      }
    });
  }, 200);
         
});

lunes, 7 de octubre de 2019

Send msg to Azure service bus que via REST


https://stackoverflow.com/questions/50914924/send-msg-to-azure-service-bus-que-via-rest

https://docs.microsoft.com/en-us/rest/api/servicebus/send-message-to-queue

public static string GetSasToken(string resourceUri, string keyName, string key, TimeSpan ttl)
{
      var expiry = GetExpiry(ttl);
      string stringToSign = HttpUtility.UrlEncode(resourceUri) + "\n" + expiry;
      HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(key));
      var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
      var sasToken = String.Format(CultureInfo.InvariantCulture, "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}",
      HttpUtility.UrlEncode(resourceUri), HttpUtility.UrlEncode(signature), expiry, keyName);
      return sasToken;
}

private static string GetExpiry(TimeSpan ttl)
{
    TimeSpan expirySinceEpoch = DateTime.UtcNow - new DateTime(1970, 1, 1) + ttl;
    return Convert.ToString((int)expirySinceEpoch.TotalSeconds);
}
string queueUrl = "https://tomtestsb.servicebus.windows.net/" + "queue" + "/messages";
string token = GetSasToken(queueUrl,"Key", "value", TimeSpan.FromDays(1));

enter image description here
enter image description here

lunes, 5 de agosto de 2019

Check if file exists on FTP server in SSIS

https://blog.reckonedforce.com/ssis-check-if-file-exists-on-ftp-server/

https://www.youtube.com/watch?v=JQsR1pQOdq8

Check if file exists on FTP server in SSIS

SSIS ETL, Lectura MS Access


https://www.mssqltips.com/sqlservertip/2656/simple-step-by-step-process-to-import-ms-access-data-into-sql-server-using-ssis/


Getting Started

In this demonstration we are going to create a Table named Customer in MS Access and then import the table to SQL Server using SSIS.
  1. Let's start the MS Access. Go to the Windows Start Menu > All Programs > Microsoft Office and click Microsoft Access 2010 

    Iniciar MS Access
  2. In Microsoft Access 2010, click the Browse icon.
     
    Browse the file
  3. In the File New Database, specify the file name and the path. In this instance the file name will be customer.accdb and it will be stored in the c:\ drive and press OK. 
    New Database
  4. In Access, press the Create button. 
  5. In the second column double click in the header and type FirstName. 
  6. In second row enter a First Name.
     
    Create a table
  7. Add some more data to the table.
     
    Add data
  8. Press the Save icon and in the Save As Window, type Customer and press OK.
    Save as the table
  9. You have just created an Access Database named customer.accdb with a table named customer. Close MS Access. 
  10. Let's start the SQL Server Business Intelligence Development Studio to import the table into SQL Server. Go to the Windows Start > All Programs > Microsoft SQL Server 2008 R2> SQL Server Business Intelligence Development Studio.
     
    Open the Development Studio
  11. In the Business Intelligence Development Studio, select File > New > Project
     
    Open the new project
  12. In the New Project Window, select Integration Services Project and specify a name and location for the project.
     
    Create a SSIS project
  13. From the Toolbox, drag and drop a DataFlow Task to the Design pane. 
  14. In the design pane double click the DataFlow Task.
     
    Drag and drop the Datataflow
  15. In the Data Flow tab, drag and drop a OLEBD Source and Destination to the design pane.
     
    Data Flow tasks
  16. Click on the green arrow and drag it to join the OLEDB Source and Destination.
     
    Join the Data flow tasks
  17. In the OLE DB Source Editor window, press the New... button to create a new connection.
     
    OLE DB Source Editor
  18. In the Configure OLE DB Connection Manager, press New... again.
     
    Configure OLE DB Connection
  19. In the Provider combobox, select Native OLE DB\Microsoft Office 12.0 Access Database Engine OLE DB Provider. 
  20. In the Server or file name type the path of the Access database. In this example it is in the c:\Customers.accdb (verify the step 3 to review). 
  21. Check the Blank Password option and press OK.
     
    Add the connection manager data
  22. In the Configure OLE DB Connection Manager, press OK 
  23. In the OLE DB Source Editor, in the Name of the Table or view select the table created in Access (created in step 8).
     
    Add the OLEDB Source Editor data
  24. Double click the OLEDB Destination.
     
    Double click the OLE DB Destination
  25. In the OLE DB Destination Editor Window, in the OLE DB connection manager, press the New... button.
     
    OLE DB Destinatio properties
  26. In the Configure OLE DB Connection Manager, press New...
     
    Configure OLE DB Destination Connection
  27. In the Connection Manager make sure that the Provider combobox is using the Native OLE DB\SQL Server Native Client 10.0 
  28. In the Server name, type the SQL Server Name. 
  29. In the select or enter Database Name, select the SQL Server database where you want to store the Access data and press OK. You can choose any database. In this instance, a database named test is used.
     
    Destination Connection Manager Properties
  30. In the OLE DB Destination Editor Window, go to the Name of the table or View combobox and press the New... button.
     
    OLE DB Destination connection Editor
  31. In the Create Table, type this and press OK:
     
    CREATE TABLE [Customers](
    [ID] int,
    [FirstName] nvarchar(255)
    )
    

    Create destination table
  32. In the OLE DB Destination Editor Click on the Mappings page and press OK.
     
    Map the columns
  33. Now the project is ready to start importing the data from MS Access to SQL Server. Now, press the start debugging icon to start importing the data.
     
    Run the start debugging
  34. To verify that everything worked, open SQL Server Management Studio and verify the data is in the database used for the import. In this case, the test database was used (verify this from step 29). 
  35. Finally query the table to verify the data was successfully imported.
     
    Verify the imported data
  36. Congratulations! You have created an SSIS project to import data from MS Access to SQL Server.