Ejemplo n.º 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (_messages != null ? _messages.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ _timeOut;
         hashCode = (hashCode * 397) ^ IsObject.GetHashCode();
         hashCode = (hashCode * 397) ^ (ObjectName != null ? ObjectName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DisplayName != null ? DisplayName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ RabbitMQSourceResourceId.GetHashCode();
         hashCode = (hashCode * 397) ^ (QueueName != null ? QueueName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Response != null ? Response.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Prefetch != null ? Prefetch.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Acknowledge.GetHashCode();
         hashCode = (hashCode * 397) ^ (TimeOut != null ? TimeOut.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ReQueue.GetHashCode();
         hashCode = (hashCode * 397) ^ (Consumer != null ? Consumer.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Connection != null ? Connection.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Channel != null ? Channel.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RabbitSource != null ? RabbitSource.GetHashCode() : 0);
         return(hashCode);
     }
 }
Ejemplo n.º 2
0
        private static Response ModifyCourseResponse(CreateCourseRequest createCourseRequest)
        {
            DatabaseManager database = new DatabaseManager();

            (MySqlDataReader reader, var Connection) = database.RunQuery($"UPDATE course_details SET coursename='{createCourseRequest.CourseName}' WHERE courseid='{createCourseRequest.UserId}' ");
            if (reader != null)
            {
                Acknowledge ack = new Acknowledge()
                {
                    Status = "OK", Reason = ""
                };
                if (reader.RecordsAffected > 0)
                {
                    Connection.Close();
                    return(new Response()
                    {
                        Type = ResponseType.Acknowledge, Content = ack, Status = "OK"
                    });
                }
            }
            Connection.Close();
            return(new Response()
            {
                Content = null, Type = ResponseType.Acknowledge, Status = "FAIL"
            });
        }
Ejemplo n.º 3
0
        private static Response LikeVideoResponse(LikeVideo likeVideo)
        {
            DatabaseManager database = new DatabaseManager();
            string          query    = "";

            if (likeVideo.LikeDislike > 0)
            {
                query = $"UPDATE video_details SET likes=likes+1 WHERE videoid = '{likeVideo.VideoID}'";
            }
            else
            {
                query = $"UPDATE video_details SET dislikes=dislikes+1 WHERE videoid = '{likeVideo.VideoID}'";
            }
            (MySqlDataReader reader, var Connection) = database.RunQuery(query);
            Acknowledge ack = new Acknowledge()
            {
                Status = "OK", Reason = "Liked"
            };
            Response resp = new Response()
            {
                Type = ResponseType.Acknowledge, Status = "OK", Content = ack
            };

            if (reader == null)
            {
                ack.Reason = "Unable to like";
                ack.Status = "FAIL";
            }
            Connection.Close();
            return(resp);
        }
Ejemplo n.º 4
0
        private void ReceiveImage(string fileName, string extWithDot, bool IsProfileImage = true)
        {
            string folder = "/User/";

            if (!IsProfileImage)
            {
                folder = "/Thumbnails/";
            }

            Acknowledge ack = new Acknowledge()
            {
                Status = "FAIL", Reason = "Photo failed to update."
            };
            Response resp = new Response()
            {
                Content = ack, Status = "OK", Type = ResponseType.Acknowledge
            };

            if (ReceiveFile(fileName, extWithDot, _client))
            {
                if (File.Exists(serverroot + folder + fileName + extWithDot))
                {
                    File.Delete(serverroot + folder + fileName + extWithDot);
                }
                File.Move(serverroot + "/Temp/" + fileName + extWithDot, serverroot + folder + fileName + extWithDot);
                ack.Status = "OK";
                ack.Reason = String.Format("{0} Updated Successfully.", IsProfileImage ? "Profile" : "Video");
            }
            NetworkStream ns       = _client.GetStream();
            var           response = JsonConvert.SerializeObject(resp);

            byte[] buffer = Encoding.UTF8.GetBytes(response);
            ns.Write(buffer, 0, response.Length);
        }
Ejemplo n.º 5
0
        private async void deleteVideoButton_Click(object sender, RoutedEventArgs e)
        {
            DeleteCourseRequest request = new DeleteCourseRequest()
            {
                CourseID = ((CourseDetails)Tag).CourseID
            };
            Object resp = await ConnectionManager.SendRequestAsync(request, RequestType.DeleteCourse, ResponseType.Acknowledge);

            if (resp != null)
            {
                Acknowledge result = ((JObject)resp).ToObject <Acknowledge>();
                if (result.Status == "OK")
                {
                    ((WrapPanel)Parent).Children.Remove(this);
                }
                AppNotificationManager.PushMessage(new AppNotification()
                {
                    Message = result.Reason
                });
            }
            else
            {
                AppNotificationManager.PushMessage(new AppNotification()
                {
                    Message = "Failed to delete course."
                });
            }
        }
Ejemplo n.º 6
0
        private static Response DeleteCommentResponse(DeleteComment deleteComment)
        {
            Acknowledge ack = new Acknowledge()
            {
                Status = "OK", Reason = ""
            };
            Response resp = new Response()
            {
                Type = ResponseType.Acknowledge, Status = "OK", Content = ack
            };
            string          query    = string.Format("DELETE FROM comments WHERE uid = '{0}' AND videoid = '{1}'", deleteComment.CommentID, deleteComment.VideoID);
            DatabaseManager database = new DatabaseManager();

            (MySqlDataReader reader, var Connection) = database.RunQuery(query);
            if (reader != null)
            {
                if (reader.RecordsAffected == 0)
                {
                    ack.Status = "FAIL";
                    ack.Reason = "Failed to delete comment.";
                }
                Connection.Close();
                return(resp);
            }
            else
            {
                Connection.Close();
                return(new Response()
                {
                    Type = ResponseType.Acknowledge, Status = "FAIL"
                });
            }
        }
    public async Task <bool> SaveAcknowledgeAsync(Acknowledge acknowledge, CancellationToken ct = default(CancellationToken))
    {
        var insertOperation = TableOperation.Insert(acknowledge.ToAcknowledgeDTO());
        var res             = await table.ExecuteAsync(insertOperation, null, null, ct);

        return(res.HttpStatusCode / 100 == 2);
    }
Ejemplo n.º 8
0
#pragma warning disable S1541 // Methods and properties should not be too complex
        public override int GetHashCode()
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            unchecked
            {
                var hashCode = base.GetHashCode();
                hashCode = (hashCode * 397) ^ (_messages != null ? _messages.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ _timeOut;
                hashCode = (hashCode * 397) ^ IsObject.GetHashCode();
                hashCode = (hashCode * 397) ^ (ObjectName != null ? ObjectName.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (DisplayName != null ? DisplayName.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ RabbitMQSourceResourceId.GetHashCode();
                hashCode = (hashCode * 397) ^ (QueueName != null ? QueueName.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Response != null ? Response.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Prefetch != null ? Prefetch.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Acknowledge.GetHashCode();
                hashCode = (hashCode * 397) ^ (TimeOut != null ? TimeOut.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ ReQueue.GetHashCode();
                hashCode = (hashCode * 397) ^ (Consumer != null ? Consumer.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Connection != null ? Connection.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Channel != null ? Channel.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (RabbitSource != null ? RabbitSource.GetHashCode() : 0);
                return(hashCode);
            }
        }
Ejemplo n.º 9
0
        public static PatternImage Create(
            string designerDirectory,
            string categoryDirectory,
            string reference,
            string version,
            PatternImageSize size)
        {
            Require.NotNullOrEmpty(designerDirectory, "directory");
            Require.NotNullOrEmpty(reference, "reference");
            Contract.Ensures(Contract.Result <PatternImage>() != null);

            switch (size)
            {
            case PatternImageSize.Preview:
                return(new Preview_ {
                    CategoryDirectory = categoryDirectory,
                    DesignerDirectory = designerDirectory,
                    Reference = reference,
                    Version = version,
                });

            case PatternImageSize.Original:
                return(new Original_ {
                    CategoryDirectory = categoryDirectory,
                    DesignerDirectory = designerDirectory,
                    Reference = reference,
                    Version = version,
                });

            default:
                throw Acknowledge.Unreachable(
                          "The pattern size '" + size.ToString() + "' is not yet handled.");
            }
        }
Ejemplo n.º 10
0
        private async void postCommentButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(commentTextBlock1.Text) || Tag == null)
            {
                return;
            }
            PostComment comment = new PostComment()
            {
                UserID    = SettingsManager.Username,
                Username  = SettingsManager.FullName,
                Content   = commentTextBlock1.Text,
                Thumbnail = SettingsManager.ProfilePath.Replace("http://" + SettingsManager.ServerIp + "/root", ""),
                VideoID   = Tag.ToString()
            };

            postCommentProgess.isActive = true;
            postCommentButton.IsEnabled = false;
            Object resp = new JObject();

            resp = await ConnectionManager.SendRequestAsync(comment, RequestType.PostComment, ResponseType.Acknowledge);

            if (resp != null)
            {
                Acknowledge ack = ((JObject)resp).ToObject <Acknowledge>();
                if (ack.Status == "OK")
                {
                    postCommentButton.Content = "Posted";

                    ((ListView)Parent).Items.Insert(1, new CommentView()
                    {
                        Comment = new Comment()
                        {
                            Content   = commentTextBlock1.Text,
                            Date      = DateTime.Now,
                            Dislikes  = 0,
                            Likes     = 0,
                            Thumbnail = SettingsManager.ProfilePath.Replace("http://" + SettingsManager.ServerIp + "/root", ""),
                            Uid       = SettingsManager.Username,
                            Username  = SettingsManager.FullName,
                            UserId    = SettingsManager.Username,
                            VideoID   = Tag.ToString()
                        }
                        , IsReadOnlyType = true
                        , VideoOwner     = ""
                        , Tag            = ack.Reason
                    });
                    commentTextBlock1.Text = "";
                }
                else
                {
                    postCommentButton.Content = "Failed";
                }
            }
            else
            {
                postCommentButton.IsEnabled = true;
                postCommentButton.Content   = "Repost";
            }
            postCommentProgess.isActive = false;
        }
Ejemplo n.º 11
0
        /// <summary>
        ///   Send <param name = "bytes">bytes</param> to given <param name = "address">address</param>
        ///   This is a non blocking method.
        /// </summary>
        public void SendTo(byte[] address, byte[] bytes, Acknowledge acknowledge = Acknowledge.Yes)
        {
            // Address must be LSByte to MSByte per nRF24L01+ Datasheet
            address = ByteReverse(address);

            // Message must be LSByte to MSByte per nRF24L01+ Datasheet
            bytes = ByteReverse(bytes);

            // Chip enable low
            SetDisabled();

            // Setup PTX (Primary TX)
            SetTransmitMode();

            // Write transmit adres to TX_ADDR register.
            Execute(Commands.W_REGISTER, Registers.TX_ADDR, address);

            // Write transmit adres to RX_ADDRESS_P0 (Pipe0) (For Auto ACK)
            Execute(Commands.W_REGISTER, Registers.RX_ADDR_P0, address);

            // Send payload
            Execute(acknowledge == Acknowledge.Yes ? Commands.W_TX_PAYLOAD : Commands.W_TX_PAYLOAD_NO_ACK, 0x00, bytes);

            // Pulse for CE -> starts the transmission.
            SetEnabled();
        }
Ejemplo n.º 12
0
        public static Protocol Create(Buffer reader, Version version)
        {
            if (BASE_SIZE > reader.BytesLeft)
            {
                return(null);
            }

            byte command_flags          = reader.ReadByte();
            var  channel                = reader.ReadByte();
            var  reliableSequenceNumber = reader.ReadUInt16();

            Protocol result;

            switch ((ProtocolCommand)(command_flags & 0x0Fu))
            {
            case ProtocolCommand.NONE: result = null; break;

            case ProtocolCommand.ACKNOWLEDGE: result = new Acknowledge(); break;

            case ProtocolCommand.CONNECT: result = new Connect(); break;

            case ProtocolCommand.VERIFY_CONNECT: result = new VerifyConnect(); break;

            case ProtocolCommand.DISCONNECT: result = new Disconnect(); break;

            case ProtocolCommand.PING: result = new Ping(); break;

            case ProtocolCommand.SEND_FRAGMENT: result = new Send.Fragment(); break;

            case ProtocolCommand.SEND_RELIABLE: result = new Send.Reliable(); break;

            case ProtocolCommand.SEND_UNRELIABLE: result = new Send.Unreliable(); break;

            case ProtocolCommand.SEND_UNSEQUENCED: result = new Send.Unsequenced(); break;

            case ProtocolCommand.BANDWIDTH_LIMIT: result = new BandwidthLimit(); break;

            case ProtocolCommand.THROTTLE_CONFIGURE: result = new ThrottleConfigure(); break;

            default: result = null; break;
            }
            ;

            if (result == null || (result.Size - BASE_SIZE) > reader.BytesLeft)
            {
                return(null);
            }

            result.ChannelID = channel;
            result.Flags     = (ProtocolFlag)(command_flags & 0xF0);
            result.ReliableSequenceNumber = reliableSequenceNumber;
            result.ReadInternal(reader, version);

            return(result);
        }
        private static Acknowledge getAcknowledgeMessage(NetMessage message)
        {
            NetAcknowledge netAck = message.Action.AcknowledgeMessage;

            Acknowledge ack = new Acknowledge();

            ack.Action_id   = netAck.ActionId;
            ack.Destination = netAck.Destination;
            ack.Message_id  = netAck.MessageId;

            return(ack);
        }
 public static AcknowledgeDTO ToAcknowledgeDTO(this Acknowledge a)
 {
     return(new AcknowledgeDTO(a.CareRecipientId, a.Action)
     {
         CareTakerId = a.CareTakerUserId,
         CareRecipientId = a.CareRecipientId,
         Action = a.Action,
         CareTakerGPSLat = a.CareTakerLocation.gpsLat,
         CareTakerGPSLong = a.CareTakerLocation.gpsLong,
         CareRecipientGPSLat = a.CareRecipientLocation.gpsLat,
         CareRecipientGPSLong = a.CareRecipientLocation.gpsLong
     });
 }
Ejemplo n.º 15
0
        protected override void ExecuteDetails(object context)
        {
            var acknowledgement = new Acknowledge(ResponseCodes.SUCCESS, "true");
            var envelope        = new Envelope()
            {
                Message = acknowledgement, EndPoint = RemoteEndPoint
            };

            if (!Send(envelope))
            {
                Error = "Cannot send back acknowledgement";
            }
        }
Ejemplo n.º 16
0
        public static KeyValuePair <string, string> ToKeyValue(this Acknowledge ack)
        {
            switch (ack)
            {
            case Acknowledge.Client:
                return(new KeyValuePair <string, string>("ack", "client"));

            case Acknowledge.ClientIndividual:
                return(new KeyValuePair <string, string>("ack", "client-individual"));

            default:
                return(new KeyValuePair <string, string>("ack", "auto"));
            }
        }
        protected override void ProcessValidResponse(Envelope env)
        {
            Acknowledge m = (Acknowledge)env.Message;

            if (m.Code == ResponseCodes.SUCCESS)
            {
                Console.WriteLine("Chat Message recieved");
                MyState = State.Success;
                return;
            }
            else
            {
                Console.WriteLine("Error Sending Chat Message");
                MyState = State.Failed;
                return;
            }
        }
Ejemplo n.º 18
0
        public static string Designer(this UrlHelper @this, DesignerKey designerKey, int pageIndex)
        {
            Acknowledge.Object(@this);

            object routeValues;

            if (pageIndex > 1)
            {
                routeValues = new { designerKey = designerKey.ToString(), p = pageIndex };
            }
            else
            {
                routeValues = new { designerKey = designerKey.ToString() };
            }

            return(SecureAction(@this, Constants.ActionName.Designer.Index, Constants.ControllerName.Designer, routeValues));
        }
Ejemplo n.º 19
0
        public static string Pattern(this UrlHelper @this, DesignerKey designerKey, string categoryKey, string reference, int pageIndex)
        {
            Acknowledge.Object(@this);

            object routeValues;

            if (pageIndex > 1)
            {
                routeValues = new { designerKey = designerKey.ToString(), categoryKey = categoryKey, reference = reference, p = pageIndex };
            }
            else
            {
                routeValues = new { designerKey = designerKey.ToString(), categoryKey = categoryKey, reference = reference };
            }

            return(SecureAction(@this, Constants.ActionName.Designer.Pattern, Constants.ControllerName.Designer, routeValues));
        }
        protected override void ExecuteDetails(object context)
        {
            ConnectToChatRequest incoming = (ConnectToChatRequest)context;

            ULRM.Add(RemoteEndPoint, incoming.User);

            var acknowledgement = new Acknowledge(ResponseCodes.SUCCESS, "true");
            var envelope        = new Envelope()
            {
                Message = acknowledgement, EndPoint = RemoteEndPoint
            };

            if (!Send(envelope))
            {
                Error = "Cannot send back acknowledgement";
            }
        }
Ejemplo n.º 21
0
        private static void Socket_OnMessage(object sender, MessageEventArgs e)
        {
            Console.WriteLine($"{DateTime.Now} - Message Received:\n{e.Data}");

            Acknowledge ack = new Acknowledge
            {
                MessageType = MessageType.Acknowledge,
                Code        = 200,
                Message     = "",
                RequestId   = "12345"
            };

            var root = new
            {
                Acknowledge = ack
            };

            Send(ack);
        }
Ejemplo n.º 22
0
        private static Response DeleteVideoResponse(DeleteVideoRequest deleteVideoRequest)
        {
            DatabaseManager database = new DatabaseManager();

            (MySqlDataReader reader, var Connection) = database.RunQuery($"DELETE FROM video_details WHERE videoid='{deleteVideoRequest.VideoID}'");
            Acknowledge ack = new Acknowledge()
            {
                Status = "OK", Reason = "Video deleted successfully."
            };
            Response resp = new Response()
            {
                Type = ResponseType.Acknowledge, Status = "OK", Content = ack
            };

            if (reader == null)
            {
                ack.Reason = "Unable to delete video.";
                ack.Status = "FAIL";
                Connection.Close();
                return(resp);
            }
            else
            {
                Connection.Close();
                (reader, Connection) = database.RunQuery($"UPDATE course_details SET videocount = videocount-1 WHERE courseid='{deleteVideoRequest.CourseID}'");
                Connection.Close();
                (reader, Connection) = database.RunQuery($"DELETE FROM comments WHERE videoid='{deleteVideoRequest.VideoID}'");
                Connection.Close();
                (reader, Connection) = database.RunQuery($"DELETE FROM tag_details WHERE videoid='{deleteVideoRequest.VideoID}'");
                Connection.Close();
                (reader, Connection) = database.RunQuery($"DELETE FROM favorites WHERE videoid='{deleteVideoRequest.VideoID}'");
                Connection.Close();
                if (File.Exists(serverroot + "/Thumbnails/" + deleteVideoRequest.VideoID + ".jpg"))
                {
                    File.Delete(serverroot + "/Thumbnails/" + deleteVideoRequest.VideoID + ".jpg");
                }
                if (File.Exists(serverroot + "/Videos/" + deleteVideoRequest.VideoID + ".mp4"))
                {
                    File.Delete(serverroot + "/Videos/" + deleteVideoRequest.VideoID + ".mp4");
                }
            }
            return(resp);
        }
Ejemplo n.º 23
0
        private static Response CreateAccountResponse(CreateAccount createAccount)
        {
            Acknowledge ack = new Acknowledge()
            {
                Status = "FAIL", Reason = "Username not available."
            };
            Response resp = new Response()
            {
                Content = ack,
                Type    = ResponseType.Acknowledge,
                Status  = "FAIL"
            };

            if (!IsUsernameAvailable(createAccount.Username))
            {
                return(resp);
            }
            DatabaseManager database = new DatabaseManager();
            string          query    = String.Format("INSERT INTO user_login(username, password) VALUES ('{0}', '{1}')", RefineContent(createAccount.Username), RefineContent(createAccount.Password));

            (MySqlDataReader reader, var Connection) = database.RunQuery(query);
            if (reader != null && reader.RecordsAffected > 0)
            {
                query = String.Format("INSERT INTO account_data (username, fullname, acctype, type) VALUES ('{0}', '{1}', '{2}', '{3}')", createAccount.Username, createAccount.FullName, createAccount.Type.ToString(), (int)createAccount.Type);
                (reader, Connection) = database.RunQuery(query);
                if (reader != null && reader.RecordsAffected > 0)
                {
                    ack.Reason  = "";
                    resp.Status = "OK";
                    ack.Status  = "OK";
                }
                else
                {
                    ack.Reason = "Account Creation Error.";
                }
            }
            else
            {
                ack.Reason = "Account Creation Error.";
            }
            Connection.Close();
            return(resp);
        }
Ejemplo n.º 24
0
        public void FileHandlingService(object FileName)
        {
            //Acknowledge Packet to acknowledge successful reception.
            Acknowledge ack = new Acknowledge()
            {
                Status = "OK", Reason = "Video Uploaded Received Successfully"
            };
            Response rsp = new Response()
            {
                Type = ResponseType.Acknowledge, Content = ack, Status = "OK"
            };
            string message = JsonConvert.SerializeObject(rsp);

            byte[] buffer = Encoding.UTF8.GetBytes(message);


            TcpClient fileSender = _backupClient.AcceptTcpClient();

            ReceiveFile((string)FileName, ".jpg", fileSender);
            StatusManager.PushMessage(FileName + " Received", StatusType.Success);

            //Getting stream and writing acknowledgement.
            var stream = fileSender.GetStream();

            stream.Write(buffer, 0, buffer.Length);

            //Receiving Video File
            ReceiveFile((string)FileName, ".mp4", fileSender);
            StatusManager.PushMessage(FileName + " Received", StatusType.Success);
            stream.Write(buffer, 0, buffer.Length);

            //Move files from temporary storage to permanant
            if (File.Exists($"{serverroot}/Temp/{FileName}.jpg"))
            {
                File.Move($"{serverroot}/Temp/{FileName}.jpg", $"{serverroot}/Thumbnails/{FileName}.jpg");
            }
            if (File.Exists($"{serverroot}/Temp/{FileName}.mp4"))
            {
                File.Move($"{serverroot}/Temp/{FileName}.mp4", $"{serverroot}/Videos/{FileName}.mp4");
            }
            _backupClient.Stop();
        }
Ejemplo n.º 25
0
        public override string ToString()
        {
            var detailsJson = "{}";

            if (Details != null)
            {
                detailsJson = JsonConvert.SerializeObject(Details);
            }

            var argumentsJson = "{}";

            if (Arguments != null)
            {
                argumentsJson = JsonConvert.SerializeObject(Arguments);
            }

            var json = "[" + MessageId + "," + RequestId + ",{\"acknowledge\":" + Acknowledge.ToString().ToLower() + ",\"exclude_me\":" +
                       ExcludeMe.ToString().ToLower() + "},\"" + Topic + "\"," + detailsJson + "," + argumentsJson + "]";

            return(json);
        }
Ejemplo n.º 26
0
        private async void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            progressRing.isActive = true;
            Object resp = new JObject();

            resp = await ConnectionManager.SendRequestAsync(new AvailUsername()
            {
                Username = usernameTextBlock.Text
            }, RequestType.UsernameAvailability, ResponseType.Acknowledge);

            if (resp != null)
            {
                Acknowledge ack = ((JObject)resp).ToObject <Acknowledge>();
                errorTextBlock.Text = ack.Reason;
            }
            else
            {
                errorTextBlock.Text = "Connection Error";
            }
            progressRing.isActive = false;
        }
Ejemplo n.º 27
0
        protected override void ExecuteDetails(object context)
        {
            SendMessageRequest incoming = (SendMessageRequest)context;

            if (incoming.SecureMessage != null)
            {
                Console.WriteLine("!! Encrypted Message: " + incoming.SecureMessage.EncryptedText);
                EMRM.AddIncomingMessage(incoming.SecureMessage);
            }

            var response = new Acknowledge(ResponseCodes.SUCCESS, "Recieved new chat message.");
            var envelope = new Envelope()
            {
                Message = response, EndPoint = RemoteEndPoint
            };

            if (!Send(envelope))
            {
                Error = "Cannot send response";
            }
        }
        public void TestDeSerializeAcknowledge()
        {
            var ack = new Acknowledge(Guid.NewGuid(), Guid.NewGuid(), 0, "Ack");

            var converter = new JsonMessageConverter();

            var blob = string.Format("{{\"SenderId\":\"{0}\",\"MessageId\":{1},\"ConversationId\":\"{2}\",\"MessageCount\":{3},\"StatusInformation\":\"{4}\"}}",
                                     ack.SenderId.ToString(),
                                     (int)ack.MessageId,
                                     ack.ConversationId.ToString(),
                                     ack.MessageCount,
                                     ack.StatusInformation);

            var message = (Acknowledge)converter.DeSerialize(System.Text.Encoding.UTF8.GetBytes(blob));

            Assert.AreEqual(ack.SenderId, message.SenderId);
            Assert.AreEqual(ack.MessageId, message.MessageId);
            Assert.AreEqual(ack.ConversationId, message.ConversationId);
            Assert.AreEqual(ack.MessageCount, message.MessageCount);
            Assert.AreEqual(ack.StatusInformation, message.StatusInformation);
        }
Ejemplo n.º 29
0
        public void WriteCmd(ItelexPacket itxPkt, Modes mode, Acknowledge ack)
        {
            if (_debugForm == null)
            {
                return;
            }

            if (itxPkt.CommandType == ItelexCommands.Heartbeat && !_debugForm.ShowHeartbeat)
            {
                return;
            }

            if (itxPkt.CommandType == ItelexCommands.Ack && !_debugForm.ShowAck)
            {
                return;
            }

            string debugStr = CmdToString(itxPkt, mode, ack);

            Write(debugStr + "\r\n", mode);
        }
Ejemplo n.º 30
0
        private async void createAccountButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            progressRing.isActive = true;
            Model.Data.CreateAccount accountRequest = new Model.Data.CreateAccount()
            {
                FullName = fullNameTextBlock.Text.Trim(),
                Username = usernameTextBlock.Text.Trim(),
                Password = Security.MD5Hash(passwordTextBlock.Password.Trim()),
                Type     = accounttextBlock.SelectedIndex == 0 ? UserType.Student : UserType.Professional
            };
            Object result = new JObject();

            result = await ConnectionManager.SendRequestAsync(accountRequest, RequestType.SignUp, ResponseType.Acknowledge);

            if (result != null)
            {
                Acknowledge ack = ((JObject)result).ToObject <Acknowledge>();
                if (ack.Status == "OK")
                {
                    AppNotificationManager.PushMessage(new AppNotification()
                    {
                        Message = "Account created Successfully"
                    });
                    Close();
                }
                else
                {
                    errorTextBlock.Text = ack.Reason;
                }
            }
            else
            {
                errorTextBlock.Text = "Connection Error";
            }
            progressRing.isActive = false;
        }
Ejemplo n.º 31
0
        /// <summary>
        ///   Send <param name = "bytes">bytes</param> to given <param name = "address">address</param>
        ///   This is a non blocking method.
        /// </summary>
        public void SendTo(byte[] address, byte[] bytes, Acknowledge acknowledge = Acknowledge.Yes)
        {
            // Chip enable low
            SetDisabled();

            // Setup PTX (Primary TX)
            SetTransmitMode();

            // Write transmit adres to TX_ADDR register. 
            Execute(Commands.W_REGISTER, Registers.TX_ADDR, address);

            // Write transmit adres to RX_ADDRESS_P0 (Pipe0) (For Auto ACK)
            Execute(Commands.W_REGISTER, Registers.RX_ADDR_P0, address);

            // Send payload
            Execute(acknowledge == Acknowledge.Yes ? Commands.W_TX_PAYLOAD : Commands.W_TX_PAYLOAD_NO_ACK, 0x00, bytes);

            // Pulse for CE -> starts the transmission.
            SetEnabled();
        }