Exemplo n.º 1
0
        public static void RemoveUserProperty(MailItem mailitem)
        {
            UserProperties mailUserProperties = null;

            try
            {
                var pointer = 0;
                mailUserProperties = mailitem.UserProperties;
                for (var i = 1; i == mailUserProperties.Count; i++)
                {
                    if (mailUserProperties[i].Name == "KayakoTicketId")
                    {
                        pointer = i;
                    }
                }
                mailUserProperties.Remove(pointer);
                mailitem.Save();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (mailUserProperties != null)
                {
                    Marshal.ReleaseComObject(mailUserProperties);
                }
            }
        }
Exemplo n.º 2
0
 protected void OnDeserialized(StreamingContext context)
 {
     if (Energieverbrauch == null)
     {
         Energieverbrauch = new List <Verbrauch>();
     }
     else if (Energieverbrauch.Count > 0)
     {
         Energieverbrauch = Energieverbrauch
                            .Select(v => Verbrauch.FixSapCdsBug(v))
                            .Where(v => !(v.Startdatum == DateTime.MinValue || v.Enddatum == DateTime.MinValue))
                            .Where(v => !(v.UserProperties != null && v.UserProperties.ContainsKey("invalid") && (bool)v.UserProperties["invalid"] == true))
                            .ToList();
         if (UserProperties != null && UserProperties.TryGetValue(Verbrauch._SAP_PROFDECIMALS_KEY, out JToken profDecimalsRaw))
         {
             var profDecimals = profDecimalsRaw.Value <int>();
             if (profDecimals > 0)
             {
                 for (int i = 0; i < profDecimals; i++)
                 {
                     // or should I import math.pow() for this purpose?
                     foreach (Verbrauch v in Energieverbrauch.Where(v => v.UserProperties == null || !v.UserProperties.ContainsKey(Verbrauch._SAP_PROFDECIMALS_KEY)))
                     {
                         v.Wert /= 10.0M;
                     }
                 }
             }
             UserProperties.Remove(Verbrauch._SAP_PROFDECIMALS_KEY);
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Our SAP Core Data Service view definition reading the profile values has a bug:
 /// The time stamp of both start- and enddatum is simply a concatenated string using the
 /// date (defining the table row) and the time (determining the column). The design of
 /// the table eprofval is pure PITA but we've got to deal with it anyway. Since it's
 /// impossible to artificially increment the date directly in the definition of the
 /// ABAP/SQL view (as of SAP 7.51), we're attempting to fix it here. On 363 days a year
 /// the symptom is easy to detect: The last time slice of the day ranges from 23:45 of
 /// the current day and has the enddatum t 00:00 still on the same day instead of the
 /// following. What makes it difficult are the edge cases. What happens on the day we
 /// switch from daylight saving time to non-daylight saving time? The time difference
 /// could be in the order of magnitude of 22 to 25 hours. Please add new unit tests for
 /// every edge case.
 /// </summary>
 public void FixSapCdsBug()
 {
     //using (MiniProfiler.Current.Step("FixSapCdsBug (Verbrauch)")) // don't do this. it slows down everything !
     // {
     if (Startdatum != null && Enddatum != null && Startdatum > Enddatum)
     {
         TimeSpan diff = Startdatum - Enddatum;
         if (diff.Hours <= 25 && diff.Hours >= 23 && diff.Minutes == 45 && Startdatum.Hour >= 22 && Enddatum.Hour == 0)
         {
             Enddatum += new TimeSpan(diff.Hours + 1, 0, 0);
         }
         else
         {
             // something seems wrong but not sure how to fix it.
         }
     }
     Startdatum = DateTime.SpecifyKind(Startdatum, DateTimeKind.Utc);
     Enddatum   = DateTime.SpecifyKind(Enddatum, DateTimeKind.Utc);
     if ((int)(Enddatum - Startdatum).TotalHours == 2)
     {
         // check DST of start and enddatum
         var startdatumLocal = TimeZoneInfo.ConvertTimeFromUtc(Startdatum, Verbrauch.CENTRAL_EUROPE_STANDARD_TIME);
         var enddatumLocal   = TimeZoneInfo.ConvertTimeFromUtc(Enddatum, Verbrauch.CENTRAL_EUROPE_STANDARD_TIME);
         if (!Verbrauch.CENTRAL_EUROPE_STANDARD_TIME.IsDaylightSavingTime(startdatumLocal - new TimeSpan(0, 0, 1)) && Verbrauch.CENTRAL_EUROPE_STANDARD_TIME.IsDaylightSavingTime(enddatumLocal))
         {
             // change winter-->summer time (e.g. UTC+1-->UTC+2)
             // this is an artefact of the sap enddatum computation
             Enddatum -= new TimeSpan(1, 0, 0); // toDo: get offset from timezoneinfo->rules->dstOffset
         }
     }
     else if ((int)(Enddatum - Startdatum).TotalMinutes == -45)
     {
         // check DST of start and enddatum
         //var startdatumLocal = TimeZoneInfo.ConvertTimeFromUtc(startdatum, Verbrauch.CENTRAL_EUROPE_STANDARD_TIME);
         var enddatumLocal = TimeZoneInfo.ConvertTimeFromUtc(Enddatum, Verbrauch.CENTRAL_EUROPE_STANDARD_TIME);
         if (!Verbrauch.CENTRAL_EUROPE_STANDARD_TIME.IsDaylightSavingTime(enddatumLocal - new TimeSpan(1, 0, 0)) && Verbrauch.CENTRAL_EUROPE_STANDARD_TIME.IsDaylightSavingTime(enddatumLocal - new TimeSpan(1, 0, 1)))
         {
             // change winter-->summer time (e.g. UTC+1-->UTC+2)
             // this is an artefact of the sap enddatum computation
             Enddatum += new TimeSpan(1, 0, 0); // toDo: get offset from timezoneinfo->rules->dstOffset
         }
     }
     if (UserProperties != null && UserProperties.TryGetValue(_SAP_PROFDECIMALS_KEY, out JToken profDecimalsRaw))
     {
         var profDecimals = profDecimalsRaw.Value <int>();
         if (profDecimals > 0)
         {
             // or should I import math.pow() for this purpose?
             for (int i = 0; i < profDecimals; i++)
             {
                 Wert /= 10.0M;
             }
         }
         UserProperties.Remove(_SAP_PROFDECIMALS_KEY);
     }
 }
Exemplo n.º 4
0
 protected void OnDeserialized(StreamingContext context)
 {
     if (Energieverbrauch == null)
     {
         Energieverbrauch = new List <Verbrauch>();
     }
     else if (Energieverbrauch.Count > 0)
     {
         Energieverbrauch = Energieverbrauch
                            .Select(Verbrauch.FixSapCdsBug)
                            .Where(v => !(v.Startdatum == DateTimeOffset.MinValue || v.Enddatum == DateTimeOffset.MinValue))
                            .Where(v => !v.UserPropertyEquals("invalid", true))
                            .ToList();
         if (UserProperties != null &&
             UserProperties.TryGetValue(Verbrauch.SapProfdecimalsKey, out var profDecimalsRaw))
         {
             var profDecimals = 0;
             if (profDecimalsRaw is string raw)
             {
                 profDecimals = int.Parse(raw);
             }
             else
             {
                 profDecimals = ((JsonElement)profDecimalsRaw).GetInt32();
             }
             if (profDecimals > 0)
             {
                 for (var i = 0; i < profDecimals; i++)
                 {
                     // or should I import math.pow() for this purpose?
                     foreach (var v in Energieverbrauch.Where(v =>
                                                              v.UserProperties == null ||
                                                              !v.UserProperties.ContainsKey(Verbrauch.SapProfdecimalsKey)))
                     {
                         v.Wert /= 10.0M;
                     }
                 }
             }
             UserProperties.Remove(Verbrauch.SapProfdecimalsKey);
         }
     }
 }