Consume Volusion eStore API Using Meteor JS

The \server\main.js in this example performs an API call to your Volusion eStore, converts the response to JSON and inserts to MongoDB.

The \client\main.js makes the call and displays the data from MongoDB.

meteor create volusionapi

cd volusionapi

meteor add http peerlibrary:xml2js

Copy these files https://github.com/cjfleischhacker/MeteorVolusionAPI.git or create these files:

\client\main.html

<head>
<title>volusion</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> vapi}}
</body>
<template name="vapi">
<h3>List Courses</h3>
<p style="color: #ff0000; margin: 10px 0 10px 0;">
{{errMessage}}
</p>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Code</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each courses}}
<tr>
<td>{{ProductID}}</td>
<td>{{ProductCode}}</td>
<td>{{ProductName}}</td>
</tr>
{{/each}}
</tbody>
</table>
</template>

\client\main.js

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
Courses = new Mongo.Collection('courses');

Meteor.call(‘getJSONFromAPI’, function (err, res) {
if (err) {
console.log(err);
} else {
console.log(res.xmldata.Products);
}
});

Template.vapi.onCreated(function helloOnCreated() {
console.log(‘oncreate…’);
});

Template.vapi.helpers({
courses: function () {
return Courses.find();
}
});

\server\main.js

import { Meteor } from 'meteor/meteor';
import { xml2js } from 'meteor/peerlibrary:xml2js';
Courses = new Mongo.Collection('courses');

Meteor.methods({
‘getJSONFromAPI’: function () {
this.unblock();
var apiUrl = ‘http://store.volusion.com/net/WebService.aspx?Login=email@mystore.com&EncryptedPassword=YourVolusionAPIEncryptedPassword&EDI_Name=Generic\\Products&SELECT_Columns=p.ProductCode,p.ProductName,pd.ProductDescription’

;
var response = Meteor.wrapAsync(apiCall)(apiUrl);
const result = xml2js.parseStringSync(response, { explicitArray: false, emptyTag: undefined });
for (var i = 0; i < result.xmldata.Products.length; i++) {
Courses.insert(result.xmldata.Products[i]);
}
return result;
}
});

var apiCall = function (apiUrl, callback) {
// try…catch allows you to handle errors
try {
var response = HTTP.get(apiUrl).content;
// A successful API call returns no error
callback(null, response);
} catch (error) {
// If the API responded with an error message and a payload
if (error.response) {
var errorCode = error.response.data.code;
var errorMessage = error.response.data.message;
// Otherwise use a generic error message
} else {
var errorCode = 500;
var errorMessage = ‘Cannot access the API’;
}
// Create an Error object and return it via callback
var myError = new Meteor.Error(errorCode, errorMessage);
callback(myError, null);
}
}

meteor

Advertisements

C# ASP.Net MVC API Web App Using Advanced DB Master as a Data Source

Been wondering how to build a C#, ASP.Net, MVC, API web app using ADBM (Advanced DB Master) data source on the back end?  You’re welcome.

Demo source on GitHub.

Install Advanced DB Master (ADBM) from http://maconsys.com then open the Sample database, ADBMSamp, and exit ADBM.

ADBM added a System DSN ODBC datasource called adbmsamp to your OS.

SystemDSN.PNG

In Visual Studio, create a C# ASP.Net Framework or Core Web Application.

VisualStudioProject.PNG

And select Web API, leaving the MVC and Web API boxes checked.

WebAPI.PNG

Optionally, you can add the data source as a database connection and work with it that way if you prefer, but that’s not necessary.

DatabaseConnection.PNG

For our needs we’ll just need a connection string in the web.config:

<connectionStrings>
<add name=”csADBMSamp” connectionString=”DSN=adbmsamp” />
</connectionStrings>

IIS 7 Application Pool Stops – HipIISEngineStub.dll failed to load.

Happened in conjunction with a McAfee update on a web server.

IIS 7 Application Pool stops for any web application on an IIS 7 web server.

Error 503 Service Unavailable.

Event log error is:

“HipIISEngineStub.dll failed to load. The data is the error.”

Edit the IIS 7.0 applicationHost.config file and remove the following configuration lines:

  1. Edit %windir%\system32\inetsrv\config\applicationHost.config as Administrator.
  2. In the <globalModules> section, remove the following line:
    <add name=”MfeEngine” image=”%windir%\System32\inetsrv\HipIISEngineStub.dll” />
  3. In the <modules> section, remove the following line:
    <add name=”MfeEngine” />
  4. Save the file, then restart IIS.

SharePoint Server 2010 Configure People Picker

When the People Picker control is used, a user’s name is resolved when the Check Name icon is clicked or a list of users is displayed when the Browse icon is clicked.

If the Web application is using Windows authentication and the site user directory path is not set, the People Picker control searches the entire Active Directory to resolve users’ names or find users, instead of searching only users within a particular organizational unit (OU). The setsiteuseraccountdirectorypath operation allows the user’s directory path to be set to a specific OU in the same domain. After the directory path is set to a site collection, the People Picker control will only search under that particular OU.

If a site collection is new and an administrator uses the setsiteuseraccountdirectorypath operation to specify a target OU, only users under the specified path can be added to the site collection and no one else can be added to the site collection.

If users have already been added to a site collection and the setsiteuseraccountdirectorypath operation is run, only users under the specified path will be able to be added going forward.

To set a list of users to a specific OU (for example, Sales) in the Contoso Corp domain, use the following syntax:

stsadm -o setsiteuseraccountdirectorypath -path “CN=Sales,DC=ContosoCorp,DC=local” –url http://server_name

http://technet.microsoft.com/en-us/library/cc263328(office.12).aspx

http://technet.microsoft.com/en-us/library/gg602075(v=office.14).aspx#section5

 

Thrice Nested Repeater for Tests, Questions and Answers

Default.aspx

            <asp:Repeater runat="server" ID="rTests">
                <ItemTemplate>
                    <h3>Test: <%# DataBinder.Eval(Container.DataItem, "Name") %>, Passing Score = <%# DataBinder.Eval(Container.DataItem,"Passing_Score") %></h3>
                    <asp:Repeater ID="rQuestions" runat="server" DataSource='<%# GetChildRelation(Container.DataItem, "Test_Question")%>'>
                        <ItemTemplate>
                            <h4>Question:<%#DataBinder.Eval(Container.DataItem, "Text")%></h4>
                            <asp:Repeater ID="rAnswers" runat="server" DataSource='<%# GetChildRelation(Container.DataItem, "Question_Answer")%>'>
                                <ItemTemplate>
                                   Answer: <b><%# DataBinder.Eval(Container.DataItem, "Text") %></b> <%# DataBinder.Eval(Container.DataItem, "correct") %><br />
                                </ItemTemplate>
                            </asp:Repeater>
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:Repeater>

If you are having problems with button events not firing, make sure to EnableViewState.
Default.aspx.cs


    private void BindrTests()
    {
        rTests.DataSource = GetTestQuestionsAndAnswers();
        rTests.DataBind();
    }

    protected DataView GetChildRelation(object dataItem, string relation)
    {
        DataRowView drv = dataItem as DataRowView;
        if (drv != null)
            return drv.CreateChildView(relation);
        else
            return null;
    }

    public static DataSet GetTestQuestionsAndAnswers()
    {
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["Training"].ToString();
            string strSql = "SELECT Tests.Ident, Tests.Name, Tests.Passing_Score FROM [Training].[dbo].Tests; " +
	                        "SELECT Test_Questions.Ident, Test_Questions.Test_Ident, Test_Questions.text FROM [Training].[dbo].Test_Questions; " +
                    		"SELECT Test_Answers.Ident, Test_Answers.Question_Ident, Test_Answers.text, Test_Answers.correct FROM [Training].[dbo].Test_Answers";
            SqlConnection conn = new SqlConnection(strConn);
            SqlDataAdapter da = new SqlDataAdapter(strSql, conn);
            da.TableMappings.Add("Tests1", "Test_Questions");
            da.TableMappings.Add("Tests2", "Test_Answers");
            DataSet dsQandA = new DataSet();
            da.Fill(dsQandA, "Tests");
            dsQandA.Relations.Add("Test_Question", dsQandA.Tables["Tests"].Columns["Ident"], dsQandA.Tables["Test_Questions"].Columns["Test_Ident"]);
            dsQandA.Relations[0].Nested = true;
            dsQandA.Relations.Add("Question_Answer", dsQandA.Tables["Test_Questions"].Columns["Ident"], dsQandA.Tables["Test_Answers"].Columns["Question_Ident"]);
            dsQandA.Relations[1].Nested = true;
            return dsQandA;
    }

ASP.Net C# Format Javascript Delete Confirmation Alert Containing Apostrophes

How to format a javascript delete confirmation alert with text containing apostrophes.

ASP.Net Button with OnClientClick

<asp:Button ID="Delete" runat="server" Text="Delete" OnClick="Delete_Function" OnClientClick='<%# FormatDeleteAlert() %>' CssClass="buttonText" />

Javascript Alert Function

protected string FormatDeleteAlert()
{
  string lineitem = "";
  lineitem = Eval("ItemName").ToString().Replace("'", "\\'");
  StringBuilder sConfirm = new StringBuilder();
  sConfirm.Append("return confirm('Are you sure you want to delete " + lineitem + "?');");
  return sConfirm.ToString();
}