public dbTSFLibrary getTSFLibraryByNameSpace(String libraryNameSpace) { dbTSFLibrary lb = null; String sql = "SELECT * FROM " + dbTSFLibrary._TABLE_NAME + " WHERE " + dbTSFLibrary._TARGET_NAMESPACE + " = ?"; OleDbParameter[] dbParams = { CreateParameter(dbTSFLibrary._ID, libraryNameSpace) }; OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams); if (reader != null) { bool reading = reader.Read(); if (reading) { lb = new dbTSFLibrary(); while (reading) { lb.load(reader); lb.Signals = getTSFLibrarySignals(lb.id); reading = reader.Read(); } } reader.Close(); reader.Dispose(); } return(lb); }
private void processTSF(HttpProcessor p) { string url = p.http_url; //Strip off /tsf/ url = url.Substring(5); string[] parts = url.Split('/'); if (parts.Length != 2) { throw new Exception("Invalid URL"); } string name = parts[0]; string version = parts[1]; SignalDAO dao = DataManager.getSignalDAO(); dbTSFLibrary lb = dao.getTSFLibraryByName(name); if (lb == null || lb.content == null) { throw new Exception(string.Format("Signal Model Library \"{0}\" was not found.", name)); } p.httpHeaders.Add("Content-Type", "text/xml"); p.httpHeaders.Add("Content-Disposition", "inline; filename=" + name + ".xml"); var writer = new BinaryWriter(p.outputStream.BaseStream, Encoding.UTF8); writer.Write(Encoding.UTF8.GetBytes(lb.content)); }
public static SignalModel GetSignalModel(string nameSpace, string signalName) { SignalModel model = null; SignalModelLibrary library = null; SignalManager sm = Instance; if (sm._signalModelLibraryCache.ContainsKey(nameSpace)) { library = sm._signalModelLibraryCache[nameSpace]; } else { SignalDAO dao = new SignalDAO(); dbTSFLibrary tsfLib = dao.getTSFLibraryByNameSpace(nameSpace); if (tsfLib != null) { string content = tsfLib.content; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(content)); library = new SignalModelLibrary(ms); sm._signalModelLibraryCache.Add(nameSpace, library); } } if (library != null) { model = library.GetSignalModel(signalName); } return(model); }
public void saveTSFLibrary(dbTSFLibrary library) { if (library.id == null) { library.DataState = BASEBean.eDataState.DS_ADD; library.id = Guid.NewGuid(); } library.save(); }
//--- Get TSF Name for the signal ---// //--- Lookup signal name in signal model library ---// private dbTSFLibrary GetTestSignalLibrary(string name) { dbTSFLibrary library = _signalDao.getTSFLibraryByName(name); if (library.id == null) { throw new Exception(string.Format("Failed to locate TSF Library \"{0}\" - You may import this library using the Signal Model Library tool.", name)); } library.Signals = _signalDao.getTSFLibrarySignals(library.id); return(library); }
public List <dbTSFLibrary> getTSFLibraries() { List <dbTSFLibrary> list = new List <dbTSFLibrary>(); String sql = "SELECT * FROM " + dbTSFLibrary._TABLE_NAME; OleDbParameter[] dbParams = {}; OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams); if (reader != null) { while (reader.Read()) { dbTSFLibrary lb = new dbTSFLibrary(); lb.load(reader); list.Add(lb); } reader.Close(); reader.Dispose(); } return(list); }
public dbTSFLibrary getTSFLibrary(Guid libraryUUID) { dbTSFLibrary lb = new dbTSFLibrary(); String sql = "SELECT * FROM " + dbTSFLibrary._TABLE_NAME + " WHERE " + dbTSFLibrary._ID + " = ?"; OleDbParameter[] dbParams = { CreateParameter(dbTSFLibrary._ID, libraryUUID) }; OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams); if (reader != null) { while (reader.Read()) { lb.load(reader); lb.Signals = getTSFLibrarySignals(libraryUUID); } reader.Close(); reader.Dispose(); } return(lb); }
public void Process(byte[] aixmlDocument) { Dictionary <string, dbTSFSignal> signalLookup = new Dictionary <string, dbTSFSignal>(); string xmlMapping = CreateSignalMappingXml(aixmlDocument); SignalMapping mapping = XmlUtils.DeserializeObject <SignalMapping>(xmlMapping); if (mapping != null) { string modelName = mapping.ModelLibrary; string sourceType = mapping.SourceType; _usedSignalsList.Clear(); dbTSFLibrary library = GetTestSignalLibrary(mapping.ModelLibrary); foreach (var noun in mapping.AtlasNouns) { string nounName = noun.Name; string tsfSignalName = noun.Tsf; _usedSignalsList.Add(nounName); SourceSignalMapBean mapBean = _signalMappingDao.GetMappedSignal(sourceType, nounName); if (mapBean == null) { mapBean = new SourceSignalMapBean(); mapBean.DataState = BASEBean.eDataState.DS_ADD; } else { mapBean.DataState = BASEBean.eDataState.DS_EDIT; } mapBean.sourceName = nounName; mapBean.sourceType = sourceType; if (string.IsNullOrEmpty(mapBean.targetType)) { mapBean.targetType = modelName; } if (string.IsNullOrEmpty(mapBean.targetName)) { mapBean.targetName = tsfSignalName; } mapBean.save(); foreach (var modifier in noun.Modifiers) { SourceSignalAttributeMapBean attribute = _signalMappingDao.GetMappedSignalAttribute( mapBean.id.ToString(), modifier.Name); if (attribute == null) { attribute = new SourceSignalAttributeMapBean(); attribute.DataState = BASEBean.eDataState.DS_ADD; attribute.mapId = mapBean.id; attribute.sourceName = modifier.Name; attribute.sourceSuffix = modifier.Suffix; attribute.targetQualifier = modifier.Qualifier; attribute.targetName = modifier.Attribute; attribute.save(); } else { attribute.DataState = BASEBean.eDataState.DS_EDIT; } } if (!string.IsNullOrEmpty(tsfSignalName)) { List <TestSignalBean> signals = _signalDao.getTSFSignals(tsfSignalName); foreach (TestSignalBean testSignalBean in signals) { } } } if (library != null) { //--- Create a lookup map for all the signals in the library ---// foreach (dbTSFSignal tsfSignal in library.Signals) { if (!signalLookup.ContainsKey(tsfSignal.signalName)) { signalLookup.Add(tsfSignal.signalName, tsfSignal); } } } } }
private void SaveSelectedSignalModel() { HourGlass.Start(); try { SignalDAO dao = DataManager.getSignalDAO(); if (_signalModelLibrary != null) { dao.DeleteTSFLibrary(_signalModelLibrary.TSFLibrary.uuid, _signalModelLibrary.TSFLibrary.targetNamespace); var library = new dbTSFLibrary(); library.IncludeKeyOnInsert = true; library.lastUpdate = DateTime.UtcNow; library.id = Guid.Parse(_signalModelLibrary.TSFLibrary.uuid); library.content = _signalModelLibrary.XmlContent; library.targetNamespace = _signalModelLibrary.TSFLibrary.targetNamespace; library.libraryName = _signalModelLibrary.TSFLibrary.name; library.DataState = (!dao.hasTSFLibrary(_signalModelLibrary.TSFLibrary.uuid)) ? BASEBean.eDataState.DS_ADD : BASEBean.eDataState.DS_EDIT; library.save(); foreach (SignalModel sm in _signalModelLibrary.SignalModels.Values) { TSFType tsf = sm.TSF; dbSignal dataSignal = dao.getSignal(sm.Name, library.targetNamespace); if (dataSignal == null) { //Add Signal to the database string baseSignalName = sm.BaseSignalName; dbSignal baseSignal = dao.getSignal(baseSignalName, sm.BaseSignalNameSpace); dataSignal = new dbSignal(); dataSignal.ParentSignal = baseSignal; dataSignal.signalName = sm.Name; dataSignal.uuid = Guid.Parse(tsf.uuid); dataSignal.xmlns = library.targetNamespace; foreach (SignalAttribute attribute in sm.Attributes) { var a = new dbSignalAttribute(); a.attributeName = attribute.Name; a.defaultValue = attribute.DefaultValue; a.DataState = BASEBean.eDataState.DS_ADD; a.type = attribute.SchemaType; a.fixedValue = attribute.FixedValue; if (dataSignal.Attributes == null) { dataSignal.Attributes = new List <dbSignalAttribute>(); } dataSignal.Attributes.Add(a); } dataSignal.DataState = BASEBean.eDataState.DS_ADD; } else { dataSignal.xmlns = library.targetNamespace; dataSignal.uuid = Guid.Parse(tsf.uuid); List <dbSignalAttribute> attributes = dataSignal.Attributes; var attrMap = new Dictionary <string, SignalAttribute>(); var dbAttrMap = new Dictionary <string, dbSignalAttribute>(); foreach (SignalAttribute sa in sm.Attributes) { attrMap.Add(sa.Name, sa); } foreach (dbSignalAttribute dbAttribute in attributes) { string an = dbAttribute.attributeName; dbAttrMap.Add(an, dbAttribute); if (attrMap.ContainsKey(an)) { SignalAttribute sa = attrMap[an]; dbAttribute.type = sa.SchemaType; dbAttribute.defaultValue = sa.DefaultValue; dbAttribute.fixedValue = sa.FixedValue; dbAttribute.DataState = BASEBean.eDataState.DS_EDIT; } else { dbAttribute.DataState = BASEBean.eDataState.DS_DELETE; } } foreach (SignalAttribute sa in sm.Attributes) { if (!dbAttrMap.ContainsKey(sa.Name)) { var dbAttribute = new dbSignalAttribute(); dbAttribute.type = sa.SchemaType; dbAttribute.defaultValue = sa.DefaultValue; dbAttribute.fixedValue = sa.FixedValue; dbAttribute.DataState = BASEBean.eDataState.DS_ADD; dataSignal.Attributes.Add(dbAttribute); } } dataSignal.DataState = BASEBean.eDataState.DS_EDIT; } dataSignal.xmlns = _signalModelLibrary.TSFLibrary.targetNamespace; dataSignal.save(); } foreach (ListViewItem item in lvSignals.Items) { var model = item.Tag as SignalModel; if (model != null) { var signal = new dbTSFSignal(); signal.signalName = model.Name; signal.id = Guid.Parse(model.TSF.uuid); signal.signalContent = model.TSF.Serialize(); signal.libraryUuid = _signalModelLibrary.TSFLibrary.uuid; signal.DataState = (!dao.hasTSFSignal(model.TSF.uuid) ? BASEBean.eDataState.DS_ADD : BASEBean.eDataState.DS_EDIT); signal.lastUpdate = DateTime.UtcNow; try { signal.save(); } catch (Exception e) { if (e.Message.ToLower().Contains("duplicate")) { TestSignalBean otherSignal = dao.getTSFSignal(model.Name, _signalModelLibrary.TSFLibrary.uuid); LogManager.Error("UUID Conflict between document data and the database for Signal {0} in Signal Library {1} ", model.Name, library.libraryName); if (otherSignal != null) { LogManager.Error("\tDocument signal uuid {0}, Database signal uuid {{{1}}} ", model.TSF.uuid, otherSignal.id.ToString().ToUpper()); if (dao.changeTSFSignalId(otherSignal.id, Guid.Parse(model.TSF.uuid))) { LogManager.Info( "The Database signal uuid has been changed to reflect the Document signal uuid"); signal.DataState = BASEBean.eDataState.DS_EDIT; signal.save(); } } } } } } } } catch (Exception e) { LogManager.Error(e, "An error has occured saving the signal model library: {0}", e.Message); } finally { HourGlass.Stop(); if (_signalModelLibrary == null) { MessageBox.Show(Resources.A_Signal_Model_must_be_selected_to_save_); } else { LogManager.Trace(Resources.Completed_Saving_Selected_Signal_Model); MessageBox.Show(Resources.Completed_Saving_Selected_Signal_Model); } } }