/// <summary>
        /// Adds a new DateTime value to the list of query parameters.
        /// </summary>
        /// <param name="key">The parameter name.</param>
        /// <param name="value">The parameter value.</param>
        /// <returns>The statement builder, for chaining method calls.</returns>
        public StatementBuilder AddValue(string key, DateTime value)
        {
            DateTimeValue queryValue = new DateTimeValue();

            queryValue.value = value;
            return(AddValue(key, queryValue));
        }
Beispiel #2
0
        public void TestGetObjectDateTimeSetValue()
        {
            DateTime dateTime = new DateTime();
            Date     date     = new Date();

            date.year           = 2012;
            date.month          = 12;
            date.day            = 2;
            dateTime.date       = date;
            dateTime.hour       = 12;
            dateTime.minute     = 45;
            dateTime.second     = 0;
            dateTime.timeZoneID = "Asia/Shanghai";
            DateTimeValue dateTimeValue = new DateTimeValue();

            dateTimeValue.value = dateTime;

            SetValue setValue = new SetValue();

            setValue.values = new Value[] { dateTimeValue };
            List <object> value = PqlUtilities.GetValue(setValue) as List <object>;

            Assert.AreEqual(1, value.Count);
            Assert.True(value.Contains(dateTime));
        }
        private static bool DateTimeValuesAreEqual(Value value1, Value value2)
        {
            DateTime dateTime1 = (value1 as DateTimeValue).value;
            DateTime dateTime2 = (value2 as DateTimeValue).value;

            return(DatesAreEqual(dateTime1.date, dateTime2.date) &&
                   dateTime1.hour == dateTime2.hour &&
                   dateTime1.minute == dateTime2.minute &&
                   dateTime1.second == dateTime2.second &&
                   String.Equals(dateTime1.timeZoneID, dateTime2.timeZoneID));
        }
        public void TestFromString()
        {
            DateTime dfpDateTime = DateTimeUtilities.FromString("20150130 23:59:58", "America/New_York");

            Assert.AreEqual(dfpDateTime.date.year, 2015);
            Assert.AreEqual(dfpDateTime.date.month, 1);
            Assert.AreEqual(dfpDateTime.date.day, 30);
            Assert.AreEqual(dfpDateTime.hour, 23);
            Assert.AreEqual(dfpDateTime.minute, 59);
            Assert.AreEqual(dfpDateTime.second, 58);
            Assert.AreEqual(dfpDateTime.timeZoneID, "America/New_York");
        }
        public void TestFromDateTimeIgnoresSystemTimeZone()
        {
            System.DateTime dateTime    = new System.DateTime(2015, 1, 30, 23, 59, 58, DateTimeKind.Utc);
            DateTime        dfpDateTime = DateTimeUtilities.FromDateTime(dateTime, "America/New_York");

            Assert.AreEqual(dfpDateTime.date.year, 2015);
            Assert.AreEqual(dfpDateTime.date.month, 1);
            Assert.AreEqual(dfpDateTime.date.day, 30);
            Assert.AreEqual(dfpDateTime.hour, 23);
            Assert.AreEqual(dfpDateTime.minute, 59);
            Assert.AreEqual(dfpDateTime.second, 58);
            Assert.AreEqual(dfpDateTime.timeZoneID, "America/New_York");
        }
    /// <summary>
    /// Converts a System.DateTime object to a Dfp DateTime object with the specified timeZoneId.
    /// Does not perform time zone conversion. This means the returned DateTime value
    /// may not represent the same instant as the System.DateTime value.
    /// </summary>
    /// <param name="dateTime">The DateTime object.</param>
    /// <param name="timeZoneId">The timeZoneId to use.</param>
    /// <returns>A Dfp Datetime object.</returns>
    public static DfpDateTime FromDateTime(System.DateTime dateTime, string timeZoneId) {
      PreconditionUtilities.CheckArgumentNotNull(dateTime, "dateTime");
      PreconditionUtilities.CheckArgumentNotNull(timeZoneId, "timeZoneId");

      DfpDateTime retval = new DfpDateTime();
      retval.date = new Date();
      retval.date.year = dateTime.Year;
      retval.date.month = dateTime.Month;
      retval.date.day = dateTime.Day;
      retval.hour = dateTime.Hour;
      retval.minute = dateTime.Minute;
      retval.second = dateTime.Second;
      retval.timeZoneID = timeZoneId;
      return retval;
    }
 public void TestGetObjectDateTimeValue() {
   DateTime dateTime = new DateTime();
   Date date = new Date();
   date.year = 2012;
   date.month = 12;
   date.day = 2;
   dateTime.date = date;
   dateTime.hour = 12;
   dateTime.minute = 45;
   dateTime.second = 0;
   dateTime.timeZoneID = "Asia/Shanghai";
   DateTimeValue dateTimeValue = new DateTimeValue();
   dateTimeValue.value = dateTime;
   Assert.AreEqual(dateTime, PqlUtilities.GetValue(dateTimeValue));
 }
        /// <summary>
        /// Converts a System.DateTime object to a Dfp DateTime object with the specified timeZoneId.
        /// Does not perform time zone conversion. This means the returned DateTime value
        /// may not represent the same instant as the System.DateTime value.
        /// </summary>
        /// <param name="dateTime">The DateTime object.</param>
        /// <param name="timeZoneId">The timeZoneId to use.</param>
        /// <returns>A Dfp Datetime object.</returns>
        public static DfpDateTime FromDateTime(System.DateTime dateTime, string timeZoneId)
        {
            PreconditionUtilities.CheckArgumentNotNull(dateTime, "dateTime");
            PreconditionUtilities.CheckArgumentNotNull(timeZoneId, "timeZoneId");

            DfpDateTime retval = new DfpDateTime();

            retval.date       = new Date();
            retval.date.year  = dateTime.Year;
            retval.date.month = dateTime.Month;
            retval.date.day   = dateTime.Day;
            retval.hour       = dateTime.Hour;
            retval.minute     = dateTime.Minute;
            retval.second     = dateTime.Second;
            retval.timeZoneID = timeZoneId;
            return(retval);
        }
        /// <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 OrderService.
            LineItemService lineItemService = (LineItemService)user.GetService(
                DfpService.v201511.LineItemService);

            long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

            // Create statement to only select line items for the given order that
            // have been modified in the last 3 days.
            DateTime threeDaysAgo =
                DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(-3), "America/New_York");
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("lastModifiedDateTime >= :lastModifiedDateTime AND orderId = :orderId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("lastModifiedDateTime", threeDaysAgo)
                                                .AddValue("orderId", orderId);

            // Set default for page.
            LineItemPage page = new LineItemPage();

            try {
                do
                {
                    // Get line items by statement.
                    page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

                    // Display results.
                    if (page != null && page.results != null)
                    {
                        foreach (LineItem lineItem in page.results)
                        {
                            Console.WriteLine("Line item with id \"{0}\", belonging to order id \"{1}\" and " +
                                              "named \"{2}\" was found.", lineItem.id, lineItem.orderId, lineItem.name);
                        }
                    }
                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while(statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {1}.", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get line items. Exception says \"{0}\"", e.Message);
            }
        }
Beispiel #10
0
        public void TestGetObjectDateTimeValue()
        {
            DateTime dateTime = new DateTime();
            Date     date     = new Date();

            date.year           = 2012;
            date.month          = 12;
            date.day            = 2;
            dateTime.date       = date;
            dateTime.hour       = 12;
            dateTime.minute     = 45;
            dateTime.second     = 0;
            dateTime.timeZoneID = "Asia/Shanghai";
            DateTimeValue dateTimeValue = new DateTimeValue();

            dateTimeValue.value = dateTime;
            Assert.AreEqual(dateTime, PqlUtilities.GetValue(dateTimeValue));
        }
Beispiel #11
0
        /// <summary>
        /// Gets the text value of an unwrapped Value object.
        /// </summary>
        /// <param name="value">The unwrapped Value.</param>
        /// <returns>A formatted text representation of the value.</returns>
        /// <remarks>DateValue is formatted in yyyy-mm-dd format. DateTimeValue is
        /// formatted in yyyy-mm-dd HH:mm:ss Z format.</remarks>
        private static string GetTextValue(Object value)
        {
            if (value == null)
            {
                return("");
            }

            if (value is Google.Api.Ads.Dfp.v201511.Date)
            {
                Google.Api.Ads.Dfp.v201511.Date date =
                    (Google.Api.Ads.Dfp.v201511.Date)value;
                return(string.Format("{0:0000}-{1:00}-{2:00}",
                                     date.year,
                                     date.month,
                                     date.day));
            }
            else if (value is Google.Api.Ads.Dfp.v201511.DateTime)
            {
                Google.Api.Ads.Dfp.v201511.DateTime dateTime =
                    (Google.Api.Ads.Dfp.v201511.DateTime)value;
                return(string.Format("{0:0000}-{1:00}-{2:00}T{3:00}:{4:00}:{5:00} {6}",
                                     dateTime.date.year,
                                     dateTime.date.month,
                                     dateTime.date.day,
                                     dateTime.hour,
                                     dateTime.minute,
                                     dateTime.second,
                                     dateTime.timeZoneID));
            }
            else if (value is List <object> )
            {
                List <string> textValues = (value as List <object>)
                                           .ConvertAll(new Converter <object, string>(GetTextValue))
                                           .ConvertAll(new Converter <string, string>(EscapeCsv));
                return(String.Join <string>(",", textValues));
            }
            else
            {
                // NumberValue, BooleanValue, TextValue
                return(value.ToString());
            }
        }
Beispiel #12
0
        public void TestGetObjectDateSetValue()
        {
            DateTime dateTime = new DateTime();
            Date     date     = new Date();

            date.year  = 2012;
            date.month = 12;
            date.day   = 2;
            DateValue dateValue = new DateValue();

            dateValue.value = date;

            SetValue setValue = new SetValue();

            setValue.values = new Value[] { dateValue };
            List <object> value = PqlUtilities.GetValue(setValue) as List <object>;

            Assert.AreEqual(1, value.Count);
            Assert.True(value.Contains(date));
        }
Beispiel #13
0
        public void TestGetTextValueDateTimeValue()
        {
            DateTime dateTime = new DateTime();
            Date     date     = new Date();

            date.year           = 2012;
            date.month          = 12;
            date.day            = 2;
            dateTime.date       = date;
            dateTime.hour       = 12;
            dateTime.minute     = 45;
            dateTime.second     = 0;
            dateTime.timeZoneID = "Asia/Shanghai";
            DateTimeValue dateTimeValue = new DateTimeValue();

            dateTimeValue.value = dateTime;

            Row row = new Row();

            row.values = new Value[] { dateTimeValue };
            string[] stringValues = PqlUtilities.GetRowStringValues(row);
            Assert.AreEqual(1, stringValues.Length);
            Assert.AreEqual("2012-12-02T12:45:00 Asia/Shanghai", stringValues[0]);
        }
 /// <summary>
 /// Adds a new DateTime value to the list of query parameters.
 /// </summary>
 /// <param name="key">The parameter name.</param>
 /// <param name="value">The parameter value.</param>
 /// <returns>The statement builder, for chaining method calls.</returns>
 public StatementBuilder AddValue(string key, DateTime value) {
   DateTimeValue queryValue = new DateTimeValue();
   queryValue.value = value;
   return AddValue(key, queryValue);
 }
    public void TestGetObjectDateTimeSetValue() {
      DateTime dateTime = new DateTime();
      Date date = new Date();
      date.year = 2012;
      date.month = 12;
      date.day = 2;
      dateTime.date = date;
      dateTime.hour = 12;
      dateTime.minute = 45;
      dateTime.second = 0;
      dateTime.timeZoneID = "Asia/Shanghai";
      DateTimeValue dateTimeValue = new DateTimeValue();
      dateTimeValue.value = dateTime;

      SetValue setValue = new SetValue();
      setValue.values = new Value[] { dateTimeValue };
      List<object> value = PqlUtilities.GetValue(setValue) as List<object>;
      Assert.AreEqual(1, value.Count);
      Assert.True(value.Contains(dateTime));
    }
    public void TestGetObjectDateSetValue() {
      DateTime dateTime = new DateTime();
      Date date = new Date();
      date.year = 2012;
      date.month = 12;
      date.day = 2;
      DateValue dateValue = new DateValue();
      dateValue.value = date;

      SetValue setValue = new SetValue();
      setValue.values = new Value[] { dateValue };
      List<object> value = PqlUtilities.GetValue(setValue) as List<object>;
      Assert.AreEqual(1, value.Count);
      Assert.True(value.Contains(date));
    }