-
Notifications
You must be signed in to change notification settings - Fork 22
/
CourseService.cs
829 lines (753 loc) · 40.4 KB
/
CourseService.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
/* Software License Agreement (BSD License)
*
* Copyright (c) 2010-2011, Rustici Software, LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Rustici Software, LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Web;
using System.Xml;
using System.Threading;
using System.IO;
namespace RusticiSoftware.HostedEngine.Client
{
/// <summary>
/// Client-side proxy for the "rustici.course.*" Hosted SCORM Engine web
/// service methods.
/// </summary>
public class CourseService
{
private Configuration configuration = null;
private ScormEngineService manager = null;
/// <summary>
/// Main constructor that provides necessary configuration information
/// </summary>
/// <param name="configuration">Application Configuration Data</param>
public CourseService(Configuration configuration, ScormEngineService manager)
{
this.configuration = configuration;
this.manager = manager;
}
/// <summary>
/// Import a SCORM .pif (zip file) from the local filesystem.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="absoluteFilePathToZip">Full path to the .zip file</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportCourse(string courseId, string absoluteFilePathToZip)
{
return ImportCourse(courseId, absoluteFilePathToZip, null);
}
/// <summary>
/// Import a SCORM .pif (zip file) from the local filesystem.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="absoluteFilePathToZip">Full path to the .zip file</param>
/// <param name="itemIdToImport">ID of manifest item to import</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportCourse(string courseId, string absoluteFilePathToZip, string itemIdToImport)
{
return ImportCourse(courseId, absoluteFilePathToZip, itemIdToImport, null);
}
/// <summary>
/// Import a SCORM .pif (zip file) from the local filesystem.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="absoluteFilePathToZip">Full path to the .zip file</param>
/// <param name="itemIdToImport">ID of manifest item to import. If null, root organization is imported</param>
/// <param name="permissionDomain">An permission domain to associate this course with,
/// for ftp access service (see ftp service below).
/// If the domain specified does not exist, the course will be placed in the default permission domain</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportCourse(string courseId, string absoluteFilePathToZip,
string itemIdToImport, string permissionDomain)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (!String.IsNullOrEmpty(itemIdToImport))
request.Parameters.Add("itemid", itemIdToImport);
if (!String.IsNullOrEmpty(itemIdToImport))
request.Parameters.Add("pd", permissionDomain);
request.FileToPost = absoluteFilePathToZip;
XmlDocument response = request.CallService("rustici.course.importCourse");
return ImportResult.ConvertToImportResults(response);
}
/// <summary>
/// Import a SCORM .pif (zip file) asynchronously from the local filesystem.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="absoluteFilePathToZip">Full path to the .zip file</param>
/// <param name="itemIdToImport">ID of manifest item to import. If null, root organization is imported</param>
/// <param name="permissionDomain">A permission domain to associate this course with,
/// for ftp access service (see ftp service below).
/// If the domain specified does not exist, the course will be placed in the default permission domain</param>
/// <returns>Token ID of Asynchronous Import</returns>
public String ImportCourseAsync(string courseId, string absoluteFilePathToZip,
string itemIdToImport, string permissionDomain)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (!String.IsNullOrEmpty(itemIdToImport))
request.Parameters.Add("itemid", itemIdToImport);
if (!String.IsNullOrEmpty(itemIdToImport))
request.Parameters.Add("pd", permissionDomain);
request.FileToPost = absoluteFilePathToZip;
XmlDocument response = request.CallService("rustici.course.importCourseAsync");
String tokenId = ((XmlElement)response
.GetElementsByTagName("token")[0])
.FirstChild.InnerText;
return tokenId;
}
/// <summary>
/// Get a URL to target a file import form for importing a course to the SCORM Cloud.
/// </summary>
/// <param name="courseId">the desired id for the course</param>
/// <param name="redirectUrl">the url for the browser to be redirected to after import</param>
/// <returns></returns>
public String GetImportCourseUrl(string courseId, string redirectUrl)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (!String.IsNullOrEmpty(redirectUrl))
request.Parameters.Add("redirecturl", redirectUrl);
return request.ConstructUrl("rustici.course.importCourse");
}
/// <summary>
/// Get a URL to target a file import form for importing a course to the SCORM Cloud asynchronously.
/// </summary>
/// <param name="courseId">the desired id for the course</param>
/// <param name="redirectUrl">the url for the browser to be redirected to after import</param>
/// <returns></returns>
public String GetImportCourseAsyncUrl(string courseId, string redirectUrl)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (!String.IsNullOrEmpty(redirectUrl))
request.Parameters.Add("redirecturl", redirectUrl);
return request.ConstructUrl("rustici.course.importCourseAsync");
}
/// <summary>
/// Import a SCORM .pif (zip file) from an existing .zip file on the
/// Hosted SCORM Engine server.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="location">The relative path (rooted at your specific appid's upload area)
/// where the zip file for importing can be found</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportUploadedCourse(string courseId, string location)
{
return ImportUploadedCourse(courseId, location, null, null);
}
/// <summary>
/// Import a SCORM .pif (zip file) from an existing .zip file on the
/// Hosted SCORM Engine server.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="path">The relative path (rooted at your specific appid's upload area)
/// where the zip file for importing can be found</param>
/// <param name="itemIdToImport">ID of manifest item to import</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportUploadedCourse(string courseId, string path, string itemIdToImport)
{
return ImportUploadedCourse(courseId, path, itemIdToImport, null);
}
/// <summary>
/// Import a SCORM .pif (zip file) from an existing .zip file on the
/// Hosted SCORM Engine server.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="path">The relative path (rooted at your specific appid's upload area)
/// where the zip file for importing can be found</param>
/// <param name="itemIdToImport">ID of manifest item to import</param>
/// <param name="permissionDomain">An permission domain to associate this course with,
/// for ftp access service (see ftp service below).
/// If the domain specified does not exist, the course will be placed in the default permission domain</param>
/// <param name="server">A specific server to perform the import on, typically this is only specified
/// by the server in an UploadResult, returned by UploadFile</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportUploadedCourse(string courseId, string path, string itemIdToImport, string permissionDomain)
{
return ImportUploadedCourse(courseId, path, itemIdToImport, permissionDomain, null, true);
}
/// <summary>
/// Import a SCORM .pif (zip file) from an existing .zip file on the
/// Hosted SCORM Engine server.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="path">The relative path (rooted at your specific appid's upload area)
/// where the zip file for importing can be found</param>
/// <param name="itemIdToImport">ID of manifest item to import</param>
/// <param name="permissionDomain">An permission domain to associate this course with,
/// for ftp access service (see ftp service below).
/// If the domain specified does not exist, the course will be placed in the default permission domain</param>
/// <param name="useAsync">Use async import</param>
/// <returns>List of Import Results</returns>
public List<ImportResult> ImportUploadedCourse(string courseId, string path, string itemIdToImport, string permissionDomain, string server, bool useAsync)
{
if (useAsync) {
String importToken = this.ImportUploadedCourseAsync(courseId, path, itemIdToImport, permissionDomain);
AsyncImportResult result;
while (true) {
Thread.Sleep(2000);
result = this.GetAsyncImportResult(importToken);
if (result.IsComplete())
break;
}
if (result.HasError()) {
throw new ServiceException(result.ErrorMessage);
}
else {
return result.ImportResults;
}
}
else {
ServiceRequest request = new ServiceRequest(configuration);
if (server != null) {
request.Server = server;
}
request.Parameters.Add("courseid", courseId);
request.Parameters.Add("path", path);
if (!String.IsNullOrEmpty(itemIdToImport))
request.Parameters.Add("itemid", itemIdToImport);
if (!String.IsNullOrEmpty(permissionDomain))
request.Parameters.Add("pd", permissionDomain);
XmlDocument response = request.CallService("rustici.course.importCourse");
return ImportResult.ConvertToImportResults(response);
}
}
public String ImportUploadedCourseAsync(string courseId, string path, string itemIdToImport, string permissionDomain)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
request.Parameters.Add("path", path);
if (!String.IsNullOrEmpty(itemIdToImport))
request.Parameters.Add("itemid", itemIdToImport);
if (!String.IsNullOrEmpty(permissionDomain))
request.Parameters.Add("pd", permissionDomain);
XmlDocument response = request.CallService("rustici.course.importCourseAsync");
String tokenId = ((XmlElement)response
.GetElementsByTagName("token")[0])
.FirstChild.InnerText;
return tokenId;
}
public AsyncImportResult GetAsyncImportResult(String tokenId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("token", tokenId);
XmlDocument response = request.CallService("rustici.course.getAsyncImportResult");
return new AsyncImportResult(response);
}
/// <summary>
/// Delete the specified course
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
public void DeleteCourse(string courseId)
{
DeleteCourse(courseId, false);
}
/// <summary>
/// Delete the specified course
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="deleteLatestVersionOnly">If false, all versions are deleted</param>
public void DeleteCourse(string courseId, bool deleteLatestVersionOnly)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (deleteLatestVersionOnly)
request.Parameters.Add("versionid", "latest");
request.CallService("rustici.course.deleteCourse");
}
/// <summary>
/// Delete the specified version of a course
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="versionId">Specific version of course to delete</param>
public void DeleteCourseVersion(string courseId, int versionId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
request.Parameters.Add("versionid", versionId);
request.CallService("rustici.course.deleteCourse");
}
/// <summary>
/// Retrieve a list of high-level data about all courses owned by the
/// configured appId that meet the filter's criteria.
/// </summary>
/// <param name="courseIdFilterRegex">Regular expresion to filter the courses by ID</param>
/// <returns>List of Course Data objects</returns>
public List<CourseData> GetCourseList(string courseIdFilterRegex)
{
ServiceRequest request = new ServiceRequest(configuration);
if (!String.IsNullOrEmpty(courseIdFilterRegex))
request.Parameters.Add("filter", courseIdFilterRegex);
XmlDocument response = request.CallService("rustici.course.getCourseList");
return CourseData.ConvertToCourseDataList(response);
}
/// <summary>
/// Retrieve a list of high-level data about all courses owned by the
/// configured appId.
/// </summary>
/// <returns>List of Course Data objects</returns>
public List<CourseData> GetCourseList()
{
ServiceRequest request = new ServiceRequest(configuration);
XmlDocument response = request.CallService("rustici.course.getCourseList");
return CourseData.ConvertToCourseDataList(response);
}
/// <summary>
/// Retrieve the course detail for a particular course
/// </summary>
/// <returns>CourseDetail object</returns>
public CourseDetail GetCourseDetail(string courseId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
XmlDocument response = request.CallService("rustici.course.getCourseDetail");
return new CourseDetail(response);
}
/// <summary>
/// Retrieve the list of course attributes associated with this course. If
/// multiple versions of the course exist, the attributes of the latest version
/// are returned.
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <returns>Dictionary of all attributes associated with this course</returns>
public Dictionary<string, string> GetAttributes(string courseId)
{
return GetAttributes(courseId, Int32.MinValue);
}
/// <summary>
/// Retrieve the list of course attributes associated with a specific version
/// of the specified course.
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="versionId">Specific version the specified course</param>
/// <returns>Dictionary of all attributes associated with this course</returns>
public Dictionary<string, string> GetAttributes(string courseId, int versionId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (versionId != Int32.MinValue)
request.Parameters.Add("versionid", versionId);
XmlDocument response = request.CallService("rustici.course.getAttributes");
// Map the response to a dictionary of name/value pairs
Dictionary<string, string> attributeDictionary = new Dictionary<string, string>();
foreach (XmlElement attrEl in response.GetElementsByTagName("attribute"))
{
attributeDictionary.Add(attrEl.Attributes["name"].Value, attrEl.Attributes["value"].Value);
}
return attributeDictionary;
}
/// <summary>
/// Update the specified attributes (name/value pairs)
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="versionId">Specific version the specified course</param>
/// <param name="attributePairs">Map of name/value pairs</param>
/// <returns>Dictionary of changed attributes</returns>
public Dictionary<string, string> UpdateAttributes(string courseId, int versionId,
Dictionary<string,string> attributePairs)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
foreach (string key in attributePairs.Keys)
{
if (!String.IsNullOrEmpty(attributePairs[key]))
{
request.Parameters.Add(key, attributePairs[key]);
}
}
XmlDocument response = request.CallService("rustici.course.updateAttributes");
// Map the response to a dictionary of name/value pairs. This list
// should contain only those values that have changed. If a param was
// specified who's value is the same as the current value, it will not
// be included in this list.
Dictionary<string, string> attributeDictionary = new Dictionary<string, string>();
foreach (XmlElement attrEl in response.GetElementsByTagName("attribute"))
{
attributeDictionary.Add(attrEl.Attributes["name"].Value, attrEl.Attributes["value"].Value);
}
return attributeDictionary;
}
/// <summary>
/// Update the specified attributes (name/value pairs) for the specified
/// course. If multiple versions of the course exist, only the latest
/// version's attributes will be updated.
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="attributePairs">Map of name/value pairs</param>
/// <returns>Dictionary of changed attributes</returns>
public Dictionary<string, string> UpdateAttributes(string courseId, Dictionary<string, string> attributePairs)
{
return UpdateAttributes(courseId, Int32.MinValue, attributePairs);
}
/// <summary>
/// Get the Course Metadata in XML Format
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="versionId">Version of the specified course</param>
/// <param name="scope">Defines the scope of the data to return: Course or Activity level</param>
/// <param name="format">Defines the amount of data to return: Summary or Detailed</param>
/// <returns>XML string representing the Metadata</returns>
public string GetMetadata(string courseId, int versionId, MetadataScope scope, MetadataFormat format)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
request.Parameters.Add("scope", Enum.GetName(scope.GetType(), scope).ToLower());
request.Parameters.Add("format", Enum.GetName(format.GetType(), format).ToLower());
XmlDocument response = request.CallService("rustici.course.getMetadata");
// Return the subset of the xml starting with the top <object>
return response.ChildNodes[1].InnerXml;
}
/// <summary>
/// Get the Course Metadata in XML Format.
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="scope">Defines the scope of the data to return: Course or Activity level</param>
/// <param name="format">Defines the amount of data to return: Summary or Detailed</param>
/// <returns>XML string representing the Metadata</returns>
public string GetMetadata(string courseId, MetadataScope scope, MetadataFormat format)
{
return GetMetadata(courseId, Int32.MinValue, scope, format);
}
/// <summary>
/// Update course files only. One or more course files can be updating them by
/// including them in a .zip file and sending updates via this method
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="versionId">Specific version of the course</param>
/// <param name="absoluteFilePathToZip">Full path to the .zip file</param>
public void UpdateAssets(string courseId, int versionId, string absoluteFilePathToZip)
{
UploadResult uploadResult = manager.UploadService.UploadFile(absoluteFilePathToZip, null);
String server = uploadResult.server;
String location = uploadResult.location;
try {
UpdateAssetsFromUploadedFile(courseId, versionId, location, server);
}
finally {
manager.UploadService.DeleteFile(location);
}
}
/// <summary>
/// Update course files only. One or more course files can be updating them by
/// including them in a .zip file and sending updates via this method. I
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <param name="absoluteFilePathToZip">Full path to the .zip file</param>
/// <remarks>If multiple versions of a course exist, only the latest version's assets will
/// be updated.</remarks>
public void UpdateAssets(string courseId, string absoluteFilePathToZip)
{
UpdateAssets(courseId, Int32.MinValue, absoluteFilePathToZip);
}
/// <summary>
/// Update course files only. One or more course files can be updating them by
/// including them in a .zip file and sending updates via this method. The
/// specified file should already exist in the upload domain space.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="versionId">Specific version of the course</param>
/// <param name="domain">Optional security domain for the file.</param>
/// <param name="fileName">Name of the file, including extension.</param>
public void UpdateAssetsFromUploadedFile(string courseId, int versionId, string path, string server)
{
ServiceRequest request = new ServiceRequest(configuration);
if (server != null) {
request.Server = server;
}
request.Parameters.Add("courseid", courseId);
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
request.Parameters.Add("path", path);
request.CallService("rustici.course.updateAssets");
}
/// <summary>
/// Update course files only. One or more course files can be updating them by
/// including them in a .zip file and sending updates via this method. The
/// specified file should already exist in the upload domain space.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="domain">Optional security domain for the file.</param>
/// <param name="fileName">Name of the file, including extension.</param>
/// <remarks>If multiple versions of a course exist, only the latest version's assets will
/// be updated.</remarks>
public void UpdateAssetsFromUploadedFile(string courseId, string path, string server)
{
UpdateAssetsFromUploadedFile(courseId, Int32.MinValue, path, server);
}
/// <summary>
/// Delete one or more files from the specified course directory
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="versionId">Version ID of the specified course</param>
/// <param name="relativeFilePaths">Path of each file to delete realtive to the course root</param>
/// <returns>Map of results as a Dictionary of booleans</returns>
public Dictionary<string, bool> DeleteFiles(string courseId, int versionId, Collection<string> relativeFilePaths)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
foreach (string fileName in relativeFilePaths)
{
request.Parameters.Add("path", fileName);
}
XmlDocument response = request.CallService("rustici.course.deleteFiles");
Dictionary<string, bool> resultsMap = new Dictionary<string, bool>();
foreach (XmlElement attrEl in response.GetElementsByTagName("result"))
{
resultsMap.Add(attrEl.Attributes["path"].Value,
Convert.ToBoolean(attrEl.Attributes["deleted"].Value));
}
return resultsMap;
}
/// <summary>
/// Delete one or more files from the specified course directory.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="relativeFilePaths">Path of each file to delete realtive to the course root</param>
/// <returns>Map of results as a Dictionary of booleans</returns>
/// <remarks>If multiple versions of a course exist, only files from the latest version
/// will be deleted.</remarks>
public Dictionary<string, bool> DeleteFiles(string courseId, Collection<string> relativeFilePaths)
{
return DeleteFiles(courseId, Int32.MinValue, relativeFilePaths);
}
/// <summary>
/// Get the file structure of the given course.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <param name="versionId">Version ID of the specified course</param>
/// <returns>XML String of the hierarchical file structure of the course</returns>
public string GetFileStructure(string courseId, int versionId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
XmlDocument response = request.CallService("rustici.course.getFileStructure");
// Return the subset of the xml starting with the top <dir>
return response.ChildNodes[1].InnerXml;
}
/// <summary>
/// Get the file structure of the given course.
/// </summary>
/// <param name="courseId">Unique Identifier for this course.</param>
/// <returns>XML String of the hierarchical file structure of the course</returns>
/// <remarks>If multiple versions of the course exist, the latest version's
/// files structure will be retured.</remarks>
public string GetFileStructure(string courseId)
{
return GetFileStructure(courseId, Int32.MinValue);
}
/// <summary>
/// Gets the url to view/edit the package properties for this course. Typically
/// used within an IFRAME
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <returns>Signed URL to package property editor</returns>
/// <param name="notificationFrameUrl">Tells the property editor to render a sub-iframe
/// with the provided url as the src. This can be used to simulate an "onload"
/// by using a notificationFrameUrl that's the same domain as the host system and
/// calling parent.parent.method()</param>
/// <param name="useLatestEditor">Whether or not to use the latest version of the
/// properties editor. We recommend setting this to true, as the new editor supports
/// more properties and is used directly on SCORM Cloud's site. Defaults to false
/// for backwards compatibility.</param>
public string GetPropertyEditorUrl(string courseId, string stylesheetUrl, string notificationFrameUrl, bool useLatestEditor = false)
{
// The local parameter map just contains method methodParameters. We'll
// now create a complete parameter map that contains the web-service
// params as well the actual method params.
IDictionary<string, object> parameterMap = new Dictionary<string, object>();
parameterMap.Add("action", "properties.view");
parameterMap.Add("package", "ApiCourseId|" + courseId);
parameterMap.Add("appid", configuration.AppId);
parameterMap.Add("ts", DateTime.UtcNow.ToString("yyyyMMddHHmmss"));
if (!String.IsNullOrEmpty(notificationFrameUrl))
parameterMap.Add("notificationframesrc", notificationFrameUrl);
if (!String.IsNullOrEmpty(stylesheetUrl))
parameterMap.Add("stylesheet", stylesheetUrl);
if (useLatestEditor)
parameterMap.Add("editor", "latest");
// Construct the url, concatonate all parameters as query string parameters
string url = configuration.ScormEngineServiceUrl + "/widget";
int cnt = 0;
foreach (string key in parameterMap.Keys)
{
// Create a query string with URL-encoded values
url += (cnt++ == 0 ? "?" : "&") + key + "=" + HttpUtility.UrlEncode(parameterMap[key].ToString());
}
url += "&sig=" + RequestSigner.GetSignatureForRequest(configuration.SecurityKey, parameterMap);
if (url.Length > 2000)
throw new ApplicationException("URL > 2000 bytes");
return url;
}
/// <summary>
/// Gets the url to view/edit the package properties for this course. Typically
/// used within an IFRAME
/// </summary>
/// <param name="courseId">Unique Identifier for the course</param>
/// <returns>Signed URL to package property editor</returns>
public string GetPropertyEditorUrl(string courseId)
{
return GetPropertyEditorUrl(courseId, null, null);
}
public string GetAssets(String toFileName, String courseId)
{
return GetAssets(toFileName, courseId, Int32.MinValue, null);
}
public string GetAssets(String toFileName, String courseId, List<String> paths)
{
return GetAssets(toFileName, courseId, Int32.MinValue, paths);
}
public string GetAssets(String toFileName, String courseId, int versionId, List<String> paths)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if(paths != null && paths.Count > 0){
foreach (String path in paths){
request.Parameters.Add("path", path);
}
}
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
//Return file path to downloaded file
return request.GetFileFromService(toFileName, "rustici.course.getAssets");
}
/// <summary>
/// Get the url that points directly to a course asset
/// </summary>
/// <param name="courseId">Unique Course Identifier</param>
/// <param name="path">Path to asset from root of course</param>
/// <param name="versionId">Specific Version</param>
/// <returns>HTTP Url to Asset</returns>
public String GetAssetUrl(String courseId, String path, int versionId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
request.Parameters.Add("path", path);
if (versionId != Int32.MinValue)
{
request.Parameters.Add("versionid", versionId);
}
return request.ConstructUrl("rustici.course.getAssets");
}
/// <summary>
/// Get the tags of a course
/// </summary>
/// <param name="courseId">Unique Course Identifier</param>
/// <returns>List of tags?</returns>
public String GetTags(String courseId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
request.Parameters.Add("appid ", configuration.AppId);
XmlDocument response = request.CallService("rustici.tagging.getCourseTags");
XmlDocument tagXML = new XmlDocument();
string tagXMLString = response.ChildNodes[1].InnerXml;
tagXML.LoadXml(tagXMLString);
string tagList = "";
for (var n = 0; n < tagXML.FirstChild.ChildNodes.Count; n++)
{
XmlNode nextTagNode = tagXML.FirstChild.ChildNodes[n];
if (n > 0) tagList += ",";
tagList += nextTagNode.InnerText;
}
return tagList;
}
/// <summary>
/// Get the url that points directly to a course asset
/// </summary>
/// <param name="courseId">Unique Course Identifier</param>
/// <param name="path">Path to asset from root of course</param>
/// <returns>HTTP Url to Asset</returns>
public String GetAssetUrl(String courseId, String path)
{
return GetAssetUrl(courseId, path, Int32.MinValue);
}
/// <summary>
/// Get the url that can be opened in a browser and used to preview this course, without
/// the need for a registration.
/// </summary>
/// <param name="courseId">Unique Course Identifier</param>
public String GetPreviewUrl(String courseId)
{
return GetPreviewUrl(courseId, null, null);
}
public String GetPreviewUrl(String courseId, String redirectOnExitUrl)
{
return GetPreviewUrl(courseId, redirectOnExitUrl, null);
}
/// <summary>
/// Get the url that can be opened in a browser and used to preview this course, without
/// the need for a registration.
/// </summary>
/// <param name="courseId">Unique Course Identifier</param>
/// <param name="versionId">Version Id</param>
public String GetPreviewUrl(String courseId, String redirectOnExitUrl, String cssUrl)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
if (!String.IsNullOrEmpty(redirectOnExitUrl))
request.Parameters.Add("redirecturl", redirectOnExitUrl);
if (!String.IsNullOrEmpty(cssUrl))
request.Parameters.Add("cssurl", cssUrl);
return request.ConstructUrl("rustici.course.preview");
}
/// <summary>
/// Returns a boolean of whether or not the a course with the given courseId exists in the associated
/// appId in the SCORM Cloud.
/// </summary>
/// <param name="courseId">Unique Course Identifier</param>
/// <returns></returns>
public bool Exists(String courseId)
{
ServiceRequest request = new ServiceRequest(configuration);
request.Parameters.Add("courseid", courseId);
XmlDocument response = request.CallService("rustici.course.exists");
return bool.Parse(response.DocumentElement.GetElementsByTagName("result").Item(0).InnerText);
}
}
}