Tuesday, May 30, 2017

Bootstrap for ASP 01

Start a new web site, asp.net empty website.

Create a new blank page, Bootstrap01.aspx

Add a reference to jquery:
tools, nuget, install jquery

Add a reference to Bootstrap using cdn:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Bootstrap01.aspx.cs" Inherits="Bootstrap01" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Bootstrap01</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>
<body>
    
    <form id="form1" runat="server">
    <div>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
    </div>
    </form>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>

Note that bootstrap requires jquery and both the .css and .js files to work properly.


d

Tuesday, May 2, 2017

JSON to C# dataset

The following will deserialize a Canvas json response into a dataset

using System;
using System.Data;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.Xml;

        private void temp2()
        {
            string pjson = System.IO.File.ReadAllText(@"c:\temp\json.txt");

            DataSet dsRecognize = new DataSet();
           
            XmlDocument xdRecognize = new XmlDocument();
            xdRecognize = (XmlDocument)JsonConvert.DeserializeXmlNode("{\"Row\":" + pjson + "}", "root");

            dsRecognize.ReadXml(new XmlNodeReader(xdRecognize));

            dataGridView1.DataSource = dsRecognize.Tables[0];

        }
**************************
Some notes:
c:\temp\json.txt is a copy of a json response. Remove the initial "while(1);" but keep the brackets "[]"

I sent the first table to a dataset, and it seemed to be good data.

Wednesday, December 16, 2015

SSL

So, I'm going to have to host my LMS Reports app locally on my home machine.
I have the webserver running IIS7, but I want both SSL and a trusted cert. So.
I've already registered my domain name (orcuttg.com) with GoDaddy

1. Setup SSL
SSL (https) runs on port 443. In IIS, for the reports website, choose "bindings"
Add https/ssl

TEST:
Now, if I go to https://www.orcuttg.com/default.aspx I get an encrypted connection, with no cert verification

2. Setup cert
I got my cert from rapidssl.com because it's cheap.
First, I need to start the server certificate request process. Go to IIS, and click Server Certificates.
PROBLEM: It may be the case that this option does not exist in IIS. In that case, go to start, run, and type MMC. Then File, Add/Remove Snap In, and add Certificates.
You may have to do this as administrator.
Now if you restart IIS you should have the server certificates option.

Second, open Server Certificates, and Create Certificate Request.
Common Name is www.orcuttg.com
All else is organization name, etc.
It will end with you saving a text file with your part of the shared certificate. Save it to you hard drive.

Third, back at the rapidssl site, it will ask you to upload the text from this file.

Fourth, you will be sent a confirmation email, and if you approve RapidSSL will send you their part of the cert. Save it as server.cer.
Copy ONLY the first block, not the intermediate certs.

Fifth, go back to IIS, and in server certificates click "Complete certificate request"
You will upload the server.cer file and give it the friendly name of your domain.

Lastly, associate the https binding with the certificate. Back at the settings for the IIS website, under bindings, the https, click Edit, and associate your certificate with this website.

Now you should have an https site that gives no errors to the end user.

Tuesday, May 12, 2015

Crystal Reports Show Value in Bar Chart

How to show a value in a bar chart in Crystal Reports, not a count.

The data source looks like this:
TermID Count Of Events

589
2148 402
2151 8238
2152 542
ldap_orgs 3
ms_rtr 6

By default, in Crystal Reports the report comes out looking like this.

We want it to look like this:
The solution:
1. Right click on the report. Choose report, formula workshop
2. Choose Formula Fields, and the add new button. Name the formula "ValueNum"
3. For ValueNum, assign the value "tonumber({Subreport.CountOfUserID})"
4. Save and close
5. Go back to Chart Expert, and on the Data tab, show value(s), add the new field "ValueNum", and check Don't Summarize.
The report will display as you wanted it to.

d

Tuesday, May 5, 2015

C-sharp console reports application

Description:
A C# console (needs no human intervention) application to do the following:
1. Order three reports from the Canvas LMS via Restful API. Wait for them to generate.
2. Download the three reports as CSV files.
3. Connect to the CSV as if it were a three-table database, and run a query to generate a single data-table for the final report:
select distinct table1.canvas_course_id,  table1.short_name,  table1.long_name,  table1.term_id
from (SELECT provisioning.canvas_course_id, provisioning.short_name, provisioning.long_name, provisioning.term_id, unused.[short name] FROM [provisioning.csv] as provisioning LEFT JOIN [unused.csv] as unused on unused.[short name] = provisioning.short_name where unused.[short name] is null) AS table1,
(SELECT provisioning.canvas_course_id, provisioning.short_name, provisioning.long_name, provisioning.term_id, unpub.[short name] FROM [provisioning.csv] as provisioning LEFT JOIN [unpublished.csv] as unpub on unpub.[short name] = provisioning.short_name where unpub.[short name] is null) AS table2
where table1.short_name = table2.short_name order by table1.short_name;

The query is left-joined, to capture rows in table 1 (provisioning.csv) that do NOT have corresponding rows in the other two tables (unpublished.csv, unused.csv)
4. Connect the above datatable to a CrystalReports .rpt object to generate a human-readable report in PDF format
5. Upload the PDF to a course in the LMS made to hold these weekly reports. The upload is to an AWS server, using the Amazon API.
6. Delete the csv and pdf files.

The source code is visible here (permission may be required). View an instance of this report (publicly visible)

The compiled application will run from any windows machine; I'm running it weekly via the Win7 Task Scheduler.

Monday, April 6, 2015

Canvas List All Available Reports via API

Using Postman (see earlier in this blog)

GET
https://uth.instructure.com/api/v1/accounts/1/reports
HEADER:
Name: Authorization
Value: Bearer 1350~MF9c2npiG...(token)

This will give you all available reports, including (for those that have been run) url's where each can be downloaded.
See: https://canvas.instructure.com/doc/api/account_reports.html

Send token as header via ssl, not as a URL parameter. The latter works, but is much less secure.

Canvas API First attempt

Access the canvas API using Postman

This command will create a new user in Canvas using the API

1. Install Postman app in Chrome (https://chrome.google.com/webstore/category/apps, find Postman REST Client)

2. Generate access token in Canvas (Settings, Approved Integrations, New Access Token). Save the text-generated access token
3. In Postman, create the following POST request:

Some notes on this:
  • The URL has two parts: the API call ("https://uth.test.instructure.com/api/v1/accounts/self/users") and the access token, authorizing the API call ("?access_token=1350~pGr2UxliAgQocy...")
  • The URL API call format is documented at https://canvas.instructure.com/doc/api/users.html, in the section "Create a user"
  • The value after "accounts" can be either "self" (as above) or the numeric value of any account; it doesn't seem to matter. But it MUST be the value of an existing account; a random number here will not work.