Beispiel #1
0
        /// <summary>
        /// Subscribes to all events for the request
        /// </summary>
        /// <param name="requestID"></param>
        /// <returns></returns>
        public Subscription CreateSubscription(string requestID)
        {
            var msg = new ExchangeMessage()
            {
                RequestID = Guid.Parse(requestID)
            };

            return(CreateSubscription <ExchangeMessage>(msg));
        }
        public ActionResult Proposition(PropositionModel model)
        {
            if (model.SelectedBooks == null)
            {
                ModelState.AddModelError("", "Musisz zaproponować co najmniej jedną książkę");
                model = GetPropositionModel(Request.QueryString["bookId"]);
                return(View(model));
            }
            AppUser currentUser;
            int     bookId = 0;

            Int32.TryParse(Request.QueryString["bookId"], out bookId);
            Book interested;
            ICollection <Book> proposedBooks = new List <Book>();

            using (var context = new AppDbContext())
            {
                currentUser = context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId());
                interested  = context.Books.Find(bookId);
                foreach (string id in model.SelectedBooks)
                {
                    proposedBooks.Add(context.Books.Find(Int32.Parse(id)));
                }
                if (interested != null && interested.Changeable)
                {
                    ExchangeMessage eMessage = new ExchangeMessage()
                    {
                        Text          = model.Text,
                        SendDate      = DateTime.Now,
                        SenderId      = currentUser.Id,
                        Sender        = currentUser,
                        ReceiverId    = interested.SellerId,
                        Receiver      = interested.Seller,
                        ForBook       = interested,
                        BookId        = interested.BookId,
                        Accepted      = false,
                        ProposedBooks = proposedBooks
                    };
                    context.ExchangeMessages.Add(eMessage);
                    context.SaveChanges();
                }
                else
                {
                    return(RedirectToAction("Information", "Info", new { text = "Error" }));
                }
            }
            return(RedirectToAction("Book", "Home", new { bookId = bookId }));
        }
        public ActionResult CancelProposition(string propositionId)
        {
            var     context     = new AppDbContext();
            AppUser currentUser = context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId());
            int     id          = 0;

            Int32.TryParse(propositionId, out id);
            ExchangeMessage eMessage = context.ExchangeMessages.Find(id);

            if (currentUser != null && eMessage != null && eMessage.SenderId == currentUser.Id)
            {
                context.ExchangeMessages.Remove(eMessage);
                context.SaveChanges();
                return(RedirectToAction("Propositions", "Transaction"));
            }
            else
            {
                return(RedirectToAction("Information", "Info", new { text = "Error" }));
            }
        }
        internal Exchange(ExchangeMessage message, RepeatedField <InstrumentMessage> instruments = null)
        {
            Id          = message.Id;
            Name        = message.Name;
            DisplayName = message.DisplayName;
            Description = message.Description.EmptyToNull();

            if (instruments != null)
            {
                var items = new Instrument[instruments.Count];
                for (var i = 0; i < items.Length; i++)
                {
                    items[i] = new Instrument(instruments[i]);
                }
#if NETSTANDARD1_5
                Instruments = items;
#else
                Instruments = Array.AsReadOnly(items);
#endif
            }
        }
Beispiel #5
0
        private static ProtocolExchange ToProtocolExchange(this ExchangeMessage message)
        {
            switch (message.Message)
            {
            case Messages.ListRoomsRequest _:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    ListRoomRequest = new ListRoomsRequest()
                });

            case Messages.ListRoomsResponse listRoomsResponse:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    ListRoomResponse = new ListRoomsResponse
                    {
                        Rooms =
                        {
                            listRoomsResponse.Rooms.Select(room => new ChatRoom
                            {
                                Id = room.Id,
                                Name = room.Name
                            })
                        }
                    }
                });

            case Messages.CreateRoomRequest createRoomRequest:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    CreateRoomRequest = new CreateRoomRequest
                    {
                        RoomName = createRoomRequest.RoomName
                    }
                });

            case Messages.CreateRoomResponse createRoomResponse:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    CreateRoomResponse = new CreateRoomResponse
                    {
                        Room = createRoomResponse.Room.ToProtobuf()
                    }
                });

            case Messages.JoinRoomRequest joinRoomRequest:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    JoinRoomRequest = new JoinRoomRequest
                    {
                        RoomId = joinRoomRequest.RoomId
                    }
                });

            case Messages.JoinRoomResponse joinRoomResponse:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    JoinRoomResponse = new JoinRoomResponse
                    {
                        Room = joinRoomResponse.Room.ToProtobuf(),
                        Messages =
                        {
                            joinRoomResponse.Messages.Select(chatMessage => chatMessage.ToProtobuf())
                        }
                    }
                });

            case Messages.LeaveRoomRequest leaveRoomRequest:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    LeaveRoomRequest = new LeaveRoomRequest
                    {
                        Room = leaveRoomRequest.Room.ToProtobuf()
                    }
                });

            case Messages.LeaveRoomResponse leaveRoomResponse:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    LeaveRoomResponse = new LeaveRoomResponse
                    {
                        Room = leaveRoomResponse.Room.ToProtobuf()
                    }
                });

            case ChatErrorResponse errorResponse:
                return(new ProtocolExchange
                {
                    ExchangeId = message.ExchangeId,
                    ChatError = new ChatError
                    {
                        Message = errorResponse.Description
                    }
                });

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public ActionResult AcceptProposition(string propositionId)
        {
            var     context     = new AppDbContext();
            AppUser currentUser = context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId());
            int     id          = 0;

            Int32.TryParse(propositionId, out id);
            ExchangeMessage eMessage = context.ExchangeMessages.Find(id);
            Transaction     transaction;
            Book            book = context.Books.Find(eMessage.BookId);
            ICollection <ExchangeMessage> allReceivedExMessages = eMessage.Sender.ReceivedExchangeMessages;
            ICollection <ExchangeMessage> allSentExMesssages    = eMessage.Sender.SentExchangeMessages;

            if (currentUser != null && eMessage != null && eMessage.ReceiverId == currentUser.Id)
            {
                eMessage.Accepted = true;
                book.isChanged    = true;
                book.Buyer        = eMessage.Sender;
                book.BuyerId      = eMessage.SenderId;
                foreach (Book b in eMessage.ProposedBooks)
                {
                    b.isChanged = true;
                }


                //deleting propositions related to changed book
                foreach (ExchangeMessage e in currentUser.ReceivedExchangeMessages.ToList())
                {
                    if (e.BookId == book.BookId && e.ExchangeMessageId != eMessage.ExchangeMessageId)
                    {
                        context.ExchangeMessages.Remove(e);
                    }
                }
                foreach (ExchangeMessage e in currentUser.SentExchangeMessages.ToList())
                {
                    if (e.ProposedBooks.Contains(book))
                    {
                        context.ExchangeMessages.Remove(e);
                    }
                }


                //deleting propositions related to proposed books by other user
                foreach (ExchangeMessage e in allReceivedExMessages.ToList())
                {
                    if (eMessage.ProposedBooks.Any(x => x.BookId == e.BookId))
                    {
                        context.ExchangeMessages.Remove(e);
                    }
                }
                foreach (ExchangeMessage e in allSentExMesssages.ToList())
                {
                    foreach (Book b in eMessage.ProposedBooks)
                    {
                        if (e.ProposedBooks.Contains(b) && e.ExchangeMessageId != eMessage.ExchangeMessageId)
                        {
                            context.ExchangeMessages.Remove(e);
                        }
                    }
                }


                transaction = new Transaction()
                {
                    Exchanged         = true,
                    SellerCommented   = false,
                    BuyerCommented    = false,
                    BuyerId           = eMessage.SenderId, //zamienić buyer z seller
                    Buyer             = eMessage.Sender,
                    SellerId          = currentUser.Id,
                    Seller            = currentUser,
                    BookId            = eMessage.BookId,
                    SoldBook          = eMessage.ForBook,
                    ExchangeMessageId = eMessage.ExchangeMessageId,
                    ExMessage         = eMessage,
                    SelectedDelivery  = null,
                    DeliveryId        = null
                };
                context.Transactions.Add(transaction);
                context.SaveChanges();
                LuceneSearchIndexer.UpdateBooksIndex();
                return(RedirectToAction("Propositions", "Transaction"));
            }
            else
            {
                return(RedirectToAction("Information", "Info", new { text = "Error" }));
            }
        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            string itemText   = null;
            string tagText    = null;
            var    senderItem = sender as MenuItem;

            if (sender is MenuItem)
            {
                itemText = (sender as MenuItem).Header as string;
            }
            tagText = senderItem.Tag as string;

            if (itemText == "Telnet")
            {
                var devName  = "STEVE26";
                var termType = "IBM-3477-FC"; // IBM-3477-FC, IBM-3179-2
                TelnetInitialConnect(
                    this.Model.SystemName, this.Model.AutoConnect, this.Model.DeviceName, this.Model.TerminalType);
            }

            else if (itemText == "Printer")
            {
                TelnetPrinterConnect(this.Model.SystemName);
            }

            else if (itemText == "Exit")
            {
                this.canAutoClose = true;
                this.Close();
            }

            else if (itemText == "Test")
            {
                var s2 = this.Model.ScreenDefnPath;
                Debug.Print("ScreenDefnPath:" + s2);
            }

            else if (itemText == "Read xml")
            {
                string    xmlPath = "c:\\skydrive\\c#\\TextCanvasLib\\xmlfile1.xml";
                var       items   = ScreenDocReader.ReadDoc(xmlPath);
                OneRowCol caret   = null;
                this.Model.TelnetCanvas.PaintScreen(items, caret);
            }

            else if (itemText == "Print log")
            {
                LinePrinter.PrintLines(this.Model.RunLog);
            }
            else if (itemText == "Clear log")
            {
                MainWindow.LogFile.ClearFile();
                this.Model.RunLog.Clear();
                this.PaintThread.PostInputMessage(ThreadMessageCode.ClearLog);
                this.MasterThread.PostInputMessage(ThreadMessageCode.ClearLog);
                this.ToThread.PostInputMessage(ThreadMessageCode.ClearLog);
                this.FromThread.PostInputMessage(ThreadMessageCode.ClearLog);
            }
            else if (itemText == "view special")
            {
                var    specialPath = "c:\\downloads\\specialLog.txt";
                string exePath     =
                    Environment.ExpandEnvironmentVariables(@"%windir%\system32\notepad.exe");
                Process.Start(exePath, specialPath);
            }

            else if (itemText == "Report canvas items")
            {
                MasterThread.PostInputMessage(ThreadMessageCode.ReportVisualItems);
                var visualItems = this.Model.TelnetCanvas.VisualItems;
                var report      = wtdReportExt.PrintVisualItems(visualItems);
                this.Model.RunLog.AddRange(report);
            }

            else if (itemText == "Send data")
            {
                var dataBytes = new byte[] { 0x00, 0x0a, 0x12, 0xa0, 0x01, 0x02,
                                             0x04, 0x00, 0x00, 0x01, 0xff, 0xef };

                dataBytes = new byte[] { 0x00, 0x0A, 0x12, 0xA0, 0x01, 0x02,
                                         0x04, 0x00, 0x00, 0x01, 0xFF, 0xEF };

                var dataMessage = new SendDataMessage(dataBytes);
                this.ToThread.PostInputMessage(dataMessage);
            }

            // capture the currently matched screen.
            else if (tagText == "Capture")
            {
                if (this.Model.MatchScreenDefn == null)
                {
                    MessageBox.Show("no matched screen to capture");
                }
                else
                {
                    // send message to master thread to get the current screen content.
                    var msg = new ExchangeMessage(ThreadMessageCode.GetScreenContent);
                    this.MasterThread.PostInputMessage(msg);
                    msg.WaitReplyEvent();
                    var content = msg.ReplyMessage as ScreenContent;

                    // send message to capture thread telling it to capture the current
                    // screen.
                    var captureMessage = new CaptureContentMessage(
                        this.Model.CaptureFolderPath, this.Model.CaptureAuto,
                        this.Model.MatchScreenDefn, content);
                    this.CaptureThread.PostInputMessage(captureMessage);
                }
            }

            else if (tagText == "CaptureViewer")
            {
                var window = new CaptureViewerWindow();
                window.CaptureFolderPath = this.Model.CaptureFolderPath;
                window.Show();
            }
        }
        /// <summary>
        /// import the ContentItems of the current ScreenContent. Use the MasterThread
        /// property to send a message to the MasterThread asking for a copy of the
        /// current screenContent. That sent message waits for a response and receives
        /// the screenContent as the reply. With the screenContent, then list the
        /// ScreenContent items and import into ScreenDefn.
        ///
        /// Necessary for this to work, the telnetClient which is the parent of the
        /// ScreenDefnListControl must bind to the MasterThread property.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void butImport_Click(object sender, RoutedEventArgs e)
        {
            // send a message to the master thread asking for a copy of the current
            // screenContent.
            ScreenContent content = null;
            {
                var msg = new ExchangeMessage(ThreadMessageCode.GetScreenContent);
                this.MasterThread.PostInputMessage(msg);
                msg.WaitReplyEvent();
                content = msg.ReplyMessage as ScreenContent;
            }

            // create screen section. type body.
            var section = new ScreenSectionModel()
            {
                ScreenLoc   = new OneScreenLoc(1, 1),
                ItemName    = "Body",
                ItemType    = ShowItemType.Section,
                PurposeCode = ScreenPurposeCode.Body
            };

            this.Model.AddItem(section);

            int fieldNum = 0;
            int litNum   = 0;

            foreach (var citem in content.ContentItems( ))
            {
                if (citem is ContentField)
                {
                    var fld = citem as ContentField;

                    {
                        fieldNum += 1;
                        var xx   = fld.IsBypass;
                        var item = new ScreenFieldModel()
                        {
                            ScreenLoc = new OneScreenLoc(fld.RowCol.ToOneBased()),
                            ItemName  = "Field" + fieldNum,
                            Length    = fld.LL_Length,
                            ItemType  = ShowItemType.Field,
                            Usage     = fld.Usage,
                            DsplyAttr = fld.AttrByte.ToDsplyAttr()
                        };
                        section.AddItem(item);
                    }
                }
                else if (citem is ContentText)
                {
                    var contentText = citem as ContentText;
                    {
                        litNum += 1;
                        var item = new ScreenLiteralModel()
                        {
                            ScreenLoc  = new OneScreenLoc(contentText.RowCol.ToOneBased()),
                            ItemName   = "Lit" + litNum,
                            ListValues = contentText.GetShowText(content).ToListString().ToObservableCollection( ),
                            Length     = contentText.GetShowText(content).Length,
                            ItemType   = ShowItemType.Literal,
                            DsplyAttr  = contentText.GetAttrByte(content).ToDsplyAttr()
                        };

#if skip
                        // adjust screenLoc to account for neutral dsply attr.
                        if (item.DsplyAttr.IsEqual(DsplyAttr.NU))
                        {
                            item.ScreenLoc = item.ScreenLoc.Advance(1, new AutoCoder.Telnet.Common.ScreenDm.ScreenDim(24, 80)) as OneScreenLoc;
                        }
#endif

                        section.AddItem(item);
                    }
                }
            }
        }