public async Task ChangeRoleAssignmentAsync(bool value, int id)
        {
            AppAccess model = ExpandModel;

            if (value)
            {
                var roles = await QueryAllRolesAsync().ConfigureAwait(false);

                var role = roles.SingleOrDefault(e => e.Id == id);

                if (role != null)
                {
                    model.AddManyItem(role);
                    await DataAccess.UpdateAsync(model).ConfigureAwait(false);
                }
            }
            else
            {
                var item = model.ManyItems.SingleOrDefault(e => e.Id == id);

                if (item != null)
                {
                    model.RemoveManyItem(item);
                    await DataAccess.UpdateAsync(model).ConfigureAwait(false);
                }
            }
            await LoadRolesAsync(model).ConfigureAwait(false);
        }
        public override async Task <IAppAccess> GetByIdAsync(int id)
        {
            var result   = default(AppAccess);
            var identity = await identityController.GetByIdAsync(id).ConfigureAwait(false);

            if (identity != null)
            {
                result = new AppAccess();
                result.Identity.CopyProperties(identity);
                foreach (var item in identityXroleController.ExecuteQuery(p => p.IdentityId == identity.Id).ToList())
                {
                    var role = await roleController.GetByIdAsync(item.RoleId).ConfigureAwait(false);

                    if (role != null)
                    {
                        var entity = new Role();

                        entity.CopyProperties(role);
                        result.RoleEntities.Add(entity);
                    }
                }
            }
            else
            {
                throw new LogicException(ErrorType.InvalidId);
            }
            return(result);
        }
        private bool GetCategoryGoodsItems(int pageIndex)
        {
            bool hasNewElement = false;
            ReadOnlyCollection <AndroidElement> allLinearLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout", true);

            foreach (AppiumWebElement element in allLinearLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> imageElements = element.FindElementsByClassName("android.widget.ImageView");
                ReadOnlyCollection <AppiumWebElement> textElements  = element.FindElementsByClassName("android.widget.TextView");
                if (imageElements != null && imageElements.Count > 0 && textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[textElements.Count - 2];
                    AppiumWebElement priceElement = textElements[textElements.Count - 1];
                    string           id           = nameElement.Text + priceElement.Text;
                    if (!GoodsElementList.Exist(id) && !nameElement.Text.StartsWith("¥") && priceElement.Text.StartsWith("¥"))
                    {
                        Point         location   = new Point(element.Location.X, element.Location.Y);
                        NcpAppElement appElement = GoodsElementList.Add(id, nameElement.Text, "", location, element.Size);
                        appElement.Attributes.Add("price", priceElement.Text.Substring(1));
                        hasNewElement = true;
                    }
                }
            }
            if (!hasNewElement && hasNoneNewElementTime == 0)
            {
                hasNoneNewElementTime++;
                hasNewElement = true;
            }
            return(hasNewElement);
        }
Beispiel #4
0
        private List <AppiumWebElement> GetCategoryElement(string name)
        {
            AndroidElement categoryMainPageElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "首页" }, true, true, true);

            categoryMainPageElement.Click();

            AndroidElement categoryMenuElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "生鲜分类" }, true, true, true);

            categoryMenuElement.Click();

            AndroidElement listElement = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout", false);
            //ReadOnlyCollection<AndroidElement> allC3Elements = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.GridView/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView", false);
            ReadOnlyCollection <AppiumWebElement> allC3Elements = listElement.FindElementsByClassName("android.widget.TextView");
            List <AppiumWebElement> foundElements = new List <AppiumWebElement>();

            for (int i = 0; i < allC3Elements.Count; i++)
            {
                AppiumWebElement element = allC3Elements[i];
                if (element.Text == name)
                {
                    foundElements.Add(element);

                    /*
                     * if (i + 3 >= allC3Elements.Count)
                     * {
                     *  return GetCategoryElementAfterFound(name);
                     * }
                     * else
                     * {
                     *  return element;
                     * }*/
                }
            }
            if (foundElements.Count > 0)
            {
                return(foundElements);
            }

            try
            {
                try
                {
                    Size winSize = AppAccess.GetWindowSize();
                    AppAccess.Swipe(new Point(300, 600),
                                    new Point(300, 300),
                                    1000);
                }
                catch (Exception ex1)
                {
                }
                Thread.Sleep(1000);
                return(this.GetCategoryElement(name));
            }
            catch (Exception ex)
            {
                throw new Exception("找不到分类元素, name = " + name, ex);
            }
        }
        private void SelectCategory(NcpAppElement categoryElement)
        {
            AndroidElement categoryMenuElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "分类" }, true, true, true);

            categoryMenuElement.Click();

            AppiumWebElement cagtegoryElement = this.GetCategoryElement(categoryElement.Name, categoryElement.Attributes["count"]);

            cagtegoryElement.Click();
        }
        public override async Task <IAppAccess> InsertAsync(IAppAccess entity)
        {
            entity.CheckArgument(nameof(entity));
            entity.OneItem.CheckArgument(nameof(entity.OneItem));
            entity.ManyItems.CheckArgument(nameof(entity.ManyItems));

            var result = new AppAccess();

            result.OneEntity.CopyProperties(entity.OneItem);
            await oneEntityController.InsertAsync(result.OneEntity).ConfigureAwait(false);

            foreach (var item in entity.ManyItems)
            {
                var role = new Role();
#pragma warning disable IDE0017 // Simplify object initialization
                var joinRole = new IdentityXRole();
#pragma warning restore IDE0017 // Simplify object initialization

                joinRole.Identity = result.OneEntity;
                if (item.Id == 0)
                {
                    item.Designation = RoleController.ClearRoleDesignation(item.Designation);

                    var qryItem = await manyEntityController.ExecuteFirstOrDefaultAsync(e => e.Designation.Equals(item.Designation))
                                  .ConfigureAwait(false);

                    if (qryItem != null)
                    {
                        role.CopyProperties(qryItem);
                        joinRole.RoleId = role.Id;
                    }
                    else
                    {
                        role.CopyProperties(item);
                        await manyEntityController.InsertAsync(role).ConfigureAwait(false);

                        joinRole.Role = role;
                    }
                }
                else
                {
                    var qryItem = await manyEntityController.GetByIdAsync(item.Id).ConfigureAwait(false);

                    if (qryItem != null)
                    {
                        role.CopyProperties(qryItem);
                    }
                    joinRole.RoleId = role.Id;
                }
                await IdentityXRoleController.InsertAsync(joinRole).ConfigureAwait(false);

                result.AddManyItem(role);
            }
            return(result);
        }
        public override async Task <IAppAccess> InsertAsync(IAppAccess entity)
        {
            entity.CheckArgument(nameof(entity));
            entity.Identity.CheckArgument(nameof(entity.Identity));
            entity.Roles.CheckArgument(nameof(entity.Roles));

            var result = new AppAccess();

            result.IdentityEntity.CopyProperties(entity.Identity);
            result.IdentityEntity.PasswordHash = AccountManager.CalculateHash(result.IdentityEntity.Password);
            await identityController.InsertAsync(result.IdentityEntity).ConfigureAwait(false);

            foreach (var item in entity.Roles)
            {
                var role     = new Role();
                var joinRole = new IdentityXRole();

                joinRole.Identity = result.IdentityEntity;
                if (item.Id == 0)
                {
                    item.Designation = RoleController.ClearRoleDesignation(item.Designation);

                    var qryItem = roleController.ExecuteQuery(e => e.Designation.Equals(item.Designation)).FirstOrDefault();

                    if (qryItem != null)
                    {
                        role.CopyProperties(qryItem);
                        joinRole.RoleId = role.Id;
                    }
                    else
                    {
                        role.CopyProperties(item);
                        await roleController.InsertAsync(role).ConfigureAwait(false);

                        joinRole.Role = role;
                    }
                }
                else
                {
                    var qryItem = await roleController.GetByIdAsync(item.Id).ConfigureAwait(false);

                    if (qryItem != null)
                    {
                        role.CopyProperties(qryItem);
                    }
                    joinRole.RoleId = role.Id;
                }
                await identityXroleController.InsertAsync(joinRole).ConfigureAwait(false);

                result.RoleEntities.Add(role);
            }
            return(result);
        }
        private async Task LoadRolesAsync(AppAccess model)
        {
            var roles = await QueryAllRolesAsync().ConfigureAwait(false);

            RoleModels = roles.Select(e =>
            {
                var role = Role.Create(e);

                role.Assigned = model.ManyItems.Any(e => e.Id == role.Id);
                return(role);
            });
        }
        protected override async Task LoadDetailsAsync(AppAccess entity, int masterId)
        {
            entity.ClearSecondItems();
            foreach (var item in IdentityXRoleController.ExecuteQuery(p => p.IdentityId == masterId).ToList())
            {
                var role = await ManyEntityController.GetByIdAsync(item.RoleId).ConfigureAwait(false);

                if (role != null)
                {
                    entity.AddSecondItem(role);
                }
            }
        }
Beispiel #10
0
        private void GetAllGoodsInCategory(NcpAppElement category3Element)
        {
            try
            {
                hasNoneNewElementTime = 0;
                GoodsElementList      = new NcpAppElementList();
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.SwipeDisplayElements(new Point(300, 1000),
                                               new Point(300, 300),
                                               1000,
                                               4000,
                                               GetCategoryGoodsItems);

                //保存到文件
                string[] goodsColumns = new string[] { "name",
                                                       "price",
                                                       "unit",
                                                       "category1Name",
                                                       "category2Name",
                                                       "category3Name" };
                Dictionary <string, int> goodsColumnDic = CommonUtil.InitStringIndexDic(goodsColumns);
                string      goodsFilePath = GetCategoryGoodsFilePath(category3Element.Id);
                ExcelWriter goodsEW       = new ExcelWriter(goodsFilePath, "List", goodsColumnDic, null);

                string category1Name = category3Element.Attributes["category1Name"];
                string category2Name = category3Element.Attributes["category2Name"];
                string category3Name = category3Element.Name;

                for (int i = 0; i < GoodsElementList.Count; i++)
                {
                    NcpAppElement element           = GoodsElementList[i];
                    string        name              = element.Name;
                    string        price             = element.Attributes["price"];
                    string        unit              = element.Attributes["unit"];
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("name", name);
                    row.Add("price", price);
                    row.Add("unit", unit);
                    row.Add("category1Name", category1Name);
                    row.Add("category2Name", category2Name);
                    row.Add("category3Name", category3Name);
                    goodsEW.AddRow(row);
                }
                goodsEW.SaveToDisk();
            }
            catch (Exception ex)
            {
                throw new Exception("获取商品信息失败, categoryId = " + category3Element.Id, ex);
            }
        }
        private bool GetCategoryItems(int pageIndex)
        {
            int  pageOffset    = pageIndex * 2000;
            bool hasNewElement = false;
            ReadOnlyCollection <AndroidElement> allRelativeLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout", true);

            foreach (AppiumWebElement element in allRelativeLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    //需要改造,将名称+宽度作为唯一标识,因为商品数量经常变
                    //获取某类下的所有商品时,商品数量要按抓取此分类时的数量为准
                    //增加店铺名的抓取
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    string           id           = nameElement.Text + countElement.Text;
                    if (!_CategoryElementList.Exist(id))
                    {
                        Point         location   = new Point(element.Location.X, element.Location.Y + pageOffset);
                        NcpAppElement appElement = CategoryElementList.Add(id, nameElement.Text, "Level1", location, element.Size);
                        appElement.Attributes.Add("count", countElement.Text.Substring(1, countElement.Text.Length - 2));
                        hasNewElement = true;
                    }
                }
            }

            ReadOnlyCollection <AndroidElement> allLinearLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout", true);

            foreach (AppiumWebElement element in allLinearLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    string           id           = nameElement.Text + countElement.Text;
                    if (!_CategoryElementList.Exist(id))
                    {
                        Point         location   = new Point(element.Location.X, element.Location.Y + pageOffset);
                        NcpAppElement appElement = CategoryElementList.Add(id, nameElement.Text, "Level2", location, element.Size);
                        appElement.Attributes.Add("count", countElement.Text.Substring(1, countElement.Text.Length - 2));
                        hasNewElement = true;
                    }
                }
            }

            return(hasNewElement);
        }
Beispiel #12
0
        private NcpAppElementList GetCategory1Items()
        {
            NcpAppElementList allC1Elements = new NcpAppElementList();
            //ReadOnlyCollection<AndroidElement> allC1Nodes = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.TextView[1]", true);
            ReadOnlyCollection <AndroidElement> allC1Nodes = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", true);

            foreach (AppiumWebElement c1Node in allC1Nodes)
            {
                NcpAppElement c1Element = new NcpAppElement();
                c1Element.Name = c1Node.Text;
                c1Element.Id   = c1Element.Name;
                allC1Elements.Add(c1Element);
            }
            return(allC1Elements);
        }
        private AppiumWebElement GetCategoryElement(string name, string count)
        {
            ReadOnlyCollection <AndroidElement> allRelativeLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout", true);

            foreach (AppiumWebElement element in allRelativeLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    if (nameElement.Text == name && countElement.Text == "(" + count + ")")
                    {
                        return(element);
                    }
                }
            }

            ReadOnlyCollection <AndroidElement> allLinearLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout", true);

            foreach (AppiumWebElement element in allLinearLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    if (nameElement.Text == name && countElement.Text == "(" + count + ")")
                    {
                        return(element);
                    }
                }
            }

            try
            {
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.Swipe(new Point(winSize.Width - 20, winSize.Height - 20),
                                new Point(winSize.Width - 20, 200),
                                2000);
                Thread.Sleep(3000);
                return(this.GetCategoryElement(name, count));
            }
            catch (Exception ex)
            {
                throw new Exception("找不到分类元素, name = " + name + ", count = " + count, ex);
            }
        }
        private void ToSelectLocationPage(string locationName)
        {
            try
            {
                AndroidElement locationInputElement = AppAccess.GetElementByClassNameAndText("android.widget.EditText", new string[] { "写字楼、小区、学校" }, true, true, true);
                locationInputElement.Click();
                locationInputElement.SendKeys(locationName);

                AndroidElement locationOptionElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { locationName }, true, true, true);
                locationOptionElement.Click();
            }
            catch (Exception ex)
            {
                throw new Exception("打开选择location页面, locatoinName = " + locationName, ex);
            }
        }
        private void GetAllGoodsInCategory(string locationName, NcpAppElement categoryElement)
        {
            try
            {
                hasNoneNewElementTime = 0;
                GoodsElementList      = new NcpAppElementList();
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.SwipeDisplayElements(new Point(winSize.Width - 20, winSize.Height - 200),
                                               new Point(winSize.Width - 20, 400),
                                               1000,
                                               10000,
                                               GetCategoryGoodsItems);

                //保存到文件
                int      goodsCount   = int.Parse(categoryElement.Attributes["count"]);
                string[] goodsColumns = new string[] { "id",
                                                       "name",
                                                       "price",
                                                       "categoryName",
                                                       "locationName" };
                Dictionary <string, int> goodsColumnDic = CommonUtil.InitStringIndexDic(goodsColumns);
                string      goodsFilePath = (goodsCount == GoodsElementList.Count ? this.GetCategoryGoodsFilePath(locationName, categoryElement.Id) : this.GetCategoryGoodsFilePath("_Error_" + locationName, categoryElement.Id));
                ExcelWriter goodsEW       = new ExcelWriter(goodsFilePath, "List", goodsColumnDic, null);

                for (int i = 0; i < GoodsElementList.Count; i++)
                {
                    NcpAppElement element           = GoodsElementList[i];
                    string        id                = element.Id;
                    string        name              = element.Name;
                    string        price             = element.Attributes["price"];
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("id", element.Id);
                    row.Add("name", name);
                    row.Add("categoryName", categoryElement.Name);
                    row.Add("price", price);
                    row.Add("locationName", locationName);
                    goodsEW.AddRow(row);
                }
                goodsEW.SaveToDisk();
            }
            catch (Exception ex)
            {
                throw new Exception("获取商品信息失败, locationName = " + locationName + ", categoryId = " + categoryElement.Id, ex);
            }
        }
Beispiel #16
0
        private void SelectCategory(NcpAppElement categoryElement)
        {
            string         category1Name = categoryElement.Attributes["category1Name"];
            AndroidElement c1Node        = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", new string[] { category1Name }, true);

            c1Node.Click();

            Thread.Sleep(1500);

            List <AppiumWebElement> cElements = this.GetCategoryElement(categoryElement.Name);
            AppiumWebElement        cElement  = cElements[cElements.Count - 1];
            Point point = cElement.Location;
            Size  size  = cElement.Size;

            //点击文字上方的图标
            AppAccess.Tap(1, point.X + size.Width / 2, point.Y - 80, 100);
            //cagtegoryElement.Click();
        }
Beispiel #17
0
        private bool GetCategoryGoodsItems(int pageIndex)
        {
            bool           hasNewElement       = false;
            List <XmlNode> allGoodsParentNodes = AppAccess.GetXmlElementsByXPath(new string[] {
                "//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.GridView/android.widget.FrameLayout",
                "//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.GridView/android.widget.FrameLayout",
                "//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.GridView/android.widget.FrameLayout"
            },
                                                                                 false);

            if (allGoodsParentNodes != null)
            {
                foreach (XmlNode goodsParentNode in allGoodsParentNodes)
                {
                    XmlNodeList goodsInfoNodes = goodsParentNode.SelectNodes("./android.widget.RelativeLayout/android.widget.TextView");
                    if (goodsInfoNodes.Count >= 3)
                    {
                        string nameValue  = goodsInfoNodes[goodsInfoNodes.Count - 3].Attributes["text"].Value;
                        string priceValue = goodsInfoNodes[goodsInfoNodes.Count - 2].Attributes["text"].Value;
                        string unitValue  = goodsInfoNodes[goodsInfoNodes.Count - 1].Attributes["text"].Value;
                        if (!GoodsElementList.Exist(nameValue) && priceValue.StartsWith("¥"))
                        {
                            NcpAppElement appElement = GoodsElementList.Add(nameValue, nameValue, "");
                            decimal       price      = decimal.Parse(priceValue.Substring(1).Trim());
                            appElement.Attributes.Add("price", price.ToString());
                            appElement.Attributes.Add("unit", unitValue.Substring(1));
                            hasNewElement = true;
                        }
                    }
                }
            }
            if (!hasNewElement && hasNoneNewElementTime < 2)
            {
                hasNoneNewElementTime++;
                hasNewElement = true;
                Thread.Sleep(2000);
            }
            else
            {
                hasNoneNewElementTime = 0;
            }
            return(hasNewElement);
        }
Beispiel #18
0
        private List <AppiumWebElement> GetCategoryElementAfterFound(string name)
        {
            //出现过找到元素了,但是点击不到的情况,那么再滑屏一下,使得元素暴露的更明显
            try
            {
                AppAccess.Swipe(new Point(300, 600),
                                new Point(300, 10),
                                2000);
            }
            catch (Exception ex)
            {
                //出错,但是界面看起来没问题,所以忽略了
            }
            AndroidElement categoryMainPageElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "首页" }, true, true, true);

            categoryMainPageElement.Click();

            AndroidElement categoryMenuElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "生鲜分类" }, true, true, true);

            categoryMenuElement.Click();
            AndroidElement listElement = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout", false);
            //ReadOnlyCollection<AndroidElement> allC3Elements = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.GridView/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView", false);
            ReadOnlyCollection <AppiumWebElement> allC3Elements = listElement.FindElementsByClassName("android.widget.TextView");
            List <AppiumWebElement> foundElements = new List <AppiumWebElement>();

            foreach (AppiumWebElement element in allC3Elements)
            {
                if (element.Text == name)
                {
                    foundElements.Add(element);
                }
            }
            if (foundElements.Count == 0)
            {
                throw new Exception("GetCategoryElementAfterFound执行出错!");
            }
            else
            {
                return(foundElements);
            }
        }
Beispiel #19
0
        private bool GetSubCategoryItems(int pageIndex)
        {
            int         pageOffset       = pageIndex * 2000;
            bool        hasNewElement    = false;
            XmlNodeList allC2ParentNodes = AppAccess.GetXmlElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout", true);

            foreach (XmlNode c2ParentNode in allC2ParentNodes)
            {
                XmlNode c2Node = c2ParentNode.SelectSingleNode("./android.widget.LinearLayout/android.widget.TextView");
                if (c2Node != null)
                {
                    string text = c2Node.Attributes["text"].Value;
                    string id   = text + "Level2";
                    if (!_CategoryElementList.Exist(id))
                    {
                        NcpAppElement appElement = CategoryElementList.Add(id, text, "Level2");
                        hasNewElement = true;
                    }
                }
                XmlNodeList allC3Nodes = c2ParentNode.SelectNodes("./android.widget.LinearLayout/android.widget.GridView/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView");
                if (allC3Nodes != null)
                {
                    foreach (XmlNode c3Node in allC3Nodes)
                    {
                        string text = c3Node.Attributes["text"].Value;
                        string id   = text + "Level3";
                        if (!_CategoryElementList.Exist(id))
                        {
                            NcpAppElement appElement = CategoryElementList.Add(id, text, "Level3");
                            hasNewElement = true;
                        }
                    }
                }
            }
            return(hasNewElement);
        }
        private void GetCategoryInfo(string locationName)
        {
            try
            {
                AndroidElement categoryMenuElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "分类" }, true, true, true);
                categoryMenuElement.Click();

                CategoryElementList = new NcpAppElementList();
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.SwipeDisplayElements(new Point(winSize.Width - 20, winSize.Height - 20),
                                               new Point(winSize.Width - 20, 200),
                                               2000,
                                               5000,
                                               GetCategoryItems);
                NcpAppElementList sortedCategoryElements = CategoryElementList.SortByPosition();

                //分级处理
                List <NcpAppElement> level1Elements    = new List <NcpAppElement>();
                NcpAppElement        lastLevel1Element = null;
                for (int i = 1; i < sortedCategoryElements.Count; i++)
                {
                    NcpAppElement element = sortedCategoryElements[i];
                    if (element.TypeName == "Level1")
                    {
                        level1Elements.Add(element);
                        lastLevel1Element = element;
                    }
                    else
                    {
                        lastLevel1Element.Children.Add(element);
                    }
                }

                //保存到文件

                string[] categoryColumns = new string[] { "id",
                                                          "category1Name",
                                                          "category2Name",
                                                          "needGrab",
                                                          "goodsCount",
                                                          "locationName" };
                Dictionary <string, int> categoryColumnDic = CommonUtil.InitStringIndexDic(categoryColumns);
                string      categoryFilePath = this.GetCategoryFilePath(locationName);
                ExcelWriter categoryEW       = new ExcelWriter(categoryFilePath, "List", categoryColumnDic, null);

                for (int i = 0; i < level1Elements.Count; i++)
                {
                    NcpAppElement element           = level1Elements[i];
                    string        category1Name     = element.Name;
                    string        needGrab          = element.Children.Count == 0 ? "是" : "否";
                    string        goodsCount        = element.Attributes["count"];
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("id", element.Id);
                    row.Add("category1Name", category1Name);
                    row.Add("category2Name", "");
                    row.Add("needGrab", needGrab);
                    row.Add("goodsCount", goodsCount);
                    row.Add("locationName", locationName);
                    categoryEW.AddRow(row);
                    if (element.Children.Count > 0)
                    {
                        for (int j = 0; j < element.Children.Count; j++)
                        {
                            NcpAppElement childElement           = element.Children[j];
                            string        category2Name          = childElement.Name;
                            string        childGoodsCount        = childElement.Attributes["count"];
                            Dictionary <string, string> childRow = new Dictionary <string, string>();
                            childRow.Add("id", childElement.Id);
                            childRow.Add("category1Name", category1Name);
                            childRow.Add("category2Name", category2Name);
                            childRow.Add("needGrab", "是");
                            childRow.Add("goodsCount", childGoodsCount);
                            childRow.Add("locationName", locationName);
                            categoryEW.AddRow(childRow);
                        }
                    }
                }
                categoryEW.SaveToDisk();
            }
            catch (Exception ex)
            {
                throw new Exception("获取分类信息失败.", ex);
            }
        }
        private void GotoYonghuiShopPage()
        {
            AndroidElement yonghuiElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "永辉超市" }, true, true, true);

            yonghuiElement.Click();
        }
Beispiel #22
0
        private void GetCategoryInfo()
        {
            string categoryFilePath = this.GetCategoryFilePath();

            if (!File.Exists(categoryFilePath))
            {
                try
                {
                    //获取一级分类信息
                    NcpAppElementList allC1Elements = this.GetCategory1Items();

                    foreach (NcpAppElement c1Element in allC1Elements)
                    {
                        //AndroidElement c1Node = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.TextView[1]", new string[] { c1Element.Name }, true);
                        AndroidElement c1Node = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", new string[] { c1Element.Name }, true);
                        c1Node.Click();

                        CategoryElementList = new NcpAppElementList();
                        Size winSize = AppAccess.GetWindowSize();
                        AppAccess.SwipeDisplayElements(new Point(300, 1000),
                                                       new Point(300, 300),
                                                       2000,
                                                       2000,
                                                       GetSubCategoryItems);

                        //分级处理
                        List <NcpAppElement> level2Elements    = new List <NcpAppElement>();
                        NcpAppElement        lastLevel2Element = null;
                        for (int i = 0; i < CategoryElementList.Count; i++)
                        {
                            NcpAppElement element = CategoryElementList[i];
                            if (element.TypeName == "Level2")
                            {
                                level2Elements.Add(element);
                                lastLevel2Element = element;
                            }
                            else
                            {
                                lastLevel2Element.Children.Add(element);
                            }
                        }
                        c1Element.Children.AddRange(level2Elements);
                    }



                    //保存到文件

                    string[] categoryColumns = new string[] { "category1Name",
                                                              "category2Name",
                                                              "category3Name" };
                    Dictionary <string, int> categoryColumnDic = CommonUtil.InitStringIndexDic(categoryColumns);
                    ExcelWriter categoryEW = new ExcelWriter(categoryFilePath, "List", categoryColumnDic, null);

                    for (int i = 0; i < allC1Elements.Count; i++)
                    {
                        NcpAppElement c1Element     = allC1Elements[i];
                        string        category1Name = c1Element.Name;
                        if (c1Element.Children.Count > 0)
                        {
                            for (int j = 0; j < c1Element.Children.Count; j++)
                            {
                                NcpAppElement c2Element     = c1Element.Children[j];
                                string        category2Name = c2Element.Name;
                                if (c2Element.Children.Count > 0)
                                {
                                    for (int k = 0; k < c2Element.Children.Count; k++)
                                    {
                                        NcpAppElement c3Element     = c2Element.Children[k];
                                        string        category3Name = c3Element.Name;

                                        Dictionary <string, string> row = new Dictionary <string, string>();
                                        row.Add("category1Name", category1Name);
                                        row.Add("category2Name", category2Name);
                                        row.Add("category3Name", category3Name);
                                        categoryEW.AddRow(row);
                                    }
                                }
                            }
                        }
                    }
                    categoryEW.SaveToDisk();
                }
                catch (Exception ex)
                {
                    throw new Exception("获取分类信息失败.", ex);
                }
            }
        }
        public override async void RowExpand(AppAccess model)
        {
            base.RowExpand(model);

            await InvokePageAsync(async() => await LoadRolesAsync(model).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public override async Task <IAppAccess> UpdateAsync(IAppAccess entity)
        {
            entity.CheckArgument(nameof(entity));
            entity.FirstItem.CheckArgument(nameof(entity.FirstItem));
            entity.SecondItems.CheckArgument(nameof(entity.SecondItems));

            var accessRoles = entity.SecondItems.Select(i =>
            {
                var entity = new Role();

                i.Designation = RoleController.ClearRoleDesignation(i.Designation);
                if (entity.Id == 0)
                {
                    var role = ManyEntityController.ExecuteQuery(e => e.Designation.Equals(i.Designation))
                               .FirstOrDefault();
                    if (role != null)
                    {
                        entity.CopyProperties(role);
                    }
                }
                return(entity);
            });

            //Delete all costs that are no longer included in the list.
            var identityXRoles = await IdentityXRoleController.ExecuteQueryAllAsync(e => e.IdentityId == entity.Id).ConfigureAwait(false);

            foreach (var item in identityXRoles)
            {
                var stillHasTheRole = accessRoles.Any(i => i.Id == item.RoleId);

                if (stillHasTheRole == false)
                {
                    await IdentityXRoleController.DeleteAsync(item.Id).ConfigureAwait(false);
                }
            }

            var result      = new AppAccess();
            var firstEntity = await OneEntityController.UpdateAsync(entity.FirstItem).ConfigureAwait(false);

            result.FirstItem.CopyProperties(firstEntity);
            foreach (var accessRole in accessRoles)
            {
                var role     = new Role();
                var joinRole = new IdentityXRole();

                role.Id             = accessRole.Id;
                joinRole.IdentityId = firstEntity.Id;
                if (accessRole.Id == 0)
                {
                    role.CopyProperties(accessRole);
                    await ManyEntityController.InsertAsync(role).ConfigureAwait(false);

                    joinRole.Role = role;
                }
                else
                {
                    var qryRole = await ManyEntityController.GetByIdAsync(role.Id).ConfigureAwait(false);

                    if (qryRole != null)
                    {
                        role.CopyProperties(qryRole);
                        joinRole.RoleId = role.Id;
                    }
                }
                var identityXRole = identityXRoles.SingleOrDefault(e => e.IdentityId == joinRole.IdentityId && e.RoleId == joinRole.RoleId);

                if (identityXRole == null)
                {
                    await IdentityXRoleController.InsertAsync(joinRole).ConfigureAwait(false);
                }
                result.AddSecondItem(role);
            }
            return(result);
        }
        public override async Task <IAppAccess> UpdateAsync(IAppAccess entity)
        {
            entity.CheckArgument(nameof(entity));
            entity.Identity.CheckArgument(nameof(entity.Identity));
            entity.Roles.CheckArgument(nameof(entity.Roles));

            //Delete all costs that are no longer included in the list.
            var identXRoles = identityXroleController.ExecuteQuery(e => e.IdentityId == entity.Identity.Id).ToList();

            foreach (var item in identXRoles)
            {
                var tmpItem = entity.Roles.SingleOrDefault(i => i.Id == item.RoleId);

                if (tmpItem == null)
                {
                    await identityXroleController.DeleteAsync(item.Id).ConfigureAwait(false);
                }
            }

            var result   = new AppAccess();
            var identity = await identityController.UpdateAsync(entity.Identity).ConfigureAwait(false);

            foreach (var item in entity.Roles)
            {
                var role     = new Role();
                var joinRole = new IdentityXRole();

                role.Id             = item.Id;
                joinRole.IdentityId = identity.Id;
                if (item.Id == 0)
                {
                    item.Designation = RoleController.ClearRoleDesignation(role.Designation);
                    var qryItem = roleController.ExecuteQuery(e => e.Designation.Equals(item.Designation))
                                  .FirstOrDefault();

                    if (qryItem != null)
                    {
                        role.CopyProperties(qryItem);
                        joinRole.RoleId = role.Id;
                    }
                    else
                    {
                        role.CopyProperties(item);
                        await roleController.InsertAsync(role).ConfigureAwait(false);

                        joinRole.Role = role;
                    }
                }
                else
                {
                    var qryItem = await roleController.GetByIdAsync(role.Id).ConfigureAwait(false);

                    if (qryItem != null)
                    {
                        role.CopyProperties(qryItem);
                        joinRole.RoleId = role.Id;
                    }
                }
                var tmpItem = identXRoles.SingleOrDefault(e => e.IdentityId == joinRole.IdentityId && e.RoleId == joinRole.RoleId);

                if (tmpItem == null)
                {
                    await identityXroleController.InsertAsync(joinRole).ConfigureAwait(false);
                }
                result.RoleEntities.Add(role);
            }
            return(result);
        }