-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServerCoreUIService.cs
1394 lines (1351 loc) · 55.9 KB
/
ServerCoreUIService.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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region license
/*
Copyright 2005 - 2021 Advantage Solutions, s. r. o.
This file is part of ORIGAM (http://www.origam.org).
ORIGAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ORIGAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using CSharpFunctionalExtensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Origam.DA;
using Origam.Gui;
using Origam.OrigamEngine.ModelXmlBuilders;
using Origam.Rule;
using Origam.Schema.GuiModel;
using Origam.Schema.LookupModel;
using Origam.Server;
using Origam.Workbench.Services;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MoreLinq;
using Origam.Extensions;
using Origam.Rule.Xslt;
using Origam.Schema;
using Origam.Schema.EntityModel;
using Origam.Schema.MenuModel;
using Origam.Schema.WorkflowModel;
using Origam.Server.Controller;
using Origam.Server.Model.UIService;
using Origam.Service.Core;
using core = Origam.Workbench.Services.CoreServices;
namespace Origam.Server
{
// ReSharper disable once InconsistentNaming
public class ServerCoreUIService : IBasicUIService
{
private const int INITIAL_PAGE_NUMBER_OF_RECORDS = 50;
// ReSharper disable once InconsistentNaming
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private readonly UIManager uiManager;
private readonly SessionManager sessionManager;
private readonly SessionHelper sessionHelper;
private readonly IReportManager reportManager;
public ServerCoreUIService(
UIManager uiManager, SessionManager sessionManager)
{
this.uiManager = uiManager;
this.sessionManager = sessionManager;
sessionHelper = new SessionHelper(sessionManager);
reportManager = new ServerCoreReportManager(sessionManager);
}
public string GetReportStandalone(
string reportId,
Hashtable parameters,
DataReportExportFormatType dataReportExportFormatType)
{
return reportManager.GetReportStandalone(
reportId, parameters, dataReportExportFormatType);
}
public UIResult InitUI(UIRequest request)
{
return uiManager.InitUI(
request: request,
addChildSession: false,
parentSession: null,
basicUIService: this);
}
public PortalResult InitPortal(int maxRequestLength)
{
OrigamUserContext.Reset();
var profile = SecurityTools.CurrentUserProfile();
var result = new PortalResult(MenuXmlBuilder.GetMenu());
var settings = ConfigurationManager.GetActiveConfiguration();
if(settings != null)
{
result.WorkQueueListRefreshInterval
= settings.WorkQueueListRefreshPeriod * 1000;
result.Slogan = settings.Slogan;
result.HelpUrl = settings.HelpUrl;
}
result.MaxRequestLength = maxRequestLength;
var logoNotificationBox = LogoNotificationBox();
if(logoNotificationBox != null)
{
result.NotificationBoxRefreshInterval
= logoNotificationBox.RefreshInterval * 1000;
}
// load favorites
var favorites = core.DataService.Instance.LoadData(
dataStructureId: new Guid("e564c554-ca83-47eb-980d-95b4faba8fb8"),
methodId: new Guid("e468076e-a641-4b7d-b9b4-7d80ff312b1c"),
defaultSetId: Guid.Empty,
sortSetId: Guid.Empty,
transactionId: null,
paramName1: "OrigamFavoritesUserConfig_parBusinessPartnerId",
paramValue1: profile.Id);
if(favorites.Tables["OrigamFavoritesUserConfig"].Rows.Count > 0)
{
result.Favorites = (string)favorites
.Tables["OrigamFavoritesUserConfig"].Rows[0]["ConfigXml"];
}
sessionManager.AddOrUpdatePortalSession(
id: profile.Id,
addSession: id => new PortalSessionStore(profile.Id),
updateSession: (storeId, portalSessionStore) =>
{
var clearAll = portalSessionStore.ShouldBeCleared();
// running session, we get all the form sessions
var sessionsToDestroy = new ArrayList();
foreach(var mainSessionStore in portalSessionStore.FormSessions)
{
if(clearAll)
{
sessionsToDestroy.Add(mainSessionStore.Id);
}
else if(sessionManager.HasFormSession(mainSessionStore.Id))
{
var sessionStore = mainSessionStore.ActiveSession
?? mainSessionStore;
if((sessionStore is SelectionDialogSessionStore)
|| sessionStore.IsModalDialog)
{
sessionsToDestroy.Add(sessionStore.Id);
}
else
{
var askWorkflowClose = false;
if(sessionStore
is WorkflowSessionStore workflowSessionStore)
{
askWorkflowClose
= workflowSessionStore.AskWorkflowClose;
}
var hasChanges = HasChanges(sessionStore);
result.Sessions.Add(
new PortalResultSession(
sessionStore.Id,
sessionStore.Request.ObjectId,
hasChanges,
sessionStore.Request.Type,
sessionStore.Request.Caption,
sessionStore.Request.Icon,
askWorkflowClose));
}
}
else
{
// session is registered in the user's portal,
// but not in the UIService anymore,
// we have to destroy it
sessionsToDestroy.Add(mainSessionStore.Id);
}
}
foreach(Guid id in sessionsToDestroy)
{
try
{
DestroyUI(id);
}
catch(Exception ex)
{
if(log.IsFatalEnabled)
{
log.LogOrigamError(
"Failed to destroy session " + id.ToString()
+ ".", ex);
}
}
}
if(clearAll)
{
portalSessionStore.ResetSessionStart();
}
return portalSessionStore;
});
result.UserName = profile.FullName;
result.UserId = profile.Id;
result.Tooltip = ToolTipTools.NextTooltip();
result.Title = ConfigurationManager.GetActiveConfiguration().TitleText;
result.InitialScreenId = GetInitialScreenId();
CreateUpdateOrigamOnlineUser();
return result;
}
private static string GetInitialScreenId()
{
MenuSchemaItemProvider menuProvider = ServiceManager.Services
.GetService<SchemaService>()
.GetProvider<MenuSchemaItemProvider>();
return menuProvider.ChildItemsRecursive
.OfType<AbstractMenuItem>()
.Where(x =>
x is ReportReferenceMenuItem || x is FormReferenceMenuItem)
.FirstOrDefault(FormTools.IsFormMenuInitialScreen)
?.Id.ToString();
}
public void Logout()
{
PortalSessionStore pss;
try
{
pss = sessionManager.GetPortalSession();
}
catch(SessionExpiredException)
{
return;
}
if(pss == null)
{
return;
}
while(pss.FormSessions.Count > 0)
{
DestroyUI(pss.FormSessions[0].Id);
}
Analytics.Instance.Log("UI_LOGOUT");
sessionManager.RemovePortalSession(SecurityTools.CurrentUserProfile().Id);
Task.Run(() => SecurityTools.RemoveOrigamOnlineUser(
SecurityManager.CurrentPrincipal.Identity.Name));
OrigamUserContext.Reset();
}
// ReSharper disable once InconsistentNaming
public void DestroyUI(Guid sessionFormIdentifier)
{
sessionHelper.DeleteSession(sessionFormIdentifier);
CreateUpdateOrigamOnlineUser();
}
public IDictionary<string, object> RefreshData(
Guid sessionFormIdentifier,
IStringLocalizer<SharedResources> localizer)
{
var sessionStore = sessionManager.GetSession(sessionFormIdentifier);
var result = sessionStore.ExecuteAction(
SessionStore.ACTION_REFRESH);
CreateUpdateOrigamOnlineUser();
if(!(result is DataSet))
{
throw new Exception(localizer["ErrorRefreshReturnInvalid",
sessionStore.GetType().Name, SessionStore.ACTION_REFRESH]);
}
IList<string> columns = null;
if(sessionStore.IsPagedLoading)
{
// for lazily-loaded data we provide all the preloaded columns
// (primary keys + all the initial sort columns)
columns = sessionStore.DataListLoadedColumns;
}
return DataTools.DatasetToHashtable(result as DataSet, columns,
INITIAL_PAGE_NUMBER_OF_RECORDS, sessionStore.CurrentRecordId,
sessionStore.DataListEntity, sessionStore);
}
public IList RestoreData(RestoreDataInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
return sessionStore.RestoreData(input.ObjectId);
}
public RuleExceptionDataCollection SaveDataQuery(
Guid sessionFormIdentifier)
{
var sessionStore = sessionManager.GetSession(sessionFormIdentifier);
if (sessionStore.Data.HasErrors)
{
throw new RuleException(Origam.Server.Resources.ErrorInForm);
}
if((sessionStore.ConfirmationRule == null) ||
!sessionStore.Data.HasChanges())
{
return new RuleExceptionDataCollection();
}
var hasRows = false;
var clone = DatasetTools.CloneDataSet(sessionStore.Data);
var rootTables = sessionStore.Data.Tables
.Cast<DataTable>()
.Where(table => table.ParentRelations.Count == 0).ToList();
foreach(var rootTable in rootTables)
{
foreach(DataRow row in rootTable.Rows)
{
if((row.RowState == DataRowState.Deleted) ||
!IsRowDirty(row))
{
continue;
}
DatasetTools.GetDataSlice(
clone, new List<DataRow>{row});
hasRows = true;
}
}
if(!hasRows)
{
return new RuleExceptionDataCollection();
}
var xmlDoc = DataDocumentFactory.New(clone);
return sessionStore.RuleEngine.EvaluateEndRule(
sessionStore.ConfirmationRule, xmlDoc);
}
public IList SaveData(Guid sessionFormIdentifier)
{
var sessionStore = sessionManager.GetSession(sessionFormIdentifier);
var output = (IList)sessionStore.ExecuteAction(
SessionStore.ACTION_SAVE);
CreateUpdateOrigamOnlineUser();
return output;
}
public IList CreateObject(CreateObjectInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
// todo: propagate requesting grid as guid?
IList output = sessionStore.CreateObject(
input.Entity, input.Values, input.Parameters,
input.RequestingGridId.ToString());
CreateUpdateOrigamOnlineUser();
return output;
}
public IList CopyObject(CopyObjectInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
IList output = sessionStore.CopyObject(
input.Entity, input.OriginalId,
input.RequestingGridId.ToString(), input.Entities,
input.ForcedValues);
CreateUpdateOrigamOnlineUser();
return output;
}
public IList UpdateObject(UpdateObjectInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
IList output = sessionStore.UpdateObjectBatch(
input.Entity, input.UpdateData);
CreateUpdateOrigamOnlineUser();
return output;
}
public IList DeleteObject(DeleteObjectInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
IList output = sessionStore.DeleteObject(input.Entity, input.Id);
CreateUpdateOrigamOnlineUser();
return output;
}
public IList DeleteObjectInOrderedList(DeleteObjectInOrderedListInput input)
{
SessionStore ss = sessionManager.GetSession(new Guid(input.SessionFormIdentifier));
ArrayList changes = ss.UpdateObjectBatch(input.Entity, input.OrderProperty, input.UpdatedOrderValues);
changes.AddRange(ss.DeleteObject(input.Entity, input.Id));
Task.Run(() => SecurityTools.CreateUpdateOrigamOnlineUser(
SecurityManager.CurrentPrincipal.Identity.Name,
sessionManager.GetSessionStats()));
return changes;
}
public ArrayList GetRowData(MasterRecordInput input)
{
SessionStore sessionStore = GetSessionStore(input.SessionFormIdentifier);
if(sessionStore == null)
{
return new ArrayList();
}
return sessionStore.GetRowData(
input.Entity, input.RowId, false);
}
public ChangeInfo GetRow(MasterRecordInput input)
{
return
GetSessionStore(input.SessionFormIdentifier)
?.GetRow(input.Entity, input.RowId);
}
public IDictionary GetParameters(Guid sessionFormIdentifier)
{
if(sessionFormIdentifier == Guid.Empty)
{
return new Hashtable();
}
SessionStore sessionStore = GetSessionStore(sessionFormIdentifier);
return sessionStore == null
? new Hashtable() : sessionStore.Request.Parameters;
}
public ArrayList GetData(GetDataInput input)
{
SessionStore sessionStore = GetSessionStore(input.SessionFormIdentifier);
if(sessionStore == null)
{
return new ArrayList();
}
return sessionStore.GetData(
input.ChildEntity,
input.ParentRecordId,
input.RootRecordId);
}
private SessionStore GetSessionStore(Guid sessionId)
{
try
{
return sessionManager.GetSession(sessionId);
}
catch (Exception ex)
{
log.Warn(ex.Message, ex);
return null;
}
}
public IList RowStates(RowStatesInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
return sessionStore.RowStates(input.Entity, input.Ids);
}
public RuleExceptionDataCollection ExecuteActionQuery(
ExecuteActionQueryInput input)
{
EntityUIAction action = GetAction(input.ActionId);
// work queue commands are treated as actions,
// but they're not part of the model,
// so the GetAction can return null
// the subsequent code needs to be able to handle it
if (action is EntityMenuAction menuAction)
{
bool isAuthorized = SecurityManager.GetAuthorizationProvider().Authorize(
SecurityManager.CurrentPrincipal, menuAction.Menu.Roles);
if (!isAuthorized)
{
return new RuleExceptionDataCollection(new []
{
new RuleExceptionData(string.Format(
Origam.Server.Resources.MenuNotAuthorized, menuAction.Menu.NodeText)
)
});
}
}
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
if (sessionStore.IsDelayedLoading &&
action?.Mode == PanelActionMode.MultipleCheckboxes &&
action is EntityWorkflowAction workflowAction &&
workflowAction.MergeType != ServiceOutputMethod.Ignore)
{
throw new Exception("Only actions with merge type Ignore can be invoked in lazily loaded screens.");
}
if(action?.ConfirmationRule == null)
{
return new RuleExceptionDataCollection();
}
List<DataRow> rows = sessionStore.GetRows(input.Entity, input.SelectedIds);
IXmlContainer xml
= DatasetTools.GetRowXml(rows, DataRowVersion.Default);
var result = sessionStore.RuleEngine.EvaluateEndRule(
action.ConfirmationRule, xml);
return result ?? new RuleExceptionDataCollection();
}
public IList ExecuteAction(ExecuteActionInput input)
{
EntityUIAction action = GetAction(input.ActionId);
if (action is EntityMenuAction menuAction)
{
bool isAuthorized = SecurityManager.GetAuthorizationProvider().Authorize(
SecurityManager.CurrentPrincipal, menuAction.Menu.Roles);
if (!isAuthorized)
{
throw new UIException(string.Format(
Origam.Server.Resources.MenuNotAuthorized,
menuAction.Menu.NodeText)
);
}
}
var actionRunnerClient
= new ServerEntityUIActionRunnerClient(
sessionManager, input.SessionFormIdentifier.ToString());
var actionRunner = new ServerCoreEntityUIActionRunner(
actionRunnerClient: actionRunnerClient,
uiManager: uiManager,
sessionManager: sessionManager,
basicUIService: this,
reportManager: reportManager);
return actionRunner.ExecuteAction(
input.SessionFormIdentifier.ToString(),
input.RequestingGrid.ToString(),
input.Entity,
input.ActionType,
input.ActionId,
input.ParameterMappings,
input.SelectedIds,
input.InputParameters);
}
private static EntityUIAction GetAction(string actionId)
{
try
{
return UIActionTools.GetAction(actionId);
}
catch
{
// ignored
}
return null;
}
public Result<RowData, IActionResult> GetRow(
Guid sessionFormIdentifier, string entity,
DataStructureEntity dataStructureEntity, Guid rowId)
{
SessionStore sessionStore = GetSessionStore(sessionFormIdentifier);
switch(sessionStore)
{
case null:
return Result.Ok<RowData, IActionResult>(
new RowData{Row = null, Entity = null});
default:
{
var row = sessionStore.GetSessionRow(entity, rowId);
return Result.Ok<RowData, IActionResult>(
new RowData{Row = row, Entity = dataStructureEntity});
}
}
}
public Result<Guid, IActionResult> GetEntityId(
Guid sessionFormIdentifier, string entity)
{
SessionStore sessionStore = GetSessionStore(sessionFormIdentifier);
switch(sessionStore)
{
case null:
return Result.Ok<Guid, IActionResult>(Guid.Empty);
default:
{
var table = sessionStore.GetTable(entity, sessionStore.Data);
var entityId = Guid.Empty;
if(table.ExtendedProperties.Contains("EntityId"))
{
entityId = (Guid)table.ExtendedProperties["EntityId"];
}
return Result.Ok<Guid, IActionResult>(entityId);
}
}
}
public UIResult WorkflowNext(WorkflowNextInput workflowNextInput)
{
if(sessionManager.GetSession(
workflowNextInput.SessionFormIdentifier)
is WorkflowSessionStore workflowSessionStore)
{
return (UIResult) workflowSessionStore.ExecuteAction(
SessionStore.ACTION_NEXT, workflowNextInput.CachedFormIds);
}
return null;
}
public RuleExceptionDataCollection WorkflowNextQuery(
Guid sessionFormIdentifier)
{
var sessionStore = sessionManager.GetSession(
sessionFormIdentifier);
return (RuleExceptionDataCollection)sessionStore.ExecuteAction(
SessionStore.ACTION_QUERYNEXT);
}
public UIResult WorkflowAbort(Guid sessionFormIdentifier)
{
var sessionStore = sessionManager.GetSession(
sessionFormIdentifier);
return (UIResult)sessionStore.ExecuteAction(
SessionStore.ACTION_ABORT);
}
#pragma warning disable 1998
public async Task<UIResult> WorkflowRepeat(
#pragma warning restore 1998
Guid sessionFormIdentifier,
IStringLocalizer<SharedResources> localizer)
{
if(!(sessionManager.GetSession(sessionFormIdentifier)
is WorkflowSessionStore workflowSessionStore))
{
throw new Exception(localizer["ErrorWorkflowSessionInvalid"]);
}
var request = new UIRequest
{
FormSessionId = null,
IsStandalone = workflowSessionStore.Request.IsStandalone,
ObjectId = workflowSessionStore.Request.ObjectId,
Type = workflowSessionStore.Request.Type,
Icon = workflowSessionStore.Request.Icon,
Caption = workflowSessionStore.Request.Caption
};
DestroyUI(sessionFormIdentifier);
return InitUI(request);
}
public int AttachmentCount(AttachmentCountInput input)
{
SecurityTools.CurrentUserProfile();
SessionStore sessionStore = GetSessionStore(input.SessionFormIdentifier);
if(sessionStore == null)
{
return 0;
}
var result = 0;
var idList = new List<object>();
// We catch any problems with reading record ids
// (they could have been unloaded by another request
// and we don't want to hear messages about this).
try
{
ChildrenRecordsIds(idList, sessionStore.GetSessionRow(
input.Entity, input.Id));
}
catch
{
return 0;
}
if(idList.Count > 500)
{
return -1;
}
foreach(var recordId in idList)
{
var lookupService
= ServiceManager.Services.GetService<IDataLookupService>();
var oneRecordCount = (int)lookupService.GetDisplayText(
lookupId: new Guid("fbf2cadd-e529-401d-80ce-d68de0a89f13"),
lookupValue: recordId,
useCache: false,
returnMessageIfNull: false,
transactionId: null);
result += oneRecordCount;
}
return result;
}
public IList<Attachment> AttachmentList(AttachmentListInput input)
{
SecurityTools.CurrentUserProfile();
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
var result = new List<Attachment>();
var idList = new List<object>();
ChildrenRecordsIds(idList, sessionStore.GetSessionRow(
input.Entity, input.Id));
foreach(var recordId in idList)
{
var oneRecordList = core.DataService.Instance.LoadData(
dataStructureId: new Guid("44a25061-750f-4b42-a6de-09f3363f8621"),
methodId: new Guid("0fda540f-e5de-4ab6-93d2-76b0abe6fd77"),
defaultSetId: Guid.Empty,
sortSetId: Guid.Empty,
transactionId: null,
paramName1: "Attachment_parRefParentRecordId",
paramValue1: recordId);
foreach(DataRow row in oneRecordList.Tables[0].Rows)
{
var user = "";
if(!row.IsNull("RecordCreatedBy"))
{
try
{
var profileProvider
= SecurityManager.GetProfileProvider();
var profile = profileProvider.GetProfile(
(Guid)row["RecordCreatedBy"]) as UserProfile;
// ReSharper disable once PossibleNullReferenceException
user = profile.FullName;
}
catch (Exception ex)
{
user = ex.Message;
}
}
var attachment = new Attachment
{
Id = row["Id"].ToString(),
CreatorName = user,
DateCreated = (DateTime)row["RecordCreated"],
FileName = (string)row["FileName"]
};
if(!row.IsNull("Note"))
{
attachment.Description = (string)row["Note"];
}
var extension
= Path.GetExtension(attachment.FileName).ToLower();
attachment.Icon = "extensions/" + extension + ".png";
result.Add(attachment);
}
}
return result;
}
public static IList<WorkQueueInfo> WorkQueueList(
IStringLocalizer<SharedResources> localizer)
{
try
{
IList<WorkQueueInfo> result = new List<WorkQueueInfo>();
// if the user is not logged on,
// we will gracefully finish by returning an empty list
try
{
SecurityTools.CurrentUserProfile();
}
catch
{
return result;
}
var workQueueService
= ServiceManager.Services.GetService<IWorkQueueService>();
var lookupService
= ServiceManager.Services.GetService<IDataLookupService>();
var data = workQueueService.UserQueueList();
var queueList = data.Tables["WorkQueue"];
foreach(DataRow row in queueList.Rows)
{
var workQueueId = row["Id"];
var workQueueClassName = (string)row["WorkQueueClass"];
long cnt = 0;
if((bool)row["IsMessageCountDisplayed"])
{
if(workQueueService.WQClass(workQueueClassName)
is WorkQueueClass workQueueClass)
cnt = (long) lookupService.GetDisplayText(
workQueueClass.WorkQueueItemCountLookupId,
workQueueId, false, false, null);
}
var workQueueInfo = new WorkQueueInfo(
workQueueId.ToString(), (string)row["Name"], cnt);
result.Add(workQueueInfo);
}
return result;
}
catch (Exception ex)
{
throw new Exception(localizer["ErrorLoadingWorkQueueList"], ex);
}
}
public void ResetScreenColumnConfiguration(ResetScreenColumnConfigurationInput input)
{
var profileId = SecurityTools.CurrentUserProfile().Id;
IPersistenceService persistence =
ServiceManager.Services.GetService<IPersistenceService>();
var item = persistence.SchemaProvider.RetrieveInstance<FormReferenceMenuItem>(input.ObjectInstanceId);
item.Screen.ChildrenRecursive
.OfType<ControlSetItem>()
.Where(controlSetItem => controlSetItem.ControlItem.IsComplexType)
.Select(controlSetItem => controlSetItem.Id)
.ForEach(screenSectionId => ResetConfiguration(screenSectionId, profileId));
}
private void ResetConfiguration(Guid screenSectionId, Guid profileId)
{
var userConfig = OrigamPanelConfigDA.LoadConfigData(
screenSectionId, Guid.Empty, profileId);
if(userConfig.Tables["OrigamFormPanelConfig"].Rows.Count == 0)
{
return;
}
object data = userConfig.Tables["OrigamFormPanelConfig"].Rows[0]["SettingsData"];
if (!(data is string strData))
{
OrigamPanelConfigDA.DeleteUserConfig(screenSectionId, Guid.Empty, profileId);
return;
}
var xDocument = new XmlDocument();
xDocument.LoadXml(strData);
var allNodes = xDocument
.GetAllNodes();
if (allNodes.Where(node =>
node.Name == "TableConfiguration").Count() < 2)
{
OrigamPanelConfigDA.DeleteUserConfig(screenSectionId, Guid.Empty, profileId);
return;
}
var configurationNodes = allNodes
.FirstOrDefault(node =>
node.Name == "tableConfigurations");
configurationNodes?.ChildNodes
.Cast<XmlNode>()
.Where(configNode =>
configNode?.Attributes?["isActive"]?.Value == "true" ||
configNode?.Attributes?["name"]?.Value == ""
)
.ToList()
.ForEach(nodeToRemove => configurationNodes.RemoveChild(nodeToRemove));
userConfig.Tables["OrigamFormPanelConfig"].Rows[0][
"SettingsData"] = xDocument.OuterXml;
OrigamPanelConfigDA.SaveUserConfig(
userConfig, screenSectionId, Guid.Empty, profileId);
}
public void SaveObjectConfig(SaveObjectConfigInput input)
{
var profileId = SecurityTools.CurrentUserProfile().Id;
WorkflowSessionStore workflowSessionStore = null;
if(input.SessionFormIdentifier != Guid.Empty)
{
workflowSessionStore = sessionManager.GetSession(
input.SessionFormIdentifier) as WorkflowSessionStore;
}
var workflowId = workflowSessionStore?.WorkflowId ?? Guid.Empty;
var userConfig = OrigamPanelConfigDA.LoadConfigData(
input.ObjectInstanceId, workflowId, profileId);
if(userConfig.Tables["OrigamFormPanelConfig"].Rows.Count == 0)
{
OrigamPanelConfigDA.CreatePanelConfigRow(
userConfig.Tables["OrigamFormPanelConfig"],
input.ObjectInstanceId, workflowId, profileId,
OrigamPanelViewMode.Grid);
}
var currentSettings = new XmlDocument();
var newSettings = currentSettings.CreateDocumentFragment();
foreach (var sectionNameAndData in input.SectionNameAndData)
{
var newSettingsNode = currentSettings.CreateElement(
sectionNameAndData.Key);
newSettingsNode.InnerXml = sectionNameAndData.Value;
newSettings.AppendChild(newSettingsNode);
XmlNode configNode;
var settingsRow
= userConfig.Tables["OrigamFormPanelConfig"].Rows[0];
if(settingsRow.IsNull("SettingsData"))
{
configNode = currentSettings.CreateElement("Configuration");
currentSettings.AppendChild(configNode);
}
else
{
currentSettings.LoadXml((string)settingsRow["SettingsData"]);
configNode = currentSettings.FirstChild;
}
foreach(XmlNode node in configNode.SelectNodes(sectionNameAndData.Key))
{
node.ParentNode.RemoveChild(node);
}
configNode.AppendChild(newSettings);
settingsRow["SettingsData"] = currentSettings.OuterXml;
OrigamPanelConfigDA.SaveUserConfig(
userConfig, input.ObjectInstanceId, workflowId, profileId);
}
}
public static void SaveSplitPanelConfig(SaveSplitPanelConfigInput input)
{
SecurityTools.CurrentUserProfile();
OrigamPanelColumnConfigDA.PersistColumnConfig(
input.InstanceId, "splitPanel", 0,
input.Position, false);
}
public static void SaveFavorites(SaveFavoritesInput input)
{
var profile = SecurityTools.CurrentUserProfile();
// save favorites
var favorites = core.DataService.Instance.LoadData(
new Guid("e564c554-ca83-47eb-980d-95b4faba8fb8"),
new Guid("e468076e-a641-4b7d-b9b4-7d80ff312b1c"),
Guid.Empty,
Guid.Empty,
null,
"OrigamFavoritesUserConfig_parBusinessPartnerId",
profile.Id);
if(favorites.Tables["OrigamFavoritesUserConfig"].Rows.Count > 0)
{
var row = favorites.Tables["OrigamFavoritesUserConfig"].Rows[0];
row["ConfigXml"] = input.ConfigXml;
row["RecordUpdated"] = DateTime.Now;
row["RecordUpdatedBy"] = profile.Id;
row["refBusinessPartnerId"] = profile.Id;
}
else
{
var row = favorites.Tables["OrigamFavoritesUserConfig"]
.NewRow();
row["Id"] = Guid.NewGuid();
row["RecordCreated"] = DateTime.Now;
row["RecordCreatedBy"] = profile.Id;
row["ConfigXml"] = input.ConfigXml;
row["refBusinessPartnerId"] = profile.Id;
favorites.Tables["OrigamFavoritesUserConfig"].Rows.Add(row);
}
core.DataService.Instance.StoreData(
new Guid("e564c554-ca83-47eb-980d-95b4faba8fb8"),
favorites, false, null);
}
public ArrayList GetPendingChanges(Guid sessionFormIdentifier)
{
var sessionStore = sessionManager.GetSession(sessionFormIdentifier);
var changes = sessionStore.PendingChanges;
sessionStore.PendingChanges = null;
return changes ?? new ArrayList();
}
public ArrayList GetChanges(ChangesInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
var hasErrors = sessionStore.Data.HasErrors;
var hasChanges = sessionStore.Data.HasChanges();
return sessionStore.GetChanges(
input.Entity, input.RowId, 0, hasErrors, hasChanges);
}
public static Result<Guid, IActionResult> SaveFilter(
DataStructureEntity entity, SaveFilterInput input)
{
var profileId = SecurityTools.CurrentUserProfile().Id;
var storedFilter = new OrigamPanelFilter();
var filterRow = storedFilter.PanelFilter.NewPanelFilterRow();
filterRow.Id = Guid.NewGuid();
filterRow.Name = input.Filter.Name;
filterRow.IsGlobal = input.Filter.IsGlobal;
filterRow.IsDefault = input.IsDefault;
filterRow.PanelId = input.PanelId;
filterRow.ProfileId = profileId;
filterRow.RecordCreated = DateTime.Now;
filterRow.RecordCreatedBy = profileId;
storedFilter.PanelFilter.Rows.Add(filterRow);
foreach(var filterDetail in input.Filter.Details)
{
if(entity.Column(filterDetail.Property) == null)
{
continue;
}
ConvertValues(entity, filterDetail);
OrigamPanelFilterDA.AddPanelFilterDetailRow(
storedFilter, profileId, filterRow.Id,
filterDetail.Property, filterDetail.Operator,
filterDetail.Value1, filterDetail.Value2);
}
OrigamPanelFilterDA.PersistFilter(storedFilter);
return Result.Ok<Guid, IActionResult>(filterRow.Id);
}
private static void ConvertValues(DataStructureEntity entity,
UIGridFilterFieldConfiguration filterDetail)
{
OrigamDataType dataType = entity.Column(filterDetail.Property).DataType;
switch (dataType)
{
case OrigamDataType.UniqueIdentifier:
{
var filterOperator = (FilterOperator)filterDetail.Operator;
if (filterDetail.Value1 is string value1)
{
if (Guid.TryParse(value1, out var parsedValue))
{
filterDetail.Value1 = parsedValue;
}
}
if ((filterDetail.Value2 != null)
&& (filterDetail.Value1 is string)
&& (filterOperator != FilterOperator.Equals)
&& (filterOperator != FilterOperator.NotEquals))
{
if (filterDetail.Value2 is string value2)
{
if (Guid.TryParse(value2, out var parsedValue))
{
filterDetail.Value2 = parsedValue;
}
}
}
break;