public OCLWriter(string ApplicationName, string ApplicationVersion, int UserId,ref OysterClassLibrary.Oyster OSystem) { this.ApplicationName = ApplicationName; this.UserId = UserId; this.OSystem = OSystem; OSVersion = System.Environment.OSVersion.ToString(); MachineName = System.Environment.MachineName; MachineIPAddress = System.Net.Dns.Resolve(Environment.MachineName).AddressList[0].ToString(); UserName = System.Environment.UserDomainName + "\\" + System.Environment.UserName; this.ApplicationVersion = ApplicationVersion; }
private void btnPostBack_ServerClick(object sender, System.EventArgs e) { //lbStatus.Visible = false; OysterClassLibrary.Oyster O = null; try { //string sServer = "10.1.0.100"; //O = new OysterClassLibrary.Oyster(sServer,"oyster1"); //O = new OysterClassLibrary.Oyster(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]); O = new OysterClassLibrary.Oyster(); } catch(Exception Err) { txtAlert.Value = Err.Message + System.Environment.MachineName; return; } try { OysterClassLibrary.User LUser = O.Login(tbUsername.Value,tbPassword.Value); if(LUser != null) { Session["LUser"] = LUser; Session["Oyster"] = O; tbUsername.Value = ""; tbPassword.Value = ""; int IsChecked = Convert.ToInt32(txtChecked.Value,10); if(IsChecked == 0) Response.Redirect("LoadScreen.aspx",true); else Response.Redirect("frmPassword.aspx",true); } else { //Response.Write("<Script> window.alert('Invalid User Id or Password'); </script>"); txtAlert.Value = "Invalid User Id or Password"; } } catch(Exception Err) { //Response.Write("<Script> window.alert('" + Err.Message + "'); </script>"); txtAlert.Value = Err.Message; } }
private void Button1_ServerClick(object sender, System.EventArgs e) { //LUser =(OysterClassLibrary.User) Session["LUser"]; txtDidOnce.Value = "DIDONCE"; OSystem = (OysterClassLibrary.Oyster) Session["Oyster"]; int RMID = Convert.ToInt32(txtRoomId.Value,10); int LUID = Convert.ToInt32(txtLUserId.Value,10); LUser = OSystem.GetUserById(LUID); OysterClassLibrary.Room RM = OSystem.GetRoomById(RMID); lbTitle.Value = "Recording Scene: " + RM.Description; tbStartTime.Value = System.DateTime.Now.ToShortTimeString(); tbEndTime.Value = System.DateTime.Now.AddHours(2).ToShortTimeString(); m_broker = new OCTLNET.Broker(); Msg("Attempting to create a new control agent..."); m_conn = m_broker.Create(RM.AllCurrentStreamingEncoders.Item(0).CurrentMediaBufferServer.Address); Msg("successfully created control agent for " + LUser.Description); Session["Connection"] = m_conn; Session["Broker"] = m_broker; if(!m_conn.Open()) { Msg("Agent failed to connect to Oyster System"); Msg("killing agent.."); txtCloseApp.Value = "Error: Failed to start recording. Unable to establish connection."; return; } Msg("Agent successfully connected to Oyster System"); int CardReaderId = RM.AllCurrentCardReaders.Item(0).ID; m_conn.CreateSession(CardReaderId); m_conn.Swipe(LUser.CardNumber); Session["Connection"] = m_conn; Session["Broker"] = m_broker; }
private void frmTestThis_Load(object sender, System.EventArgs e) { OO = new OysterClassLibrary.Oyster(); columnHeader1.Width = listView1.Width; // instead of using the ROOMS member of the OCL, copy only the Rooms // we want to see into an ArrayList. That way we can skip those Rooms // we don't ever want to select like 'Not Assigned' System.Collections.ArrayList Rooms = new System.Collections.ArrayList(); foreach (OysterClassLibrary.Room r in OO.ROOMS) { if (r.ID != OO.UnassignedIDs[(int)UnassignedSystemObjects.Room]) Rooms.Add(r); } comboBox1.DataSource = Rooms; comboBox1.DisplayMember = "Description"; comboBox1.ValueMember = "ID"; m_con.MessageReceived += new OCTLNET.Connection.MessageReceivedHandler(m_con_MessageReceived); }
void ThreadProc() { _stopEvent.Reset(); string myPath = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location); string myConfig = myPath + @"\applicationConfig.xml"; ApplicationSettings mySettings = new ScheduledFtpService.ApplicationSettings(); string SourceDirectoryPath; string FailedDirectoryPath; string ManagementServerAddress; string ManagementServerPassword; if (!File.Exists(myConfig)) { Log.WriteLog(myConfig + " does not exist. Creating one."); ClearAndWriteSettingsRow(mySettings); mySettings.WriteXml(myConfig); } mySettings.ReadXml(myConfig); ApplicationSettings.SettingsRow settingsRow; if (mySettings.Settings.Count == 0) { Log.WriteLog("There are no settings in " + myConfig); ClearAndWriteSettingsRow(mySettings); } settingsRow = mySettings.Settings[0]; if (settingsRow.SourceDirectory.Length == 0) { Log.WriteLog("SourceDirectory in " + myConfig + " is empty. Exiting."); _done = true; return; } ManagementServerAddress = settingsRow.ManagementServerAddress; if (ManagementServerAddress.Length == 0) { Log.WriteLog("ManagementServerAddress in " + myConfig + " is empty. Exiting."); _done = true; return; } if (settingsRow.IsIdEncrypted) ManagementServerPassword = CarverLab.Utility.Crypto.DecryptFromBase64String(settingsRow.ManagementServerId); else ManagementServerPassword = settingsRow.ManagementServerId; SourceDirectoryPath = settingsRow.SourceDirectory; FailedDirectoryPath = Path.Combine(SourceDirectoryPath, "Failed"); DirectoryInfo SourceDirectoryInfo = TryGetDirectory(SourceDirectoryPath); if (SourceDirectoryInfo == null) return; DirectoryInfo FailedDirectoryInfo = TryGetDirectory(FailedDirectoryPath); if (FailedDirectoryInfo == null) return; int TransferRetryMaxCount = mySettings.Settings[0].TransferRetryMaxCount; if (TransferRetryMaxCount == 0) { TransferRetryMaxCount = 3; } HybridDictionary WaitingFileList = new HybridDictionary(); Session ftpSession = null; while (!_done) { try { FileInfo[] FileInfoList = SourceDirectoryInfo.GetFiles("*.xml"); SortedList SortedFileInfoList = new SortedList( new FileInfoDateComparer(FileInfoDateComparer.DateCompareType.CreationTime)); foreach (FileInfo fi in FileInfoList) { if (!SortedFileInfoList.Contains(fi)) SortedFileInfoList.Add(fi,fi); else // this should never happen, but it did! what?!??! Log.WriteLog("For some reason, " + fi.FullName + " showed up twice in the directory!"); } foreach (DictionaryEntry entry in SortedFileInfoList) { if (_done) break; FileInfo xmlFileInfo = entry.Value as FileInfo; ScheduledFTPFile transferFile = new ScheduledFTPFile(); ScheduledFTPFile.FileUploadRow row; try { transferFile.ReadXml(xmlFileInfo.FullName); } catch (System.Exception e) { Log.WriteLog(xmlFileInfo.FullName + " Exception: " + e.Message); OnFireUploadedEvent(xmlFileInfo.FullName, false); continue; } row = transferFile.FileUpload[0]; string wmvPath = row.FilePath; if (!File.Exists(wmvPath)) { Log.WriteLog(wmvPath + " does not exist. Moving to Failed directory."); try { File.Move(xmlFileInfo.FullName, FailedDirectoryInfo.FullName + "\\" + xmlFileInfo.Name); } catch (System.Exception e) { Log.WriteLog("Could not move " + xmlFileInfo.FullName + ": " + e.Message); } OnFireUploadedEvent(xmlFileInfo.FullName, false); continue; } // open the file and see if it is in use... if it is, continue and try again... // and keep trying until WME lets go of the file... sheesh try { Log.WriteLog("Checking to see if " + wmvPath + " is still held by the encoder..."); FileStream fileCheck = new FileStream(wmvPath, FileMode.Open, FileAccess.ReadWrite); fileCheck.Close(); Log.WriteLog(wmvPath + " is free to upload."); } catch (System.Exception e) { if (e.Message.IndexOf("because it is being used") != -1) { Log.WriteLog("Yep, " + wmvPath + " is in use. Will try again... and again."); continue; } // just try again anyway... Log.WriteLog("Error: " + wmvPath + " error: " + e.Message); continue; } if (ftpSession != null) { Log.WriteLog("*** ERROR *** : ftpSession variable should be null!"); if (ftpSession.IsConnected) ftpSession.Close(); ftpSession = null; //throw new ApplicationException("ftpSession should be null. There must be a serious problem."); } ftpSession = new Session(); ftpSession.Server = row.ServerAddress; ftpSession.Port = row.ServerPort; string user, pass; if (row.EncryptedCredentials) { user = Crypto.DecryptFromBase64String(row.User); pass = Crypto.DecryptFromBase64String(row.Password); } else { user = row.User; pass = row.Password; } try { Log.WriteLog("Connecting to ftp server..."); ftpSession.Connect(user, pass); } catch (Exception ftpex) { Log.WriteLog("Could not connect to " + row.ServerAddress + ":" + row.ServerPort + ftpex.Message); OnFireUploadedEvent(xmlFileInfo.FullName, false); continue; } FtpDirectory dir; Log.WriteLog("Setting ftp current directory to " + row.Directory); if (row.Directory.Length == 0 || row.Directory == ".") { dir = ftpSession.CurrentDirectory; Log.WriteLog("Current ftp directory: " + dir.FullName); } else { Log.Verbose("Subdirectories:"); foreach (FtpDirectory dd in ftpSession.CurrentDirectory.SubDirectories) { Log.Verbose(string.Format("Name: {0}; Full name: {1};", dd.Name, dd.FullName)); } dir = ftpSession.CurrentDirectory.FindSubdirectory(row.Directory, true); if (dir == null) { Log.WriteLog("Subdirectory " + row.Directory + " doesn't exist on the server."); File.Move(xmlFileInfo.FullName, FailedDirectoryInfo.FullName + "\\" + xmlFileInfo.Name); OnFireUploadedEvent(xmlFileInfo.FullName, false); continue; } Log.WriteLog("Uploading to ftp directory: " + dir.FullName); } try { Log.WriteLog("Opening file " + wmvPath); Stream localStream = File.OpenRead(wmvPath); Log.WriteLog("Creating ftp stream."); string wmvName = Path.GetFileName(wmvPath); Stream remoteStream = dir.CreateFileStream(wmvName); int readed; byte[] uploadBuffer = new byte[4096]; Log.WriteLog("Transferring file " + wmvName); while ((readed = localStream.Read(uploadBuffer,0,4096)) != 0) { if (_done) break; remoteStream.Write(uploadBuffer, 0, 4096); } if (_done) break; remoteStream.Close(); localStream.Close(); ftpSession.Close(); ftpSession = null; Log.WriteLog("Transfer complete on file " + xmlFileInfo.FullName); Log.WriteLog("Connecting to Oyster system at " + ManagementServerAddress); OysterClassLibrary.Oyster oyster = new OysterClassLibrary.Oyster( ManagementServerAddress, ManagementServerPassword); OysterClassLibrary.Recording rec = oyster.GetRecordingByName(wmvName); if (rec == null) { throw new ApplicationException(wmvName + " is not a valid recording on the server."); } rec.IsReady = true; Log.WriteLog("Recording is ready: " + wmvName); xmlFileInfo.Delete(); Log.WriteLog("Deleted : " + xmlFileInfo.Name); System.IO.File.Delete(wmvPath); Log.WriteLog("Deleted : " + wmvName); OnFireUploadedEvent(xmlFileInfo.FullName, true); } catch (System.Exception upex) { Log.WriteLog("Transfer failed: " + xmlFileInfo.FullName + ": " + upex.Message); TryFileMove(xmlFileInfo.FullName, Path.Combine( FailedDirectoryInfo.FullName, xmlFileInfo.Name)); OnFireUploadedEvent(xmlFileInfo.FullName, false); continue; } } System.Threading.Thread.Sleep(1000); } catch (System.Exception mainex) { Log.WriteLog("Exception in main loop: " + mainex.ToString()); if (ftpSession != null) { if (ftpSession.IsConnected) { ftpSession.Close(); } ftpSession = null; } } } _stopEvent.Set(); }
static void Main(string[] args) { try { try { string sRecordingName, sMBSLog; System.Collections.Specialized.StringCollection scLines; string sCurrentLine; int iCurrentLine = 0; System.IO.FileInfo fileinfo; string sFileTitle, sFullPathTitle; int iAgeInMinutes = 240; sRecordingName = args[0]; sMBSLog = args[1]; if (args.GetLength(0) >= 3) { iAgeInMinutes = System.Convert.ToInt32(args[2]); } if (!System.IO.File.Exists(sRecordingName)) { Console.WriteLine(sRecordingName + " does not exist. Exiting."); return; } fileinfo = new System.IO.FileInfo(sRecordingName); if (fileinfo.Extension.ToLower() != ".mpg") { Console.WriteLine(sRecordingName + " must have a .mpg extension. Exiting."); return; } sFileTitle = fileinfo.Name.Substring(0,fileinfo.Name.Length - fileinfo.Extension.Length); sFullPathTitle = fileinfo.FullName.Substring(0,fileinfo.FullName.Length - fileinfo.Extension.Length); if (System.IO.File.Exists(sFullPathTitle + ".xml")) { Console.WriteLine(sRecordingName + " already has an XML file associated with it. Creating a recording from the xml file, if it doesn't already exist."); OysterClassLibrary.Oyster oyster = new OysterClassLibrary.Oyster(); OysterClassLibrary.Recording rec = oyster.GetRecordingByName(sFileTitle + ".wmv"); if (rec != null) { Console.WriteLine(sFileTitle + ".wmv" + " already exists as a recording. Exiting."); return; } CarverLab.Utility.CARDVIDEO cv;// = new CarverLab.Utility.CARDVIDEO(); System.Xml.Serialization.XmlSerializer xmlser = new System.Xml.Serialization.XmlSerializer(typeof(CarverLab.Utility.CARDVIDEO)); System.IO.StreamReader xmlfile = System.IO.File.OpenText(sFullPathTitle + ".xml"); cv = (CarverLab.Utility.CARDVIDEO) xmlser.Deserialize(xmlfile); OysterClassLibrary.User usr = oyster.GetUserByCardNumber(cv.CARDID); // make a recording in the db for this user with this name in this room rec = oyster.CreateRecording(sFileTitle + ".wmv",cv.DISPLAYNAME,usr.ID, cv.VIDEOSTORAGESERVERID,cv.STREAMINGENCODERID,null,null); //now change the date to the date of the MPG file rec.CreatedDate = fileinfo.CreationTime; if (rec == null) { Console.WriteLine("could not create a recording. Exiting."); } else Console.WriteLine("recording created."); return; } System.TimeSpan ts = DateTime.Now - fileinfo.CreationTime; if (ts.TotalMinutes < iAgeInMinutes) { Console.WriteLine(sRecordingName + " is only " + ts.TotalMinutes + " minutes old. Not old enough. Exiting."); return; } if (fileinfo.Length == 0) { Console.WriteLine(sRecordingName + " is empty. Exiting."); return; } Console.WriteLine("rbr searching for " + sRecordingName + " in " + sMBSLog); scLines = new System.Collections.Specialized.StringCollection(); string sptnDateTime = @"\[(?<date>[0-9]{1,2}/[0-9]{1,2}/[0-9]{4})\x20(?<time>[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})\]"; string sptnCardId = @"\sm_sCardId\x20=\x20;(?<cardid>[0-9]+=)"; string sptnRoomId = @"\sm_dwRoomId\x20=\x20(?<roomid>[0-9]+),"; // string sptnCardSwipeId = @"\sm_dwCardSwipeId\x20\=\x20(?<cardswipeid>[0-9]+\,"; // string sptnCommand = @"\sm_eCommand\x20\=\x20(?<command>[0-9]+\"; string sptnGF = sptnDateTime + @"\x20CMediaBufferServer::GenerateFilename\(.+" + sFileTitle + @".mpg\)"; string sptnEncoderAddress = sptnDateTime + @"\x20CMediaBufferServer::StartRecording\(STREAM_PROTOCOL\)\x20from\x20" + @"(?<ipaddress>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}):(?<port>[0-9]+)"; // @"(?<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}):(?<port>\d+)"; string sptnEncoderRoomAndId = sptnDateTime + @"\x20CStreamingEncoder\[(?<roomid>[0-9]+),(?<encoderid>[0-9]+)\]" + @"::StartRecording:\x20starting\x20encoder\x20at\x20"; //TODO:add encoder address:port for accurate search System.Text.RegularExpressions.Regex regex; System.Text.RegularExpressions.Match match; int iRoomId = 0; // int iCardReaderId; int iEncoderId = 0; string sEncoderAddress = ""; int iEncoderPort = 0; // int iCommand; string sCardNumber = ""; DateTime dtGF = DateTime.MinValue, dtCurrent = DateTime.MaxValue; bool bErroredOut = false; string sptn; bool bDone = false; System.IO.TextReader tr = System.IO.File.OpenText(sMBSLog); SearchingState CurrentState = SearchingState.GF; while (!bDone) { switch (CurrentState) { case SearchingState.GF: // find the file on the MBS::GenerateFilename line sptn = sptnGF; regex = new System.Text.RegularExpressions.Regex(sptn); while (true) { sCurrentLine = tr.ReadLine(); if (sCurrentLine == null) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } scLines.Add(sCurrentLine); iCurrentLine = scLines.Count - 1; match = regex.Match(scLines[iCurrentLine]); if (match.Success) { string sdate = match.Groups["date"].Value; string stime = match.Groups["time"].Value; dtGF = System.DateTime.Parse(sdate + " " + stime); CurrentState = SearchingState.EncoderAddress; break; } } break; case SearchingState.EncoderAddress: // backup to the least previous encoder address line sptn = sptnEncoderAddress; regex = new System.Text.RegularExpressions.Regex(sptn); while (true) { --iCurrentLine; if (iCurrentLine <= 0) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } match = regex.Match(scLines[iCurrentLine]); if (match.Success) { string sdate = match.Groups["date"].Value; string stime = match.Groups["time"].Value; dtCurrent = System.DateTime.Parse(sdate + " " + stime); sEncoderAddress = match.Groups["ipaddress"].Value; iEncoderPort = System.Convert.ToInt32(match.Groups["port"].Value); CurrentState = SearchingState.RoomId; break; } } break; case SearchingState.RoomId: // backup to the least previous room id line sptn = sptnEncoderRoomAndId + sEncoderAddress + ":" + iEncoderPort.ToString(); regex = new System.Text.RegularExpressions.Regex(sptn); while (true) { --iCurrentLine; if (iCurrentLine <= 0) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } match = regex.Match(scLines[iCurrentLine]); if (match.Success) { string sdate = match.Groups["date"].Value; string stime = match.Groups["time"].Value; dtCurrent = System.DateTime.Parse(sdate + " " + stime); iRoomId = System.Convert.ToInt32(match.Groups["roomid"].Value); iEncoderId = System.Convert.ToInt32(match.Groups["encoderid"].Value); CurrentState = SearchingState.CardRoomId; break; } } break; case SearchingState.CardRoomId: // backup to the least previous line with the room id on it sptn = sptnRoomId; regex = new System.Text.RegularExpressions.Regex(sptn); while (true) { --iCurrentLine; if (iCurrentLine <= 0) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } match = regex.Match(scLines[iCurrentLine]); if (match.Success) { if (iRoomId == System.Convert.ToInt32(match.Groups["roomid"].Value)) { CurrentState = SearchingState.CardId; break; } } } break; case SearchingState.CardId: // backup to the least previous card id line sptn = sptnCardId; regex = new System.Text.RegularExpressions.Regex(sptn); while (true) { --iCurrentLine; if (iCurrentLine <= 0) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } match = regex.Match(scLines[iCurrentLine]); if (match.Success) { string scardid = match.Groups["cardid"].Value; sCardNumber = scardid.Substring(scardid.Length - 11,10); CurrentState = SearchingState.MakingRecording; break; } else { bErroredOut = true; CurrentState = SearchingState.CleaningUp; } } break; case SearchingState.MakingRecording: // search for the user with this userid OysterClassLibrary.Oyster oyster = new OysterClassLibrary.Oyster(); OysterClassLibrary.User usr = oyster.GetUserByCardNumber(sCardNumber); OysterClassLibrary.StreamingEncoder se = oyster.GetStreamingEncoderById(iEncoderId); string sDisplayName = dtGF.ToString("MM/dd/yyyy hh:mm tt"); if (usr == null) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } // make a recording in the db for this user with this name in this room OysterClassLibrary.Recording rec = oyster.CreateRecording(sFileTitle + ".wmv",sDisplayName,usr.ID, se.CurrentRoom.VideoStorageServerID,se.ID,null,null); if (rec == null) { bErroredOut = true; CurrentState = SearchingState.CleaningUp; break; } // make the xml file for this recording CarverLab.Utility.CARDVIDEO cv = new CarverLab.Utility.CARDVIDEO(); System.Xml.Serialization.XmlSerializer xmlser = new System.Xml.Serialization.XmlSerializer(typeof(CarverLab.Utility.CARDVIDEO)); System.IO.StreamWriter xmlfile = System.IO.File.CreateText(sFullPathTitle + ".xml"); cv.FILENAME = fileinfo.FullName; cv.CARDID = sCardNumber; cv.DISPLAYNAME = sDisplayName; cv.FILETITLE = sFileTitle; cv.ROOMID = iRoomId; cv.STREAMINGENCODERID = iEncoderId; cv.TIMESTART = dtGF; cv.VIDEOSTORAGESERVERID = se.CurrentRoom.VideoStorageServerID; /* cv.BITRATE = "0"; cv.MPEGFORMAT = "n/a"; cv.SESSIONID = "n/a"; cv.SESSIONNAME = "n/a"; */ xmlser.Serialize(xmlfile,cv); bErroredOut = false; CurrentState = SearchingState.CleaningUp; break; case SearchingState.CleaningUp: if (bErroredOut) { Console.WriteLine("An error occured. Unable to find correct information. Cleaning up for exit."); } else { Console.WriteLine("Work is complete. Cleaning up for exit."); } bDone = true; break; default: throw new ApplicationException("Unknown SearchingState: " + CurrentState); } } } catch (System.IndexOutOfRangeException) { Start.DisplayUsage(); } } catch (System.Exception ex) { Console.WriteLine("Unknown Exception occurred {0}", ex.Message); Console.WriteLine("Here is the Full Message output"); Console.WriteLine("{0}", ex.ToString()); } }
void MakeXMLFile(string[] MPEGPathName, string XMLPath, OysterClassLibrary.User User, OysterClassLibrary.StreamingEncoder StreamingEncoder) { OysterClassLibrary.Oyster oyster = new OysterClassLibrary.Oyster(); OysterClassLibrary.User usr = User; OysterClassLibrary.StreamingEncoder se = StreamingEncoder; OysterClassLibrary.Recording rec; bool bMakeSession = false, bFirstTime = true; string sSessionId = Guid.NewGuid().ToString(), sSessionName = ""; FileInfo fiMPEG; if (chkSingleSession.Checked) { bMakeSession = true; } int i = 0; foreach (string mpegfile in MPEGPathName) { fiMPEG = new FileInfo(mpegfile); if (string.Compare(fiMPEG.Extension,".mpg",true) != 0) { MessageBox.Show("All MPEG files must have a .mpg extension. Stopping."); break; } string sDisplayName = fiMPEG.CreationTime.ToString("MM/dd/yyyy hh:mm tt"); string sRecordingName; if (bFirstTime) { bFirstTime = false; sSessionName = sDisplayName; } if (bMakeSession) { sRecordingName = "Camera " + (char) ('A' + i++); } else sRecordingName = sDisplayName; string sFileTitle = fiMPEG.Name.Substring(0,fiMPEG.Name.Length - 4); rec = oyster.GetRecordingByName(sFileTitle + ".wmv"); if (rec != null) { if (MessageBox.Show(this,sFileTitle + ".wmv is already in the database. Delete it and continue?", "Recording Already Exists...",MessageBoxButtons.YesNo) == DialogResult.Yes) { oyster.DeleteRecordingById(rec.ID); } else { MessageBox.Show("Cannot continue with an already existing recording. Stopping."); break; } } // make a recording in the db for this user with this name in this room if (bMakeSession) { rec = oyster.CreateRecording(sFileTitle + ".wmv",sRecordingName,usr.ID, se.CurrentRoom.VideoStorageServerID,se.ID,sSessionId,sSessionName); } else { rec = oyster.CreateRecording(sFileTitle + ".wmv",sRecordingName,usr.ID, se.CurrentRoom.VideoStorageServerID,se.ID,null,null); } if (rec == null) { MessageBox.Show("Recording " + sFileTitle + " could not be created. Stopping."); break; } // make the xml file for this recording CarverLab.Utility.CARDVIDEO cv = new CarverLab.Utility.CARDVIDEO(); System.Xml.Serialization.XmlSerializer xmlser = new System.Xml.Serialization.XmlSerializer(typeof(CarverLab.Utility.CARDVIDEO)); System.IO.StreamWriter xmlfile = System.IO.File.CreateText( XMLPath + @"\" + sFileTitle + ".xml"); cv.FILENAME = mpegfile; cv.CARDID = usr.CardNumber; cv.DISPLAYNAME = sRecordingName; cv.FILETITLE = sFileTitle; cv.ROOMID = se.CurrentRoom.ID; cv.STREAMINGENCODERID = se.ID; cv.TIMESTART = DateTime.Now; cv.VIDEOSTORAGESERVERID = se.CurrentRoom.VideoStorageServerID; if (bMakeSession) { cv.SESSIONID = sSessionId; cv.SESSIONNAME = sSessionName; } xmlser.Serialize(xmlfile,cv); } MessageBox.Show(this,"Done."); }
private void frmStart_Load(object sender, System.EventArgs e) { // browse for input directory folderBrowserDialog1.SelectedPath = Environment.GetFolderPath(folderBrowserDialog1.RootFolder); folderBrowserDialog2.SelectedPath = Environment.GetFolderPath(folderBrowserDialog2.RootFolder); lblOutputFolder.Text = folderBrowserDialog1.SelectedPath; lblInputFolder.Text = folderBrowserDialog2.SelectedPath; DirectoryInfo di = new DirectoryInfo(folderBrowserDialog2.SelectedPath); foreach (FileInfo fi in di.GetFiles()) { if (string.Compare(fi.Extension,".mpg",true) == 0) { ListViewItem lvi = new ListViewItem( new string[] {fi.Name,fi.Length.ToString("N"),fi.CreationTime.ToString("G"), fi.LastAccessTime.ToString("G")}); lvi.Tag = fi; listView1.Items.Add(lvi); } } OysterClassLibrary.Oyster oyster = new OysterClassLibrary.Oyster(); foreach (OysterClassLibrary.User usr in oyster.CurrentSystemUsers) { if (usr.LoginName != "sa") { comboBox1.Items.Add(usr); } } comboBox1.DisplayMember = "LoginName"; foreach (OysterClassLibrary.StreamingEncoder se in oyster.STREAMINGENCODERS) { if (se.ControlAddress != "Not Assigned") { comboBox2.Items.Add(se); } } comboBox2.DisplayMember = "ControlAddress"; comboBox1.SelectedItem = comboBox1.Items[0]; comboBox2.SelectedItem = comboBox2.Items[0]; lvwColumnSorter = new ListViewColumnSorter(); this.listView1.ListViewItemSorter = lvwColumnSorter; }
private void btnLoginName_Click(object sender, System.EventArgs e) { string g_sLoginName = tbLoginName.Text; string g_sLoginPassword = tbLoginPassword.Text; this.Opacity = 0; FrmParent.Msg("Authenticating User..."); MyGlobals.Logger.WriteLog("authenticating {0}", g_sLoginName); tryagain:{} try { OSystem = new OysterClassLibrary.Oyster(); } catch (Exception Err) { this.Opacity = 100; if (Err.Message == "SQL Server does not exist or access denied.") { MyGlobals.Logger.WriteLog("SQL Server not found. Asking for server location."); DialogResult DR = MessageBox.Show("Do you wish to try to locate the server manually", CarverLab.Utility.AppInfo.Title + ": Server connection error.", System.Windows.Forms.MessageBoxButtons.YesNo); if(DR == DialogResult.No) { this.DialogResult = DialogResult.Abort; return; } frmServerLocation SL = new frmServerLocation(); DR = SL.ShowDialog(this); if (DR != DialogResult.OK) { this.DialogResult = DialogResult.Abort; return; } goto tryagain; } else { MyGlobals.Logger.WriteLog("SQL Server not found. Exception: {0}.", Err.ToString()); MessageBox.Show(this, Err.Message, CarverLab.Utility.AppInfo.Title + ": Server connection error."); this.DialogResult = DialogResult.None; return; } } try { try { LoginUser = OSystem.Login(g_sLoginName,g_sLoginPassword); } catch (Exception Err) { string peek = Err.Message; MyGlobals.Logger.WriteLog("Login error. Exception: {0}.", Err.ToString()); MessageBox.Show("Invalid Login ID or Password.", CarverLab.Utility.AppInfo.Title + ": Login Message"); return; } if(LoginUser != null) { if(!CheckForValidLicense(LoginUser)) { LoginUser = null; return; } FrmParent.Msg("User authenticated."); } if(OSystem.SystemAdminLoginDenied == true) { MessageBox.Show("Someone has already logged in with System Administrator access...\nYour SYSTEM privileges are being set to READONLY Access.\nFor Full Access please try to login again at a later time.",CarverLab.Utility.AppInfo.Title + ": System Administrator account in use!"); } } catch(Exception Err) { //Splash.Dispose(); if(Err.Message == "SQL Server does not exist or access denied.") { DialogResult DR = MessageBox.Show("Do you wish to try to locate the server manually","Unable to establish a connection to Oyster Server",System.Windows.Forms.MessageBoxButtons.YesNo); if(DR == DialogResult.No) { this.DialogResult = DialogResult.Abort; return; } frmServerLocation SL = new frmServerLocation(); DR = SL.ShowDialog(this); if(DR != DialogResult.OK) { this.DialogResult = DialogResult.Abort; return; } goto tryagain; } else { this.Opacity = 100; #if USE_LICENSING MessageBox.Show("Possible license authentication error.","Unknown Error"); #else MessageBox.Show(Err.Message, "Oyster Hardcopy Error"); #endif MessageBox.Show("Application will now close","Oyster Hardcopy"); this.DialogResult = DialogResult.Abort; return; } } #if USE_CARDSCAN if(g_COMPORT != cbConfigureCardScan.Text.ToString()) { g_COMPORT = cbConfigureCardScan.Text.ToString(); RK = Registry.CurrentUser.OpenSubKey("Software\\" + sProductKey,true); RK.SetValue("COMPORT",g_COMPORT); } #endif this.DialogResult = DialogResult.OK; }
private void btnLoginName_Click(object sender, System.EventArgs e) { string g_sLoginName = tbLoginName.Text; string g_sLoginPassword = tbLoginPassword.Text; FrmParent.Msg("Authenticating User..."); tryagain:{} try { try { //OSystem = new OysterClassLibrary.Oyster(serveraddress,password); //OSystem = new OysterClassLibrary.Oyster(); OSystem = new OysterClassLibrary.Oyster(ConnectionString); } catch(Exception Err) { if(Err.Message == "SQL Server does not exist or access denied.") { DialogResult DR = MessageBox.Show("Do you wish to try to locate the server manually","Unable to establish a connection to Oyster Server",System.Windows.Forms.MessageBoxButtons.YesNo); if(DR == DialogResult.No) { this.DialogResult = DialogResult.Abort; return; } frmServerLocation SL = new frmServerLocation(); DR = SL.ShowDialog(this); if(DR != DialogResult.OK) { this.DialogResult = DialogResult.Abort; return; } goto tryagain; } } try { LoginUser = OSystem.Login(g_sLoginName,g_sLoginPassword); } catch (Exception Err) { string peek = Err.Message; MessageBox.Show("Invalid Login ID or Password.","Oyster Executive: Login Message"); return; } if(LoginUser != null) { if(!CheckForValidLicense(LoginUser)) { LoginUser = null; return; } //Splash.Dispose(); FrmParent.Msg("User authenticated."); } if(OSystem.SystemAdminLoginDenied == true) { MessageBox.Show("Someone has already logged in with System Administrator access...\nYour SYSTEM priviledges are being set to READONLY Access.\nFor Full Access please try to login again at a later time.","System Administrator account in use!"); } } catch(Exception Err) { //Splash.Dispose(); if(Err.Message == "SQL Server does not exist or access denied.") { DialogResult DR = MessageBox.Show("Do you wish to try to locate the server manually","Unable to establish a connection to Oyster Server",System.Windows.Forms.MessageBoxButtons.YesNo); if(DR == DialogResult.No) { this.DialogResult = DialogResult.Abort; return; } frmServerLocation SL = new frmServerLocation(); DR = SL.ShowDialog(this); if(DR != DialogResult.OK) { this.DialogResult = DialogResult.Abort; return; } goto tryagain; } else { this.Opacity = 100; MessageBox.Show("Unknown error occurred while attempting to login to system","Unknown Error"); MessageBox.Show("Application will now close","Oyster Executive"); this.DialogResult = DialogResult.Abort; return; } } if(g_COMPORT != cbConfigureCardScan.Text.ToString()) { g_COMPORT = cbConfigureCardScan.Text.ToString(); RK = Registry.LocalMachine.OpenSubKey("Software\\Carver Lab\\Oyster V2.0\\Data",true); RK.SetValue("COMPORT",g_COMPORT); } this.DialogResult = DialogResult.OK; }
private void Form1_Load(object sender, System.EventArgs e) { Array ar = System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName); m_iAppCount = ar.Length; txtPort.Text = (14000 + ar.Length).ToString(); ocl = new OysterClassLibrary.Oyster(); m_arrayUsers = new ArrayList(); foreach (OysterClassLibrary.User u in ocl.CurrentSystemUsers) { AUser nu = new AUser(u.LastName + ", " + u.FirstName,u); m_arrayUsers.Add(nu); } //m_arrayUsers.Sort(); comboBox1.DataSource = m_arrayUsers; comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "User"; m_bDone = false; m_bStarted = false; }
public void MainLoop() { string sXMLSourceDirectory = @"c:\mediafiles\backup"; bool bFound = false; RetryXMLFileList retrylist = new RetryXMLFileList(); bool bVerbose = false; #if DEBUG log.WriteLog("Sleeping for 10 seconds"); System.Threading.Thread.Sleep(10000); #endif ActiveThreadCount = 0; MaxActiveThreadCount = 1; // begin routine // determine how many encoders can be active at once try { Microsoft.Win32.RegistryKey regKey = log.CarverLabRegistryKey(); MaxActiveThreadCount = (int)regKey.GetValue("MaxUploadThreadCount",1); int itemp; itemp = (int)regKey.GetValue("EncoderResponseTimeoutMinutes",7); if (itemp > short.MaxValue) EncoderResponseTimeoutMinutes = short.MaxValue; else EncoderResponseTimeoutMinutes = (short)itemp; log.bDebugMode = ((string)regKey.GetValue("DebugMode") == "1"); itemp = (int)regKey.GetValue("EncoderRetryFileIntervalSeconds",300); if (itemp > short.MaxValue) EncoderRetryFileIntervalSeconds = short.MaxValue; else EncoderRetryFileIntervalSeconds = (short)itemp; itemp = (int)regKey.GetValue("VerboseLogOutput"); if (itemp > 0) { bVerbose = true; log.WriteLog("*** Verbose output enabled! ***"); } } catch (System.Exception regex) { log.WriteLog("Registry read error: " + regex.Message); } log.WriteLog("Oyster Encoder will spawn at most " + MaxActiveThreadCount + " encoding threads."); // create a thread sync'ed list to hold thread instances ThreadList = new EncoderThreadList(); // get the directory name that video and xml files are dropped // into and store into vdirectory try { bFound = false; OysterClassLibrary.Oyster o = new OysterClassLibrary.Oyster(); foreach (OysterClassLibrary.ForwardingServer fs in o.FORWARDINGSERVERS) { if (fs.Address != "Not Assigned") { foreach (OysterClassLibrary.MediaBufferServer mbs in fs.CurrentMediaBufferServers) { if (mbs.Address != "Not Assigned") { sXMLSourceDirectory = mbs.StorageDirectory; bFound = true; // get OysterRootDirectory from the system OysterRootDirectory = (string) o.GetVideoStorageServerById(fs.CurrentVideoStorageServer.ID).CurrentVideoStorageServerType["OysterRootDirectory"]; // get OysterSourceDirectory from the system OysterSourceDirectory = (string) o.GetVideoStorageServerById(fs.CurrentVideoStorageServer.ID).CurrentVideoStorageServerType["OysterSourceDirectory"]; // get OysterProfileName from the system OysterProfileName = (string) o.GetVideoStorageServerById(fs.CurrentVideoStorageServer.ID).CurrentVideoStorageServerType["OysterProfile"]; break; } } } } if (!bFound) { log.WriteLog("Could not find a source directory in the configuration. There is nothing to do. Aborting."); return; } } catch (System.Exception oex) { log.WriteLog("MainLoop: When attempting to open the OysterClassLibrary and exception occured: " + oex.Message); return; } if (false == System.IO.Directory.Exists(sXMLSourceDirectory)) { try { System.IO.Directory.CreateDirectory(sXMLSourceDirectory); } catch (System.Exception dex) { log.WriteLog("Unable to create the directory " + sXMLSourceDirectory + ": " + dex.Message + ". Aborting."); return; } } log.WriteLog("Reading files from " + sXMLSourceDirectory); m_EventMonitor = new System.Threading.ManualResetEvent(true); CarverLab.Utility.EncodingServiceInfo esi = new CarverLab.Utility.EncodingServiceInfo(); esi.Initialize(@"c:\EncodingServiceInfo.xml"); dtStart = System.DateTime.Now; string FAILEDFILE = ""; // while this thread is active log.WriteLog("Entering work loop..."); while (false == IsDone) { try { #if !DEBUG System.Threading.Thread.Sleep(5000); #endif if (bVerbose) { log.WriteLog("Serializing EncodingServiceInfo"); } esi.Serialize(); // get a list of all files in vdirectory with a .xml extension System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sXMLSourceDirectory); System.IO.FileInfo[] fiFileInfoList = di.GetFiles("*.xml"); System.Collections.SortedList slFileInfoList = new System.Collections.SortedList(new FileInfoDateComparer(FileInfoDateComparer.DateCompareType.CreationTime)); System.IO.FileInfo[] fiFileInfoErrorList = di.GetFiles("*.err"); // check to see that the system is still running... // for each file in vdirectory if (bVerbose) { log.WriteLog("Read XML files from " + sXMLSourceDirectory); } System.Collections.ArrayList alErrs = new System.Collections.ArrayList(); if (esi.m_esi.CurrentEncodings != null) { for (int i = 0; i < esi.m_esi.CurrentEncodings.Length; i++) { CarverLab.Utility.Encoding enc = esi.m_esi.CurrentEncodings[i]; if (enc.XMLPathFile.EndsWith(".err")) { if (!System.IO.File.Exists(enc.XMLPathFile)) { alErrs.Add(enc); } } } } m_EventMonitor.WaitOne(10000,false); foreach (object obj in alErrs) { CarverLab.Utility.Encoding enc = (CarverLab.Utility.Encoding) obj; esi.Remove(enc.UniqueIdentifier); } m_EventMonitor.Set(); if (bVerbose) { log.WriteLog("Scanning files..."); } foreach (System.IO.FileInfo fi in fiFileInfoErrorList) { if (esi.UniqueIdentifierOfXMLFile(fi.FullName) == null) { m_EventMonitor.WaitOne(10000,false); string su = esi.Add(fi.FullName,"","",-1.0); esi.AddError(su,"Error File"); m_EventMonitor.Set(); if (bVerbose) { log.WriteLog("Error file: " + fi.FullName); } } } System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); foreach (System.IO.FileInfo fi in fiFileInfoList) { if (esi.UniqueIdentifierOfXMLFile(fi.FullName) == null) { FAILEDFILE = fi.FullName; CheckAndFixXMLInput(fi.FullName); CarverLab.Utility.CARDVIDEO cv = (CarverLab.Utility.CARDVIDEO)Deserialize(fi.FullName, typeof(CarverLab.Utility.CARDVIDEO)); m_EventMonitor.WaitOne(10000,false); if (cv == null) { esi.Add(fi.FullName,"","",-1.0); } else { esi.Add(fi.FullName,cv.FILENAME,cv.FILETITLE,-1.0); } if (bVerbose) { log.WriteLog("File: " + fi.FullName); } m_EventMonitor.Set(); } if (!retrylist.Contains(fi.FullName)) { slFileInfoList.Add(fi,fi); } else { TimeSpan ts = DateTime.Now - retrylist[fi.FullName].LastChecked; if (ts.TotalSeconds > EncoderRetryFileIntervalSeconds) { retrylist.Remove(fi.FullName); } } } foreach (System.Collections.DictionaryEntry entry in slFileInfoList) { System.IO.FileInfo fi = entry.Value as System.IO.FileInfo; if (bVerbose) { log.WriteLog("Considering " + fi.FullName); } // } // foreach (System.IO.FileInfo fi in fiFileInfoList) // { // sleep a bit to save processor time #if !DEBUG System.Threading.Thread.Sleep(1000); #endif if (ActiveThreadCount >= MaxActiveThreadCount) { break; } string sXMLFilename, sVideoFilename; FAILEDFILE = fi.FullName; sXMLFilename = fi.FullName; // search for filename in thread list // if filename exists in thread list skip to next file if (ThreadList.Contains(sXMLFilename)) { if (bVerbose) { log.WriteLog(fi.FullName + " is already active"); } continue; } // endif // open the xml file if (bVerbose) { log.WriteLog("Reading XML file " + sXMLFilename); } CarverLab.Utility.CARDVIDEO cv = (CarverLab.Utility.CARDVIDEO)Deserialize(sXMLFilename, typeof(CarverLab.Utility.CARDVIDEO)); // read the video file name in the xml file sVideoFilename = cv.FILENAME; // if no matching video file exists continue with the next file if (bVerbose) { log.WriteLog("Checking for matching video file"); } if (false == System.IO.File.Exists(sVideoFilename)) { m_EventMonitor.WaitOne(10000,false); ErrorRenameXML(null,sXMLFilename,"*ERROR* " + sVideoFilename + " does not exist for " + sXMLFilename); m_EventMonitor.Set(); continue; } System.IO.FileStream tfs; try { if (bVerbose) { log.WriteLog("Opening file: " + sVideoFilename); } tfs = System.IO.File.Open(sVideoFilename,System.IO.FileMode.Open); if (null == tfs) { m_EventMonitor.WaitOne(10000,false); ErrorRenameXML(null,sXMLFilename,"*ERROR* " + sVideoFilename + " could not open file."); m_EventMonitor.Set(); continue; } } catch (Exception ex1) { m_EventMonitor.WaitOne(10000,false); ErrorRenameXML(null,sXMLFilename,"*ERROR* " + sVideoFilename + " could not open file: " + ex1.Message); m_EventMonitor.Set(); continue; } if (bVerbose) { log.WriteLog("Checking length of file " + sVideoFilename); } long len = tfs.Length; tfs.Close(); if (len < (256 * 1024)) { m_EventMonitor.WaitOne(10000,false); ErrorRenameXML(null,sXMLFilename,"*ERROR* " + sVideoFilename + " file is too small, will not process."); m_EventMonitor.Set(); continue; } if (bVerbose) { log.WriteLog("Creating encoder for " + sVideoFilename); } EncoderThreadItem eti = new EncoderThreadItem(); // create a new thread that is suspended // assign the EncodeFile routine to the new thread System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ThreadStart(eti.Encode)); // pass the thread list index into the new thread eti.log = this.log; eti.m_bIsCompleted = false; eti.m_EncodeFileThread = thr; eti.m_sXMLFilename = sXMLFilename; eti.OysterProfileName = this.OysterProfileName; eti.OysterRootDirectory = this.OysterRootDirectory; eti.OysterSourceDirectory = this.OysterSourceDirectory; eti.m_EventMonitor = this.m_EventMonitor; eti.m_esi = esi; // place filename into the thread list ThreadList.Add(sXMLFilename,eti); // activate the new thread thr.Start(); //ActiveThreadCount++; log.WriteLog("New encoding thread created. ActiveThreadCount = " + (ActiveThreadCount + 1) + " of " + MaxActiveThreadCount); FAILEDFILE = ""; // endfor } fiFileInfoList = null; di = null; } catch (System.Exception whex) { if (FAILEDFILE.Length > 0) { retrylist[FAILEDFILE] = new RetryXMLFile(); TimeSpan ts = DateTime.Now - retrylist[FAILEDFILE].LastChecked; retrylist[FAILEDFILE].LastChecked = DateTime.Now; if (ts.TotalSeconds > 15) // if (retrylist[FAILEDFILE].CheckedCount++ > 5) { log.WriteLog(FAILEDFILE + " being renamed."); System.IO.FileInfo fi = new System.IO.FileInfo(FAILEDFILE); fi.MoveTo(System.IO.Path.ChangeExtension(fi.FullName,"failed")); } } else { log.WriteLog("*ERROR* EncodeLauncher.MainLoop Exception: " + whex.Message); log.WriteLog(" Pausing for one second before continuing..."); } System.Threading.Thread.Sleep(1000); } // cleanup any completed threads System.Collections.ArrayList al = new System.Collections.ArrayList(); foreach (string ss in ThreadList) { EncoderThreadItem ti = ThreadList[ss]; bool bAddIt, bAbortIt; bAddIt = false; bAbortIt = false; if (ti.IsCompleted) { bAddIt = true; log.WriteLog(ti.m_sXMLFilename + " is scheduled for release."); } else { try { // if no error on the encoder // check for the encoder lockup by comparing the the encoding // time right now with the encoding time save one minute ago. if (false == ti.IsEncoderResponding(EncoderResponseTimeoutMinutes)) { log.WriteLog(ti.m_sXMLFilename + " is scheduled for emergency release."); bAddIt = true; bAbortIt = true; } } catch (System.Exception handlerex) { log.WriteLog("In the Thread Freeze handler: " + handlerex.Message); bAddIt = true; if (null != ti.m_EncodeFileThread) bAbortIt = true; } } if (bAddIt) { if (!bAbortIt) { al.Add(ti.m_sXMLFilename); //ActiveThreadCount--; } //log.WriteLog(ss + ": encoding thread destroyed. ActiveThreadCount = " + ActiveThreadCount // + " of " + MaxActiveThreadCount); } if (bAbortIt) { log.WriteLog(ss + ": encoder not responding, **ABORTING** thread."); log.WriteLog(ss + ": Performing Emergency Stop."); ti.EmergencyStop(); m_EventMonitor.WaitOne(10000,false); ThreadList.Remove(ti.m_sXMLFilename); m_EventMonitor.Set(); log.WriteLog(ss + ": Thread removed from management list."); ActiveThreadCount--; } } foreach (string ss in al) { string sXMLFilename, sVideoFilename; sXMLFilename = ss; // open the xml file CarverLab.Utility.CARDVIDEO cv = (CarverLab.Utility.CARDVIDEO)Deserialize(sXMLFilename, typeof(CarverLab.Utility.CARDVIDEO)); // read the video file name in the xml file sVideoFilename = cv.FILENAME; // delete the XML and video files log.WriteLog("Cleaning up XML and video source files"); try { if (ThreadList[sXMLFilename].DidEncodingFail) { // skip deletion of files log.WriteLog("\t" + sXMLFilename + " is being skipped for deletion."); } else { log.WriteLog("\t" + sXMLFilename); System.IO.File.Delete(sXMLFilename); log.WriteLog("\t" + sVideoFilename); System.IO.File.Delete(sVideoFilename); } m_EventMonitor.WaitOne(10000,false); esi.Remove(ThreadList[ss].m_sUniqueIdentifier); m_EventMonitor.Set(); } catch(System.Exception fdex) { log.WriteLog("Unable to delete file: " + fdex.Message); //esi.UpdateError(ThreadList[ss].m_sUniqueIdentifier,"Failed to stop."); } ThreadList.Remove(ss); } // end while } // end routine esi.DeInitialize(); log.WriteLog("Clean exit."); }
private void imgbtnLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e) { OysterClassLibrary.Oyster O = null; try { //O = new OysterClassLibrary.Oyster(true); string sServer = "10.1.0.100"; O = new OysterClassLibrary.Oyster(sServer,"oyster1"); } catch(Exception Err) { txtAlert.Value = Err.Message; return; } try { OysterClassLibrary.User LUser = O.Login(tbUsername.Value,tbPassword.Value); if(LUser != null) { Session["LUser"] = LUser; Session["Oyster"] = O; tbUsername.Value = ""; tbPassword.Value = ""; int IsChecked = Convert.ToInt32(txtChecked.Value,10); if(IsChecked == 0) Response.Redirect("LoadScreen.aspx",true); else Response.Redirect("frmPassword.aspx",true); } else { //Response.Write("<Script> window.alert('Invalid User Id or Password'); </script>"); txtAlert.Value = "Invalid User Id or Password"; } } catch(Exception Err) { //Response.Write("<Script> window.alert('" + Err.Message + "'); </script>"); txtAlert.Value = Err.Message; } }
private void btnLoginCardScan_Click(object sender, System.EventArgs e) { #if USE_CARDSCAN if((g_COMPORT != cbConfigureCardScan.Text.ToString())&&(cbConfigureCardScan.Text != "NO COMPORTS")) { g_COMPORT = cbConfigureCardScan.Text.ToString(); RK = Registry.CurrentUser.OpenSubKey("Software\\" + sProductKey,true); RK.SetValue("COMPORT",g_COMPORT); } FrmParent.Msg("Scan User Identification Card"); this.Opacity = 0; string CardNumber = CardSwipe.Scan(g_COMPORT); if(CardNumber == "")return; CardNumber = FormatCardNumber(CardNumber); tryagain2:{} FrmParent.Msg("Authenticating User..."); try { OSystem = new OysterClassLibrary.Oyster(); try { LoginUser = OSystem.Login(CardNumber); } catch (Exception Err) { string peek = Err.Message; MessageBox.Show("Invalid Login ID or Password.","Oyster Hardcopy: Login Message"); return; } if(LoginUser != null) { if(!CheckForValidLicense(LoginUser)) { LoginUser = null; return; } FrmParent.Msg("User authenticated."); } } catch(Exception Err) { if(Err.Message == "SQL Server does not exist or access denied.") { DialogResult DR = MessageBox.Show("Do you wish to try to locate the server manually","Unable to establish a connection to Oyster Server",System.Windows.Forms.MessageBoxButtons.YesNo); if(DR == DialogResult.No) { this.DialogResult = DialogResult.Abort; return; } frmServerLocation SL = new frmServerLocation(); DR = SL.ShowDialog(this); if(DR != DialogResult.OK) { this.DialogResult = DialogResult.Abort; return; } goto tryagain2; } else { this.Opacity = 100; MessageBox.Show("Possible license authentication error.","Unknown Error"); MessageBox.Show("Application will now close","Oyster Hardcopy"); this.DialogResult = DialogResult.Abort; return; } } if(OSystem.SystemAdminLoginDenied == true) { MessageBox.Show("Someone has already logged in with System Administrator access...\nYour SYSTEM privileges are being set to READONLY Access.\nFor Full Access please try to login again at a later time.","System Administrator account in use!"); } FrmParent.Msg("User authenticated."); this.DialogResult = DialogResult.OK; #endif }
private void btnLoginCardScan_Click(object sender, System.EventArgs e) { if((g_COMPORT != cbConfigureCardScan.Text.ToString())&&(cbConfigureCardScan.Text != "NO COMPORTS")) { g_COMPORT = cbConfigureCardScan.Text.ToString(); RK = Registry.CurrentUser.OpenSubKey("Software\\Carver Lab\\Oyster V2.0\\Data",true); RK.SetValue("COMPORT",g_COMPORT); } FrmParent.Msg("Scan User Identification Card"); string CardNumber = CardSwipe.Scan(g_COMPORT); if(CardNumber == "")return; CardNumber = FormatCardNumber(CardNumber); tryagain2:{} FrmParent.Msg("Searching for server please wait..."); try { OSystem = new OysterClassLibrary.Oyster(); FrmParent.Msg("Authenticating User..."); try { LoginUser = OSystem.Login(CardNumber); } catch (Exception Err) { string peek = Err.Message; MessageBox.Show("Unrecognized Access Card.","Oyster Executive: Login Message"); return; } //LoginUser = OSystem.Login(g_sLoginName,g_sLoginPassword); if(LoginUser != null) { if(!CheckForValidLicense(LoginUser)) { FrmParent.Msg("All available login slots are currently in use."); LoginUser = null; return; } FrmParent.Msg("User authenticated."); } } catch(Exception Err) { if(Err.Message == "SQL Server does not exist or access denied.") { DialogResult DR = MessageBox.Show("Do you wish to try to locate the server manually","Unable to establish a connection to Oyster Server",System.Windows.Forms.MessageBoxButtons.YesNo); if(DR == DialogResult.No) { this.DialogResult = DialogResult.Abort; return; } frmServerLocation SL = new frmServerLocation(); DR = SL.ShowDialog(this); if(DR != DialogResult.OK) { this.DialogResult = DialogResult.Abort; return; } //FrmParent.Msg("Searching for server please wait..."); goto tryagain2; } else { this.Opacity = 100; MessageBox.Show("Error received while attempting to login user.","Unknown Error"); MessageBox.Show("Application will now close","Oyster Executive"); this.DialogResult = DialogResult.Abort; return; } } if(OSystem.SystemAdminLoginDenied == true) { MessageBox.Show("Someone has already logged in with System Administrator access...\nYour SYSTEM priviledges are being set to READONLY Access.\nFor Full Access please try to login again at a later time.","System Administrator account in use!"); } FrmParent.Msg("User authenticated."); this.DialogResult = DialogResult.OK; }
private void Form1_Load(object sender, System.EventArgs e) { this.Opacity = 0; Splash = new frmSplash(); Splash.lblVersion.Text = VERSION; Splash.lblStatus.Text = "Loading Login Screen..."; Splash.Show(); Login1 L = new Login1(); System.Windows.Forms.DialogResult LDR = L.ShowDialog(this); if(LDR != DialogResult.OK) { Application.Exit(); return; } else { Splash.Msg("Loading User data..."); OSystem = L.OSystem; LoginUser = L.LoginUser; g_COMPORT = L.g_COMPORT; g_LoginDenied = OSystem.SystemAdminLoginDenied; } // if(this.Tag is PassOysterLogin) // { // // PassOysterLogin POL = (PassOysterLogin)this.Tag; // OSystem = POL.OSystem; // LoginUser = POL.LoginUser; // g_COMPORT = POL.COMPORT; // g_LoginDenied = OSystem.SystemAdminLoginDenied; // this.Tag = null; // } // else // return; //ReadMediaBufferServerLocalAddress(); g_Obj = new System.Object(); try { CardSwipe = new CARDSCAN.SerialPortScanClass(); //MHClient = new MHCOM.MediaHawkClientClass(); } catch(Exception Err) { MessageBox.Show(Err.Message,"Application Closing.."); Application.Exit(); return; } gLogTime = new DateTime(); gLogTime = System.DateTime.Now; gLastActivity = System.DateTime.Now; StatusTimer.Enabled = true; ActivityTimer.Enabled = true; HighestSectionType = LoginUser.HighestAuthorityLevel; MainSystemSection = OSystem.CurrentSystemSection("6419DC43-84B9-43e2-89FE-BB8C96D5CF6F"); menuItem1.Visible = false; menuItem3.Visible = false; mnuSystem.Visible = false; mnuHelp.Visible = false; //For Oakland Permissions if(HighestSectionType.ID == OSystem.SectionTypeSysAdmin.ID) { menuItem3.Visible = true; mnuSystem.Visible = true; menuItem1.Visible = true; } else if(HighestSectionType.ID == OSystem.SectionTypeSysAdmin.NextSectionTypeID) { mnuSystem.Visible = true; menuItem3.Visible = true; menuItem1.Visible = true; } else { foreach(OysterClassLibrary.Permission P in HighestSectionType.CanShareRecordings) { string peek = P.TargetSectionTypeId.ToString(); menuItem1.Visible = true; break; } } ShowDisplay(ShowUserInfo); Splash.Msg("Building Users Hierarchy..."); Status(LoginUser.Description + " logged in..."); BuildUserHierarchy(); BuildCameraView(); treeView1.Focus(); if(treeView1.SelectedNode != null) { if(treeView1.SelectedNode.Tag is OysterClassLibrary.Section) { } else { treeView1.SelectedNode = treeView1.Nodes[0]; } } else { treeView1.SelectedNode = treeView1.Nodes[0]; } treeView1_MouseUp(treeView1,new MouseEventArgs(MouseButtons.Left,1,0,0,0)); Splash.Msg("Completed..exiting Splash Screen"); Splash.Dispose(); this.Opacity = 100; }
public void Encode() { EncodeLauncher.ActiveThreadCount++; string sError = "N/A"; string sVideoFilename, sBaseFilename; int iVideoStorageServerId; OysterClassLibrary.Oyster o; try { // begin routine // use the index to find the object holding the filename // open the xml file CarverLab.Utility.CARDVIDEO cv = (CarverLab.Utility.CARDVIDEO)EncodeLauncher.Deserialize(m_sXMLFilename, typeof(CarverLab.Utility.CARDVIDEO)); // read video filename and store in vfilename sVideoFilename = cv.FILENAME; iVideoStorageServerId = cv.VIDEOSTORAGESERVERID; sBaseFilename = cv.FILETITLE; cv = null; // start encoding log.WriteLog(sVideoFilename + ": begins encoding now..."); if (OysterRootDirectory[OysterRootDirectory.Length - 1] != '\\') OysterRootDirectory += "\\"; if (OysterSourceDirectory[OysterSourceDirectory.Length - 1] != '\\') OysterSourceDirectory += "\\"; string sSourceFile = sVideoFilename; string sDestFile = OysterRootDirectory + sBaseFilename + ".wmv"; if (false == StartEncoding(sSourceFile,sDestFile,OysterProfileName,"","","","","")) { sError = sVideoFilename + ": *ERROR* StartEncoding failed."; m_bStartupFailed = true; goto Encode_Err; } m_EventMonitor.WaitOne(10000,false); string su = m_esi.UniqueIdentifierOfXMLFile(m_sXMLFilename); if (su != null) { m_esi.Remove(su); } m_sUniqueIdentifier = m_esi.Add(m_sXMLFilename,sSourceFile,sBaseFilename,System.Convert.ToDouble(m_iDuration)); m_esi.EncodingActive(m_sUniqueIdentifier,true); m_EventMonitor.Set(); // wait for encoding to complete int iLast = -1; while (WMEncoderLib.WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED != m_wme.RunState) { // notify the log file every 10% int iPercentComplete = PercentOfEncodingComplete(); if (iPercentComplete % 10 == 0) { if (iLast != iPercentComplete) { log.WriteLog(" -- " + sVideoFilename + ": " + iPercentComplete + "% complete."); iLast = iPercentComplete; m_EventMonitor.WaitOne(10000,false); m_esi.Update(m_sUniqueIdentifier,System.Convert.ToDouble(iPercentComplete)); m_EventMonitor.Set(); } } System.Threading.Thread.Sleep(250); } log.WriteLog(sVideoFilename + ": encoding is complete."); log.WriteLog(" Video Duration: " + System.TimeSpan.FromMilliseconds(m_iDuration).ToString()); log.WriteLog(" Encode Time: " + System.TimeSpan.FromTicks(System.DateTime.Now.Ticks - m_nEncodingStartTimeTicks).ToString()); DateTime dtStartWaitingForQuit = DateTime.Now; TimeSpan tsWaitingForQuit = TimeSpan.MinValue; while (WMEncoderLib.WMENC_INDEXER_STATE.WMENC_INDEXER_RUNNING == m_wme.IndexerState) { if (m_bEmergencyStop) { m_EventMonitor.WaitOne(10000,false); m_esi.EmergencyStop(m_sUniqueIdentifier,true); m_EventMonitor.Set(); sError = sBaseFilename + ".wmv: *ERROR* ALL STOP. Emergency stop called during encoding process."; m_wme.Stop(); // stop all activity so that all files are released m_wme.PrepareToEncode(false); // now explicitly get rid of the Encoder objects. m_wme = null; goto Encode_Err; } System.Threading.Thread.Sleep(250); tsWaitingForQuit = DateTime.Now - dtStartWaitingForQuit; if (tsWaitingForQuit.Ticks > (TimeSpan.TicksPerMinute * 5) /* five minutes */) { log.WriteLog(sBaseFilename + ".wmv -- TIMED OUT waiting " + tsWaitingForQuit.TotalSeconds + " seconds for Indexer to complete. Forcing indexer to stop."); m_wme.Stop(); break; } } // stop all activity so that all files are released m_wme.PrepareToEncode(false); // now explicitly get rid of the Encoder objects. m_wme = null; // enable the video within the Oyster Player try { o = new OysterClassLibrary.Oyster(); } catch (System.Exception oex) { sError = "*ERROR* Encode: When attempting to open the OysterClassLibrary and exception occured: " + oex.Message; goto Encode_Err; } OysterClassLibrary.Recording rec = o.GetRecordingByName(sBaseFilename + ".wmv"); if (null == rec) { log.WriteLog(sBaseFilename + ".wmv: *ERROR* not found in database. Nothing to enable."); } else { rec.IsReady = true; rec = null; } // end routine goto Encode_Exit; Encode_Err: m_bFailed = true; // log.WriteLog(sError); if (m_bStartupFailed) { goto Encode_Startup_Err; } m_EventMonitor.WaitOne(10000,false); m_esi.AddError(m_sUniqueIdentifier,sError); m_EventMonitor.Set(); try { if (null != m_wme && !m_bEmergencyStop && !m_bStartupFailed) { log.WriteLog(sBaseFilename + ":Shutting down encoder"); m_wme.PrepareToEncode(false); log.WriteLog(sBaseFilename + ":Encoder is shut down."); } } catch { log.WriteLog(sBaseFilename + ":Encoder failed to shut down."); } Encode_Startup_Err: m_EventMonitor.WaitOne(10000,false); EncodeLauncher.ErrorRenameXML(null,m_sXMLFilename,sError,log,m_bStartupFailed); if (!EncodeLauncher.ResetReqursted) { System.Net.IPEndPoint ep = new System.Net.IPEndPoint(System.Net.Dns.Resolve(Environment.MachineName).AddressList[0],22580); System.Net.Sockets.UdpClient u = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork); string s = "reset"; u.Send(System.Text.ASCIIEncoding.ASCII.GetBytes(s),s.Length,ep); log.WriteLog(sBaseFilename + ":Requested a reset..."); EncodeLauncher.ResetReqursted = true; } m_EventMonitor.Set(); Encode_Exit: m_wme = null; // mark the thread as complete in the global array list of threads m_bIsCompleted = true; EncodeLauncher.ActiveThreadCount--; log.WriteLog(m_sXMLFilename + ": encoding thread destroyed. ActiveThreadCount = " + EncodeLauncher.ActiveThreadCount + " of " + EncodeLauncher.MaxActiveThreadCount); } catch (System.Exception encex) { CarverLabUtility.Logger.WriteLog("EncodingService","EncoderThreadItem.Encode " + m_sXMLFilename + ": Exception thrown on outer try/catch: " + encex.Message); m_bIsCompleted = true; m_bFailed = true; m_wme = null; GC.Collect(); //GC.WaitForPendingFinalizers(); System.IO.FileInfo fi = new System.IO.FileInfo(m_sXMLFilename); m_EventMonitor.WaitOne(10000,false); fi.MoveTo(System.IO.Path.ChangeExtension(m_sXMLFilename,"catastrophic.err")); //System.IO.File.Move(m_sXMLFilename, m_sXMLFilename + ".catastrophic.err"); EncodeLauncher.ActiveThreadCount--; if (!EncodeLauncher.ResetReqursted) { System.Net.IPEndPoint ep = new System.Net.IPEndPoint(System.Net.Dns.Resolve(Environment.MachineName).AddressList[0],22580); System.Net.Sockets.UdpClient u = new System.Net.Sockets.UdpClient(System.Net.Sockets.AddressFamily.InterNetwork); string s = "reset"; u.Send(System.Text.ASCIIEncoding.ASCII.GetBytes(s),s.Length,ep); log.WriteLog(m_sXMLFilename + ":Requested a reset..."); EncodeLauncher.ResetReqursted = true; } m_EventMonitor.Set(); } }