import clr import sys from System import String, DateTime, DateTimeOffset from System.Windows.Forms import DialogResult, MessageBox, MessageBoxButtons, MessageBoxIcon clr.AddReference("Symyx.Framework") clr.AddReference("Symyx.Notebook") from Symyx.Framework.Vault import VaultWorkspace, DataScope, RetrievalOptions, VaultId, VaultObjectTypes from Symyx.Framework.Vault import Reference, Annotation from Symyx.Notebook.Sections.Reference import ReferenceSection from Symyx.Framework import Extensibility from Symyx.Framework.Extensibility import AssemblyCache from Symyx.Notebook import Document def GetForm(document, fname): ret = None for sec in document.Sections: if sec.Title == fname: ret = sec break return ret def GetFolder(): folder = None repo = active_workspace.VaultRepositories[0] folderId = editor.Document.ManagedFolderId if not folderId.IsEmpty(): folder = active_workspace.Get(folderId, DataScope.Properties) cp = folder.VaultPath.Replace('Sintesi', 'Analisi') destino = repo.Get(cp, DataScope.Properties) if destino is not None: folder = destino[0] return folder def GetGroup(gname): lista = active_workspace.Get(gname, VaultObjectTypes.Group, DataScope.Minimal) if lista is not None: telo = lista[0] else: telo = None return telo def GetUser(gname): lista = active_workspace.Get(gname, VaultObjectTypes.User, DataScope.Minimal) if lista is not None: telo = lista[0] else: telo = None return telo def GetPermission(application, permission): cid = 'ConfigurationVaultId' data = None ape = active_workspace.CurrentUser.ApplicationPermissions.GetApplicationPermissionFor(application, permission) if ape is not None and ape.ExtendedProperties.Contains(cid): vid = VaultId(ape.ExtendedProperties[cid].Value.ToString()) data = active_workspace.Get(vid, DataScope.All, RetrievalOptions.UseCachedVersionOffline) return data def GetPermissionData(appermission, name): reso = None if appermission is not None and not String.IsNullOrEmpty(name): for item in appermission: if item.Key == name: reso = item.Value.ToString().Replace("\r", "") break return reso assemblyLoaded = True try: # This next line is only used if you are debugging an assembly. # This AddReference assumes that the SolutionCalc.dll is in perma = GetPermission('Recordati.Custom', 'Templates.LT') endpoint = GetPermissionData(perma, 'recnetWS') proxy = GetPermissionData(perma, 'recnetProxy') assembly = AssemblyCache.GetAssembly(proxy) clr.AddReference(assembly) from RecNetReg import RecNetIO #proxy = AssemblyCache.GetAssemblyFullName('AppHelpers') #assembly = AssemblyCache.GetAssembly(proxy) #clr.AddReference(assembly) #from AppHelpers import * #clr.AddReference("AnRequest") #from AnRequest import * except: assemblyLoaded = False #errMsg = 'An error was encountered referencing a required assembly (AnRequest).' errMsg = sys.exc_info()[1] MessageBox.Show(str(errMsg), 'Assembly Reference Error', MessageBoxButtons.OK, MessageBoxIcon.Error) section = editor.ActiveDocumentSection if not section.IsLocked and not editor.IsReadOnly: bckcontrols = GetForm(editor.Document, "Background").View.Forms['BaseForm1'].Controls group = bckcontrols["GroupBox1"] nbid = group.Controls["TextBox1"].Text perma = GetPermission('Recordati.Custom', 'Templates.LT') template = GetPermissionData(perma, 'ANTemplateId') gname = GetPermissionData(perma, 'ANGroupId') template = active_workspace.Get(VaultId(template), DataScope.All) currentVaultObj = Document.Create(template) currentVaultObj.Title = 'AN_' + nbid #group.Controls["txtBoxAnId"].Text = currentVaultObj.VaultKey # Update reference in AN doc association1 = Reference(editor.Document, True, editor.Document.Title) association1.Name = editor.Document.Title currentVaultObj.References.Add(association1) #vaultUriCollection.append(currentVaultObj.VaultUri) #copy all the data anfora = GetForm(currentVaultObj, "Analysis Results") rows = section.GetRows() ora = DateTimeOffset.Now for row in rows: if row.Properties['AnalysisRequest']['RequestTime'].IsNull: row.Properties['AnalysisRequest']['RequestTime'].Value = ora nora = anfora.AddRow() nora.Properties['AnalysisRequest']['SampleID'].Value = row.Properties['AnalysisRequest']['SampleID'].Value nora.Properties['Batch_SYS']['LotNumber'].Value = row.Properties['Batch_SYS']['LotNumber'].Value nora.Properties['AnalysisRequest']['Analytical'].Value = row.Properties['AnalysisRequest']['Analytical'].Value nora.Properties['AnalysisRequest']['ProductType'].Value = row.Properties['AnalysisRequest']['ProductType'].Value nora.Properties['AnalysisRequest']['RequestTime'].Value = ora nora.Properties['AnalysisRequest']['Amount'].Value = row.Properties['AnalysisRequest']['Amount'].Value nora.Properties['AnalysisRequest']['RequestFlag'].Value = row.Properties['AnalysisRequest']['RequestFlag'].Value nora.Properties['AnalysisRequest']['SyntheisComment'].Value = row.Properties['AnalysisRequest']['SyntheisComment'].Value nora.Properties['RecLT_analysis']['SampleName'].Value = row.Properties['RecLT_analysis']['SampleName'].Value nora.Properties['RecLT_analysis']['Test'].Value = row.Properties['RecLT_analysis']['Test'].Value section.View.RefreshData() anfora.View.RefreshData() pletora = GetForm(currentVaultObj, "Background").View.Forms["BaseForm1"].Controls pletora = pletora["GroupBox1"] pletora.Controls["txtBoxSynID"].Text = nbid pletora.Controls["ComboBox1"].Text = group.Controls["ComboBox1"].Text pletora.Controls["ComboBox5"].Text = group.Controls["ComboBox5"].Text pletora.Controls["ComboBox4"].Text = group.Controls["ComboBox4"].Text pletora.Controls["TextBox7"].Text = group.Controls["TextBox7"].Text association1 = Reference(section, True, section.Title) association1.Name = section.Title currentVaultObj.References.Add(association1) #refse = ReferenceSection(editor.Document.VaultUri, section.VaultUri) refse = ReferenceSection() refse.InsertReference(editor.Document.VaultUri, editor.Document.Title, editor.Document.Autoname, section.VaultUri, section.Title) currentVaultObj.Add(refse) #save document active_workspace.Add(currentVaultObj, GetFolder()) # Update reference inside the CH doc association = Reference(currentVaultObj, True, currentVaultObj.Title) association.Name = currentVaultObj.Title editor.Document.References.Add(association) #add section reference in SYN editor.InsertReferenceSection(anfora.Document.VaultUri, anfora.Document.Title, anfora.Document.Autoname, anfora.VaultUri, anfora.Title) #get specific info anDesc = 'Analysis request for ' + nbid anReqType = 0 if assemblyLoaded: try: data = RecNetIO.GetUserDetails(endpoint, anDesc) anDesc = data.Description gname = data.Recipients anReqType = 2 #try: #data = RequestDetails.GetDetails(GetPermissionData(perma, 'Connection'), anDesc) #anDesc = data.Description #gname = data.Recipient #anReqType = 1 except: errMsg = 'Error requesting submission details. Request will be sent with default details.' #errMsg = sys.exc_info()[1] MessageBox.Show(errMsg, 'Assembly Reference Error', MessageBoxButtons.OK, MessageBoxIcon.Error) #send message recipe = None reccount = 0 if anReqType < 2: recipe = GetGroup(gname) if anReqType > 1 or recipe is not None: annota = Annotation("Workflow category") if anReqType < 2: annota.Recipients.Add(recipe.VaultId) else: if gname is not None: for username in gname: recipe = GetUser(username) if recipe is not None: annota.Recipients.Add(recipe.VaultId) reccount = reccount + 1 userid = active_workspace.CurrentUser.VaultId annota.CreatorId = userid annota.Context = "Analysis Request" annota.Title = currentVaultObj.Title annota.Description = anDesc annota.DeletableBy = Annotation.Actors.Creator or Annotation.Actors.Recipient active_workspace.AddAnnotation(currentVaultObj, annota)