CalDavSynchronizer.ThoughtvCardWorkaround.vCardImprovedWriter.BuildProperties_PHOTO C# (CSharp) Метод

BuildProperties_PHOTO() приватный Метод

private BuildProperties_PHOTO ( vCardPropertyCollection properties, Thought.vCards.vCard card ) : void
properties vCardPropertyCollection
card Thought.vCards.vCard
Результат void
      private void BuildProperties_PHOTO(
          vCardPropertyCollection properties,
          vCard card)
      {

        foreach (vCardPhoto photo in card.Photos)
        {

          if (photo.Url == null)
          {

            // This photo does not have a URL associated
            // with it.  Therefore a property can be
            // generated only if the image data is loaded.
            // Otherwise there is not enough information.

            if (photo.IsLoaded)
            {
              var property = new vCardProperty ("PHOTO", photo.GetBytes());
              property.Subproperties.Add ("TYPE", "JPEG");
              properties.Add (property);
            }
          }
          else
          {

            // This photo has a URL associated with it.  The
            // PHOTO property can either be linked as an image
            // or embedded, if desired.

            bool doEmbedded =
                photo.Url.IsFile ? this.embedLocalImages : this.embedInternetImages;

            if (doEmbedded)
            {

              // According to the settings of the card writer,
              // this linked image should be embedded into the
              // vCard data.  Attempt to fetch the data.

              try
              {
                photo.Fetch();
              }
              catch
              {

                // An error was encountered.  The image can
                // still be written as a link, however.

                doEmbedded = false;
              }

            }

            // At this point, doEmbedded is true only if (a) the
            // writer was configured to embed the image, and (b)
            // the image was successfully downloaded.

            if (doEmbedded)
            {
              properties.Add(
                  new vCardProperty("PHOTO", photo.GetBytes()));
            }
            else
            {

              vCardProperty uriPhotoProperty =
                  new vCardProperty("PHOTO");

              // Set the VALUE property to indicate that
              // the data for the photo is a URI.

              uriPhotoProperty.Subproperties.Add("VALUE", "URI");
              uriPhotoProperty.Value = photo.Url.ToString();

              properties.Add(uriPhotoProperty);
            }

          }
        }
      }