示例#1
0
            public override async IAsyncEnumerable <Record> ReadRecordsAsync(IApiClient apiClient,
                                                                             DateTime?lastReadTime = null, TaskCompletionSource <DateTime>?tcs = null, bool isDiscoverRead = false)
            {
                var response = await apiClient.GetAsync(
                    $"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}");

                var recordsList =
                    JsonConvert.DeserializeObject <SuppressionListsResponse>(await response.Content.ReadAsStringAsync());

                if (recordsList.SuppressionLists == null)
                {
                    yield break;
                }

                foreach (var recordMap in recordsList.SuppressionLists)
                {
                    var normalizedRecordMap = new Dictionary <string, object?>();

                    foreach (var kv in recordMap)
                    {
                        if (kv.Key.Equals(EndpointHelper.LinksPropertyId))
                        {
                            continue;
                        }

                        normalizedRecordMap.TryAdd(kv.Key, kv.Value);
                    }

                    yield return(new Record
                    {
                        Action = Record.Types.Action.Upsert,
                        DataJson = JsonConvert.SerializeObject(normalizedRecordMap)
                    });
                }
            }
示例#2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Recu(CNL.First(), 0, "", "0");
            int minindex = AllPath.FindIndex(y => y.cost == AllPath.Min(x => x.cost));

            textBox2.Text = $"最低成本值總和:{AllPath[minindex].cost}\r\n路徑次序:{AllPath[minindex].citypath}\r\n連線數值:{AllPath[minindex].costpath}";
        }
示例#3
0
        public virtual async Task <Count> GetCountOfRecords(IApiClient apiClient)
        {
            var response = await apiClient.GetAsync($"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}");

            var recordsList = JsonConvert.DeserializeObject <DataWrapper>(await response.Content.ReadAsStringAsync());

            return(new Count
            {
                Kind = Count.Types.Kind.Exact,
                Value = (int)recordsList.TotalRecords
            });
        }
示例#4
0
            private async Task PreLoadLookup(IApiClient apiClient)
            {
                var readResponse = await apiClient.GetAsync(
                    $"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}");

                var recordsList =
                    JsonConvert.DeserializeObject <ListsResponse>(await readResponse.Content.ReadAsStringAsync());

                foreach (var list in recordsList.Lists)
                {
                    NameToListIdDictionary.TryAdd(list["Name"].ToString() ?? "UNKNOWN_LIST", (long)list["ListID"]);
                }
            }
示例#5
0
        public virtual async IAsyncEnumerable <Record> ReadRecordsAsync(IApiClient apiClient, Schema schema, bool isDiscoverRead = false)
        {
            var after   = "";
            var hasMore = false;

            do
            {
                var response = await apiClient.GetAsync(
                    $"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}?limit=100&properties={string.Join(",",schema.Properties.Select(p => p.Id))}{(string.IsNullOrWhiteSpace(after) ? "" : $"&after={after}")}");

                response.EnsureSuccessStatusCode();

                var objectResponseWrapper =
                    JsonConvert.DeserializeObject <ObjectResponseWrapper>(await response.Content.ReadAsStringAsync());

                after   = objectResponseWrapper?.Paging?.Next?.After ?? "";
                hasMore = !string.IsNullOrWhiteSpace(after);

                if (objectResponseWrapper?.Results.Count == 0)
                {
                    yield break;
                }

                foreach (var objectResponse in objectResponseWrapper?.Results)
                {
                    var recordMap = new Dictionary <string, object>();

                    foreach (var objectProperty in objectResponse.Properties)
                    {
                        try
                        {
                            recordMap[objectProperty.Key] = objectProperty.Value.ToString() ?? "";
                        }
                        catch
                        {
                            recordMap[objectProperty.Key] = "";
                        }
                    }

                    yield return(new Record
                    {
                        Action = Record.Types.Action.Upsert,
                        DataJson = JsonConvert.SerializeObject(recordMap)
                    });
                }
            } while (hasMore);
示例#6
0
        /// <summary>
        /// 将指定路径的下的文件及文件夹显示在ListView控件中
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="imglist">ImageList控件对象</param>
        /// <param name="lv">ListView控件对象</param>
        /// <param name="ppath">标识要执行的操作</param>
        public void GetPath(string path, ImageList imglist, ListView lv, int intflag)
        {
            string pp = "";
            string uu = "";

            try
            {
                if (intflag == 0)
                {
                    if (AllPath != path)
                    {
                        lv.Items.Clear();
                        AllPath = path;
                        GetListViewItem(AllPath, imglist, lv);
                    }
                }
                else
                {
                    uu = AllPath + path;
                    if (Directory.Exists(uu))
                    {
                        AllPath = AllPath + path + "\\";
                        pp      = AllPath.Substring(0, AllPath.Length - 1);
                        lv.Items.Clear();
                        GetListViewItem(pp, imglist, lv);
                    }
                    else
                    {
                        if (path.IndexOf("\\") == -1)//判断如果不是完整路径,先转换为完整路径,再打开
                        {
                            uu = AllPath + path;
                            System.Diagnostics.Process.Start(uu);
                        }
                        else//判断如果是完整路径,则直接打开
                        {
                            System.Diagnostics.Process.Start(path);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#7
0
 public void GoBack(ListView lv, ImageList il, string path)
 {
     if (AllPath.Length != 3)
     {
         string NewPath = AllPath.Remove(AllPath.LastIndexOf("\\")).Remove(AllPath.Remove(AllPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\";
         lv.Items.Clear();
         GetListViewItem(NewPath, il, lv);
         AllPath = NewPath;
     }
     else
     {
         if (k == 0)
         {
             lv.Items.Clear();
             GetListViewItem(path, il, lv);
             k++;
         }
     }
 }
示例#8
0
 private void GetChildNodes(TreeNodeEx child)
 {
     for (int i = 0; i < child.Nodes.Count; i++)
     {
         if (child.Nodes[i].ImageIndex == 1)
         {
             if (!(child.Tag as DigiPower.ERM.Model.FileRecording_Templet).zrr.StartsWith("系统管理员"))
             {
                 continue;
             }
             else
             {
                 AllPath.Add(child.Nodes[i].Name);
                 GetChildNodes((TreeNodeEx)child.Nodes[i]);
             }
         }
         else
         {
             AllPath.Add(child.Nodes[i].Name);
             archiveNodes.Add(child.Nodes[i].Name);
         }
     }
 }
示例#9
0
        public virtual async IAsyncEnumerable <Record> ReadRecordsAsync(IApiClient apiClient,
                                                                        DateTime?lastReadTime = null, TaskCompletionSource <DateTime>?tcs = null, bool isDiscoverRead = false)
        {
            long     pageNumber = 1;
            long     maxPageNumber;
            DateTime tcsDateTime;

            do
            {
                var response = await apiClient.GetAsync(
                    $"{BasePath.TrimEnd('/')}/{AllPath.TrimStart('/')}?PageNumber={pageNumber}{(lastReadTime.HasValue ? $"&Since={lastReadTime.Value.ToUniversalTime():O}" : "")}");

                Logger.Debug($"Date Header value: {response.Headers.Date}");
                tcsDateTime = response.Headers.Date?.UtcDateTime ?? DateTime.UtcNow;

                var recordsList =
                    JsonConvert.DeserializeObject <DataWrapper>(await response.Content.ReadAsStringAsync());

                maxPageNumber = recordsList.TotalPages;

                if (recordsList.Items == null)
                {
                    yield break;
                }

                foreach (var recordMap in recordsList.Items)
                {
                    var normalizedRecordMap = new Dictionary <string, object?>();

                    foreach (var kv in recordMap)
                    {
                        if (
                            !string.IsNullOrWhiteSpace(DetailPath) &&
                            !string.IsNullOrWhiteSpace(DetailPropertyId) &&
                            kv.Key.Equals(DetailPropertyId) && kv.Value != null)
                        {
                            var detailResponse =
                                await apiClient.GetAsync(
                                    $"{BasePath.TrimEnd('/')}/{DetailPath.TrimStart('/')}/{kv.Value}");

                            var detailsRecord =
                                JsonConvert.DeserializeObject <Dictionary <string, object> >(
                                    await detailResponse.Content.ReadAsStringAsync());

                            foreach (var detailKv in detailsRecord)
                            {
                                if (detailKv.Key.Equals(EndpointHelper.CustomFieldsId) && detailKv.Value != null)
                                {
                                    var customFields =
                                        JsonConvert.DeserializeObject <List <CustomField> >(
                                            JsonConvert.SerializeObject(detailKv.Value));
                                    foreach (var cf in customFields)
                                    {
                                        normalizedRecordMap.TryAdd(cf.FieldName, cf.Value);
                                    }

                                    continue;
                                }

                                if (detailKv.Key.Equals(EndpointHelper.LinksPropertyId))
                                {
                                    continue;
                                }

                                normalizedRecordMap.TryAdd(detailKv.Key, detailKv.Value);
                            }

                            continue;
                        }

                        if (kv.Key.Equals(EndpointHelper.CustomFieldsId) && kv.Value != null)
                        {
                            var customFields =
                                JsonConvert.DeserializeObject <List <CustomField> >(
                                    JsonConvert.SerializeObject(kv.Value));
                            foreach (var cf in customFields)
                            {
                                normalizedRecordMap.TryAdd(cf.FieldName, cf.Value);
                            }

                            continue;
                        }

                        if (kv.Key.Equals(EndpointHelper.LinksPropertyId))
                        {
                            continue;
                        }

                        normalizedRecordMap.TryAdd(kv.Key, kv.Value);
                    }

                    yield return(new Record
                    {
                        Action = Record.Types.Action.Upsert,
                        DataJson = JsonConvert.SerializeObject(normalizedRecordMap)
                    });
                }

                pageNumber++;
            } while (pageNumber <= maxPageNumber);

            if (tcs != null)
            {
                Logger.Debug($"Setting tcs with value {tcsDateTime.ToUniversalTime():O}");
                tcs.SetResult(tcsDateTime);
            }
        }
示例#10
0
        /// <summary>
        /// 地图初始化
        /// </summary>
        /// <param name="xdoc"></param>
        /// <returns></returns>
        public static XDocument MapInit(XDocument xdoc)
        {
            Map map = new Map(xdoc, 900, 550);

            AllPaths = new Dictionary <ODPair, PathList>(AllPath.FindAllPath(map, 1));
            string      strPointName;
            string      strArcsName;
            List <uint> arcList;
            List <uint> pointList;

            AllArcPaths   = new ConcurrentDictionary <PointToPoint, List <uint> >();
            AllPointPaths = new ConcurrentDictionary <PointToPoint, List <uint> >();

            Point     point, startPoint, endPoint;
            XDocument myXDoc   = new XDocument(new XElement("allPaths"));
            XElement  rootNode = myXDoc.Root;

            foreach (var item in AllPaths)
            {
                arcList    = new List <uint>();
                pointList  = new List <uint>();
                startPoint = item.Key.StartPoint;
                endPoint   = item.Key.EndPoint;
                if (!startPoint.Equals(endPoint) && item.Value.paths != null)
                {
                    //定义一个XElement结构
                    XElement odNode = new XElement("OD", new XAttribute("start", startPoint.ID.ToString()), new XAttribute("end", endPoint.ID.ToString()));

                    strArcsName = "";
                    arcList.Clear();
                    pointList.Clear();


                    foreach (Path path in item.Value.paths)
                    {
                        strPointName = path.path[0].ID.ToString();
                        pointList.Add(path.path[0].ID);
                        for (int i = 1; i < path.path.Length; i++)
                        {
                            point        = path.path[i];
                            strPointName = $"{strPointName}-{point.ID}";
                            map.arcsID.TryGetValue($"{path.path[i - 1].ID},{path.path[i].ID}", out uint tmpUint);
                            map.arcs.TryGetValue(tmpUint, out Vector tmpVector);
                            strArcsName = $"{strArcsName}-{tmpVector.ArcCode}";
                            pointList.Add(path.path[i].ID);
                            arcList.Add(tmpVector.ArcCode);
                        }

                        AllArcPaths.TryAdd(new PointToPoint(startPoint.ID, endPoint.ID), arcList);
                        AllPointPaths.TryAdd(new PointToPoint(startPoint.ID, endPoint.ID), pointList);

                        strArcsName = strArcsName.Substring(1, strArcsName.Length - 1);

                        XElement newNode = new XElement("path", new XElement("points", strPointName), new XElement("length", path.length.ToString()));
                        odNode.Add(newNode);

                        XElement newNodeArcs = new XElement("pathArcs", new XElement("Arc", strArcsName), new XElement("length", path.arcs.Length.ToString()));
                        odNode.Add(newNodeArcs);
                    }
                    rootNode.Add(odNode);
                }
                else if (!startPoint.Equals(endPoint) && item.Value.paths == null)
                {
                    XElement odNode  = new XElement("OD", new XAttribute("start", startPoint.ID.ToString()), new XAttribute("end", endPoint.ID.ToString()));
                    XElement newNode = new XElement("path", "");
                    odNode.Add(newNode);
                    rootNode.Add(odNode);
                }
            }
            return(myXDoc);
        }
示例#11
0
 public void OnEnable()
 {
     _allPath = target as AllPath;
 }