private bool GenerateSpriteSignatures(ref ClientItems items) { if (items.SignatureCalculated) { return(true); } ProgressForm progress = new ProgressForm(); progress.StartPosition = FormStartPosition.Manual; progress.Location = new Point(Location.X + ((Width - progress.Width) / 2), Location.Y + ((Height - progress.Height) / 2)); progress.bar.Minimum = 0; progress.bar.Maximum = items.Count; progress.Show(this); progress.progressLbl.Text = "Calculating image signatures..."; foreach (ClientItem clientItem in items.Values) { clientItem.GenerateSignature(); if (progress.bar.Value % 20 == 0) { Application.DoEvents(); } progress.bar.Value++; } items.SignatureCalculated = true; progress.Close(); return(true); }
public void CloseClient() { inputStream?.Dispose(); outputStream?.Dispose(); inputStream = null; outputStream = null; streamSocket.Dispose(); clientIsConnected = false; ClientItems.Add("client closed its socket"); }
public async void StartClient() { try { // Create the StreamSocket and establish a connection to the echo server. streamSocket = new StreamSocket(); // The server hostname that we will be establishing a connection to. In this example, the server and client are in the same process. var hostName = new Windows.Networking.HostName(ServerAddress); ClientItems.Add(string.Format("client is trying to connect to {0}:{1} ...", ServerAddress, ServerPort)); await streamSocket.ConnectAsync(hostName, ServerPort); clientIsConnected = true; ClientItems.Add("client connected"); } catch (Exception ex) { SocketErrorStatus webErrorStatus = SocketError.GetStatus(ex.GetBaseException().HResult); ClientItems.Add(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message); } }
public async void SendClientMessage() { try { // Send a request to the echo server. //string request = "Hello, World!"; if (outputStream == null) { outputStream = streamSocket.OutputStream.AsStreamForWrite(); } var streamWriter = new StreamWriter(outputStream); await streamWriter.WriteLineAsync(ClientMessage); await streamWriter.FlushAsync(); ClientItems.Add(string.Format("client sent the request: \"{0}\"", ClientMessage)); // Read data from the echo server. string response; if (inputStream == null) { inputStream = streamSocket.InputStream.AsStreamForRead(); } StreamReader streamReader = new StreamReader(inputStream); response = await streamReader.ReadLineAsync(); ClientItems.Add(string.Format("client received the response: \"{0}\" ", response)); } catch (Exception ex) { SocketErrorStatus webErrorStatus = SocketError.GetStatus(ex.GetBaseException().HResult); ClientItems.Add(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message); CloseClient(); } }
private void ToolsUpdateVersionMenuItem_Click(object sender, EventArgs e) { UpdateForm form = new UpdateForm(); form.MainForm = this; DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { // Update OTB Plugin updatePlugin = form.SelectedPlugin; SupportedClient updateClient = form.UpdateClient; if (updatePlugin == null) { return; } if (!this.LoadClient(updatePlugin, updateClient.OtbVersion)) { return; } UpdateSettingsForm updateSettingsForm = new UpdateSettingsForm(); result = updateSettingsForm.ShowDialog(); if (result != DialogResult.OK) { return; } if (updateSettingsForm.generateSignatureCheck.Checked) { // Calculate an image signature using fourier transformation and calculate a signature we can // use to compare it to other images (kinda similar to md5 hash) except this // can also be used to find images with some variation. ClientItems currentClientItems = this.CurrentPlugin.Instance.Items; this.GenerateSpriteSignatures(ref currentClientItems); ClientItems updateClientItems = updatePlugin.Instance.Items; this.GenerateSpriteSignatures(ref updateClientItems); } ClientItems currentItems = this.CurrentPlugin.Instance.Items; ClientItems updateItems = updatePlugin.Instance.Items; List <ushort> assignedSpriteIdList = new List <ushort>(); // store the previous plugin (so we can display previous sprite, and do other comparisions) this.PreviousPlugin = this.CurrentPlugin; // update the current plugin the one we are updating to this.CurrentPlugin = updatePlugin; // update version information this.serverItems.ClientVersion = updateClient.Version; this.serverItems.MinorVersion = updateClient.OtbVersion; this.serverItems.BuildNumber = this.serverItems.BuildNumber + 1; this.CurrentOtbVersion = this.serverItems.MinorVersion; // Most items does have the same sprite after an update, so lets try that first uint foundItemCounter = 0; foreach (ServerItem item in this.serverItems) { item.SpriteAssigned = false; if (item.Type == ServerItemType.Deprecated) { continue; } ClientItem updateClientItem; if (updateItems.TryGetValue(item.ClientId, out updateClientItem)) { bool compareResult = updateClientItem.Equals(item); if (Utils.ByteArrayCompare(updateClientItem.SpriteHash, item.SpriteHash)) { if (compareResult) { item.PreviousClientId = item.ClientId; item.ClientId = updateClientItem.ID; item.SpriteAssigned = true; assignedSpriteIdList.Add(updateClientItem.ID); ++foundItemCounter; // Trace.WriteLine(String.Format("Match found id: {0}, clientid: {1}", item.otb.id, item.dat.id)); } else { // Sprite matches, but not the other attributes. // Trace.WriteLine(String.Format("Attribute changes found id: {0}.", item.id)); } } } } if (updateSettingsForm.reassignUnmatchedSpritesCheck.Checked) { foreach (Item updateItem in updateItems.Values) { foreach (ServerItem item in this.serverItems) { if (item.Type == ServerItemType.Deprecated) { continue; } if (item.SpriteAssigned) { continue; } if (Utils.ByteArrayCompare(updateItem.SpriteHash, item.SpriteHash)) { if (updateItem.Equals(item)) { if (updateItem.ID != item.ClientId) { Trace.WriteLine(string.Format("New sprite found id: {0}, old: {1}, new: {2}.", item.ID, item.ClientId, updateItem.ID)); } item.PreviousClientId = item.ClientId; item.ClientId = updateItem.ID; item.SpriteAssigned = true; assignedSpriteIdList.Add(updateItem.ID); ++foundItemCounter; break; } } } } } Trace.WriteLine(string.Format("Found {0} of {1}.", foundItemCounter, this.serverItems.MaxId)); if (updateSettingsForm.reloadItemAttributesCheck.Checked) { uint reloadedItemCounter = 0; foreach (ServerItem item in this.serverItems) { if (item.Type == ServerItemType.Deprecated) { continue; } // implicit assigned item.PreviousClientId = item.ClientId; item.SpriteAssigned = true; if (!assignedSpriteIdList.Contains(item.ClientId)) { assignedSpriteIdList.Add(item.ClientId); } if (!this.CompareItem(item, true)) { // sync with dat info this.ReloadItem(item); ++reloadedItemCounter; } } Trace.WriteLine(string.Format("Reloaded {0} of {1} items.", reloadedItemCounter, this.serverItems.MaxId)); } if (updateSettingsForm.createNewItemsCheck.Checked) { uint newItemCounter = 0; foreach (Item updateItem in updateItems.Values) { if (!assignedSpriteIdList.Contains(updateItem.ID)) { ++newItemCounter; ServerItem newItem = this.CreateItem(updateItem); this.serverItems.Add(newItem); Trace.WriteLine(string.Format("Creating item id {0}", newItem.ID)); } } Trace.WriteLine(string.Format("Created {0} new items.", newItemCounter)); } // done this.BuildItemsListBox(); } }
private async void StartClient() { try { // Create the StreamSocket and establish a connection to the echo server. using (var streamSocket = new Windows.Networking.Sockets.StreamSocket()) { // The server hostname that we will be establishing a connection to. In this example, the server and client are in the same process. var hostName = new Windows.Networking.HostName("localhost"); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ClientItems.Add("client is trying to connect...")); await streamSocket.ConnectAsync(hostName, PortNumber); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ClientItems.Add("client connected")); // Send a request to the echo server. string request = "Hello, World!"; using (Stream outputStream = streamSocket.OutputStream.AsStreamForWrite()) { using (var streamWriter = new StreamWriter(outputStream)) { await streamWriter.WriteLineAsync(request); await streamWriter.FlushAsync(); } } await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ClientItems.Add(string.Format("client sent the request: \"{0}\"", request))); // Read data from the echo server. string response; using (Stream inputStream = streamSocket.InputStream.AsStreamForRead()) { using (StreamReader streamReader = new StreamReader(inputStream)) { response = await streamReader.ReadLineAsync(); } } await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ClientItems.Add(string.Format("client received the response: \"{0}\" ", response))); } await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ClientItems.Add("client closed its socket")); } catch (Exception ex) { Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ClientItems.Add(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message)); } //RaisePropertyChanged("ClientItems"); }
private bool GenerateSpriteSignatures(ref ClientItems items) { if (items.SignatureCalculated) { return true; } ProgressForm progress = new ProgressForm(); progress.StartPosition = FormStartPosition.Manual; progress.Location = new Point(Location.X + ((Width - progress.Width) / 2), Location.Y + ((Height - progress.Height) / 2)); progress.bar.Minimum = 0; progress.bar.Maximum = items.Count; progress.Show(this); progress.progressLbl.Text = "Calculating image signatures..."; foreach (ClientItem clientItem in items.Values) { clientItem.GenerateSignature(); if (progress.bar.Value % 20 == 0) { Application.DoEvents(); } progress.bar.Value++; } items.SignatureCalculated = true; progress.Close(); return true; }
private bool GenerateSpriteSignatures(ref ClientItems items) { if (items.signatureCalculated) { return true; } ProgressForm progress = new ProgressForm(); progress.StartPosition = FormStartPosition.Manual; progress.Location = new Point(Location.X + ((Width - progress.Width) / 2), Location.Y + ((Height - progress.Height) / 2)); progress.bar.Minimum = 0; progress.bar.Maximum = items.Count; progress.Show(this); foreach (ClientItem clientItem in items.Values) { Bitmap spriteBmp = GetBitmap(clientItem); Bitmap ff2dBmp = Fourier.fft2dRGB(spriteBmp, false); clientItem.SpriteSignature = ImageUtils.CalculateEuclideanDistance(ff2dBmp, 1); if (progress.bar.Value % 20 == 0) { Application.DoEvents(); } progress.progressLbl.Text = String.Format("Calculating image signature for item {0}.", clientItem.id); ++progress.bar.Value; } items.signatureCalculated = true; progress.Close(); return true; }