public void Constructor_String()
        {
            // If a filename (string) is passed to the constructor, then
            // the scheme of the URI should be set as file.

            vCardPhoto photo = new vCardPhoto("c:\\fake-picture.gif");

            Assert.IsTrue(
                photo.Url.IsFile);
        }
        private void MapPhoto2To1(vCard source, ContactItem target, IEntityMappingLogger logger)
        {
            if (source.Photos.Count > 0)
            {
                if (target.HasPicture && _configuration.KeepOutlookPhoto)
                {
                    return;
                }

                vCardPhoto contactPhoto = source.Photos[0];

                if (contactPhoto.IsLoaded)
                {
                    try
                    {
                        string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg";
                        File.WriteAllBytes(picturePath, contactPhoto.GetBytes());
                        try
                        {
                            target.AddPicture(picturePath);
                        }
                        catch (COMException x)
                        {
                            s_logger.Warn("Could not add picture for contact.", x);
                            logger.LogMappingWarning("Could not add picture for contact.", x);
                        }
                        File.Delete(picturePath);
                    }
                    catch (Exception ex)
                    {
                        s_logger.Warn("Could not add picture for contact.", ex);
                        logger.LogMappingWarning("Could not add picture for contact.", ex);
                    }
                }
            }
            else
            {
                if (target.HasPicture)
                {
                    try
                    {
                        target.RemovePicture();
                    }
                    catch (COMException x)
                    {
                        s_logger.Warn("Could not remove picture for contact.", x);
                        logger.LogMappingWarning("Could not remove picture for contact.", x);
                    }
                }
            }
        }
        public void Constructor_Encoded_Data()
        {
            vCardPhoto p = new vCardPhoto(TestPhotoUrl);

            p.Fetch();
            var bytes = p.GetBytes();

            var base64Image = Convert.ToBase64String(bytes);

            vCardPhoto photo = new vCardPhoto(base64Image, true);

            Assert.IsTrue(photo.HasEncodedData, "encoded data is false");

            var data = photo.EncodedData;

            Assert.AreEqual(base64Image, data);
        }
Exemplo n.º 4
0
        public void Fetch_Good()
        {
            // You may wish to ignore this test if you run
            // extensive unit tests and your Internet connection
            // is slow.

            vCardPhoto photo = new vCardPhoto(TestPhotoUrl);

            Assert.IsFalse(
                photo.IsLoaded,
                "The photo has not been loaded yet.");

            photo.Fetch();

            Assert.IsTrue(
                photo.IsLoaded,
                "The photo should have been loaded.");

            // Get the bytes of the image.

            byte[] data = photo.GetBytes();

            Assert.AreEqual(
                TestPhotoSize,
                data.Length,
                "The length of the photo is unexpected.");

            #if Linux
            // Throw new NotImplementedException("Not implemented OSX test.");
            #elif OSX
            // Throw new NotImplementedException("Not implemented OSX test.");
            #elif Windows
            using (Bitmap bitmap = photo.GetBitmap())
            {
                Assert.AreEqual(
                    TestPhotoHeight,
                    bitmap.Size.Height,
                    "The photo height is unexpected.");

                Assert.AreEqual(
                    TestPhotoWidth,
                    bitmap.Size.Width,
                    "The photo width is unexpected.");
            }
            #endif
        }
Exemplo n.º 5
0
        public static void Equals(vCardPhoto p1, vCardPhoto p2)
        {
            Assert.AreEqual(
                p1.IsLoaded,
                p2.IsLoaded,
                "vCardPhoto.IsLoaded differs.");

            Assert.AreEqual(
                p1.ToString(),
                p2.ToString(),
                "vCardPhoto.ToString differs.");

            Assert.AreEqual(
                p1.Url,
                p2.Url,
                "vCardPhoto.Url differs.");
        }
        private static void MapPhoto2To1(vCard source, ContactItem target)
        {
            if (source.Photos.Count > 0)
            {
                vCardPhoto contactPhoto = source.Photos[0];

                if (contactPhoto.IsLoaded)
                {
                    string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg";
                    using (FileStream fs = new FileStream(picturePath, FileMode.Create))
                    {
                        fs.Write(contactPhoto.GetBytes(), 0, contactPhoto.GetBytes().Length);
                        fs.Flush();
                    }
                    target.AddPicture(picturePath);
                    File.Delete(picturePath);
                }
            }
        }
 public void Constructor_String_Null()
 {
     vCardPhoto photo = new vCardPhoto((string)null);
 }
 public void Constructor_String_Empty()
 {
     vCardPhoto photo = new vCardPhoto(string.Empty);
 }
        private async Task MapPhoto2To1(vCard source, ContactItem target, IEntitySynchronizationLogger logger)
        {
            if (source.Photos.Count > 0)
            {
                if (target.HasPicture && _configuration.KeepOutlookPhoto)
                {
                    return;
                }

                vCardPhoto contactPhoto = source.Photos[0];

                string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg";
                try
                {
                    if (!contactPhoto.IsLoaded && contactPhoto.Url != null)
                    {
                        using (var client = _webClientFactory())
                        {
                            await client.DownloadFileTaskAsync(contactPhoto.Url, picturePath);
                        }
                    }
                    else if (contactPhoto.IsLoaded)
                    {
                        File.WriteAllBytes(picturePath, contactPhoto.GetBytes());
                    }
                    else
                    {
                        s_logger.Warn("Could not load picture for contact.");
                        logger.LogWarning("Could not load picture for contact.");
                        return;
                    }

                    try
                    {
                        target.AddPicture(picturePath);
                    }
                    catch (COMException x)
                    {
                        s_logger.Warn("Could not add picture for contact.", x);
                        logger.LogWarning("Could not add picture for contact.", x);
                    }

                    File.Delete(picturePath);
                }
                catch (Exception ex)
                {
                    s_logger.Warn("Could not add picture for contact.", ex);
                    logger.LogWarning("Could not add picture for contact.", ex);
                }
            }
            else
            {
                if (target.HasPicture)
                {
                    try
                    {
                        target.RemovePicture();
                    }
                    catch (COMException x)
                    {
                        s_logger.Warn("Could not remove picture for contact.", x);
                        logger.LogWarning("Could not remove picture for contact.", x);
                    }
                }
            }
        }