Ejemplo n.º 1
0
        void Receive(object obj)
        {
            Socket     client     = obj as Socket;
            string     clientIP   = client.RemoteEndPoint.ToString().Split(':')[0];
            ClientInfo clientInfo = clientInfoManager.Find(clientIP);

            try
            {
                while (true)
                {
                    byte[] buffer = new byte[BUFFER_SIZE];
                    client.Receive(buffer);

                    DataContainer dataContainer = DataContainer.Deserialize(buffer);

                    switch (dataContainer.Type)
                    {
                    case DataContainerType.SendPcName:

                        string pcName = dataContainer.Data as string;
                        clientInfo.PCName = pcName;
                        clientInfo.Status = ClientInfoStatus.ClientConnected;

                        if (_onClientListChanged != null)
                        {
                            _onClientListChanged(clientInfoManager.Clients);
                        }

                        break;

                    case DataContainerType.SendStudent:
                        Student student1 = dataContainer.Data as Student;

                        clientInfo.StudentInfo = student1;
                        clientInfo.Status      = ClientInfoStatus.StudentConnected;

                        if (_onClientListChanged != null)
                        {
                            _onClientListChanged(clientInfoManager.Clients);
                        }

                        break;

                    case DataContainerType.ThuBai:

                        FileContainer fileNopBaiContainer = dataContainer.Data as FileContainer;

                        string savePath = this.serverPath;

                        if (!Directory.Exists(savePath))
                        {
                            Directory.CreateDirectory(savePath);
                        }

                        string fileName = fileNopBaiContainer.FileInfo.Name;
                        string fullPath = Path.Combine(savePath, fileName);

                        byte[] fileContent = fileNopBaiContainer.FileContent;

                        using (var fileStream = File.Create(fullPath))
                            fileStream.Write(fileContent, 0, fileContent.Length);

                        break;

                    case DataContainerType.SendList:
                        break;

                    case DataContainerType.SendString:
                        break;

                    case DataContainerType.BeginExam:
                        break;

                    case DataContainerType.FinishExam:
                        break;

                    case DataContainerType.LockClient:
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                clientInfo.Status = ClientInfoStatus.Disconnected;

                if (_onClientListChanged != null)
                {
                    _onClientListChanged(clientInfoManager.Clients);
                }

                clientList.Remove(client);
                client.Close();
            }
        }
Ejemplo n.º 2
0
 public Server(ServerConfig config, bool isPersistent = false, string workingDirectory = null)
 {
     _workingDirectory = workingDirectory;
     IsPersistent      = isPersistent;
     _dataContainer    = new DataContainer(config, _serverProfiler);
 }
Ejemplo n.º 3
0
        private void generateSummaryBtn_Click(object sender, EventArgs e)
        {
            String comparedFilesHeader    = String.Join(@";", "File1", "File2", "Ip", "Port", "ProcessorInfo", "ComparingTime", "DownloadFile1Time", "DownloadFile2Time", "SendingResultTime", "TotalNewtworkTransferTime", "PercentOfSimilarityFile1", "PercentOfSimilarityFile2");
            String notComparedFilesHeader = @"File1;File2";

            List <String> uncomparedFilesRows = DataContainer.read().UniquePairsOfFilesToCompare
                                                .Where(pairOfFiles => pairOfFiles.ComparingResult == null)
                                                .Select(pair =>
            {
                return(String.Format("{0};{1}", pair.FileName1, pair.FileName2));
            }).ToList();

            String notComparedFilesSummary = uncomparedFilesRows.Count() == 0 ? "" : String.Join(Environment.NewLine, uncomparedFilesRows);

            List <String> rows = DataContainer.read().UniquePairsOfFilesToCompare
                                 .Where(pairOfFiles => pairOfFiles.ComparingResult != null)
                                 .Select(pair =>
            {
                var client = pair.ComparedBy;                     //getClient(pair.ComparingResult.ClientUUID);
                var result = pair.ComparingResult;

                return(String.Join(@";",
                                   pair.FileName1,
                                   pair.FileName2,
                                   client.Ip,
                                   client.Port,
                                   client.ProcessorInfo.Replace(Environment.NewLine, ""),
                                   result.ComparingTime.TotalMilliseconds,
                                   result.File1DownloadingTime.TotalMilliseconds,
                                   result.File2DownloadingTime.TotalMilliseconds,
                                   result.SendingTime.TotalMilliseconds,
                                   result.File1DownloadingTime.TotalMilliseconds + result.File2DownloadingTime.TotalMilliseconds + result.SendingTime.TotalMilliseconds,
                                   result.PercentOfSimilarityFile1,
                                   result.PercentOfSimilarityFile2));
            }).ToList();


            String comparedFilesSummary = String.Join(Environment.NewLine, rows);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(comparedFilesHeader);
            sb.Append(comparedFilesSummary);
            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine();
            if (uncomparedFilesRows.Count() != 0)
            {
                sb.AppendLine("NotComparedFiles");
                sb.AppendLine(notComparedFilesHeader);
                sb.Append(notComparedFilesSummary);
            }

            String summaryContent = comparedFilesSummary;


            var    bytes        = Encoding.ASCII.GetBytes(sb.ToString());
            String filePathRoot = DataContainer.read().PathToFiles + @"\comparing_summary";

            if (!Directory.Exists(filePathRoot))
            {
                Directory.CreateDirectory(filePathRoot);
            }
            String strDate = DateTime.Now.ToString();

            strDate = strDate.Replace(":", "-").Replace(" ", "_");

            String newFileName = @"comparing_summary_" + strDate + ".csv";

            using (var fileStream = File.OpenWrite(filePathRoot + @"\" + newFileName))
            {
                fileStream.Write(bytes, 0, bytes.Length);
            }

            DataContainer.read().LogMessages.Add("Podsumowanie zostało zapisane w pliku: " + newFileName);
        }
Ejemplo n.º 4
0
 private void MonitorForm_Load(object sender, EventArgs e)
 {
     this.allFilesView.DataSource          = DataContainer.read().AllFiles;
     this.pairOfUniqueFilesView.DataSource = DataContainer.read().UniquePairsOfFilesToCompare.Select(el => new PairView(el)).ToList();
     this.workersView.DataSource           = DataContainer.read().AllClients.Select(el => new WorkerView(el)).ToList();
 }
Ejemplo n.º 5
0
 private void LogMessages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     textBox1.Text = "";
     textBox1.AppendText(String.Join(Environment.NewLine, DataContainer.read().LogMessages));
 }
Ejemplo n.º 6
0
 private void UniquePairsOfFilesToCompare_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     this.pairOfUniqueFilesView.DataSource = null;
     this.pairOfUniqueFilesView.DataSource = DataContainer.read().UniquePairsOfFilesToCompare.Select(el => new PairView(el)).ToList();
     this.pairOfUniqueFilesView.Refresh();
 }
Ejemplo n.º 7
0
 private void processorInfoBtn_Click(object sender, EventArgs e)
 {
     DataContainer.read().LogMessages.Add(new ProcessorService().getProcessorInfo());
 }