Exemplo n.º 1
0
        /// <summary>単一行の各文字を比較します</summary>
        /// <param name="textA">元テキスト</param>
        /// <param name="textB">変更テキスト</param>
        /// <returns>比較結果</returns>
        public static IList <DiffResult> DiffChar(string textA, string textB)
        {
            if (string.IsNullOrEmpty(textA) || string.IsNullOrEmpty(textB))
            {
                return(StringNullOrEmpty(textA, textB));
            }

            FastDiff diff = new FastDiff();

            if (textA.Length <= textB.Length)
            {
                diff.dataA = textA;
                diff.dataB = textB;
            }
            else
            {
                diff.isSwap = true;
                diff.dataA  = textB;
                diff.dataB  = textA;
            }

            diff.isSame = delegate(int posA, int posB)
            {
                return(diff.dataA[posA] == diff.dataB[posB]);
            };

            return(diff.DetectDiff());
        }
Exemplo n.º 2
0
        public void Serialize(Stream stream, ApiData data)
        {
            var     path = data.RequestUri.AbsoluteUri;
            var     previousRequestBody  = "";
            var     previousResponseBody = "";
            ApiData previousData;

            if (this.dataDictionary.TryGetValue(path, out previousData))
            {
                previousRequestBody  = previousData.RequestBody;
                previousResponseBody = previousData.ResponseBody;
            }
            Serializer.SerializeWithLengthPrefix(stream, new KancolleApiSendModel {
                LoginSessionId       = this.sessionId,
                AgentId              = this.agentId,
                Path                 = path,
                RequestValuePatches  = FastDiff.DiffChar(previousRequestBody, data.RequestBody),
                ResponseValuePatches = FastDiff.DiffChar(previousResponseBody, data.ResponseBody),
                StatusCode           = data.StatusCode,
                HttpDate             = data.HttpDateHeaderValue,
                LocalTime            = data.ReceivedLocalTime.UtcDateTime.ToString("r"),
            }, PrefixStyle.Base128, 0);
            this.dataDictionary[path] = data;
        }