Exemple #1
0
        public void CanLogMessageThroughHelpers()
        {
            // Arrange
            var logId = _fixture.Create<Guid>();
            string actualData = null;

            var webClientMock = new Mock<IWebClient>();
            webClientMock
                .Setup(x => x.Post(It.IsAny<WebHeaderCollection>(), It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<Func<WebHeaderCollection, string, string>>()))
                .Callback<WebHeaderCollection, Uri, string, Func<WebHeaderCollection, string, string>>((headers, uri, data, resultor) => { actualData = data; })
                .Returns(Task.FromResult(string.Empty));

            var logger = new Logger(logId, null, webClientMock.Object);

            var utcDate = DateTime.UtcNow.ToString("yyyy-MM-dd");
            var value = _fixture.Create<string>();

            // Act
            logger.Verbose("{0}", value);

            // Assert
            Assert.That(actualData, Is.Not.Null);
            Assert.That(actualData, Is.StringContaining(value));
            Assert.That(actualData, Is.StringContaining(Severity.Verbose.ToString()));
            Assert.That(actualData, Is.StringContaining(utcDate));
        }
        internal GlobalSingleInstanceActivationMaintainer(LocalGrainDirectory router, Logger logger, GlobalConfiguration config)
        {
            this.router = router;
            this.logger = logger;
            this.period = config.GlobalSingleInstanceRetryInterval;
            logger.Verbose("GSIP:M GlobalSingleInstanceActivationMaintainer Started, Period = {0}", period);

        }
        /// <summary>
        /// Synchronizes files to an android device.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="device">The device.</param>
        /// <param name="fileMapping">The file mapping (relative target path, source HDD filename).</param>
        /// <param name="androidPath">The android path.</param>
        /// <param name="cacheFile">The cache file.</param>
        public static void Synchronize(Logger logger, string device, Dictionary<string, string> fileMapping, string androidPath, string cacheFile)
        {
            // Ensure android path ends up with directory separator
            if (!androidPath.EndsWith("/"))
                androidPath = androidPath + "/";

            // Search files
            var currentVersions = fileMapping
                .ToDictionary(x => x.Key, x => new FileVersion(x.Value));

            // Try to read previous cache file
            var previousVersions = new Dictionary<string, FileVersion>();
            try
            {
                using (var file = File.OpenRead(cacheFile))
                {
                    var binaryReader = new BinarySerializationReader(file);
                    binaryReader.Serialize(ref previousVersions, ArchiveMode.Deserialize);
                }
            }
            catch (IOException)
            {
            }

            var filesToRemove = new List<string>();
            var filesToUpload = new List<string>();

            // Remove unecessary files (in previousVersions but not in currentVersions)
            foreach (var file in previousVersions.Where(x => !currentVersions.ContainsKey(x.Key)))
            {
                filesToRemove.Add(file.Key);
            }

            // Upload files that are either not uploaded yet, or not up to date
            foreach (var file in currentVersions)
            {
                FileVersion fileVersion;
                if (!previousVersions.TryGetValue(file.Key, out fileVersion)
                    || fileVersion.FileSize != file.Value.FileSize
                    || fileVersion.LastModifiedDate != file.Value.LastModifiedDate)
                {
                    filesToUpload.Add(file.Key);
                }
            }

            // Upload files
            foreach (var file in filesToUpload)
            {
                if (logger != null)
                    logger.Verbose("Copying file {0}", file);
                RunAdb(device, string.Format("push \"{0}\" \"{1}\"", fileMapping[file], androidPath + file.Replace('\\', '/')));
            }

            // Remove files
            foreach (var file in filesToRemove)
            {
                if (logger != null)
                    logger.Verbose("Deleting file {0}", file);
                RunAdb(device, string.Format("shell \"rm {0}\"", androidPath + file.Replace('\\', '/')));
            }

            // Write new cache file
            using (var file = File.Create(cacheFile))
            {
                var binaryWriter = new BinarySerializationWriter(file);
                binaryWriter.Write(currentVersions);
            }
        }