Ejemplo n.º 1
0
        /// <summary>
        /// Starts synchronizing time.
        /// </summary>
        public void SyncTime()
        {
            RunInBackground(() =>
            {
                SystemDateTime dt = Client.GetSystemDateAndTime();

                System.DateTime now = System.DateTime.Now.ToUniversalTime();
                DateTime deviceTime = new DateTime();
                deviceTime.Date     = new Date();
                deviceTime.Time     = new Time();

                deviceTime.Date.Year   = now.Year;
                deviceTime.Date.Month  = now.Month;
                deviceTime.Date.Day    = now.Day;
                deviceTime.Time.Hour   = now.Hour;
                deviceTime.Time.Minute = now.Minute;
                deviceTime.Time.Second = now.Second;

                Client.SetSystemDateAndTime(SetDateTimeType.Manual, dt.DaylightSavings,
                                            null, deviceTime);
            });
        }
Ejemplo n.º 2
0
        void CompareLists(IEnumerable <RecordingInformation> recordings1, IEnumerable <RecordingInformation> recordings2)
        {
            bool          ok     = true;
            StringBuilder logger = new StringBuilder();

            List <string> common = new List <string>();

            // check that all tokens from full list are present in list of found recordings
            foreach (RecordingInformation item in recordings1)
            {
                string token = item.RecordingToken;
                RecordingInformation[] foundItems =
                    recordings2.Where(RI => RI.RecordingToken == token).ToArray();

                if (foundItems.Length == 0)
                {
                    logger.AppendFormat(
                        "Recording with token {0} not found in second list{1}",
                        item.RecordingToken, Environment.NewLine);
                    ok = false;
                }
                else
                {
                    common.Add(token);
                }
            }

            foreach (RecordingInformation item in recordings2)
            {
                string token = item.RecordingToken;
                RecordingInformation[] foundItems =
                    recordings1.Where(RI => RI.RecordingToken == token).ToArray();

                if (foundItems.Length == 0)
                {
                    logger.AppendFormat(
                        "Recording with token {0} not found in first list{1}",
                        item.RecordingToken, Environment.NewLine);
                    ok = false;
                }
            }

            // for common only

            foreach (RecordingInformation info1 in recordings1)
            {
                string token = info1.RecordingToken;
                if (!common.Contains(token))
                {
                    continue;
                }

                RecordingInformation info2 = recordings2.Where(RI => RI.RecordingToken == token).FirstOrDefault();

                StringBuilder dump =
                    new StringBuilder(string.Format("Information for recording with token '{0}' is different:{1}", token,
                                                    Environment.NewLine));

                bool localOk = true;

                if (info1.Content != info2.Content)
                {
                    localOk = false;
                    dump.AppendLine("   Content is different");
                }
                if (info1.RecordingStatus != info2.RecordingStatus)
                {
                    localOk = false;
                    dump.AppendLine("   RecordingStatus is different");
                }

                Action <Func <RecordingInformation, bool>, Func <RecordingInformation, System.DateTime>, string> check =
                    new Action <Func <RecordingInformation, bool>, Func <RecordingInformation, System.DateTime>, string>(
                        (specifiedSelector, valueSelector, fieldName) =>
                {
                    bool specified1 = specifiedSelector(info1);
                    bool specified2 = specifiedSelector(info2);

                    if (specified1 || specified2)
                    {
                        if (specified1 && specified2)
                        {
                            System.DateTime value1 = valueSelector(info1);
                            System.DateTime value2 = valueSelector(info2);

                            if (value1 != value2)
                            {
                                localOk = false;
                                dump.AppendFormat("   {0} is different{1}", fieldName, Environment.NewLine);
                            }
                        }
                        else
                        {
                            if (!specified1)
                            {
                                localOk = false;
                                dump.AppendFormat("   {0} not specified for the first list{1}", fieldName,
                                                  Environment.NewLine);
                            }
                            if (!specified2)
                            {
                                localOk = false;
                                dump.AppendFormat("   {0} not specified for the second list{1}", fieldName,
                                                  Environment.NewLine);
                            }
                        }
                    }
                });

                check(RI => RI.EarliestRecordingSpecified, RI => RI.EarliestRecording, "EarliestRecording");
                check(RI => RI.LatestRecordingSpecified, RI => RI.LatestRecording, "LatestRecording");

                RecordingSourceInformation source1 = info1.Source;
                RecordingSourceInformation source2 = info2.Source;

                if (source1 != null || source2 != null)
                {
                    if (source1 != null && source2 != null)
                    {
                        Action <string, Func <RecordingSourceInformation, string> > checkStringAction =
                            new Action <string, Func <RecordingSourceInformation, string> >(
                                (name, fieldSelector) =>
                        {
                            string value1 = fieldSelector(source1);
                            string value2 = fieldSelector(source2);
                            if (value1 != value2)
                            {
                                localOk = false;
                                dump.AppendFormat("   Source.{0} field is different {1}", name, Environment.NewLine);
                            }
                        });

                        checkStringAction("Address", S => S.Address);
                        checkStringAction("Description", S => S.Description);
                        checkStringAction("Location", S => S.Location);
                        checkStringAction("Name", S => S.Name);
                        checkStringAction("SourceId", S => S.SourceId);
                    }
                    else
                    {
                        if (source1 == null)
                        {
                            dump.AppendLine("   RecordingSourceInformation is missing for the item from the first list{0}");
                            localOk = false;
                        }
                        if (source2 == null)
                        {
                            dump.AppendLine("   RecordingSourceInformation is missing for the item from the second list{0}");
                            localOk = false;
                        }
                    }
                }

                bool trackList1Ok = info1.Track != null && info1.Track.Length > 0;
                bool trackList2Ok = info2.Track != null && info2.Track.Length > 0;

                if (trackList1Ok || trackList2Ok)
                {
                    if (trackList1Ok && trackList2Ok)
                    {
                        // compare track by track

                        bool tracksOk = true;

                        /***************************************************************/

                        TrackInformation[] tracks1 = info1.Track;
                        TrackInformation[] tracks2 = info2.Track;

                        StringBuilder sb       = new StringBuilder();
                        bool          tokensOk = ArrayUtils.ValidateTokens(tracks1, TR => TR.TrackToken, sb);
                        if (!tokensOk)
                        {
                            dump.AppendFormat("   List of tracks is not valid for item from the first list - not all checks will be performed{0}", Environment.NewLine);
                            tracksOk = false;
                        }

                        sb       = new StringBuilder();
                        tokensOk = ArrayUtils.ValidateTokens(tracks2, TR => TR.TrackToken, sb);
                        if (!tokensOk)
                        {
                            dump.AppendFormat("   List of tracks is not valid for item from the second list - not all checks will be performed{0}", Environment.NewLine);
                            tracksOk = false;
                        }

                        {
                            List <string> commonTracks = new List <string>();

                            // compare tokens
                            foreach (TrackInformation info in tracks1)
                            {
                                TrackInformation inf =
                                    tracks2.Where(T => T.TrackToken == info.TrackToken).FirstOrDefault();
                                if (inf == null)
                                {
                                    tracksOk = false;
                                    // not found
                                    dump.AppendFormat("   Track with token {0} not found for recording from second list{1}", info.TrackToken, Environment.NewLine);
                                }
                                else
                                {
                                    int cnt = tracks1.Where(T => T.TrackToken == info.TrackToken).Count();
                                    if (cnt == 1)
                                    {
                                        commonTracks.Add(info.TrackToken);
                                    }
                                }
                            }
                            foreach (TrackInformation info in tracks2)
                            {
                                TrackInformation inf =
                                    tracks1.Where(T => T.TrackToken == info.TrackToken).FirstOrDefault();
                                if (inf == null)
                                {
                                    tracksOk = false;
                                    // not found
                                    dump.AppendFormat("   Track with token {0} not found for recording from  first list{1}", info.TrackToken, Environment.NewLine);
                                }
                            }

                            {
                                // compare common

                                foreach (TrackInformation trackInfo1 in tracks1)
                                {
                                    string trackToken = trackInfo1.TrackToken;

                                    if (!commonTracks.Contains(trackToken))
                                    {
                                        continue;
                                    }

                                    TrackInformation[] infos = tracks2.Where(T => T.TrackToken == trackToken).ToArray();
                                    if (infos.Length != 1)
                                    {
                                        // error is added to log already
                                        continue;
                                    }
                                    TrackInformation trackInfo2 = infos[0];

                                    // DataFrom, DataTo, Description, TrackType

                                    if (trackInfo1.Description != trackInfo2.Description)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   Description is different for tracks with token '{0}'{1}",
                                                          trackToken, Environment.NewLine);
                                    }

                                    if (trackInfo1.TrackType != trackInfo2.TrackType)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   TrackType is different for tracks with token '{0}' {1}",
                                                          trackToken, Environment.NewLine);
                                    }

                                    if (trackInfo1.DataFrom != trackInfo2.DataFrom)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   DataFrom is different for tracks with token '{0}' {1}",
                                                          trackToken, Environment.NewLine);
                                    }
                                    if (trackInfo1.DataTo != trackInfo2.DataTo)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   DataFrom is different for tracks with token '{0}' {1}",
                                                          trackToken, Environment.NewLine);
                                    }
                                }
                            }
                        }

                        /****************************************************************/
                        localOk = localOk && tracksOk;
                    }
                    else
                    {
                        if (!trackList1Ok)
                        {
                            dump.AppendFormat("   Track list is missing for the item from the first list{0}",
                                              Environment.NewLine);
                            localOk = false;
                        }
                        if (!trackList2Ok)
                        {
                            dump.AppendFormat("   Track list is missing for the item from the first list{0}",
                                              Environment.NewLine);
                            localOk = false;
                        }
                    }
                }

                if (!localOk)
                {
                    logger.Append(dump.ToString());
                    ok = false;
                }
            }

            Assert(ok, logger.ToStringTrimNewLine(), "Check that all recordings are returned");
        }