Esempio n. 1
0
        void INetworkListener.OnFileError(string sender, string recipient, string filename)
        {
            CCBLogConfig.GetLogger().Debug("Tagging file completed with error: {0}\n", filename);
            try
            {
                CCBP2PFile infile = GetInFile(filename);

                if ((null != infile) && infile.CheckNode(sender, recipient))
                {
                    infile.OnError();
                    m_signal.Set();
                }
                lock (m_outbox)
                {
                    foreach (CCBP2PFile outfile in m_outbox.Values)
                    {
                        if ((0 == string.Compare(outfile.LocalName, filename)) && outfile.CheckNode(sender, recipient))
                        {
                            outfile.OnError();
                            m_signal.Set();
                        }
                    }
                }
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception OnFileError {0}: {1}", filename, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception OnFileError {0}: {1}", filename, ex.Message);
            }
        }
Esempio n. 2
0
        void ICeebeetlePeer.OnFileError(string sender, string recipient, string filename)
        {
            if ((m_uid.Equals(sender)) || (m_uid.Equals(recipient)))
            {
                try
                {
                    INetworkListener[] listeners = GetListeners();

                    foreach (INetworkListener listener in listeners)
                    {
                        listener.OnFileError(sender, recipient, filename);
                    }
                }
                catch (System.IO.IOException ioex)
                {
                    CCBLogConfig.GetLogger().Error("IO Exception in OnFileError: {0}", ioex.Message);
                }
                catch (System.ServiceModel.CommunicationException commEx)
                {
                    CCBLogConfig.GetLogger().Error("Comm Exception in OnFileError: {0}", commEx.Message);
                }
                catch (Exception ex)
                {
                    CCBLogConfig.GetLogger().Error("Exception in OnFileError: {0}", ex.Message);
                }
            }
        }
Esempio n. 3
0
        //We write the data directly on the networker thread. The reason is that if the write is fast, it's ok;
        //if it's slow, the file worker thread would back up while the chunks came in, leaving significant parts
        //of the file in memory. With only 2 threads, it's better to write the data out immediately. If the file
        //transfer system needs to scale up, this should be changed and more file worker threads should be added.
        void INetworkListener.OnFileData(string filename, long offset, byte[] data)
        {
            CCBLogConfig.GetLogger().Debug(string.Format("Receiving {0} bytes of {1}\n", data.Length, filename));
            try
            {
                CCBP2PFile infile = GetInFile(filename);

                if (null == infile)
                {
                    CCBLogConfig.GetLogger().Error("No file data for {0}, ignoring file data.", filename);
                }
                else
                {
                    infile.WriteData(offset, data);
                }
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception OnFileData {0}: {1}", filename, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception OnFileData {0}: {1}", filename, ex.Message);
            }
        }
Esempio n. 4
0
        //On the peer implementation, the sent data is actually received data...
        void ICeebeetlePeer.SendFileData(string sender, string recipient, string filename, long offset, byte[] data)
        {
            if (m_uid.Equals(recipient))
            {
                try
                {
                    INetworkListener[] listeners = GetListeners();

                    foreach (INetworkListener listener in listeners)
                    {
                        listener.OnFileData(filename, offset, data);
                    }
                }
                catch (System.IO.IOException ioex)
                {
                    CCBLogConfig.GetLogger().Error("IO Exception in SendFileData: {0}", ioex.Message);
                }
                catch (System.ServiceModel.CommunicationException commEx)
                {
                    CCBLogConfig.GetLogger().Error("Comm Exception in SendFileData: {0}", commEx.Message);
                }
                catch (Exception ex)
                {
                    CCBLogConfig.GetLogger().Error("Exception in SendFileData: {0}", ex.Message);
                }
            }
        }
Esempio n. 5
0
        void MainWindow_Closing(object sender, CancelEventArgs evtArgs)
        {
            m_timer.Stop();
            m_timer.Close();
            Save();
            if (null != m_chatWnd)
            {
                m_chatWnd.Exit();
            }
            try
            {
                //Save here always, in case there was some problem with the dirty logic.
                if (!m_games.SaveGames(m_config))
                {
                    MessageBoxResult mbr = System.Windows.MessageBox.Show("There was an error saving games. Do you still want to exit?", "Confirm Ceebeetle Exit", MessageBoxButton.YesNo);

                    if (mbr == MessageBoxResult.No)
                    {
                        evtArgs.Cancel = true;
                    }
                }
                if (!m_storeManager.SaveStores(m_config))
                {
                    CCBLogConfig.GetLogger().Log("Failed to write store file. Ignoring for now.");
                }
                CCBLogConfig.Close();
            }
            catch (IOException iox)
            {
                CCBLogConfig.GetLogger().Log(iox.ToString());
                evtArgs.Cancel = true;
            }
        }
Esempio n. 6
0
        //After having written the file, we mark it as finalized, which will make the file worker thread
        //calculate and check the hash.
        void INetworkListener.OnFileComplete(string filename, byte[] hash)
        {
            CCBLogConfig.GetLogger().Debug("Completing file: {0}\n", filename);
            try
            {
                CCBP2PFile infile = GetInFile(filename);

                if (null == infile)
                {
                    CCBLogConfig.GetLogger().Debug("No file data for {0}, ignoring file completion event.", filename);
                }
                else
                {
                    infile.OnFinalized(hash);
                    m_signal.Set();
                }
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception OnFileData {0}: {1}", filename, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception OnFileData {0}: {1}", filename, ex.Message);
            }
        }
Esempio n. 7
0
        void ICeebeetlePeer.SendCharacterTo(string sender, string recipient, CCBCharacter character)
        {
            if (m_uid.Equals(recipient))
            {
                try
                {
                    INetworkListener[] listeners = GetListeners();

                    foreach (INetworkListener listener in listeners)
                    {
                        listener.OnCharacterReceived(sender, character);
                    }
                }
                catch (System.IO.IOException ioex)
                {
                    CCBLogConfig.GetLogger().Error("IO Exception in OnFileComplete: {0}", ioex.Message);
                }
                catch (System.ServiceModel.CommunicationException commEx)
                {
                    CCBLogConfig.GetLogger().Error("Comm Exception in OnFileComplete: {0}", commEx.Message);
                }
                catch (Exception ex)
                {
                    CCBLogConfig.GetLogger().Error("Exception in OnFileComplete: {0}", ex.Message);
                }
            }
        }
Esempio n. 8
0
        public bool CalcLocalHash(WaitHandle closeEvent)
        {
            MD5 hashCalcer = MD5.Create();

            m_tick = DateTime.Now;
            try
            {
                FileStream filePtr   = null;
                byte[]     dataBlock = new byte[BlobSize];
                long       filelen   = GetFileSize(m_localFile);
                long       offset    = 0;
                MD5        hash      = MD5.Create();

                if (!m_closed)
                {
                    Close();
                }
                filePtr = new FileStream(m_localFile, FileMode.Open);
                while (offset < filelen)
                {
                    int curBlockSize = (int)(((long)offset + (long)BlobSize) > filelen ? (filelen - offset) : (long)BlobSize);

                    filePtr.Read(dataBlock, 0, curBlockSize);
                    if ((offset + curBlockSize) >= filelen)
                    {
                        hash.TransformFinalBlock(dataBlock, 0, curBlockSize);
                    }
                    else
                    {
                        hash.TransformBlock(dataBlock, 0, curBlockSize, null, 0);
                    }
                    if (closeEvent.WaitOne(0))
                    {
                        break;
                    }
                    offset += curBlockSize;
                }
                m_localHash = new byte[hash.Hash.Length];
                hash.Hash.CopyTo(m_localHash, 0);
                filePtr.Close();
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception in CheckHash {0}: {1}", m_localFile, ioex.Message);
                m_error = true;
            }
            catch (NullReferenceException nullx)
            {
                CCBLogConfig.GetLogger().Fatal("Null reference exception in CheckHash {0}: {1}", m_localFile, nullx.Message);
                m_error = true;
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception in CheckHash {0}: {1}", m_localFile, ex.Message);
                m_error = true;
            }
            return(false);
        }
Esempio n. 9
0
 private void ShowError(string errorText)
 {
     CCBLogConfig.GetLogger().Error("Adding Chat window error: {0}", errorText);
     lock (m_errorList)
     {
         m_errorList.Add(errorText);
     }
     Application.Current.Dispatcher.BeginInvoke(m_showLastErrorCallback);
 }
Esempio n. 10
0
 void ICeebeetlePeer.CancelFile(string sender, string recipient, string filename)
 {
     CCBLogConfig.GetLogger().Debug("Canceling file: " + filename);
     if (null != m_fileTransferResponseCallback)
     {
         if (0 == string.Compare(sender, m_uid))
         {
             m_fileTransferResponseCallback(recipient, filename, false);
         }
     }
 }
Esempio n. 11
0
 private void TestLinkCB(object sender, RoutedEventArgs e)
 {
     try
     {
         Hyperlink hl = (Hyperlink)sender;
         AddChatText("Link was clicked." + hl.CommandParameter.ToString());
     }
     catch (Exception ex)
     {
         CCBLogConfig.GetLogger().Log("TestLinkCB: " + ex.Message);
     }
 }
Esempio n. 12
0
        public long LoadNextBlob()
        {
            int curBlobSize = 0;

            try
            {
                CCBLogConfig.GetLogger().Debug("Loading blob: {0} for {1}\n", m_offsetCur, m_localFile);
                if (-1 == m_filesize)
                {
                    InitFileSize();
                }
                if (null == m_filePtr)
                {
                    m_filePtr = new FileStream(m_localFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                if ((m_offsetCur + BlobSize) < m_filesize)
                {
                    curBlobSize = BlobSize;
                }
                else
                {
                    curBlobSize = (int)(m_filesize - m_offsetCur);
                }
                m_offsetCur += m_filePtr.Read(m_data, 0, curBlobSize);
                if (m_offsetCur == m_filesize)
                {
                    AddToHash(m_data, curBlobSize, true);
                    m_localHash = GetHash();
                }
                else
                {
                    AddToHash(m_data, curBlobSize, false);
                }
            }
            catch (CryptographicUnexpectedOperationException unexpected)
            {
                CCBLogConfig.GetLogger().Error("Crypto Exception hashing file {0}: {1}", m_localFile, unexpected.Message);
                m_error = true;
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception reading file {0}: {1}", m_localFile, ioex.Message);
                m_error = true;
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception reading file {0}: {1}", m_localFile, ex.Message);
            }
            m_tick = DateTime.Now;
            return(curBlobSize);
        }
Esempio n. 13
0
        private void OnFileClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                Hyperlink hl     = (Hyperlink)sender;
                string    path   = hl.CommandParameter.ToString();
                string    folder = System.IO.Path.GetDirectoryName(path);

                Process.Start(folder);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Log("ChatWnd.OnFileClicked: " + ex.Message);
            }
        }
Esempio n. 14
0
        public bool LoadStores(string docPath)
        {
            lock (this)
            {
                CCBLogger logger   = CCBLogConfig.GetLogger();
                XmlReader xsReader = null;

                try
                {
                    xsReader = XmlReader.Create(docPath);
                    DataContractSerializer dsReader = new DataContractSerializer(typeof(CCBStoreManager));
                    CCBStoreManager        stores   = (CCBStoreManager)dsReader.ReadObject(xsReader);

                    m_places.MergePlaces(stores.m_places);
                    MergeStores(stores.m_stores);
                    m_dirty = false;
                    xsReader.Close();
                    return(true);
                }
                catch (System.IO.FileNotFoundException nothere)
                {
                    logger.Debug(String.Format("No data file, not loading stores [{0}]", nothere.FileName));
                    if (null != xsReader)
                    {
                        xsReader.Close();
                    }
                }
                catch (System.Runtime.Serialization.SerializationException serex)
                {
                    logger.Error(String.Format("XML parsing error, not loading stores [{0}]", serex.ToString()));
                    if (null != xsReader)
                    {
                        xsReader.Close();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Exception reading store document: " + ex.ToString());
                    if (null != xsReader)
                    {
                        xsReader.Close();
                    }
                }
            }
            return(false);
        }
Esempio n. 15
0
        public bool SaveStores(CCBConfig conf)
        {
            XmlWriter xmlWriter = null;
            CCBLogger logger    = CCBLogConfig.GetLogger();

            lock (this)
            {
                try
                {
                    DataContractSerializer dsWriter = new DataContractSerializer(typeof(CCBStoreManager));

                    conf.MaybeBackup(conf.GetStoreTmpFilePath());
                    xmlWriter = XmlWriter.Create(conf.GetStoreTmpFilePath());
                    dsWriter.WriteObject(xmlWriter, this);
                    xmlWriter.Flush();
                    xmlWriter.Close();
                    m_dirty = false;
                    try
                    {
                        System.IO.File.Copy(conf.GetStoreTmpFilePath(), conf.GetStoreFilePath(), true);
                    }
                    catch (System.IO.IOException ioex)
                    {
                        logger.Error("Error copying file: " + ioex.ToString());
                    }
                    return(true);
                }
                catch (IOException ioex)
                {
                    logger.Error("IO Exception saving store definitions: " + ioex.ToString());
                }
                catch (XmlException xmlex)
                {
                    logger.Error("XML Exception saving store definitions: " + xmlex.ToString());
                }
                catch (Exception ex)
                {
                    logger.Error("Exception saving store definitions: " + ex.ToString());
                }
            }
            if (null != xmlWriter)
            {
                xmlWriter.Close();
            }
            return(false);
        }
Esempio n. 16
0
        private void BackupDelete()
        {
            try
            {
                string dstPath = Path.Combine(Path.GetTempPath(), Path.GetFileName(m_localFile));

                //TODO: How to do pending IO op in .net?
                File.Move(m_localFile, dstPath);
            }
            catch (IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception in BackupDeleting file {0}: {1}", m_localFile, ioex.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception in BackupDeleting file {0}: {1}", m_localFile, ex.Message);
            }
        }
Esempio n. 17
0
 public void Close()
 {
     if (null != m_filePtr)
     {
         try
         {
             m_filePtr.Close();
         }
         catch (IOException ioex)
         {
             CCBLogConfig.GetLogger().Error("IO Exception closing file {0}: {1}", m_localFile, ioex.Message);
         }
         catch (Exception ex)
         {
             CCBLogConfig.GetLogger().Error("Exception closing file {0}: {1}", m_localFile, ex.Message);
         }
     }
     m_closed = true;
 }
Esempio n. 18
0
 public void Delete()
 {
     if (null != m_localFile)
     {
         try
         {
             System.IO.File.Delete(m_localFile);
         }
         catch (IOException ioex)
         {
             CCBLogConfig.GetLogger().Debug("IO Exception in Deleting file {0}: {1}", m_localFile, ioex.Message);
             BackupDelete();
         }
         catch (Exception ex)
         {
             CCBLogConfig.GetLogger().Error("Exception in Deleting file {0}: {1}", m_localFile, ex.Message);
         }
     }
 }
Esempio n. 19
0
 protected bool CheckHash()
 {
     if ((null != m_remoteHash) && (null != m_localHash))
     {
         if (m_remoteHash.Length == m_localHash.Length)
         {
             for (uint ixb = 0; ixb < m_remoteHash.Length; ixb++)
             {
                 if (m_remoteHash[ixb] != m_localHash[ixb])
                 {
                     return(false);
                 }
             }
             return(true);
         }
         CCBLogConfig.GetLogger().Error("Hash sizes don't match for {0}", m_localFile);
     }
     return(false);
 }
Esempio n. 20
0
        public int RetrieveDataToSend(ref CCBP2PFileDataEnvelope data)
        {
            try
            {
                if (m_bytesSent < m_offsetCur)
                {
                    int dataSize = (int)(m_offsetCur - m_bytesSent);

                    data = new CCBP2PFileDataEnvelope(m_bytesSent, dataSize, m_filesize,
                                                      m_recipient, m_localFile, m_remoteFile);
                    data.Put(m_data, dataSize);
                    return(dataSize);
                }
            }
            catch (Exception unex)
            {
                CCBLogConfig.GetLogger().Error("Unexpected exception in RetrieveDataToSend: {0}", unex.Message);
            }
            return(0);
        }
Esempio n. 21
0
        private void OnObjectClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                Hyperlink hl   = (Hyperlink)sender;
                string    link = hl.NavigateUri.ToString();

                System.Diagnostics.Process.Start(link);
            }
            catch (System.ComponentModel.Win32Exception noBrowser)
            {
                if (noBrowser.ErrorCode == -2147467259)
                {
                    MessageBox.Show(noBrowser.Message);
                }
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Log("OnObjectClicked: " + ex.Message);
            }
        }
Esempio n. 22
0
 private void CloseAll(CCBP2PFileList files)
 {
     lock (files)
     {
         foreach (CCBP2PFile file in files.Values)
         {
             try
             {
                 file.Close();
             }
             catch (IOException ioex)
             {
                 CCBLogConfig.GetLogger().Error("IO Exception closing file {0}: {1}", file.LocalName, ioex.Message);
             }
             catch (Exception ex)
             {
                 CCBLogConfig.GetLogger().Error("Exception closing file {0}: {1}", file.LocalName, ex.Message);
             }
         }
     }
 }
Esempio n. 23
0
 public void WriteData(long offset, byte[] bytes)
 {
     try
     {
         if (null == m_filePtr)
         {
             CCBLogConfig.GetLogger().Debug("Opening {0} for writing", m_localFile);
             m_filePtr = new FileStream(m_localFile, FileMode.Create);
         }
         m_filePtr.Seek(offset, SeekOrigin.Begin);
         m_filePtr.Write(bytes, 0, bytes.Length);
     }
     catch (IOException ioex)
     {
         CCBLogConfig.GetLogger().Error("IO Exception writing file {0}: {1}", m_localFile, ioex.Message);
     }
     catch (Exception ex)
     {
         CCBLogConfig.GetLogger().Error("Exception writing file {0}: {1}", m_localFile, ex.Message);
     }
     m_tick = DateTime.Now;
 }
Esempio n. 24
0
 public MainWindow()
 {
     m_config                       = new CCBConfig();
     m_games                        = new CCBGameData();
     m_templates                    = new List <CCBGameTemplate>();
     m_storeManager                 = new CCBStoreManager();
     m_deleteEnabled                = false;
     m_deleteUsed                   = false;
     m_onCharacterListUpdateD       = new DOnCharacterListUpdate(OnCharacterListUpdate);
     m_onAddingNewEntityModeD       = new DOnAddingNewEntityMode(OnAddingNewEntityMode);
     m_onCreateNewGameD             = new DOnCreateNewGame(OnCreateNewGame);
     m_onCreateNewTemplateD         = new DOnCreateNewTemplate(OnCreateNewTemplate);
     m_gameAdderEntry               = new CCBTreeViewGameAdder();
     m_worker                       = new BackgroundWorker();
     m_worker.WorkerReportsProgress = true;
     m_timer                        = new Timer(133337);
     m_timer.Elapsed               += new ElapsedEventHandler(OnTimer);
     m_timer.Start();
     m_chatWnd = null;
     InitializeComponent();
     try
     {
         m_config.Initialize();
         CCBLogConfig.InitLogging(m_config);
         tbStatus.Text = System.String.Format("{0} [v{1}]", m_config.DocPath, System.Environment.Version.ToString());
     }
     catch (System.Reflection.TargetInvocationException ex)
     {
         System.Diagnostics.Debug.WriteLine("Error caught in Main.");
         System.Diagnostics.Debug.WriteLine(ex.ToString());
     }
     m_worker.ProgressChanged    += new ProgressChangedEventHandler(Worker_OnProgressChanged);
     m_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_OnPersistenceCompleted);
     m_loaderD        = new DoWorkEventHandler(Worker_Load);
     m_worker.DoWork += m_loaderD;
     m_worker.RunWorkerAsync(m_config);
     SetDefaultView();
     AddOrMoveAdder();
 }
Esempio n. 25
0
        private void OnObjectClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                Hyperlink    hl        = (Hyperlink)sender;
                string       name      = hl.CommandParameter.ToString();
                CCBCharacter character = m_charactersReceived.FindSafe(name);

                if (null == character)
                {
                    AddChatText(string.Format("'{0}' not found.", name));
                }
                else
                {
                    CharacterSheetWnd characterWnd = new CharacterSheetWnd(character);

                    characterWnd.Show(this);
                }
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Log("OnObjectClicked: " + ex.Message);
            }
        }
Esempio n. 26
0
        private void OnUserConnectedEvent(string uid)
        {
            try
            {
                INetworkListener[] listeners = GetListeners();

                foreach (INetworkListener listener in listeners)
                {
                    listener.OnUser(uid);
                }
            }
            catch (System.IO.IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception in OnUser: {0}", ioex.Message);
            }
            catch (System.ServiceModel.CommunicationException commEx)
            {
                CCBLogConfig.GetLogger().Error("Comm Exception in OnUser: {0}", commEx.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception in OnUser: {0}", ex.Message);
            }
        }
Esempio n. 27
0
        public void OnDisconnected()
        {
            try
            {
                INetworkListener[] listeners = GetListeners();

                foreach (INetworkListener listener in listeners)
                {
                    listener.OnDisconnected();
                }
            }
            catch (System.IO.IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("Exception in OnDisconnected: {0}", ioex.Message);
            }
            catch (System.ServiceModel.CommunicationException commEx)
            {
                CCBLogConfig.GetLogger().Error("Exception in OnDisconnected: {0}", commEx.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception in OnDisconnected: {0}", ex.Message);
            }
        }
Esempio n. 28
0
        void ICeebeetlePeer.ChatMessage(string uid, string message)
        {
            try
            {
                INetworkListener[] listeners = GetListeners();

                foreach (INetworkListener listener in listeners)
                {
                    listener.OnMessage(uid, message);
                }
            }
            catch (System.IO.IOException ioex)
            {
                CCBLogConfig.GetLogger().Error("IO Exception in ChatMessage: {0}", ioex.Message);
            }
            catch (System.ServiceModel.CommunicationException commEx)
            {
                CCBLogConfig.GetLogger().Error("Comm Exception in ChatMessage: {0}", commEx.Message);
            }
            catch (Exception ex)
            {
                CCBLogConfig.GetLogger().Error("Exception in ChatMessage: {0}", ex.Message);
            }
        }
Esempio n. 29
0
 public CCBWindow()
     : base()
 {
     m_logger = CCBLogConfig.GetLogger();
 }
Esempio n. 30
0
 private void btn_CountableClicked(object sender, RoutedEventArgs e)
 {
     CCBLogConfig.GetLogger().Log("Countable clicked");
 }