Пример #1
0
        public static ZScanResponse ToZScanResponse(this ScanResponse source)
        {
            if (source == null)
            {
                return(null);
            }

            List <ZItem> data = null;

            if (source.Data != null && source.Data.Count > 0)
            {
                data = new List <ZItem>();

                for (int i = 0; i < source.Data.Count; i++)
                {
                    var zi = new ZItem();

                    zi.Value = source.Data[i];

                    if (!string.IsNullOrEmpty(zi.Value) && zi.Value.IndexOf("\r\n$") > -1)
                    {
                        var arr = zi.Value.Split("\r\n");
                        zi.Value = arr[0];
                        zi.Score = double.Parse(arr[2]);
                    }
                    else
                    {
                        var score = 0D;

                        if (i + 1 < source.Data.Count)
                        {
                            double.TryParse(source.Data[i + 1], out score);
                            i++;
                        }
                        zi.Score = score;
                    }

                    data.Add(zi);
                }
            }

            var result = new ZScanResponse()
            {
                Offset = source.Offset,
                Data   = data
            };

            return(result);
        }
Пример #2
0
        public static List <ZItem> ToList(this ResponseData source)
        {
            if (source == null)
            {
                return(null);
            }

            if (source.Type == ResponseType.Error)
            {
                throw new Exception(source.Data);
            }

            List <ZItem> result = null;

            if (!string.IsNullOrEmpty(source.Data))
            {
                var arr = source.Data.Split(_enter);

                if (arr != null && arr.Length > 0)
                {
                    result = new List <ZItem>();

                    for (int i = 0; i < arr.Length; i++)
                    {
                        ZItem zItem = new ZItem();

                        var val = arr[i];

                        if (!string.IsNullOrEmpty(val))
                        {
                            if (i + 1 < arr.Length)
                            {
                                double score = 0D;
                                double.TryParse(arr[i + 1], out score);
                                i++;
                                zItem.Value = val;
                                zItem.Score = score;
                                result.Add(zItem);
                            }
                        }
                    }
                }
            }


            return(result);
        }
Пример #3
0
        public static ZScanResponse ToZScanResponse(this ScanResponse source)
        {
            if (source == null)
            {
                return(null);
            }

            List <ZItem> data = null;

            if (source.Data != null && source.Data.Count > 0)
            {
                data = new List <ZItem>();

                for (int i = 0; i < source.Data.Count; i++)
                {
                    var zi = new ZItem();

                    zi.Value = source.Data[i];

                    var score = 0D;

                    if (i + 1 < source.Data.Count)
                    {
                        double.TryParse(source.Data[i + 1], out score);
                        i++;
                    }
                    zi.Score = score;

                    data.Add(zi);
                }
            }

            var result = new ZScanResponse()
            {
                Offset = source.Offset,
                Data   = data
            };

            return(result);
        }