public async stt::Task UpdateAnswerRecordRequestObjectAsync()
        {
            moq::Mock <AnswerRecords.AnswerRecordsClient> mockGrpcClient = new moq::Mock <AnswerRecords.AnswerRecordsClient>(moq::MockBehavior.Strict);
            UpdateAnswerRecordRequest request = new UpdateAnswerRecordRequest
            {
                AnswerRecord = new AnswerRecord(),
                UpdateMask   = new wkt::FieldMask(),
            };
            AnswerRecord expectedResponse = new AnswerRecord
            {
                AnswerRecordName     = AnswerRecordName.FromProjectAnswerRecord("[PROJECT]", "[ANSWER_RECORD]"),
                AnswerFeedback       = new AnswerFeedback(),
                AgentAssistantRecord = new AgentAssistantRecord(),
            };

            mockGrpcClient.Setup(x => x.UpdateAnswerRecordAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AnswerRecord>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AnswerRecordsClient client = new AnswerRecordsClientImpl(mockGrpcClient.Object, null);
            AnswerRecord        responseCallSettings = await client.UpdateAnswerRecordAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            AnswerRecord responseCancellationToken = await client.UpdateAnswerRecordAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Esempio n. 2
0
            public static AnswerRecord ReadAnswerRecord(byte[] bBuffer, int startIndex)
            {
                AnswerRecord retval = new AnswerRecord();

                retval.mOriginalBuffer = new byte[bBuffer.Length];
                retval.mStartIndex     = startIndex;
                Array.Copy(bBuffer, 0, retval.mOriginalBuffer, 0, bBuffer.Length);
                UInt16 i      = GetUInt16(bBuffer, startIndex);
                int    offset = 0;

                if (i > 0xc000)
                {
                    retval.mName = GetNameAtLocation(bBuffer, i - 0xc000);
                    offset       = 2;
                }
                else
                {
                    retval.Name = GetNameAtLocation(bBuffer, i);
                    offset      = i;
                }
                retval.mNameBufferLength = GetLabelLength(bBuffer, startIndex);
                retval.mType             = GetUInt16(bBuffer, startIndex + offset);
                retval.mClass            = GetUInt16(bBuffer, startIndex + offset + 2);
                retval.TTL = GetUInt32(bBuffer, startIndex + offset + 4);
                UInt16 RDLength = GetUInt16(bBuffer, startIndex + offset + 8);

                retval.mData = new byte[RDLength];
                Array.Copy(bBuffer, startIndex + offset + 10, retval.mData, 0, RDLength);
                retval.mLength = offset + RDLength + 10;
                if (retval.Type == (UInt16)TYPECODE.NS)
                {
                    retval = new NameServerRecord(retval);
                }
                if (retval.Type == (UInt16)TYPECODE.A)
                {
                    retval = new AddressRecord(retval);
                }
                if (retval.Type == (UInt16)TYPECODE.MX)
                {
                    retval = new MailExchangeRecord(retval);
                }
                if (retval.Type == (UInt16)TYPECODE.CNAME)
                {
                    retval = new CanonicalNameRecord(retval);
                }
                if (retval.Type == (UInt16)TYPECODE.SOA)
                {
                    retval = new StartOfAuthorityRecord(retval);
                }
                if (retval.Type == (UInt16)TYPECODE.TXT)
                {
                    retval = new TextRecord(retval);
                }
                if (retval.Type == (UInt16)TYPECODE.PTR)
                {
                    retval = new PointerRecord(retval);
                }
                return(retval);
            }
 public void UpdateAnswer(AnswerRecord answer)
 {
     if (answer.Id == 0)
         _answerRepository.Create(answer);
     else
         _answerRepository.Update(answer);
     _answerRepository.Flush();
 }
Esempio n. 4
0
        public int AddAnswer(AnswerRecord parRecord)
        {
            var res = AnswerTable.Count;

            parRecord.ID = res;
            AnswerTable.Add(parRecord);
            Casher.Save(this);
            return(res);
        }
Esempio n. 5
0
 public void CopyTo(AnswerRecord ar)
 {
     ar.mName             = mName;
     ar.mType             = mType;
     ar.mClass            = mClass;
     ar.mTTL              = mTTL;
     ar.mData             = (byte[])mData.Clone();
     ar.mLength           = mLength;
     ar.mNameBufferLength = mNameBufferLength;
     ar.mOriginalBuffer   = (byte[])mOriginalBuffer.Clone();
     ar.mStartIndex       = mStartIndex;
 }
Esempio n. 6
0
 /// <summary>Snippet for UpdateAnswerRecord</summary>
 public void UpdateAnswerRecord()
 {
     // Snippet: UpdateAnswerRecord(AnswerRecord, FieldMask, CallSettings)
     // Create client
     AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.Create();
     // Initialize request argument(s)
     AnswerRecord answerRecord = new AnswerRecord();
     FieldMask    updateMask   = new FieldMask();
     // Make the request
     AnswerRecord response = answerRecordsClient.UpdateAnswerRecord(answerRecord, updateMask);
     // End snippet
 }
Esempio n. 7
0
            public StartOfAuthorityRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mOriginalName       = GetNameAtLocation(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + 10);
                mOriginalNameLength = GetLabelLength(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + 10);
                mMailboxName        = GetNameAtLocation(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + 10);
                mMailboxNameLength  = GetLabelLength(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + 10);
                mSerialNumber       = GetUInt32(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + mMailboxNameLength + 12);
                mRefresh            = GetUInt32(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + mMailboxNameLength + 12);
                mRetry   = GetUInt32(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + mMailboxNameLength + 14);
                mExpire  = GetUInt32(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + mMailboxNameLength + 16);
                mMinimum = GetUInt32(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + mOriginalNameLength + mMailboxNameLength + 18);
            }
Esempio n. 8
0
            public MailExchangeRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mMailServer = GetNameAtLocation(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + 12);
                byte[] bPreference = new byte[2];
                bPreference[0] = OriginalBuffer[ar.StartIndex + ar.NameBufferLength + 10];
                bPreference[1] = OriginalBuffer[ar.StartIndex + ar.NameBufferLength + 11];
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(bPreference);
                }
                mPreference = BitConverter.ToInt16(bPreference, 0);
            }
Esempio n. 9
0
        /// <summary>Snippet for UpdateAnswerRecordAsync</summary>
        public async Task UpdateAnswerRecordAsync()
        {
            // Snippet: UpdateAnswerRecordAsync(AnswerRecord, FieldMask, CallSettings)
            // Additional: UpdateAnswerRecordAsync(AnswerRecord, FieldMask, CancellationToken)
            // Create client
            AnswerRecordsClient answerRecordsClient = await AnswerRecordsClient.CreateAsync();

            // Initialize request argument(s)
            AnswerRecord answerRecord = new AnswerRecord();
            FieldMask    updateMask   = new FieldMask();
            // Make the request
            AnswerRecord response = await answerRecordsClient.UpdateAnswerRecordAsync(answerRecord, updateMask);

            // End snippet
        }
 public void UpdateAnswer(AnswerRecord record)
 {
     if (string.IsNullOrWhiteSpace(record.GUIdentifier))
     {
         record.GUIdentifier = Guid.NewGuid().ToString("n");
     }
     if (record.Id == 0)
     {
         _repositoryAnswer.Create(record);
     }
     else
     {
         _repositoryAnswer.Update(record);
     }
 }
Esempio n. 11
0
 /// <summary>Snippet for UpdateAnswerRecord</summary>
 public void UpdateAnswerRecordRequestObject()
 {
     // Snippet: UpdateAnswerRecord(UpdateAnswerRecordRequest, CallSettings)
     // Create client
     AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.Create();
     // Initialize request argument(s)
     UpdateAnswerRecordRequest request = new UpdateAnswerRecordRequest
     {
         AnswerRecord = new AnswerRecord(),
         UpdateMask   = new FieldMask(),
     };
     // Make the request
     AnswerRecord response = answerRecordsClient.UpdateAnswerRecord(request);
     // End snippet
 }
Esempio n. 12
0
        /// <summary>Snippet for UpdateAnswerRecordAsync</summary>
        public async Task UpdateAnswerRecordRequestObjectAsync()
        {
            // Snippet: UpdateAnswerRecordAsync(UpdateAnswerRecordRequest, CallSettings)
            // Additional: UpdateAnswerRecordAsync(UpdateAnswerRecordRequest, CancellationToken)
            // Create client
            AnswerRecordsClient answerRecordsClient = await AnswerRecordsClient.CreateAsync();

            // Initialize request argument(s)
            UpdateAnswerRecordRequest request = new UpdateAnswerRecordRequest
            {
                AnswerRecord = new AnswerRecord(),
                UpdateMask   = new FieldMask(),
            };
            // Make the request
            AnswerRecord response = await answerRecordsClient.UpdateAnswerRecordAsync(request);

            // End snippet
        }
        public void UpdateAnswerRecord()
        {
            moq::Mock <AnswerRecords.AnswerRecordsClient> mockGrpcClient = new moq::Mock <AnswerRecords.AnswerRecordsClient>(moq::MockBehavior.Strict);
            UpdateAnswerRecordRequest request = new UpdateAnswerRecordRequest
            {
                AnswerRecord = new AnswerRecord(),
                UpdateMask   = new wkt::FieldMask(),
            };
            AnswerRecord expectedResponse = new AnswerRecord
            {
                AnswerRecordName     = AnswerRecordName.FromProjectAnswerRecord("[PROJECT]", "[ANSWER_RECORD]"),
                AnswerFeedback       = new AnswerFeedback(),
                AgentAssistantRecord = new AgentAssistantRecord(),
            };

            mockGrpcClient.Setup(x => x.UpdateAnswerRecord(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AnswerRecordsClient client   = new AnswerRecordsClientImpl(mockGrpcClient.Object, null);
            AnswerRecord        response = client.UpdateAnswerRecord(request.AnswerRecord, request.UpdateMask);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Esempio n. 14
0
        public String deserialize(dnsRequest request)
        {
            string result = "";

            //Append request count
            result += reqCount.ToString("X4");
            //Build and append flags
            int flags = 0;

            flags   = (response << 15) | (opcode << 11) | (AuthAnswer << 10) | (truncation << 9) | (recursion_desired << 8) | (recursion_available << 7) | (reserved << 4) | return_code;
            result += flags.ToString("X4");
            //Append resource record counts
            result += question_resource_record_count.ToString("X4");
            result += answer_resource_record_count.ToString("X4");
            result += authority_resource_record_count.ToString("X4");
            result += additional_resource_record_count.ToString("X4");

            //Deserialize records

            foreach (GeneralRecord gr in request.records)
            {
                if (gr.resource_type == DnsResourceType.Query)
                {
                    string name   = deserializeLabel(gr.rName);
                    string type   = gr.rType.ToString("X4");
                    string rclass = gr.rClass.ToString("X4");
                    result += name;
                    result += "00";
                    result += type;
                    result += rclass;
                }
                if (gr.resource_type == DnsResourceType.Answer)
                {
                    AnswerRecord ar      = (AnswerRecord)gr;
                    string       name    = deserializeLabel(ar.rName);
                    string       type    = ar.rType.ToString("X4");
                    string       rclass  = ar.rClass.ToString("X4");
                    string       ttl     = ar.ttl.ToString("X8");
                    string       aresult = deserializeIP(ar.result, ar.ipv6Hex);
                    string       length  = (aresult.Length / 2).ToString("X4");
                    result += name + "00";
                    result += type;
                    result += rclass;
                    result += ttl;
                    result += length;
                    result += aresult;
                }
                if (gr.resource_type == DnsResourceType.Authority)
                {
                    AuthoritiveRecord ar      = (AuthoritiveRecord)gr;
                    string            name    = deserializeLabel(ar.rName);
                    string            type    = ar.rType.ToString("X4");
                    string            rclass  = ar.rClass.ToString("X4");
                    string            ttl     = ar.ttl.ToString("X8");
                    string            pDnsSrv = deserializeLabel(ar.primaryNS);
                    string            mailbox = deserializeLabel(ar.authorityMailbox);
                    string            serial  = ar.serialNum.ToString("X8");
                    string            refresh = ar.refreshInterval.ToString("X8");
                    string            retry   = ar.retryInterval.ToString("X8");
                    string            expire  = ar.expireLimit.ToString("X8");
                    string            minttl  = ar.minttl.ToString("X8");
                    string            length  = ((pDnsSrv.Length + mailbox.Length + 40) / 2).ToString("X4");
                    result += name + "00";
                    result += type;
                    result += rclass;
                    result += ttl;
                    result += length;
                    result += pDnsSrv + "00";
                    result += mailbox + "00";
                    result += serial;
                    result += refresh;
                    result += retry;
                    result += expire;
                    result += minttl;
                }
                if (gr.resource_type == DnsResourceType.Additional)
                {
                    AdditionalRecord ar = (AdditionalRecord)gr;
                    result += ar.hexDump;
                }
            }

            //Deserialize done :)
            return(result);
        }
Esempio n. 15
0
 private object serializeRecords(String question, DnsResourceType rType, out int questionStart, int startingQStart, String fullDump)
 {
     if (rType == DnsResourceType.Query)
     {
         GeneralRecord gr = new GeneralRecord();
         gr.resource_type = rType;
         String rest     = "";
         int    iTracker = 0;
         lookup_hostname = serializeLabel(out iTracker, question, out rest);
         //Get Question type and class
         string lastPart = question.Substring(iTracker).Substring(2);
         startingQStart += iTracker + 2;
         question_type   = int.Parse(lastPart.Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
         question_class  = int.Parse(lastPart.Substring(4, 4), System.Globalization.NumberStyles.HexNumber);
         startingQStart += 8;
         gr.rName        = lookup_hostname;
         gr.rClass       = question_class;
         gr.rType        = question_type;
         //records.Add(query);
         questionStart = startingQStart;
         return(gr);
     }
     else if (rType == DnsResourceType.Answer)
     {
         AnswerRecord ar = new AnswerRecord();
         ar.resource_type = rType;
         String rest     = "";
         int    iTracker = 0;
         //Read the pointer pointing to the original address
         string pointer   = question.Substring(2, 2);
         int    offset    = int.Parse(pointer, System.Globalization.NumberStyles.HexNumber);
         string hostLabel = fullDump.Substring(offset * 2);
         lookup_hostname = serializeLabel(out iTracker, hostLabel, out rest);
         //Get Question type and class
         string lastPart = question.Substring(4);
         question_type  = int.Parse(lastPart.Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
         question_class = int.Parse(lastPart.Substring(4, 4), System.Globalization.NumberStyles.HexNumber);
         ar.rName       = lookup_hostname;
         ar.rClass      = question_class;
         ar.rType       = question_type;
         ar.ttl         = int.Parse(lastPart.Substring(8, 8), System.Globalization.NumberStyles.HexNumber);
         ar.dataLength  = int.Parse(lastPart.Substring(16, 4), System.Globalization.NumberStyles.HexNumber);
         if (ar.dataLength == 4 || ar.dataLength == 16)
         {
             ar.result = serializeIP(lastPart.Substring(20, ar.dataLength * 2));                                             //ipv4 or ipv6 address
         }
         else
         {
             ar.result = serializeLabel(out iTracker, lastPart.Substring(20, ar.dataLength * 2), out rest);
         }
         if (ar.dataLength == 16)
         {
             ar.ipv6Hex = lastPart.Substring(20, ar.dataLength * 2);
         }
         startingQStart += 20 + ar.dataLength * 2;
         questionStart   = startingQStart;
         return(ar);
     }
     else if (rType == DnsResourceType.Authority)
     {
         AuthoritiveRecord ar = new AuthoritiveRecord();
         ar.resource_type = rType;
         String rest     = "";
         int    iTracker = 0;
         string lastPart = "";
         int    sub      = 0;
         //Get pointer
         if (question.Substring(0, 2) == "00")
         {
             ar.rName = "<Root>";
         }
         else
         {
             string pointer = question.Substring(0, 4);
             string p1      = pointer.Substring(0, 2);
             string p2      = pointer.Substring(2);
             int    i1      = int.Parse(p1, System.Globalization.NumberStyles.HexNumber);
             int    i2      = int.Parse(p2, System.Globalization.NumberStyles.HexNumber);
             string binary  = Convert.ToString((i1 + i2), 2);
             binary = binary.Substring(2);
             int    offset    = Convert.ToInt32(binary, 2);
             string hostLabel = fullDump.Substring(offset);
             if (hostLabel.StartsWith("00"))
             {
                 hostLabel = hostLabel.Substring(2);
             }
             lookup_hostname = serializeLabel(out iTracker, hostLabel, out rest);
             lastPart        = question.Substring(4);
             sub             = 4;
         }
         if (lastPart == "")
         {
             lastPart = question.Substring(2);
         }
         if (sub == 0)
         {
             sub = 2;
         }
         question_type  = int.Parse(lastPart.Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
         question_class = int.Parse(lastPart.Substring(4, 4), System.Globalization.NumberStyles.HexNumber);
         ar.rName       = lookup_hostname;
         ar.rType       = question_type;
         ar.rClass      = question_class;
         ar.ttl         = int.Parse(lastPart.Substring(8, 8), System.Globalization.NumberStyles.HexNumber);
         ar.dataLength  = int.Parse(lastPart.Substring(16, 4), System.Globalization.NumberStyles.HexNumber);
         string   dataPart  = lastPart.Substring(20);
         String[] parts     = multiSplit("00", dataPart);
         string   pDnsSrv   = parts[0];
         string   rAuthMail = parts[1];
         int      pdnsl     = 0;
         if (!containsPointer(pDnsSrv) && !pDnsSrv.EndsWith("00"))
         {
             pDnsSrv += "00";
             pdnsl   += 2;
         }
         ar.primaryNS = serializeLabel(out iTracker, pDnsSrv, out rest, fullDump);
         pdnsl       += iTracker;
         string afterPart = "";
         if (containsPointer(pDnsSrv))
         {
             bool ismailPointer = containsPointer(rest);
             ar.authorityMailbox = serializeLabel(out iTracker, rest, out rest, fullDump);
             pdnsl += ar.authorityMailbox.Length * 2 + 4;
             if (ismailPointer)
             {
                 pdnsl    -= (ar.authorityMailbox.Length * 2 + 4);
                 pdnsl    += iTracker;
                 afterPart = question.Substring(20 + pdnsl + sub);
             }
             else
             {
                 afterPart = question.Substring(20 + pdnsl + sub);
             }
         }
         else
         {
             bool ismailPointer = containsPointer(rAuthMail);
             ar.authorityMailbox = serializeLabel(out iTracker, rAuthMail, out rest, fullDump);
             pdnsl += ar.authorityMailbox.Length * 2 + 4;
             if (ismailPointer)
             {
                 pdnsl    -= (ar.authorityMailbox.Length * 2 + 4);
                 pdnsl    += iTracker;
                 afterPart = question.Substring(20 + pdnsl + sub);
             }
             else
             {
                 afterPart = question.Substring(20 + pdnsl + sub);
             }
         }
         ar.serialNum       = int.Parse(afterPart.Substring(0, 8), System.Globalization.NumberStyles.HexNumber);
         ar.refreshInterval = int.Parse(afterPart.Substring(8, 8), System.Globalization.NumberStyles.HexNumber);
         ar.retryInterval   = int.Parse(afterPart.Substring(16, 8), System.Globalization.NumberStyles.HexNumber);
         ar.expireLimit     = int.Parse(afterPart.Substring(24, 8), System.Globalization.NumberStyles.HexNumber);
         ar.minttl          = int.Parse(afterPart.Substring(32, 8), System.Globalization.NumberStyles.HexNumber);
         startingQStart    += 24 + pdnsl + 40;
         questionStart      = startingQStart;
         return(ar);
     }
     else
     {
         AdditionalRecord ar = new AdditionalRecord();
         ar.resource_type = rType;
         ar.hexDump       = question;
         ar.rName         = "-1";
         ar.rType         = -1;
         ar.rClass        = -1;
         questionStart    = question.Length;
         return(ar);
     }
 }
Esempio n. 16
0
        public void serialize(String hexDump)
        {
            //Dns request parts reference: https://technet.microsoft.com/en-us/library/dd197470%28v=ws.10%29.aspx

            //Get Request Count
            reqCount = int.Parse(hexDump.Substring(0, 4), System.Globalization.NumberStyles.HexNumber); //.Substring(2).Substring(0, 2)
            //Get the request flags
            string ff     = hexDump.Substring(4).Substring(0, 4);                                       //ff = flagsField
            string binary = Convert.ToString(Convert.ToInt32(ff, 16), 2);

            binary = binary.PadLeft(16, '0');

            /* Response = 1 bit
             * OpCode = 4 bit
             * Authoritive answer = 1 bit
             * truncation = 1 bit
             * rec desired = 1 bit
             * rec avail = 1 bit
             * reserved = 3 bit (const 0)
             * return code = 4 bit
             */
            response          = Convert.ToInt32(binary.Substring(0, 1), 2);
            opcode            = Convert.ToInt32(binary.Substring(1, 4), 2);
            AuthAnswer        = Convert.ToInt32(binary.Substring(5, 1), 2);
            truncation        = Convert.ToInt32(binary.Substring(6, 1), 2);
            recursion_desired = Convert.ToInt32(binary.Substring(7, 1), 2);
            if ((DnsResponse)response != DnsResponse.request)
            {
                recursion_available = Convert.ToInt32(binary.Substring(8, 1), 2);
                return_code         = Convert.ToInt32(binary.Substring(12, 4), 2);
            }
            else
            {
                recursion_available = 0;
                return_code         = 0;
            }

            /*int flagCode = int.Parse(ff, System.Globalization.NumberStyles.HexNumber);
             * response = (flagCode >> 15);
             * if (response != 0) //Message is a request
             * {
             *  return_code = (flagCode >> 3);
             *  recursion_available = (flagCode >> 7);
             * }
             * else
             * {
             *  return_code = 0;
             *  recursion_available = 0;
             * }
             * recursion_desired = (flagCode >> 8);
             * truncation = (flagCode >> 9);
             * AuthAnswer = (flagCode >> 10);
             * opcode = (flagCode >> 14);*/
            //Get resource record counts
            question_resource_record_count   = int.Parse(hexDump.Substring(8).Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
            answer_resource_record_count     = int.Parse(hexDump.Substring(12).Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
            authority_resource_record_count  = int.Parse(hexDump.Substring(16).Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
            additional_resource_record_count = int.Parse(hexDump.Substring(20).Substring(0, 4), System.Globalization.NumberStyles.HexNumber);
            int questionStart = 24;

            for (int q = 0; q < question_resource_record_count; q++)
            {
                //Get Question hostname
                string        question      = hexDump.Substring(questionStart);
                int           bytesRead     = 0;
                GeneralRecord queryResource = (GeneralRecord)serializeRecords(question, DnsResourceType.Query, out bytesRead, 0, hexDump);
                questionStart += bytesRead;
                records.Add(queryResource);
            }

            for (int q = 0; q < answer_resource_record_count; q++)
            {
                //Get Question hostname
                string       question       = hexDump.Substring(questionStart);
                int          bytesRead      = 0;
                AnswerRecord answerResource = (AnswerRecord)serializeRecords(question, DnsResourceType.Answer, out bytesRead, 0, hexDump);
                questionStart += bytesRead;
                records.Add(answerResource);
            }

            for (int q = 0; q < authority_resource_record_count; q++)
            {
                //Get Question hostname
                string            question          = hexDump.Substring(questionStart);
                int               bytesRead         = 0;
                AuthoritiveRecord authorityResource = (AuthoritiveRecord)serializeRecords(question, DnsResourceType.Authority, out bytesRead, 0, hexDump);
                questionStart += bytesRead;
                records.Add(authorityResource);
            }

            for (int q = 0; q < additional_resource_record_count; q++)
            {
                //Get Question hostname
                string           question           = hexDump.Substring(questionStart);
                int              bytesRead          = 0;
                AdditionalRecord additionalResource = (AdditionalRecord)serializeRecords(question, DnsResourceType.Additional, out bytesRead, 0, hexDump);
                questionStart += bytesRead;
                records.Add(additionalResource);
            }

            //Serialization Completed!! yay :)
            Console.WriteLine("Serialized!");
        }
Esempio n. 17
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(AnswerRecord model)
 {
     this._repoAnswerRecord.Delete(model);
 }
Esempio n. 18
0
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(AnswerRecord model)
 {
     this._repoAnswerRecord.Update(model);
 }
Esempio n. 19
0
            public NameServerRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mNameServer = GetNameAtLocation(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + 10);
            }
 private void OnNewRecord(AnswerRecord record)
 {
     reportWindow.AddQuestionRecord(record.Question.Text, record.Choice.Text, record.Choice.Status);
 }
Esempio n. 21
0
            public CanonicalNameRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mCanonicalName = GetNameAtLocation(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + 10);
            }
Esempio n. 22
0
        public DNSPacket(byte[] bDatagram)
        {
            mID = DNSPacket.GetUInt16(bDatagram, 0);
            mQR = (bDatagram[2] & 0x80) == 0x80;
            mAuthorativeAnswer  = (bDatagram[2] & 0x04) == 0x04;
            mTruncated          = (bDatagram[2] & 0x02) == 0x02;
            mRecursionDesired   = (bDatagram[2] & 0x01) == 0x01;
            mRecursionAvailable = (bDatagram[3] & 0x80) == 0x80;
            mOpCode             = Convert.ToUInt16((bDatagram[2] & 0x78) / 0x08);
            mResponseCode       = Convert.ToUInt16(bDatagram[3] & 0x0F);
            mReservedBlock      = Convert.ToUInt16((bDatagram[3] & 0x70) / 0x10);
            if ((mReservedBlock & 0x02) == 0x02)
            {
                mAuthenticData = true;
            }
            if ((mReservedBlock & 0x01) == 0x01)
            {
                mCheckingDisabled = true;
            }

            UInt16 questionBlocks         = DNSPacket.GetUInt16(bDatagram, 4);
            UInt16 answerBlocks           = DNSPacket.GetUInt16(bDatagram, 6);
            UInt16 nameserverBlocks       = DNSPacket.GetUInt16(bDatagram, 8);
            UInt16 additionalRecordBlocks = DNSPacket.GetUInt16(bDatagram, 10);
            int    curLocation            = 12;

            mQuestionRecords = new List <QuestionRecord>();
            for (int i = 0; i < questionBlocks; i++)
            {
                QuestionRecord currentQuestionRecord = QuestionRecord.ReadQuestionRecord(bDatagram, curLocation);
                curLocation += currentQuestionRecord.Length;
                mQuestionRecords.Add(currentQuestionRecord);
            }
            mAnswerRecords = new List <AnswerRecord>();
            if (mResponseCode == 0 && curLocation < bDatagram.Length)
            {
                for (int i = 0; i < answerBlocks; i++)
                {
                    AnswerRecord currentAnswerRecord = AnswerRecord.ReadAnswerRecord(bDatagram, curLocation);
                    curLocation += currentAnswerRecord.Length;
                    mAnswerRecords.Add(currentAnswerRecord);
                }
            }
            mAuthorityRecords = new List <AnswerRecord>();
            if (mResponseCode == 0 && curLocation < bDatagram.Length)
            {
                for (int i = 0; i < nameserverBlocks; i++)
                {
                    AnswerRecord currentAnswerRecord = AnswerRecord.ReadAnswerRecord(bDatagram, curLocation);
                    curLocation += currentAnswerRecord.Length;
                    mAuthorityRecords.Add(currentAnswerRecord);
                }
            }
            mAdditionalRecords = new List <AnswerRecord>();
            if (mResponseCode == 0 && curLocation < bDatagram.Length)
            {
                for (int i = 0; i < additionalRecordBlocks; i++)
                {
                    AnswerRecord currentAnswerRecord = AnswerRecord.ReadAnswerRecord(bDatagram, curLocation);
                    curLocation += currentAnswerRecord.Length;
                    mAdditionalRecords.Add(currentAnswerRecord);
                }
            }
        }
Esempio n. 23
0
            public PointerRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mDomain = GetNameAtLocation(OriginalBuffer, ar.StartIndex + ar.NameBufferLength + 10);
            }
Esempio n. 24
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public AnswerRecord Insert(AnswerRecord model)
 {
     return(this._repoAnswerRecord.Insert(model));
 }
Esempio n. 25
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public AnswerRecord Insert(AnswerRecord model)
 {
     return(this._AnswerRecordBiz.Insert(model));
 }
Esempio n. 26
0
            public AddressRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mIPAddress = new System.Net.IPAddress(ar.Data);
            }
Esempio n. 27
0
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(AnswerRecord model)
 {
     this._AnswerRecordBiz.Update(model);
 }
Esempio n. 28
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(AnswerRecord model)
 {
     this._AnswerRecordBiz.Delete(model);
 }
        public async Task <IActionResult> SubmitAnswerRecord([FromBody] SubmitAnswerRecordPostViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new
                {
                    message = "request forbidened"
                }));
            }

            var userID = User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value;
            var user   = await _userManager.FindByIdAsync(userID);

            if (user == null)
            {
                return(NotFound(new
                {
                    message = "user's token is invalid"
                }));
            }

            var answerRecordNew = new AnswerRecord
            {
                AssignmentRecordID = model.AssignmentRecordID,

                SentenceEN             = model.SentenceEN,
                SentenceJP             = model.SentenceJP,
                Division               = model.Division,
                StandardAnswerDivision = model.StandardAnswerDivision,

                Resolution = model.Resolution,

                AnswerDivision = model.AnswerDivision,
                IsCorrect      = model.StandardAnswerDivision == model.AnswerDivision ? true:false,

                ConfusionDegree  = model.ConfusionDegree,
                ConfusionElement = model.ConfusionElement,

                StartDate = model.StartDate,
                EndDate   = model.EndDate
            };

            _arDbContext.AnswserRecords.Add(answerRecordNew);
            _arDbContext.SaveChanges();

            // For debug

            // Save movements
            var movementCollection = model.MovementCollection.OrderBy(m => m.Index).ToList();

            for (int i = 0; i < movementCollection.Count; i++)
            {
                movementCollection[i].AnswerRecordID = answerRecordNew.ID;
                _arDbContext.Movements.Add(movementCollection[i]);
                _arDbContext.SaveChanges();
            }
            //_arDbContext.Movements.AddRange(movementCollection);
            //_arDbContext.SaveChanges();

            // Save deviceAccelerations
            var deviceAccelerationCollection = model.DeviceAccelerationCollection.OrderBy(da => da.Index).ToList();

            for (int i = 0; i < deviceAccelerationCollection.Count; i++)
            {
                deviceAccelerationCollection[i].AnswerRecordID = answerRecordNew.ID;
                _arDbContext.DeviceAccelerations.Add(deviceAccelerationCollection[i]);
                _arDbContext.SaveChanges();
            }
            //_arDbContext.DeviceAccelerations.AddRange(deviceAccelerationCollection);
            //_arDbContext.SaveChanges();


            var specificAssignmentRecord = _arDbContext.AssignmentRecords.Where(ar => ar.ID == model.AssignmentRecordID).ToList().FirstOrDefault();

            specificAssignmentRecord.CurrentQuestionIndex = specificAssignmentRecord.CurrentQuestionIndex + 1;

            var answerRecords = _arDbContext.AnswserRecords.Where(q => q.AssignmentRecordID == specificAssignmentRecord.ID).ToList();

            specificAssignmentRecord.AccuracyRate = float.Parse((answerRecords.Where(a => a.IsCorrect == true).Count() / (float)answerRecords.Count).ToString("#0.00"));

            var allQuestionsInExercise = (from q in _arDbContext.Questions
                                          join eqc in _arDbContext.ExerciseQuestionRelationMap on q.ID equals eqc.QuestionID
                                          where eqc.ExerciseID == specificAssignmentRecord.ExerciseID
                                          orderby eqc.SerialNumber ascending
                                          select q).ToList();

            if (allQuestionsInExercise.Count <= specificAssignmentRecord.CurrentQuestionIndex)
            {
                specificAssignmentRecord.IsFinished = true;
                specificAssignmentRecord.EndDate    = DateTime.Now;
            }

            _arDbContext.SaveChanges();

            return(Ok(new
            {
                message = "submit answer successfully"
            }));
        }
Esempio n. 30
0
            public TextRecord(AnswerRecord ar)
            {
                ar.CopyTo(this);

                mText = ASCIIEncoding.ASCII.GetString(ar.Data);
            }