-
Notifications
You must be signed in to change notification settings - Fork 1
/
SASCopyColumnsTask.cs
175 lines (150 loc) · 5.9 KB
/
SASCopyColumnsTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copy Columns task
* Copyright 2015 SAS Institute
* Support: Chris Hemedinger
* http://blogs.sas.com/sasdummy
* Purpose:
To copy the column names from a data set so that you can paste the names into another
document: such as a SAS program or Excel spreadsheet.
There are three versions of the task; each version copies the column names in a slightly
different way.
1. Copy Column Names (new lines) - copies the names as a list with each column name on
a separate line.
2. Copy Column Names (comma list) - copies the names as a comma-separated list, all
on a single line
3. Copy Column Names (new lines with commas) - copies the names as a list with
each column name on a separate line, with a comma between each name
*/
using System;
using System.Text;
using SAS.Shared.AddIns;
using SAS.Tasks.Toolkit;
namespace SASCopyColumns
{
// unique identifier for this task
[ClassId("20bae62e-8f75-4a31-8ec2-c4f1fb422a90")]
// location of the task icon to show in the menu and process flow
[IconLocation("SASCopyColumns.task.ico")]
[InputRequired(InputResourceType.Data)]
public class SASCopyColumnsTask : SAS.Tasks.Toolkit.SasTask
{
#region Initialization
public SASCopyColumnsTask()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.TaskCategory = "Data Utilities";
this.TaskDescription = "Copy the column names from the active data set";
this.TaskName = "Copy Column Names (comma list)";
}
#endregion
#region overrides
/// <summary>
/// Show the task user interface
/// </summary>
/// <param name="Owner"></param>
/// <returns>whether to cancel the task, or run now</returns>
public override ShowResult Show(System.Windows.Forms.IWin32Window Owner)
{
ISASTaskData2 ds = this.Consumer.InputData[0] as ISASTaskData2;
string[] listColNames;
if (ds.Accessor.Open())
{
ds.Accessor.ColumnNames(out listColNames);
for (int i = 0; i < listColNames.Length; i++)
listColNames[i] = SAS.Tasks.Toolkit.Helpers.UtilityFunctions.SASValidLiteral(listColNames[i]);
ds.Accessor.Close();
string list = string.Join(", ", listColNames);
System.Windows.Forms.Clipboard.SetText(list);
}
return ShowResult.Canceled;
}
#endregion
}
// unique identifier for this task
[ClassId("56F932CB-DA4C-4E4E-9BF0-95BE41911BEF")]
// location of the task icon to show in the menu and process flow
[IconLocation("SASCopyColumns.task.ico")]
[InputRequired(InputResourceType.Data)]
public class SASCopyColumnsTaskList : SAS.Tasks.Toolkit.SasTask
{
#region Initialization
public SASCopyColumnsTaskList()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.TaskCategory = "Data Utilities";
this.TaskDescription = "Copy the column names from the active data set";
this.TaskName = "Copy Column Names (new lines)";
}
#endregion
#region overrides
/// <summary>
/// Show the task user interface
/// </summary>
/// <param name="Owner"></param>
/// <returns>whether to cancel the task, or run now</returns>
public override ShowResult Show(System.Windows.Forms.IWin32Window Owner)
{
ISASTaskData2 ds = this.Consumer.InputData[0] as ISASTaskData2;
string[] listColNames;
if (ds.Accessor.Open())
{
ds.Accessor.ColumnNames(out listColNames);
for (int i = 0; i < listColNames.Length; i++)
listColNames[i] = SAS.Tasks.Toolkit.Helpers.UtilityFunctions.SASValidLiteral(listColNames[i]);
ds.Accessor.Close();
string list = string.Join("\n", listColNames);
System.Windows.Forms.Clipboard.SetText(list);
}
return ShowResult.Canceled;
}
#endregion
}
// unique identifier for this task
[ClassId("6FE149A5-31AC-46ED-88F8-6D5B953804FB")]
// location of the task icon to show in the menu and process flow
[IconLocation("SASCopyColumns.task.ico")]
[InputRequired(InputResourceType.Data)]
public class SASCopyColumnsTaskListCommas : SAS.Tasks.Toolkit.SasTask
{
#region Initialization
public SASCopyColumnsTaskListCommas()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.TaskCategory = "Data Utilities";
this.TaskDescription = "Copy the column names from the active data set";
this.TaskName = "Copy Column Names (new lines with commas)";
}
#endregion
#region overrides
/// <summary>
/// Show the task user interface
/// </summary>
/// <param name="Owner"></param>
/// <returns>whether to cancel the task, or run now</returns>
public override ShowResult Show(System.Windows.Forms.IWin32Window Owner)
{
ISASTaskData2 ds = this.Consumer.InputData[0] as ISASTaskData2;
string[] listColNames;
if (ds.Accessor.Open())
{
ds.Accessor.ColumnNames(out listColNames);
for (int i = 0; i < listColNames.Length; i++ )
listColNames[i] = SAS.Tasks.Toolkit.Helpers.UtilityFunctions.SASValidLiteral(listColNames[i]);
ds.Accessor.Close();
string list = string.Join("\n, ", listColNames);
System.Windows.Forms.Clipboard.SetText(list);
}
return ShowResult.Canceled;
}
#endregion
}
}