how to Read data from Excel and put them in a dictionary? - testcomplete

I am using Testcomplete software and C# scripting.
I am able to read the data from the excel but I am not able to put them in a dictionary.So seeking help.

C#Script is based on the Microsoft JScript language (the same as JavaScript). Objects in this language behave in the same way as Dictionary objects and so you can use this functionality without any problems:
var dict = new Object();
dict["MyKey1"] = ["Obj1Val1", "Obj1Val2"];
dict["MyKey2"] = ["Obj2Val1", "Obj2Val2"];
dict["MyKey3"] = ["Obj3Val1", "Obj3Val2"];
Log.Message(dict["MyKey2"][1]);

Related

How to Implement a Session Variable on MS Bot Framework

I'm searching for guidance about how to implement a session-level variable on bot framework.
I've created a class to store global vars that is working fine.
However, these variables are persisted across all bot sessions which is not what I need now.
Thanks in advance,
I'm not sure of you are using the Node or the C# SDK. You can easily store data like this in the Databags provided by the SDK. UserData, ConversationData, and PrivateConversationData
For the purposes of just demonstrating how to use this i'm only going to use UserData but any databag could be used the same way
Node
For node, you would set values as if you were using a dictionary or hashmap in other languages:
You can use either dot notation or bracket notation:
session.userData.SomeProperty = "someValue";
session.userData["SomeProperty"] = "someValue"
And then to use the data later, again you can use either dot notation or bracket notation:
var foo = session.userData.SomeProperty;
var foo = session.userData["SomeProperty"]
C#
To set Data:
context.UserData.SetValue("SomeProperty", "SomeValue");
To get data:
context.UserData.GetValue<string>("SomeProperty");
In C# if you need to do this in a place you do not have access to the context object refer to this SO answer

OS X - JavaScript for Automation - How to create and store variable for future use

I am creating a small program that will help automate the initialization of a virtual environment and startup of a Django server. I would like to share this program with others.
I am looking for a way to create a variable (location of a folder) through the use of an open file browser and store that variable so that the user does not have to enter it in the future.
How can I store new information in my program for future use? I investigated the use of the plist file but cant find any documentation anywhere. Thanks for your help!
You can persistently store simple values in the user's preferences by using the NSUserDefaults class from Cocoa.
The following script asks the user to choose a folder location the first time it is run and then stores the chosen location in the user's defaults. When the script is run again, it returns the stored location without prompting the user. (Change the suiteName and locationKey values as appropriate for your script.)
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
var suiteName = "your.suite.name";
var locationKey = "your.prefs.key";
var $ud = $.NSUserDefaults.alloc.initWithSuiteName(suiteName);
var $location = $ud.stringForKey(locationKey);
var locationPath = $location.isNil() ? currentApp.chooseFolder() : Path($location.js);
$ud.setObjectForKey($(locationPath.toString()), locationKey);
locationPath
Note that you can also interact with the user's preferences using the defaults command-line tool, e.g.:
defaults read your.suite.name your.prefs.key
defaults delete your.suite.name your.prefs.key
I suggested using plist above, but I just ran across this great tool:
JSON Helper
It is a app that supports scripting. The examples are shown in AppleScript, but should be easily translated to JXA.
JSON Helper is an agent (or scriptable background application) which
allows you to do useful things with JSON (JavaScript Object Notation)
directly from AppleScript. JSON Helper has no interface, and runs in
the background waiting for AppleScripts [or JXA] to ask it to do something,
just like Apple's own System Events does.
JSON Helper contains a
number of commands that help you parse JSON into regular AppleScript
lists and records, and convert AppleScript list and records back into
valid JSON. In addition JSON Helper contains some convenience commands
to allow you to communicate easily with web based APIs.

Storing Excel templates in my Access database

What I want:
I am working with an MS Access database to produce a report for the Ontario Professional Engineering University Accreditation board. The PEO have their templates in MS Excel and I MUST use their exact format.
I want to output the data from the Access DB to the Excel sheet (easy enough), but I want to copy their formatting when producing a new file. (I do NOT want to keep an empty template file and copy it each time).
So essentially I'm looking to somehow store the template in code. (Other suggestions are welcome!)
What I've tried:
Some of you will read this and think i'm an idiot. But what i tried was to get the data from excel on the MS Clipboard through the API Code and store the DataObject as (i was hoping) some sort of string.
But i could not preserve the formatting or cell shading from the original MS Excel template.
Any suggestions?...
You could store the Excel template(s) within the database by creating a table that includes an Attachment field
creating a record and saving the Excel template as an attachment to that record
and then using VBA code like this to save a new copy of the Excel document to disk whenever you need one:
Option Compare Database
Option Explicit
Public Sub SaveReportTemplateToFile()
Dim cdb As DAO.Database, rowRst As DAO.Recordset, attachRst As DAO.Recordset2, attachField As DAO.Field2
Set cdb = CurrentDb
Set rowRst = cdb.OpenRecordset("SELECT TemplateFile FROM ReportTemplates WHERE ID=1")
Set attachRst = rowRst.Fields("TemplateFile").Value
Set attachField = attachRst.Fields("FileData")
attachField.SaveToFile "C:\Users\Gord\Desktop\" & attachRst.Fields("FileName").Value
Set attachField = Nothing
attachRst.Close
Set attachRst = Nothing
rowRst.Close
Set rowRst = Nothing
Set cdb = Nothing
End Sub
What you are going to have to do is first export all the data into a new sheet of an empty template, then link all the data to the correct place on the template and then remove the sheet with all the data, keeping the data on the template.
As far as I know there is no quicker way to do this, but here is an example: http://www.rogersaccesslibrary.com/forum/topic350.html
It will be quite a job, but doable, if the template is well setup.

How to retrieve data from SSAS Cube using EDMX?

I was given a cube with all relevant information. Now, I want to query cube and get the data through .net EDMX framework.
Could anyone help me out from where I should start on this? I am really confused and have no idea how to use MDX with edmx.
Is it possible to get the data from Cubes without using MDX using EDMX with LINQ?
It's not possible currently, there is a company who do a version of LinqToMdx, I think they've posted on here before, I don't think they go via the EDMX route exactly.
Standard method in .Net is ADOMD.Net http://msdn.microsoft.com/en-us/library/ms123477.aspx
A nice way of getting data is via the CellSet class, as it contains cells of both the native value and the formatted string for measures:
CellSet adomdCellSet;
using (var adomdConnection = new AdomdConnection())
{
adomdConnection.ConnectionString = "YourConnectionString";
adomdConnection.Open();
var adomdCommand = adomdConnection.CreateCommand();
adomdCommand.CommandText = "YourMDXQuery";
adomdCellSet = adomdCommand.ExecuteCellSet();
}
return adomdCellSet;
Edit: Found the site of the guys who wrote a provider - I can't vouch for them as I've never used it, but it looks interesting http://www.agiledesignllc.com/Products.htm

Programmatically list WMI classes and their properties

Is there any known way of listing the WMI classes and their properties available for a particular system? Im interested in a vbscript approach, but please suggest anything really :)
P.S. Great site.
I believe this is what you want.
WMI Code Creator
A part of this nifty utility allows you to browse namespaces/classes/properties on the local and remote PCs, not to mention generating WMI code in VBScript/C#/VB on the fly. Very useful.
Also, the source code used to create the utility is included in the download, which could provide a reference if you wanted to create your own browser like interface.
This MSDN page walks through enumerating the available classes: How to: List the Classes in a WMI Namespace
for retrieving properties from a class:
ManagementPath l_Path = new ManagementPath(l_className);
ManagementClass l_Class = new ManagementClass(myScope, l_ManagementPath, null);
foreach (PropertyData l_PropertyData in l_Class.Properties)
{
string l_type = l_PropertyData.Type.ToString());
int l_length = Convert.ToInt32(l_PropertyData.Qualifiers["maxlen"].Value);
}

Resources