Exemplo n.º 1
0
        private async void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            IStoredImage item = ((FrameworkElement)e.OriginalSource).DataContext as IStoredImage;

            if (item != null)
            {
                await this.ViewModel.LabelPreviewAsync(item);
            }
        }
Exemplo n.º 2
0
        public Task LabelPreviewAsync(IStoredImage item = null)
        {
            if (this.SelectedLabel != null)
            {
                Process.Start(new ProcessStartInfo(item == null ? this.SelectedLabel.FullPath : item.FullPath)
                {
                    UseShellExecute = true
                });
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        protected async Task DeleteLabelAsync()
        {
            try
            {
                if (this.SelectedLabel != null)
                {
                    int currentIndex = this.Labels.IndexOf(this.SelectedLabel);

                    if (await this.ImageCacheRepository.DeleteImageAsync(this.ImagePath, Path.GetFileName(this.SelectedLabel.FullPath)))
                    {
                        this.Labels.Remove(this.SelectedLabel);

                        if (this.Labels.Any())
                        {
                            IStoredImage label = this.Labels.ElementAt(currentIndex >= this.Labels.Count() ? currentIndex - 1 : currentIndex);

                            if (label != null)
                            {
                                this.SelectedLabel = label;
                            }
                            else
                            {
                                this.SelectedLabel = this.Labels.Last();
                            }
                        }
                        else
                        {
                            this.SelectedLabel = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.StatusText = $"Error: {ex.Message}";
            }
            finally
            {
                this.RefreshCommands();
            }
        }
Exemplo n.º 4
0
        public async Task StartSessionAsync(TcpClient client, ILabelConfiguration labelConfiguration, string imagePathRoot)
        {
            //
            // Set parameters.
            //
            client.ReceiveTimeout    = 1000;
            client.SendTimeout       = 1000;
            client.LingerState       = new LingerOption(false, 0);
            client.NoDelay           = true;
            client.ReceiveBufferSize = 8192;
            client.SendBufferSize    = 8192;

            //
            // Get the network stream.
            //
            NetworkStream stream = client.GetStream();

            while (client.Connected && stream.CanRead)
            {
                if (stream.DataAvailable)
                {
                    try
                    {
                        //
                        // Create a buffer for the data that is available.
                        //
                        byte[] buffer = new byte[client.Available];

                        //
                        // Read the data into the buffer.
                        //
                        int bytesRead = await stream.ReadAsync(buffer.AsMemory(0, buffer.Length));

                        if (bytesRead > 0)
                        {
                            //
                            // Get the label image
                            //
                            string zpl = Encoding.UTF8.GetString(buffer);

                            if (zpl != "NOP")
                            {
                                IGetLabelResponse response = await this.LabelService.GetLabelAsync(labelConfiguration, zpl);

                                //
                                // Save the image.
                                //
                                IStoredImage storedImage = await this.ImageCacheRepository.StoreImageAsync(imagePathRoot, response.Label);

                                //
                                // Publish the new label.
                                //
                                this.EventAggregator.GetEvent <LabelCreatedEvent>().Publish(new LabelCreatedEventArgs()
                                {
                                    PrintRequest = new PrintRequestEventArgs()
                                    {
                                        LabelConfiguration = labelConfiguration,
                                        Zpl = zpl
                                    },
                                    Label   = storedImage,
                                    Result  = response.Result,
                                    Message = response.Result ? "Label successfully created." : response.Error
                                });
                            }
                        }
                    }
                    finally
                    {
                        client.Close();
                    }
                }
            }
        }