public void ToStringGeneratesXml()
        {
            var item          = new ItemStatus();
            var theName       = "myItemName";
            var theDesc       = "A description";
            var theError      = "any error here";
            var theStatus     = ItemBuildStatus.CompletedFailed;
            var startTime     = new DateTime(2010, 1, 1, 12, 12, 12);
            var completedTime = new DateTime(2010, 1, 1, 13, 12, 12);
            var estimatedTime = new DateTime(2010, 1, 1, 14, 12, 12);
            var aChild        = new ItemStatus("aChild");

            item.Name                      = theName;
            item.Description               = theDesc;
            item.Error                     = theError;
            item.Status                    = theStatus;
            item.TimeStarted               = startTime;
            item.TimeCompleted             = completedTime;
            item.TimeOfEstimatedCompletion = estimatedTime;
            item.ChildItems.Add(aChild);
            var xml      = item.ToString();
            var expected = "<itemStatus xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" name=\"myItemName\" status=\"CompletedFailed\">" +
                           "<description>A description</description>" +
                           "<error>any error here</error>" +
                           "<timeStarted>2010-01-01T12:12:12</timeStarted>" +
                           "<timeCompleted>2010-01-01T13:12:12</timeCompleted>" +
                           "<timeOfEstimatedCompletion>2010-01-01T14:12:12</timeOfEstimatedCompletion>" +
                           "<childItems>" +
                           "<childItem name=\"aChild\" status=\"Unknown\">" +
                           "<timeStarted xsi:nil=\"true\" />" +
                           "<timeCompleted xsi:nil=\"true\" />" +
                           "<timeOfEstimatedCompletion xsi:nil=\"true\" />" +
                           "<childItems />" +
                           "</childItem>" +
                           "</childItems>" +
                           "</itemStatus>";

            //Assert.AreEqual(expected, xml);

            XDocument.Parse(xml).Should().BeEquivalentTo(XDocument.Parse(expected));
        }
        /// <summary>
        /// Stores a snapshot of a project build.
        /// </summary>
        /// <param name="result">The result that the snapshot is for.</param>
        /// <param name="snapshot">The project snapshot.</param>
        public void StoreProjectSnapshot(IIntegrationResult result, ItemStatus snapshot)
        {
            var dirPath = this.RootFolder(result.ArtifactDirectory, this.SnapshotsFolder);

            Log.Info("Writing snapshot (XML) to [" + dirPath + "]");

            var logFile  = new LogFile(result);
            var filePath = Path.ChangeExtension(
                Path.Combine(dirPath, logFile.Filename),
                "snapshot");

            this.FileSystem.EnsureFolderExists(filePath);
            Log.Debug("Creating new snapshot (XML) [" + filePath + "]");
            using (var stream = this.FileSystem.OpenOutputStream(filePath))
            {
                using (var writer = new StreamWriter(stream))
                {
                    Log.Debug("Writing snapshot (XML)");
                    writer.Write(snapshot.ToString());
                    Log.Debug("Snapshot (XML) written");
                }
            }
        }
Esempio n. 3
0
        internal static async void Add(string name, string path, string oldValue, string newValue, ItemStatus status)
        {
            if (isSaving || isLoading)
            {
                while (isSaving || isLoading)
                {
                    await Task.Delay(100);
                }
            }

            HistoryItem item = new HistoryItem(ClientHelper.Server, name, path, oldValue, newValue, status.ToString(), DateTime.Now);

            items.Insert(0, item);
            newItems.Add(item);

            Save();
        }
        public void WriteLibrarySync(IEnumerable <LibItem> items, ItemStatus status)
        {
            var newRecs        = new List <ItemRec>();
            var upRecs         = new List <ItemRec>();
            var itemCollection = _liteDb.GetCollection <ItemRec>(ItemsCollection);

            foreach (var i in items)
            {
                var newTime = i.SyncApiModified;

                var rec = itemCollection.Find(x => x.ItemId == i.Id).FirstOrDefault();

                var newRec = new ItemRec
                {
                    ItemId       = i.Id,
                    Status       = status,
                    LastModified = newTime,
                    MediaType    = i.ItemType
                };

                if (rec == null)
                {
                    newRecs.Add(newRec);
                }
                else if (rec.LastModified < newTime)
                {
                    newRec.Id = rec.Id;
                    upRecs.Add(newRec);
                }
                else
                {
                    _logger.LogDebug("NewTime: {NewTime}  OldTime: {LastModified}   Status: {Status}", newTime, rec.LastModified, status);
                    newRec = null;
                }

                if (newRec != null)
                {
                    _logger.LogDebug("{StatusType} ItemId: '{ItemId}'", status.ToString(), newRec.ItemId.ToString("N", CultureInfo.InvariantCulture));
                }
                else
                {
                    _logger.LogDebug("ItemId: '{ItemId}' Skipped", i.Id.ToString("N", CultureInfo.InvariantCulture));
                }
            }

            if (newRecs.Count > 0)
            {
                _logger.LogDebug("{@NewRecs}", newRecs);
                itemCollection.Insert(newRecs);
            }

            if (upRecs.Count > 0)
            {
                var data = itemCollection.FindAll().ToList();

                foreach (var rec in upRecs)
                {
                    data.Where(d => d.Id == rec.Id).ToList().ForEach(i =>
                    {
                        i.ItemId       = rec.ItemId;
                        i.Status       = rec.Status;
                        i.LastModified = rec.LastModified;
                        i.MediaType    = rec.MediaType;
                    });
                }

                itemCollection.Update(data);

                data = itemCollection.FindAll().ToList();
                _logger.LogDebug("{@Data}", data);
            }
        }