/// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the ActivityService.
      ActivityService activityService =
          (ActivityService) user.GetService(DfpService.v201511.ActivityService);

      int totalResultsCounter = 0;

      try {
        StatementBuilder statementBuilder = new StatementBuilder()
            .OrderBy("id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

        ActivityPage page = new ActivityPage();

        do {
          // Get activities by statement.
          page = activityService.getActivitiesByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            foreach (Activity activity in page.results) {
              Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\" and type \"{3}\" " +
                  "was found.\n", totalResultsCounter, activity.id, activity.name,
                  activity.type);
              totalResultsCounter++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}.", totalResultsCounter);
      } catch (Exception e) {
        Console.WriteLine("Failed to get activities. Exception says \"{0}\"", e.Message);
      }
    }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ActivityService.
            ActivityService activityService =
                (ActivityService)user.GetService(DfpService.v201502.ActivityService);

            // Create a statement to select active activities.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("status = :status")
                                                .OrderBy("id")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("status", ActivityStatus.ACTIVE.ToString());

            ActivityPage page = new ActivityPage();

            try {
                do
                {
                    page = activityService.getActivitiesByStatement(statementBuilder.ToStatement());

                    // Display results.
                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (Activity activity in page.results)
                        {
                            Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\", and type \"{3}\" " +
                                              "was found.", i, activity.id, activity.name, activity.type);
                            i++;
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {0}.", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get activities. Exception says \"{0}\"", e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            using (ActivityService activityService =
                       (ActivityService)dfpUser.GetService(DfpService.v201708.ActivityService)) {
                // Create a statement to select activities.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .OrderBy("id ASC")
                                                    .Limit(pageSize);

                // Retrieve a small amount of activities at a time, paging through until all
                // activities have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    ActivityPage page = activityService.getActivitiesByStatement(
                        statementBuilder.ToStatement());

                    // Print out some information for each activity.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (Activity activity in page.results)
                        {
                            Console.WriteLine(
                                "{0}) Activity with ID {1} and name \"{2}\" was found.",
                                i++,
                                activity.id,
                                activity.name
                                );
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(pageSize);
                } while (statementBuilder.GetOffset() < totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (ActivityService activityService = user.GetService <ActivityService>())
            {
                // Create a statement to select activities.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("status = :status")
                                                    .OrderBy("id ASC")
                                                    .Limit(pageSize)
                                                    .AddValue("status", ActivityStatus.ACTIVE.ToString());

                // Retrieve a small amount of activities at a time, paging through until all
                // activities have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    ActivityPage page =
                        activityService.getActivitiesByStatement(statementBuilder.ToStatement());

                    // Print out some information for each activity.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (Activity activity in page.results)
                        {
                            Console.WriteLine(
                                "{0}) Activity with ID {1}, name \"{2}\", and type \"{3}\" was " +
                                "found.",
                                i++, activity.id, activity.name, activity.type);
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(pageSize);
                } while (statementBuilder.GetOffset() < totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
Example #5
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ActivityService.
            ActivityService activityService =
                (ActivityService)user.GetService(DfpService.v201408.ActivityService);

            int totalResultsCounter = 0;

            try {
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .OrderBy("id ASC")
                                                    .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

                ActivityPage page = new ActivityPage();

                do
                {
                    // Get activities by statement.
                    page = activityService.getActivitiesByStatement(statementBuilder.ToStatement());

                    // Display results.
                    if (page.results != null)
                    {
                        foreach (Activity activity in page.results)
                        {
                            Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\" and type \"{3}\" " +
                                              "was found.\n", totalResultsCounter, activity.id, activity.name,
                                              activity.type);
                            totalResultsCounter++;
                        }
                    }
                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);
                Console.WriteLine("Number of results found: {0}.", totalResultsCounter);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get contacts. Exception says \"{0}\"", ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ActivityService.
            ActivityService activityService =
                (ActivityService)user.GetService(DfpService.v201311.ActivityService);

            int totalResultsCounter = 0;

            try {
                Statement filterStatement = new StatementBuilder("").ToStatement();

                ActivityPage page   = new ActivityPage();
                int          offset = 0;

                do
                {
                    filterStatement.query = "ORDER BY id LIMIT 500 OFFSET " + offset;
                    // Get activities by statement.
                    page = activityService.getActivitiesByStatement(filterStatement);

                    // Display results.
                    if (page.results != null)
                    {
                        foreach (Activity activity in page.results)
                        {
                            Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\" and type \"{3}\" " +
                                              "was found.\n", totalResultsCounter, activity.id, activity.name,
                                              activity.type);
                            totalResultsCounter++;
                        }
                    }
                    offset += 500;
                } while (offset < page.totalResultSetSize);
                Console.WriteLine("Number of results found: {0}.", totalResultsCounter);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get contacts. Exception says \"{0}\"", ex.Message);
            }
        }
Example #7
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the ActivityService.
            ActivityService activityService =
                (ActivityService)user.GetService(DfpService.v201705.ActivityService);

            // Set the ID of the activity to update.
            int activityId = int.Parse(_T("INSERT_ACTIVITY_ID_HERE"));

            try {
                // Get the activity.
                StatementBuilder statemetnBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", activityId);

                ActivityPage page = activityService.getActivitiesByStatement(
                    statemetnBuilder.ToStatement());
                Activity activity = page.results[0];

                // Update the expected URL.
                activity.expectedURL = "https://www.google.com";

                // Update the activity on the server.
                Activity[] activities = activityService.updateActivities(new Activity[] { activity });

                foreach (Activity updatedActivity in activities)
                {
                    Console.WriteLine("Activity with ID \"{0}\" and name \"{1}\" was updated.",
                                      updatedActivity.id, updatedActivity.name);
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to update activities. Exception says \"{0}\"", e.Message);
            }
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the ActivityService.
      ActivityService activityService =
          (ActivityService) user.GetService(DfpService.v201511.ActivityService);

      // Create a statement to select active activities.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("id")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", ActivityStatus.ACTIVE.ToString());

      ActivityPage page = new ActivityPage();

      try {
        do {
          page = activityService.getActivitiesByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            int i = page.startIndex;
            foreach (Activity activity in page.results) {
              Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\", and type \"{3}\" " +
                  "was found.", i, activity.id, activity.name, activity.type);
              i++;
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {0}.", page.totalResultSetSize);
      } catch (Exception e) {
        Console.WriteLine("Failed to get activities. Exception says \"{0}\"", e.Message);
      }
    }
Example #9
0
        /* public Issue GetIssueNote()
         * {
         *
         *           ActivityPage = NewIssuePage.GoToProjectsPage().ViewOverallactivity();
         *           Issue issue = new Issue("subj");
         *   issue =  ActivityPage.ReturnNewIssueNote(issue);
         *   return issue;
         *
         * }*/



        public Note GetNote(string number)
        {
            return(ActivityPage.GetCreatedIssueNote(number));
        }
Example #10
0
        /// <summary>
        /// 获取新的完整状态树
        /// </summary>
        /// <param name="state">当前 UI 状态</param>
        /// <param name="userManager"><see cref="KeylolUserManager"/></param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="coupon"><see cref="CouponProvider"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <param name="pointIdCode">据点识别码</param>
        /// <param name="authorIdCode">作者识别码</param>
        /// <param name="userIdCode">用户识别码</param>
        /// <param name="sidForAuthor">文章在作者名下的序号</param>
        /// <param name="keyword">搜索关键字</param>
        /// <returns>完整状态树</returns>
        public static async Task <Root> Locate(string state, [Injected] KeylolUserManager userManager,
                                               [Injected] KeylolDbContext dbContext, [Injected] CouponProvider coupon,
                                               [Injected] CachedDataProvider cachedData, string pointIdCode = null, string authorIdCode = null,
                                               string userIdCode = null, int sidForAuthor = 0, string keyword = null)
        {
            var root          = new Root();
            var currentUserId = StateTreeHelper.GetCurrentUserId();
            var isOperator    = StateTreeHelper.GetCurrentUser().IsInRole(KeylolRoles.Operator);

            if (await StateTreeHelper.CanAccessAsync <Root>(nameof(CurrentUser)))
            {
                var user = await userManager.FindByIdAsync(currentUserId);

                root.CurrentUser = await CurrentUser.CreateAsync(user, userManager, dbContext, coupon, cachedData);
            }

            switch (state)
            {
            case "entrance":
                root.Entrance = await EntranceLevel.CreateAsync(currentUserId,
                                                                States.Entrance.EntrancePage.Auto, dbContext, cachedData);

                break;

            case "entrance.discovery":
                root.Entrance = await EntranceLevel.CreateAsync(currentUserId,
                                                                States.Entrance.EntrancePage.Discovery, dbContext, cachedData);

                break;

            case "entrance.points":
                root.Entrance = await EntranceLevel.CreateAsync(currentUserId,
                                                                States.Entrance.EntrancePage.Points, dbContext, cachedData);

                break;

            case "entrance.timeline":
                root.Entrance = await EntranceLevel.CreateAsync(currentUserId,
                                                                States.Entrance.EntrancePage.Timeline, dbContext, cachedData);

                break;

            case "aggregation.point":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.Auto, dbContext, cachedData)
                };
                break;

            case "aggregation.point.frontpage":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.Frontpage, dbContext, cachedData)
                };
                break;

            case "aggregation.point.intel":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.Intel, dbContext, cachedData)
                };
                break;

            case "aggregation.point.product":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.Product, dbContext, cachedData)
                };
                break;

            case "aggregation.point.timeline":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.Timeline, dbContext, cachedData)
                };
                break;

            case "aggregation.point.edit.info":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.EditInfo, dbContext, cachedData)
                };
                break;

            case "aggregation.point.edit.style":
                root.Aggregation = new AggregationLevel
                {
                    Point = await PointLevel.CreateAsync(currentUserId, pointIdCode,
                                                         States.Aggregation.Point.EntrancePage.EditStyle, dbContext, cachedData)
                };
                break;

            case "aggregation.user":
                root.Aggregation = new AggregationLevel
                {
                    User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Auto,
                                                       dbContext, cachedData, userManager)
                };
                break;

            case "aggregation.user.dossier":
                root.Aggregation = new AggregationLevel
                {
                    User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Dossier,
                                                       dbContext, cachedData, userManager)
                };
                break;

            case "aggregation.user.people":
                root.Aggregation = new AggregationLevel
                {
                    User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.People,
                                                       dbContext, cachedData, userManager)
                };
                break;

            case "aggregation.user.timeline":
                root.Aggregation = new AggregationLevel
                {
                    User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Timeline,
                                                       dbContext, cachedData, userManager)
                };
                break;

            case "aggregation.user.edit":
                root.Aggregation = new AggregationLevel
                {
                    User = await UserLevel.CreateAsync(currentUserId, userIdCode, EntrancePage.Edit,
                                                       dbContext, cachedData, userManager)
                };
                break;

            case "content.article":
                root.Content = new ContentLevel
                {
                    Article =
                        await
                        States.Content.Article.ArticlePage.CreateAsync(authorIdCode, sidForAuthor, currentUserId,
                                                                       isOperator, dbContext, cachedData, userManager)
                };
                break;

            case "content.activity":
                root.Content = new ContentLevel
                {
                    Activity = await ActivityPage.CreateAsync(authorIdCode, sidForAuthor, currentUserId,
                                                              isOperator, dbContext, cachedData, userManager)
                };
                break;

            case "post-office.unread":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice)))
                {
                    root.PostOffice = new PostOfficeLevel
                    {
                        Unread = await UnreadPage.CreateAsync(currentUserId, dbContext, cachedData)
                    }
                }
                ;
                break;

            case "post-office.social-activity.comment":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice)))
                {
                    root.PostOffice = new PostOfficeLevel
                    {
                        SocialActivity = new SocialActivityLevel
                        {
                            Comment = await CommentPage.CreateAsync(currentUserId, dbContext, cachedData)
                        }
                    }
                }
                ;
                break;

            case "post-office.social-activity.like":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice)))
                {
                    root.PostOffice = new PostOfficeLevel
                    {
                        SocialActivity = new SocialActivityLevel
                        {
                            Like = await LikePage.CreateAsync(currentUserId, dbContext, cachedData)
                        }
                    }
                }
                ;
                break;

            case "post-office.social-activity.subscriber":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice)))
                {
                    root.PostOffice = new PostOfficeLevel
                    {
                        SocialActivity = new SocialActivityLevel
                        {
                            Subscriber = await SubscriberPage.CreateAsync(currentUserId, dbContext, cachedData)
                        }
                    }
                }
                ;
                break;

            case "post-office.missive":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(PostOffice)))
                {
                    root.PostOffice = new PostOfficeLevel
                    {
                        Missive = await MissivePage.CreateAsync(currentUserId, dbContext, cachedData)
                    }
                }
                ;
                break;

            case "coupon.detail":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(Coupon)))
                {
                    root.Coupon = new CouponLevel
                    {
                        Detail = await DetailPage.CreateAsync(currentUserId, dbContext, userManager)
                    }
                }
                ;
                break;

            case "coupon.store":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(Coupon)))
                {
                    root.Coupon = new CouponLevel
                    {
                        Store =
                            await StorePage.CreateAsync(currentUserId, dbContext, cachedData, userManager, coupon)
                    }
                }
                ;
                break;

            case "coupon.ranking":
                if (await StateTreeHelper.CanAccessAsync <Root>(nameof(Coupon)))
                {
                    root.Coupon = new CouponLevel
                    {
                        Ranking = await RankingPage.CreateAsync(currentUserId, dbContext, cachedData)
                    }
                }
                ;
                break;

            case "search.point":
                root.Search = new SearchLevel
                {
                    Point = await PointPage.CreateAsync(currentUserId, keyword, dbContext, cachedData)
                };
                break;

            case "search.article":
                root.Search = new SearchLevel
                {
                    Article = await ArticlePage.CreateAsync(keyword, dbContext, cachedData)
                };
                break;

            case "search.user":
                root.Search = new SearchLevel
                {
                    User = await UserPage.CreateAsync(currentUserId, keyword, dbContext, cachedData)
                };
                break;

            default:
                throw new NotSupportedException("Not supported state.");
            }
            return(root);
        }