diff --git a/PROMS/VEPROMS User Interface/frmVEPROMS.cs b/PROMS/VEPROMS User Interface/frmVEPROMS.cs index 61004513..d67cdace 100644 --- a/PROMS/VEPROMS User Interface/frmVEPROMS.cs +++ b/PROMS/VEPROMS User Interface/frmVEPROMS.cs @@ -449,7 +449,7 @@ namespace VEPROMS { log4net.Appender.FileAppender fApp = (log4net.Appender.FileAppender)iApp; string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - fApp.File = folderPath + @"\VEPROMS\" + NewFilename; + fApp.File = folderPath + @"\VEPROMS\" + (Volian.Base.Library.VlnSettings.GetCommand("U","") + "_").TrimStart("_".ToCharArray()) + NewFilename; ErrorLogFileName = fApp.File; fApp.ActivateOptions(); return true; // Appender found and name changed to NewFilename @@ -847,6 +847,7 @@ namespace VEPROMS private SessionInfo MySessionInfo; private System.Threading.Timer MyActivityTimer; + private System.Threading.Timer MyRefreshTimer; private DevComponents.DotNetBar.ButtonItem btnManageSecurity; private DevComponents.DotNetBar.ButtonItem btnResetSecurity; private DevComponents.DotNetBar.ButtonItem btnAdministrativeTools; @@ -855,17 +856,52 @@ namespace VEPROMS { get { return _MyCloseTabList; } } + private int myCounterPingSession = 0; + private int myCounterRefreshChanged = 0; private void PingSession(Object obj) { + myCounterPingSession++; + if (myCounterPingSession > 10) + { + _MyLog.InfoFormat("Ping Session at: {0} with LastChanged of: {1}", DateTime.Now.ToString("yyyyMMdd HHmmssnnn"), MySessionInfo.LastChanged); + myCounterPingSession = 0; + } + MySemaphore.WaitOne(); List myList = MySessionInfo.PingSession(); foreach (DisplayTabItem dti in tc.MyBar.Items) { if (!myList.Contains(dti.OwnerID)) MyCloseTabList.PushDTI(dti); } + MySemaphore.Release(); + } + private void RefreshChanged(Object obj) + { + myCounterRefreshChanged++; + if (myCounterRefreshChanged > 10) + { + _MyLog.InfoFormat("RefreshChanged at: {0} with LastChanged of: {1}", DateTime.Now.ToString("yyyyMMdd HHmmssnnn"), MySessionInfo.LastChanged); + myCounterRefreshChanged = 0; + } + MySemaphore.WaitOne(); + string lastChanged = string.Empty; + foreach (int id in MySessionInfo.ChangedContents.Keys) + { + using (Content c = Content.Get(id)) + { + _MyLog.InfoFormat("Text of contentid: {0} is {1}", id, c.Text); + ContentInfo.Refresh(c); + lastChanged = MySessionInfo.ChangedContents[id]; + _MyLog.InfoFormat("Refreshing contentid: {0} with LastChanged of {1}", id, lastChanged); + } + } + MySessionInfo.ChangedContents.Clear(); + if(lastChanged != string.Empty) + MySessionInfo.LastChanged = lastChanged; + MySemaphore.Release(); } public Timer tmrCloseTabItems; - + public System.Threading.Semaphore MySemaphore = new System.Threading.Semaphore(1, 1); private void frmVEPROMS_Load(object sender, EventArgs e) { InitializeSecurity(); @@ -922,11 +958,15 @@ namespace VEPROMS tv.MySessionInfo = MySessionInfo; System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false); //System.Threading.TimerCallback timerDelegate = new System.Threading.TimerCallback(MySessionInfo.PingSession); - System.Threading.TimerCallback timerDelegate = new System.Threading.TimerCallback(this.PingSession); - - if (!System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToLower().EndsWith("vshost")) - //MyActivityTimer = new System.Threading.Timer(timerDelegate, autoEvent, 30000, 30000); + //System.Diagnostics.Process xyzzy = System.Diagnostics.Process.GetCurrentProcess(); + if(!System.Diagnostics.Debugger.IsAttached) + { + System.Threading.TimerCallback timerDelegate = new System.Threading.TimerCallback(this.PingSession); MyActivityTimer = new System.Threading.Timer(timerDelegate, autoEvent, 10000, 10000); + System.Threading.Thread.Sleep(5000); + System.Threading.TimerCallback timerRefresh = new System.Threading.TimerCallback(this.RefreshChanged); + MyRefreshTimer = new System.Threading.Timer(timerRefresh, autoEvent, 10000, 10000); + } //string debugMode = ConfigurationManager.AppSettings["Debug"]; //VlnSettings.DebugMode = bool.Parse(debugMode); // set debug for the Volian.Controls.Library @@ -2220,8 +2260,7 @@ namespace VEPROMS { if (args.MyEditItem.MyItemInfo.IsSection || args.MyEditItem.MyItemInfo.IsProcedure) { - infotabRO.Visible = false; - infotabTransition.Visible = args.MyEditItem.MyItemInfo.ActiveFormat.PlantFormat.FormatData.TransData.AllowTransitionFromSection; + infotabRO.Visible = infotabTransition.Visible = false; infotabTags.Visible = false; displayTags.Visible = false; } @@ -2779,9 +2818,9 @@ namespace VEPROMS { if (tc.SelectedDisplayTabItem != null && tc.SelectedDisplayTabItem.MyStepTabPanel.SelectedEditItem != null) { - frmPropGrid pg = new frmPropGrid(tc.SelectedDisplayTabItem.MyStepTabPanel.SelectedEditItem, "EditItem"); - pg.Show(); - } + frmPropGrid pg = new frmPropGrid(tc.SelectedDisplayTabItem.MyStepTabPanel.SelectedEditItem, "EditItem"); + pg.Show(); + } else MessageBox.Show("Select Item First", "Item not selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index c1596ba2..e4d82813 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -554,6 +554,10 @@ namespace VEPROMS.CSLA.Library } public partial class ContentInfo { + public static bool IsInCache(int contentID) + { + return _CacheByPrimaryKey.ContainsKey(contentID.ToString()); + } public static event StaticContentInfoEvent StaticContentInfoChange; private static void OnStaticContentInfoChange(object sender, StaticContentInfoEventArgs args) { @@ -979,5 +983,66 @@ namespace VEPROMS.CSLA.Library } this.RaiseListChangedEvents = true; } + public static ContentInfoList GetChangedList(byte[] lastChanged) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new ChangeListCriteria(lastChanged)); +// ContentInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.GetChangedList", ex); + } + } + [Serializable()] + private class ChangeListCriteria + { + private byte[] _LastChanged; + public byte[] LastChanged + { + get { return _LastChanged; } + set { _LastChanged = value; } + } + public ChangeListCriteria(byte[] lastChanged) + { + _LastChanged = lastChanged; + } + } + private void DataPortal_Fetch(ChangeListCriteria criteria) + { + this.RaiseListChangedEvents = false; + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ListContentsAfterLastChanged"; + cm.Parameters.AddWithValue("@LastChanged", criteria.LastChanged); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentInfo contentInfo = new ContentInfo(dr); + this.Add(contentInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("ContentInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } } } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs index 5e6a2757..ac24bbc0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs @@ -68,6 +68,17 @@ namespace VEPROMS.CSLA.Library #region SessionInfo stuff public partial class SessionInfo { + private string _LastChanged = string.Empty; + public string LastChanged + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("LastChanged", true); + return _LastChanged; + } + set { _LastChanged = value; } + } public static SessionInfo BeginSession(string machineName, int processID) { try @@ -85,10 +96,26 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on SessionInfo.BeginSession", ex); } } + private Dictionary _ChangedContents; + public Dictionary ChangedContents + { + get { return _ChangedContents; } + set { _ChangedContents = value; } + } public List PingSession() { List myList = new List(); SessionPing.Execute(this.SessionID); + ChangedContents = SessionChangedContents.Execute(this.LastChanged); + //ContentInfoList cil = ContentInfoList.GetChangedList(Convert.FromBase64String(this.LastChanged)); + //foreach (ContentInfo ci in cil) + // if (!ChangedContentIDs.ContainsKey(ci.ContentID)) + // ChangedContentIDs.Add(ci.ContentID, false); + //foreach(ContentInfo ci in cil) + // if(ContentInfo.IsInCache(ci.ContentID)) + // using (Content cc = ci.Get()) + // ContentInfo.Refresh(cc); + OwnerInfoList oil = OwnerInfoList.GetBySessionID(this.SessionID); foreach (OwnerInfo oi in oil) myList.Add(oi.OwnerID); @@ -188,6 +215,7 @@ namespace VEPROMS.CSLA.Library return; } ReadData(dr); + _LastChanged = Convert.ToBase64String(dr["LastChanged"] as byte[]); } } // removing of item only needed for local data portal @@ -572,6 +600,58 @@ namespace VEPROMS.CSLA.Library } #endregion } + public class SessionChangedContents : CommandBase + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private string _LastChanged; + public string LastChanged + { + get { return _LastChanged; } + set { _LastChanged = value; } + } + private Dictionary _ChangedContents; + public Dictionary ChangedContents + { + get { return _ChangedContents; } + set { _ChangedContents = value; } + } + #region Factory Methods + public static Dictionary Execute(string lastChanged) + { + SessionChangedContents cmd = new SessionChangedContents(); + cmd.LastChanged = lastChanged; + cmd = DataPortal.Execute(cmd); + return cmd.ChangedContents; + } + #endregion + #region Server-Side Code + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = new SqlCommand("vesp_ListContentsAfterLastChanged2", cn)) + { + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandTimeout = 0; + cmd.Parameters.AddWithValue("@LastChanged", Convert.FromBase64String(LastChanged)); + cmd.Parameters.AddWithValue("@UserID", Volian.Base.Library.VlnSettings.UserID); + SqlDataReader dr = cmd.ExecuteReader(); + ChangedContents = new Dictionary(); + while (dr.Read()) + ChangedContents.Add(dr.GetInt32(0), Convert.ToBase64String(dr["LastChanged"] as byte[])); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionChangedContents Error", ex); + throw new ApplicationException("Failure on SessionChangedContents", ex); + } + } + #endregion + } #endregion #region OwnerInfo stuff public partial class OwnerInfoList