Exemplo n.º 1
0
        private Packet GetRange(GetRangeRequest req)
        {
            var res = new GetRangeResponse();

            try
            {
                var calendarItems  = new CalendarItemCollection();
                var calendarFolder = _outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                var filter         = string.Format("[End] > '{0}' and [Start] < '{1}'", req.Start.ToString("g"), req.End.ToString("g"));
                var appoItems      = calendarFolder.Items.Restrict(filter);
                foreach (Outlook.AppointmentItem appoItem in appoItems)
                {
                    if (appoItem.RecurrenceState != Outlook.OlRecurrenceState.olApptNotRecurring)
                    {
                        continue;
                    }
                    // filterでうまくフィルタできなかったことがあるので、ここで再チェックする
                    if ((appoItem.End >= req.Start) && (appoItem.Start < req.End))
                    {
                        _appointmentItems.Add(appoItem);
                        var calendarItem = CreateCalendarItem(appoItem);
                        calendarItems.Add(calendarItem);
                    }
                }
                res.CalendarItems = calendarItems;
            }
            catch (Exception ex)
            {
                res.ErrorMessage = ex.Message;
            }
            return(res);
        }
        public static void GetRange()
        {
            Console.WriteLine("Start get range...");

            PrepareTable();
            PrepareData();

            OTSClient otsClient = Config.GetClient();
            // 读取 (0, INF_MIN)到(100, INF_MAX)这个范围内的所有行
            PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey();

            inclusiveStartPrimaryKey.Add("pk0", new ColumnValue(0));
            inclusiveStartPrimaryKey.Add("pk1", ColumnValue.INF_MIN);

            PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey();

            exclusiveEndPrimaryKey.Add("pk0", new ColumnValue(100));
            exclusiveEndPrimaryKey.Add("pk1", ColumnValue.INF_MAX);
            GetRangeRequest request = new GetRangeRequest(TableName, GetRangeDirection.Forward, inclusiveStartPrimaryKey, exclusiveEndPrimaryKey);

            GetRangeResponse            response = otsClient.GetRange(request);
            IList <RowDataFromGetRange> rows     = response.RowDataList;
            PrimaryKey nextStartPrimaryKey       = response.NextPrimaryKey;

            while (nextStartPrimaryKey != null)
            {
                request             = new GetRangeRequest(TableName, GetRangeDirection.Forward, nextStartPrimaryKey, exclusiveEndPrimaryKey);
                response            = otsClient.GetRange(request);
                nextStartPrimaryKey = response.NextPrimaryKey;
                foreach (RowDataFromGetRange row in response.RowDataList)
                {
                    rows.Add(row);
                }
            }

            foreach (RowDataFromGetRange row in rows)
            {
                Console.WriteLine("-----------------");
                foreach (KeyValuePair <string, ColumnValue> entry in row.PrimaryKey)
                {
                    Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
                }
                foreach (KeyValuePair <string, ColumnValue> entry in row.Attribute)
                {
                    Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
                }
                Console.WriteLine("-----------------");
            }

            Console.WriteLine("TotalRowsRead: " + rows.Count);
        }
        public static void GetRange()
        {
            Console.WriteLine("Start get range...");

            PrepareTable();
            PrepareData();

            OTSClient otsClient = Config.GetClient();
            // 读取 (0, INF_MIN)到(100, INF_MAX)这个范围内的所有行
            PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(0) },
                { "pk1", ColumnValue.INF_MIN }
            };

            PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(100) },
                { "pk1", ColumnValue.INF_MAX }
            };

            GetRangeRequest request = new GetRangeRequest(TableName, GetRangeDirection.Forward, inclusiveStartPrimaryKey, exclusiveEndPrimaryKey);

            GetRangeResponse response            = otsClient.GetRange(request);
            IList <Row>      rows                = response.RowDataList;
            PrimaryKey       nextStartPrimaryKey = response.NextPrimaryKey;

            while (nextStartPrimaryKey != null)
            {
                request             = new GetRangeRequest(TableName, GetRangeDirection.Forward, nextStartPrimaryKey, exclusiveEndPrimaryKey);
                response            = otsClient.GetRange(request);
                nextStartPrimaryKey = response.NextPrimaryKey;
                foreach (var row in response.RowDataList)
                {
                    rows.Add(row);
                }
            }

            foreach (var row in rows)
            {
                PrintRow(row);
            }

            Console.WriteLine("TotalRowsRead: " + rows.Count);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 从索引表中读取数据
        /// </summary>
        public static void GetRangeFromIndexTable()
        {
            Console.WriteLine("Start getRange from index...");
            OTSClient otsClient = Config.GetClient();
            // 指定第一主键Col1的值,进行扫描
            PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey
            {
                { Col1, new ColumnValue("Col1Value") },
                { Pk1, ColumnValue.INF_MIN },
                { Pk2, ColumnValue.INF_MIN }
            };

            PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey
            {
                { Col1, new ColumnValue("Col1Value") },
                { Pk1, ColumnValue.INF_MAX },
                { Pk2, ColumnValue.INF_MAX }
            };

            GetRangeRequest request = new GetRangeRequest(IndexName, GetRangeDirection.Forward, inclusiveStartPrimaryKey, exclusiveEndPrimaryKey);

            GetRangeResponse response            = otsClient.GetRange(request);
            IList <Row>      rows                = response.RowDataList;
            PrimaryKey       nextStartPrimaryKey = response.NextPrimaryKey;

            while (nextStartPrimaryKey != null)
            {
                request             = new GetRangeRequest(TableName, GetRangeDirection.Forward, nextStartPrimaryKey, exclusiveEndPrimaryKey);
                response            = otsClient.GetRange(request);
                nextStartPrimaryKey = response.NextPrimaryKey;
                foreach (var row in response.RowDataList)
                {
                    rows.Add(row);
                }
            }

            foreach (var row in rows)
            {
                PrintRow(row);
            }

            Console.WriteLine("TotalRowsRead: " + rows.Count);
        }
        public static void GetRangeWithFilter()
        {
            Console.WriteLine("Start get range with filter ...");
            PrepareTable();
            PrepareData();

            OTSClient otsClient = Config.GetClient();
            // 读取 (0, INF_MIN)到(100, INF_MAX)这个范围内的所有行,且col2等于false的行
            PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(0) },
                { "pk1", ColumnValue.INF_MIN }
            };

            PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey
            {
                { "pk0", new ColumnValue(100) },
                { "pk1", ColumnValue.INF_MAX }
            };

            // 构造列过滤条件
            var condition = new RelationalCondition("col2",
                                                    CompareOperator.EQUAL,
                                                    new ColumnValue(false));

            var queryCriteria = new RangeRowQueryCriteria(TableName)
            {
                Direction = GetRangeDirection.Forward,
                InclusiveStartPrimaryKey = inclusiveStartPrimaryKey,
                ExclusiveEndPrimaryKey   = exclusiveEndPrimaryKey,
                Filter = condition.ToFilter()
            };

            GetRangeResponse response            = otsClient.GetRange(new GetRangeRequest(queryCriteria));
            IList <Row>      rows                = response.RowDataList;
            PrimaryKey       nextStartPrimaryKey = response.NextPrimaryKey;

            while (nextStartPrimaryKey != null)
            {
                queryCriteria = new RangeRowQueryCriteria(TableName)
                {
                    Direction = GetRangeDirection.Forward,
                    InclusiveStartPrimaryKey = nextStartPrimaryKey,
                    ExclusiveEndPrimaryKey   = exclusiveEndPrimaryKey,
                    Filter = condition.ToFilter()
                };

                response            = otsClient.GetRange(new GetRangeRequest(queryCriteria));
                nextStartPrimaryKey = response.NextPrimaryKey;
                foreach (var row in response.RowDataList)
                {
                    rows.Add(row);
                }
            }

            foreach (var row in rows)
            {
                PrintRow(row);
            }

            Console.WriteLine("TotalRowsRead with filter: " + rows.Count);
        }