Beispiel #1
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     var scm = new Smc(Smc.ServiceProviderEnum.DES);
     
     var jd = new journal_contentData();
     jd.CodeOborude = codeOborude.Text;
     jd.Date = DateTime.Now.ToShortDateString();
     jd.Description = descriptionText.Text;
     jd.ModifyDate = DateTime.Now.ToShortDateString();
     jd.Enable = true;
     jd.Family = familyText.Text;
     jd.NameOborude = nameText.Text;
     jd.Smena = smenaText.Text;
     jd.Status = statusText.Text;
     jd.ID = EntryID;
     JournalPacket metadata = new JournalPacket(jd);
     string metatype = metadata.GetType().FullName;
     Client.Instance.SendCommand(Client.Instance.ServerIp, (EntryID != -1 ? OpcoDes.CMSG_SEND_JOURNAL_ENTRY : OpcoDes.CMSG_SEND_JOURNAL_ENTRY), metatype, metadata);
 }
Beispiel #2
0
        private void HandleCMSG_GETTING_JOURNAL(ClientManager cm, TimedEventArgs ea)
        {
            try
            {
                SSocket sSocket = cm.SSocket;
                if (!sSocket.Connected)
                    return;

                ResponsePacket d = (ResponsePacket)sSocket.Metadata;
                string news = new Smc(Smc.ServiceProviderEnum.TripleDES).Decrypt(d.Response);

                s_log.Debug("CMSG_GETTING_JOURNAL: {0} :: {1}:[{2}]", cm.ClientKey, ea.EventTime, news.Split(';').Length.ToString()/* + "::" + d.Response*/);
                
                string[] IdJournal = news.Split(';');
                for (int i = 0; i < IdJournal.Length; ++i)
                {
                    if (IdJournal[i] != "")
                    {
                        int _id = Convert.ToInt32(IdJournal[i].Split('-')[0]);
                        if (JournalManager.Instance.Contains(_id))
                        {
                            journal_contentData nct = JournalManager.Instance.FindByID(_id);

                            if (nct.ID > 0)
                            {
                                string md = IdJournal[i].Split('-')[1];
                                string pd = IdJournal[i].Split('-')[2];

                                if (string.IsNullOrEmpty(md) || md != nct.ModifyDate ||
                                    string.IsNullOrEmpty(pd) || pd != nct.Date)
                                {
                                    JournalPacket pck = new JournalPacket(nct);
                                    SendCommand(cm, OpcoDes.SMSG_JOURNAL_MODIFY_SYNC, pck);
                                    s_log.Trace("У клиента {0} :: Изменены записи: [{1}]", cm.ClientKey, _id);
                                }
                            }
                        }
                        else
                        {
                            ResponsePacket pck = new ResponsePacket("SocketServer", cm.UserName, _id.ToString());
                            SendCommand(cm, OpcoDes.SMSG_JOURNAL_REMOVE_SYNC, pck);
                            s_log.Trace("У клиента {0} :: Удалены записи: [{1}]", cm.ClientKey, _id);
                        }
                    }
                }
                SendResponse(cm, OpcoDes.SMSG_JOURNAL_SYNC_END, "SYNC_1");
            }
            catch (Exception exc)
            {
                LogUtil.ErrorException(exc, false, "HandleCMSG_GETTING_JOURNAL");
            }
        }
Beispiel #3
0
        private void HandleCMSG_GETTING_JOURNAL_2(ClientManager cm, TimedEventArgs ea)
        {
            DictionaryB idList = new DictionaryB();

            try
            {
                SSocket sSocket = cm.SSocket;
                if (!sSocket.Connected)
                    return;

                ResponsePacket d = (ResponsePacket)sSocket.Metadata;
                string news = new Smc(Smc.ServiceProviderEnum.TripleDES).Decrypt(d.Response);

                s_log.Debug("CMSG_GETTING_JOURNAL_2: {0} :: {1}:[{2}]", cm.ClientKey, ea.EventTime, news.Split(';').Length.ToString()/* + "::" + d.Response*/);

                string[] IdNews = news.Split(';');
                for (int i = 0; i < IdNews.Length; ++i)
                {
                    if (IdNews[i] != "")
                    {
                        int _id = Convert.ToInt32(IdNews[i]);
                        idList[_id] = _id.ToString();
                    }
                }

                StringBuilder IDS = new StringBuilder();
                IEnumerator en = JournalManager.Instance.JournalData.OrderBy(x=>x.ID).GetEnumerator();
                while (en.MoveNext())
                {
                    var entry = en.Current as JournalContentData;
                    if (!idList.Contains(entry.ID))
                    {
                        IDS.Append(entry.ID + ";");
                        JournalPacket pck = new JournalPacket(entry);
                        SendCommand(cm, OpcoDes.SMSG_JOURNAL_ADD_SYNC, pck); 
                    }
                }
                SendResponse(cm, OpcoDes.SMSG_JOURNAL_SYNC_END, "SYNC_2");
                if (IDS.Length > 0)
                {
                    s_log.Trace("У клиента {0} :: Добавлены записи: [{1}]", cm.ClientKey, IDS.ToString());
                    IDS.Remove(0, IDS.Length);
                }
                IDS = null;
            }
            catch (Exception exc)
            {
                LogUtil.ErrorException(exc, false, "HandleCMSG_GETTING_JOURNAL_2");
            }
            finally
            {
            }
        }
Beispiel #4
0
        private void HandleCMSG_SEND_JOURNAL_ENTRY(ClientManager cm, TimedEventArgs ea)
        {
            SSocket chatSocket = cm.SSocket;
            JournalPacket pck = (JournalPacket)chatSocket.Metadata;

            journal_contentData jd = pck.Data;
            if (JournalManager.Instance.Contains(jd.ID))
            {
                s_log.Info("Получили модифицированную запись с ID:" + jd.ID);
                JournalManager.Instance.Set(jd);

            }
            else if (JournalManager.Instance.Add(ref jd))
            {
                s_log.Info("Получили новую запись с ID:" + jd.ID);
            }

            JournalPacket data = new JournalPacket(jd);
            lock (clients.SyncRoot)
            {
                IEnumerator clientEnumerator = clients.GetEnumerator();
                while (clientEnumerator.MoveNext())
                {
                    DictionaryEntry entry = (DictionaryEntry)clientEnumerator.Current;
                    ClientManager c = (ClientManager)entry.Value;

                    SSocket ss = c.SSocket;
                    SendCommand(c, (pck.Data.ID != -1 ? OpcoDes.SMSG_JOURNAL_MODIFY : OpcoDes.SMSG_JOURNAL_ADD), data);
                }
            }
        }