When I open more than 1 tab in IE(Chrome or Firefox) then only tab can be streaming data. Others tab is not streaming data. Why?
This is my code in class StockBoardAdapter:
Code:
public class StockBoardAdapter : IDataProvider
{
public StructFileManager m_PRSFileStructManager = null;
private IItemEventListener _listener;
private volatile string lstStock = "";
private volatile bool go;
private volatile int temp = 0;
private Global _myGlobal = new Global();
public void Init(IDictionary parameters, string configFile)
{
}
public bool IsSnapshotAvailable(string itemName)
{
return false;
}
public void SetListener(IItemEventListener eventListener)
{
_listener = eventListener;
}
public void Subscribe(string itemName)
{
itemName = itemName.Trim();
_myGlobal._myGlobal = itemName.Substring(4);
Thread t = new Thread(new ThreadStart(Run));
t.Start();
}
public void Unsubscribe(string itemName)
{
itemName = itemName.Trim();
_myGlobal._myGlobal = itemName.Substring(4);
go = false;
}
private void SetData(ref IDictionary eventData, Security i)
{
//eventData["ma_ck"] = i.StockSymbol;
Double gia3=(Double.Parse(i.Best3Bid.ToString())/100);
eventData["gia3"] = gia3.ToString();
eventData["kl3"] = i.Best3BidVolumn.ToString();
Double gia2 = (Double.Parse(i.Best2Bid.ToString()) / 100);
eventData["gia2"] = gia2.ToString();
eventData["kl2"] = i.Best2BidVolumn.ToString();
Double gia1 = (Double.Parse(i.Best1Bid.ToString()) / 100);
eventData["gia1"] = gia1.ToString();
eventData["kl1"] = i.Best1BidVolumn.ToString();
Double gia = (Double.Parse(i.Last.ToString()) / 100);
eventData["gia"] = gia.ToString();
eventData["kl"] = i.LastVol.ToString();
eventData["tong_kl"] = i.LastVol.ToString();
Double gia_1 = (Double.Parse(i.Best1Offer.ToString()) / 100);
eventData["gia_1"] = gia_1.ToString();
eventData["kl_1"] = i.Best1OfferVolumn.ToString();
Double gia_2 = (Double.Parse(i.Best2Offer.ToString()) / 100);
eventData["gia_2"] = gia_2.ToString();
eventData["kl_2"] = i.Best2OfferVolumn.ToString();
Double gia_3 = (Double.Parse(i.Best3Offer.ToString()) / 100);
eventData["gia_3"] = gia_3.ToString();
eventData["kl_3"] = i.Best3OfferVolumn.ToString();
}
public void Run()
{
IDictionary eventData;// = new Hashtable();
go = true;
while (go)
{
eventData = new Hashtable();
if (lstStock == "" && DataAdapterLauncher.lstSec_All != null)
{
lstStock = DataAdapterLauncher.lstStock;
eventData["Items"] = lstStock;
_listener.Update("itemMa", eventData, false);
Thread.Sleep(10000);
foreach (Security i in DataAdapterLauncher.lstSec_All)
{
if (i.StockType.ToUpper() == "U" || i.StockType.ToUpper() == "S")
{
eventData = new Hashtable();
SetData(ref eventData, i);
_listener.Update("item" + i.StockSymbol.ToUpper(), eventData, false);
Thread.Sleep(10);
}
}
System.Console.WriteLine("Local_1_" + temp.ToString());
temp++;
}
else if (DataAdapterLauncher.lstSec_Update != null)
{
foreach (Security i in DataAdapterLauncher.lstSec_Update)
{
if (i.StockType.ToUpper() == "U" || i.StockType.ToUpper() == "S")
{
eventData = new Hashtable();
SetData(ref eventData, i);
_listener.Update("item" + i.StockSymbol.ToUpper(), eventData, false);
}
}
System.Console.WriteLine("Local_2_" + temp.ToString());
temp++;
}
System.Console.WriteLine("Global_1_" + temp.ToString());
temp++;
Thread.Sleep(1000);
}
}
}
public class Global
{
public string _myGlobal="";
and i get data from file Security.DAT (Binary file)...
This is class DataAdapterLauncher:
Code:
public class DataAdapterLauncher
{
public static List<Security> lstSec_All = null;
public static List<Security> lstSec_Update = null;
public static string lstStock = "";
//public static byte[] m_CopiedReadSecurities = null;
//public static byte[] m_All = null;
//public static byte[] m_Update = null;
public static string constDataPathFileName = "DATAPATH.MAP", constDataPathTempFileName = "DATAPATH1.MAP";
public static void Main(string[] args)
{
//string host = "125.234.15.210";
string host = Commons.GetConfigKey("server_add");
int reqrepPort = 3333;
int notifPort = 4444;
try
{
DataProviderServer server = new DataProviderServer();
server.Adapter = new StockBoardAdapter();
TcpClient reqrepSocket = new TcpClient(host, reqrepPort);
server.RequestStream = reqrepSocket.GetStream();
server.ReplyStream = reqrepSocket.GetStream();
TcpClient notifSocket = new TcpClient(host, notifPort);
server.NotifyStream = notifSocket.GetStream();
server.Start();
Thread t = new Thread(new ThreadStart(GetData));
t.Start();
System.Console.WriteLine("Remote Adapter connected to Lightstreamer Server.");
System.Console.WriteLine("Ready to publish data...");
}
catch (Exception e)
{
System.Console.WriteLine("Could not connect to Lightstreamer Server.");
System.Console.WriteLine("Make sure Lightstreamer Server is started before this Adapter.");
System.Console.WriteLine(e);
}
}
public static void NumOfStock(List<Security> lstSec)
{
foreach (Security i in lstSec)
{
if (i.StockType.ToUpper() == "U" || i.StockType.ToUpper() == "S")
{
if (lstStock == "")
lstStock += i.StockSymbol.ToUpper();
else
lstStock += "|" + i.StockSymbol.ToUpper();
}
}
}
public static void GetData()
{
bool l_IsTodays = false;
string m_PRS_Root_Path = GetConfigKey("PRS_Root"), m_PRS_File_Path = "";
l_IsTodays = ReadDataPathFile(m_PRS_Root_Path, ref m_PRS_File_Path);
byte[] m_CopiedReadSecurities = null;
byte[] m_All = null;
byte[] m_Update = null;
while (true)
{
try
{
FileInfo l_FileInfo = new FileInfo(m_PRS_File_Path + "\\\\SECURITY.DAT");
m_All = ReadFileSpecial(l_FileInfo.FullName, 0, l_FileInfo.Length);
lstSec_All = Security.GetSecuritiesEntities(m_All);
if (lstStock == "")
NumOfStock(lstSec_All);
if (m_CopiedReadSecurities==null)
m_All = GetUpdatedSecuritiesRecords(l_FileInfo, ref m_CopiedReadSecurities);
m_Update = GetUpdatedSecuritiesRecords(l_FileInfo, ref m_CopiedReadSecurities);
if (m_Update != null && m_Update.Length>0)
lstSec_Update = Security.GetSecuritiesEntities(m_Update);
m_All = null;
m_Update = null;
}
catch
{
}
Thread.Sleep(1000);
}
}
public static bool ReadDataPathFile(string m_PRS_Root_Path, ref string m_PRS_File_Path)
{
//READ DATAPATH.MAP FILE GET ALL DATA INSERT TO HASHTABLE
string l_StrDATAPATH = "";
try
{
FileStream l_FileStream = new FileStream(m_PRS_Root_Path + "\\" + constDataPathFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamReader l_StreamReader = new StreamReader(l_FileStream);
l_StrDATAPATH = l_StreamReader.ReadLine();
l_StreamReader.Close();
l_FileStream.Close();
}
catch (IOException ex)
{
//WriteLog("IO Exception", ex.Message + "\r\n" + ex.StackTrace, Commons.m_excepLog);
}
Hashtable l_HashTable = new Hashtable();
int l_StrLen = l_StrDATAPATH.Length;
int l_Index = 0;
while (l_Index < l_StrLen)
{
string l_StrTemp = l_StrDATAPATH.Substring(l_Index, 18);
if (l_HashTable.Contains(l_StrTemp.Substring(0, 10)))
l_HashTable.Remove(l_StrTemp.Substring(0, 10));
l_HashTable.Add(l_StrTemp.Substring(0, 10), l_StrTemp.Substring(10));
l_Index = l_Index + 18;
}
string l_StrToDay = DateTime.Now.ToString("dd") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("yyyy");
//WriteLog
if (l_HashTable.Contains(l_StrToDay))
{
m_PRS_File_Path = String.Concat(m_PRS_Root_Path, "\\");
m_PRS_File_Path = String.Concat(m_PRS_Root_Path, l_HashTable[l_StrToDay].ToString());
return true;
}
else
{
return false;
}
}
public static string GetConfigKey(string key)
{
try
{
if (key.Trim() != "" || ConfigurationManager.AppSettings[key.Trim()] != null)
return ConfigurationManager.AppSettings[key.Trim()].ToString();
else
return key.Trim();
}
catch (Exception ex)
{
return key;
}
}
public static byte[] GetUpdatedSecuritiesRecords(FileInfo pFileInfo,ref byte[] m_CopiedReadSecurities)
{
try
{
byte[] l_Ret = null;
byte[] l_NewSecurity = null;
l_NewSecurity = ReadFileSpecial(pFileInfo.FullName, 0, pFileInfo.Length);
int l_RecLen = Security.constSTC_RECORD_LENGTH;
int l_Len = 0;
if (l_NewSecurity != null)
l_Len = l_NewSecurity.Length;
if (m_CopiedReadSecurities != null && l_Len > 0)
{
int[] l_RecIdx = new int[l_Len / l_RecLen]; // Array of record indexes of those are actually changed
int l_NumChangedRecs = 0;
// Find indexes of records that are actually changed
for (int i = 0; i < l_Len; i++)
{
if (m_CopiedReadSecurities[i] != l_NewSecurity[i])
{
l_RecIdx[l_NumChangedRecs] = i / l_RecLen;
i = ((l_RecIdx[l_NumChangedRecs] + 1) * l_RecLen) - 1; // Move up to compare the subsequent record
l_NumChangedRecs++;
}
}
// Copy the changed records into the array to be returned
l_Ret = new byte[l_NumChangedRecs * l_RecLen];
for (int i = 0; i < l_NumChangedRecs; i++)
{
// Copy record of index RecIdx[i] into the returned array
int k = i * l_RecLen;
int j = l_RecIdx[i] * l_RecLen;
for (int cnt = 0; cnt < l_RecLen; cnt++, k++, j++)
{
l_Ret[k] = l_NewSecurity[j];
}
}
}
else
{
l_Ret = l_NewSecurity; // There is no copied of SECURITY.DAT in memory, so just return the whole content
}
// Save the content of SECURITY.DAT
m_CopiedReadSecurities = l_NewSecurity;
return l_Ret;
}
catch (Exception ex)
{
Commons.WriteLog("UpdateSecurityRecord", ex.Message + "\r\n" + ex.StackTrace, Commons.m_excepLog);
return null;
}
}
public static byte[] ReadFileSpecial(string pFullFileName, long pStartPos, long pNumBytes)
{
try
{
return ReadFileAppend(pFullFileName, pStartPos, pNumBytes);
}
catch (IOException ioex)
{
Commons.WriteLog("ReadSpecialIO", "***** ReadFileSpecial IOException:" + ioex.Message, Commons.m_excepLog);
return null;
}
catch (Exception ex)
{
Commons.WriteLog("ReadSpecialEx", "***** ReadFileSpecial IOException:" + ex.Message, Commons.m_excepLog);
return null;
}
}
public static byte[] ReadFileAppend(string p_FileName, long p_StartPos, long p_NumBytes)
{
byte[] hByt = new byte[p_NumBytes];
try
{
FileStream l_FileStream = new FileStream(p_FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
BinaryReader l_BinaryReader = new BinaryReader(l_FileStream);
l_FileStream.Seek(p_StartPos, SeekOrigin.Begin);
l_BinaryReader.Read(hByt, 0, (int)p_NumBytes);
l_BinaryReader.Close();
l_FileStream.Close();
return hByt;
}
catch (UnauthorizedAccessException ex)
{
Commons.WriteLog("ReadFileAppend_UnauthorizedAccessException", ex.Message, Commons.m_excepLog);
return null;
}
catch (Exception ex)
{
Commons.WriteLog("ReadFileAppend", ex.Message, Commons.m_excepLog);
return null;
}
}
}
and this is index.htm:
Code:
<html>
<head>
<title>Stock Board with Lightstreamer</title>
<link rel="stylesheet" type="text/css" href="css/table.css" />
<script language="JavaScript" src="LS/lscommons.js"></script>
<script language="JavaScript" src="LS/lspushpage.js"></script>
<script src="scriptaculous/prototype.js" type="text/javascript"></script>
<script src="scriptaculous/scriptaculous.js?load=slider" type="text/javascript"></script>
</head>
<body>
<!--MyCode-->
<!-- stock table -->
<table width="766" border="0">
<tr>
<td><a href="http://www.lightstreamer.com" target="_blank">
<img src="images/logo.gif" alt="LIGHTSTREAMER" hspace="0" border="0" /></a></td>
<td class="demoTitle">STOCK-LIST DEMO</td>
</tr>
</table>
<div id="dvStatus"></div>
<br />
<table border="0">
<tr>
<td colspan="2" id="hlc" class="note" style="text-align:left;font-weight:bold;">Highlight Color</td>
</tr>
<tr>
<td colspan="2">
<div class="slideLine" id="selectColor">
<div class="blueCursor" id="selectBlue"> </div>
<div class="greenCursor" id="selectGreen"> </div>
<div class="redCursor" id="selectRed"> </div>
</div>
</td>
</tr>
</table>
<form name="myForm">
<input type="hidden" name="hiddencount" value="1" />
</form>
<table><div source="lightstreamer" table="a" item="item0" field="Count" style="display: none"></div></table>
<table id = "stocks" cellspacing="0" cellpadding="2" width="766" border="0" >
<tr class="tableTitle">
<td width="200" style="text-align: left">Ma CK</td>
<td width="100">Gia 3</td>
<td width="100">KL 3</td>
<td width="100">Gia 2</td>
<td width="100">KL 2</td>
<td width="100">Gia 1</td>
<td width="100">KL 1</td>
<td width="150">Gia</td>
<td width="100">KL</td>
<td width="150">Tong KL</td>
<td width="100">Gia 1</td>
<td width="100">KL 1</td>
<td width="100">Gia 2</td>
<td width="100">KL 2</td>
<td width="100">Gia 3</td>
<td width="100">KL 3</td>
<td width="100">Thoi Gian</td>
</tr>
<script>
//var schema1 =["Count"];
var schema =["gia3", "kl3", "gia2", "kl2", "gia1", "kl1", "gia", "kl", "tong_kl", "gia_1", "kl_1", "gia_2", "kl_2", "gia_3", "kl_3","time"];
var page1 = ["itemMa"];
var schema1=["Items"];
var flag = true;
var imgUp = '<img src="images/quotes_up.gif" alt="up" width="20" height="8" border="0">';
var imgDown = '<img src="images/quotes_down.gif" alt="down" width="20" height="8" border="0">';
var doFade = false;
var hotColor = "#f29e05";
var redColor = "#f8b87a";
var greenColor = "lightgreen";
var page = new PushPage();
page.onEngineCreation = function(engine) {
engine.connection.setAdapterName("PROXY_HELLOWORLD");
engine.changeStatus("STREAMING");
}
page.bind();
page.createEngine("HelloWorldApp", "LS", "SHARE_SESSION");
var pushtable = new OverwriteTable(page1, schema1, "MERGE");
pushtable.onItemUpdate = updateItem1;
page.onEngineReady = function(lsEngine) {
lsEngine.onStatusChange = function(newStatus) {
ShowStatus(newStatus, page.isMasterPushPage());
};
// take the current engine status into account
lsEngine.onStatusChange(lsEngine.getStatus());
};
page.onEngineLost = function() {
ShowStatus("WAITING FOR ENGINE...", true);
};
function updateItem1(item,updateInfo) {
if (updateInfo.isValueChanged("Items")){
var ars = updateInfo.getNewValue("Items").split('|');
if(ars != null){
if((parseInt(document.myForm.hiddencount.value) < ars.length)&&(flag)){
var page1Group = new Array(ars.length);
for(var i = 0;i<=ars.length-parseInt(document.myForm.hiddencount.value);i++){
addRow('stocks',i, ars[i]);
page1Group[i]="item"+ars[i];
}
page = new PushPage();
page.onEngineCreation = function(engine) {
engine.connection.setAdapterName("PROXY_HELLOWORLD");
engine.changeStatus("STREAMING");
}
}
page.bind();
pushtable = new OverwriteTable(page1Group, schema, "MERGE");
pushtable.setSnapshotRequired(true);
pushtable.setRequestedMaxFrequency(1.0);
pushtable.setPushedHtmlEnabled(true);
// set highlighting effect when updating a cell
pushtable.onChangingValues = function(itemPos, visualUpdateInfo, itemName) {
if (visualUpdateInfo != null) {
var cold = (itemPos % 2 == 1) ? "#eeeeee" : "#ddddee";
if(visualUpdateInfo !="#arrow")
visualUpdateInfo.setRowAttribute(hotColor, cold, "backgroundColor");
}
};
pushtable.onItemUpdate = updateItem;
page.addTable(pushtable, "stocks");
flag = false;
}
}
}
page.addTable(pushtable, "a");
//add row table
function addRow(tableID,i,itemID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var suff = (i % 2 == 0) ? "A" : "B";
var cell0 = row.insertCell(0);
cell0.innerHTML ='<td nowrap style="text-align: left"><a href="#"><img src="images/popup.gif" width="16" height="16" border="0" align="left" hspace="1" alt="Graphic Chart"><div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item'+ itemID +'" field="ma_ck">' + itemID + '</div></a></td>';
var cell1 = row.insertCell(1);
cell1.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item'+ itemID +'" field="gia3">-</div>';
var cell2 = row.insertCell(2);
cell2.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="kl3">-</div>';
var cell3 = row.insertCell(3);
cell3.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="gia2">-</div>';
var cell4 = row.insertCell(4);
cell4.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="kl2">-</div>';
var cell5 = row.insertCell(5);
cell5.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="gia1">-</div>';
var cell6 = row.insertCell(6);
cell6.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="kl1">-</div>';
var cell7 = row.insertCell(7);
cell7.innerHTML ='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="gia">-</div>';
var cell8 = row.insertCell(8);
cell8.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="#kl">-</div>';
var cell9 = row.insertCell(9);
cell9.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="tong_kl">-</div>';
var cell10 = row.insertCell(10);
cell10.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="gia_1">-</div>';
var cell11 = row.insertCell(11);
cell11.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="kl_1">-</div>';
var cell12 = row.insertCell(12);
cell12.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="gia_2">-</div>';
var cell13 = row.insertCell(13);
cell13.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="kl_2">-</div>';
var cell14 = row.insertCell(14);
cell14.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="gia_3">-</div>';
var cell15 = row.insertCell(15);
cell15.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="kl_3">-</div>';
var cell16 = row.insertCell(16);
cell16.innerHTML='<div class="stockname'+suff+'" source="lightstreamer" table="stocks" item="item' + itemID + '" field="time">-</div>';
}
///(Optional) Block Escape Key
document.onkeydown = checkEscape;
document.onkeypress = checkEscape;
function checkEscape(e) {
if(!e) e = event;
if(e.keyCode == 27) return false;
}
/////////////////////
if (location.search.indexOf("fade=ON") > -1) {
doFade = true;
}
//////////////// Event Handlers for the Stock Table
function updateItem(item, updateInfo) {
if (updateInfo == null) {
return;
}
// check for a void update, so as to ignore it;
// the case is possible when testing the Remote version of the Data Adapter
// in bundle with the Robust version of the Proxy Adapter
if(updateInfo.isValueChanged("tong_kl")&&(updateInfo.getOldValue("tong_kl")!=null)){
var kl = (updateInfo.getNewValue("tong_kl") - updateInfo.getOldValue("tong_kl"));
var test = '<div>'+kl.toFixed(2)+'</div>';
updateInfo.addField("#kl",test);
}
}
var colValues = new Array();
for (var x = 0; x <= 255; x++) {
colValues[colValues.length] = x;
}
new Control.Slider(['selectRed','selectGreen','selectBlue'],'selectColor',{sliderValue:[242,158,5],range:$R(0,255),step:1,increment:1,values:colValues,
onChange:function(v){
updateColInd(v);
},
onSlide:function(v){
updateColInd(v);
}});
document.getElementById("selectColor").style.backgroundColor = hotColor;
document.getElementById("hlc").style.color = hotColor;
function updateColInd(v) {
var colArr = v.toArray();
var applyCol = "rgb("+colArr[0]+","+colArr[1]+","+colArr[2]+")";
document.getElementById("selectColor").style.backgroundColor = applyCol;
document.getElementById("hlc").style.color = applyCol;
hotColor = applyCol;
}
//////////////// Stock Details Popup Management
var unique = Math.floor(Math.random() * 1000);
function openPopup(row,length) {
var Group = new Array(length);
for(var i = 0;i<=length;i++){
Group[i] = "item"+(i+1);
}
var item = Group[row-1];
var fadeStr = "";
if (doFade)
{
fadeStr = "&fade=ON";
}
wdt = window.open("popup.html?item=" + item + fadeStr, "SLDpopup_" + unique + "_" + item, "width=600,height=400,history=0,resizable,status=1,menubar=1");
wdt.focus();
return false;
}
function ShowStatus(content){
document.getElementById('dvStatus').innerHTML = content;
};
</script>
</table>
</body>
</html>
I don't know why only 1 tab have data...
There are 2 pictures
Bookmarks