Example #1
0
 private void AddObjectToCommunity(long _CommunityId, long?_ComponentId, object _target, int maxProgress)
 {
     try
     {
         apiUsers uploadApi = new apiUsers();
         if (_target is Folder)
         {
             Folder folder    = (Folder)_target;
             string thumbnail = string.IsNullOrEmpty(folder.Thumbnail) ?
                                CloudCommunities.CallUploader(CloudCommunities.ImageToByteArray(folder.ThumbNail), folder.Name, "image/jpeg", true) :
                                folder.Thumbnail;
             CloudCommunityComponentsAPI.apiCommunityComponents api =
                 new CloudCommunityComponentsAPI.apiCommunityComponents();
             CloudCommunityComponentsAPI.WWTCommunityComponentSt f =
                 api.Create(CloudCommunities.GetTokenFromId(), _CommunityId,
                            CloudCommunityComponentsAPI.WWTComponentTypes.WWTCollection,
                            _ComponentId, folder.Name, thumbnail, "", null);
             int childNumber = 0, progActual = progress.Value,
                 progDiff = maxProgress - progress.Value;
             foreach (object obj in folder.Children)
             {
                 int maxProgChild = (++childNumber) * progDiff / folder.Children.Length;
                 AddObjectToCommunity(f.CommunityId, f.ComponentId, obj, progActual + maxProgChild);
             }
             CloudCommunities.SetAvoidCache(_CommunityId, _ComponentId);
         }
         else
         {
             CloudCommunities.AddUpdObjectToCommunity(_CommunityId, _ComponentId, _target, false);
         }
     }
     catch (Exception e)
     {
         errorList.Add(_target.GetType().ToString() + ": " + getTargetName(_target) + " - Error: " + e.Message);
     }
     backgroundUpdater.ReportProgress(maxProgress);
 }
 private void AddObjectToCommunity(long _CommunityId, long? _ComponentId, object _target, int maxProgress)
 {
     try
     {
         apiUsers uploadApi = new apiUsers();
         if (_target is Folder)
         {
             Folder folder = (Folder)_target;
             string thumbnail = string.IsNullOrEmpty(folder.Thumbnail) ?
                 CloudCommunities.CallUploader(CloudCommunities.ImageToByteArray(folder.ThumbNail), folder.Name, "image/jpeg", true) :
                 folder.Thumbnail;
             CloudCommunityComponentsAPI.apiCommunityComponents api =
                 new CloudCommunityComponentsAPI.apiCommunityComponents();
             CloudCommunityComponentsAPI.WWTCommunityComponentSt f =
                 api.Create(CloudCommunities.GetTokenFromId(), _CommunityId,
                 CloudCommunityComponentsAPI.WWTComponentTypes.WWTCollection,
                 _ComponentId, folder.Name, thumbnail, "", null);
             int childNumber = 0, progActual = progress.Value,
                 progDiff = maxProgress - progress.Value;
             foreach (object obj in folder.Children)
             {
                 int maxProgChild = (++childNumber) * progDiff / folder.Children.Length;
                 AddObjectToCommunity(f.CommunityId, f.ComponentId, obj, progActual + maxProgChild);
             }
             CloudCommunities.SetAvoidCache(_CommunityId, _ComponentId);
         }
         else
         {
             CloudCommunities.AddUpdObjectToCommunity(_CommunityId, _ComponentId, _target, false);
         }
     }
     catch (Exception e)
     {
         errorList.Add(_target.GetType().ToString() + ": " + getTargetName(_target) + " - Error: " + e.Message);
     }
     backgroundUpdater.ReportProgress(maxProgress);
 }
Example #3
0
        public static void AddUpdObjectToCommunity(long CommunityId, long?ComponentId, object target, bool isUpdate)
        {
            CloudCommunityComponentsAPI.apiCommunityComponents api =
                new CloudCommunityComponentsAPI.apiCommunityComponents();
            string name = "", thumbnail = "", authorThumbnail = "";

            if (target is Tour)
            {
                Tour tour = (Tour)target;
                name      = tour.Name;
                thumbnail = tour.ThumbnailUrl;
                if (string.IsNullOrEmpty(thumbnail) || File.Exists(thumbnail))
                {
                    thumbnail = CallUploader(ImageToByteArray(tour.ThumbNail), tour.Name, "image/jpeg", true);
                }
                authorThumbnail = tour.AuthorImageUrl;
                if ((string.IsNullOrEmpty(authorThumbnail) || File.Exists(authorThumbnail)) && tour.AuthorImage != null)
                {
                    authorThumbnail = CallUploader(ImageToByteArray(tour.AuthorImage), tour.Author, "image/jpeg", true);
                }
            }
            else
            {
                if (target is IPlace)
                {
                    IPlace iplace = (IPlace)target;
                    name      = iplace.Name;
                    thumbnail = iplace.Thumbnail;
                    if (string.IsNullOrEmpty(thumbnail) || File.Exists(thumbnail))
                    {
                        thumbnail = CallUploader(ImageToByteArray(iplace.ThumbNail), iplace.Name, "image/jpeg", true);
                    }
                }
                else
                {
                    if (target is ImageSet)
                    {
                        ImageSet imageset = (ImageSet)target;
                        name      = imageset.Name;
                        thumbnail = imageset.ThumbnailUrl;
                        if (string.IsNullOrEmpty(thumbnail) || File.Exists(thumbnail))
                        {
                            thumbnail = CallUploader(ImageToByteArray(imageset.ThumbNail), imageset.Name, "image/jpeg", true);
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format(Language.GetLocalizedText(-1, "Error: {0} not supported in client upload at the moment..."), target.GetType()));
                        return;
                    }
                }
            }
            XmlDocument   doc       = new XmlDocument();
            XmlSerializer xml       = new XmlSerializer(target.GetType());
            MemoryStream  memStream = new MemoryStream();

            xml.Serialize(memStream, target);
            memStream.Seek(0, SeekOrigin.Begin);
            doc.Load(memStream);
            foreach (XmlNode x in doc.DocumentElement.Attributes)
            {
                bool isImage = (target is IPlace && ((IPlace)target).IsImage) ||
                               x.Name == "Thumbnail" ||
                               x.Name == "ThumbnailUrl";
                switch (x.Name)
                {
                case "Thumbnail":
                case "Url":
                case "TourUrl":
                    if (File.Exists(x.InnerText))
                    {
                        string contentType = FileContentType(x.InnerText);
                        if (contentType != null)
                        {
                            x.InnerText = CallUploader(x.InnerText, x.Name, contentType, isImage);
                        }
                    }
                    break;

                case "ThumbnailUrl":
                    x.InnerText = thumbnail;
                    break;

                case "AuthorImageUrl":
                    x.InnerText = authorThumbnail;
                    break;
                }
            }
            if (isUpdate)
            {
                api.Update(GetTokenFromId(), CommunityId, ComponentId.Value, name, thumbnail,
                           doc.DocumentElement.OuterXml, true, null, null);
            }
            else
            {
                api.Create(GetTokenFromId(), CommunityId,
                           CloudCommunityComponentsAPI.WWTComponentTypes.WWTSimpleComponent,
                           ComponentId, name, thumbnail, doc.DocumentElement.OuterXml, null);
            }
            CloudCommunities.SetAvoidCache(CommunityId, ComponentId);
        }
 public static void AddUpdObjectToCommunity(long CommunityId, long? ComponentId, object target, bool isUpdate)
 {
     CloudCommunityComponentsAPI.apiCommunityComponents api =
         new CloudCommunityComponentsAPI.apiCommunityComponents();
     string name = "", thumbnail = "", authorThumbnail = "";
     if (target is Tour)
     {
         Tour tour = (Tour)target;
         name = tour.Name;
         thumbnail = tour.ThumbnailUrl;
         if (string.IsNullOrEmpty(thumbnail) || File.Exists(thumbnail))
         {
             thumbnail = CallUploader(ImageToByteArray(tour.ThumbNail), tour.Name, "image/jpeg", true);
         }
         authorThumbnail = tour.AuthorImageUrl;
         if ((string.IsNullOrEmpty(authorThumbnail) || File.Exists(authorThumbnail)) && tour.AuthorImage != null)
         {
             authorThumbnail = CallUploader(ImageToByteArray(tour.AuthorImage), tour.Author, "image/jpeg", true);
         }
     }
     else
     {
         if (target is IPlace)
         {
             IPlace iplace = (IPlace)target;
             name = iplace.Name;
             thumbnail = iplace.Thumbnail;
             if (string.IsNullOrEmpty(thumbnail) || File.Exists(thumbnail))
             {
                 thumbnail = CallUploader(ImageToByteArray(iplace.ThumbNail), iplace.Name, "image/jpeg", true);
             }
         }
         else
         {
             if (target is ImageSet)
             {
                 ImageSet imageset = (ImageSet)target;
                 name = imageset.Name;
                 thumbnail = imageset.ThumbnailUrl;
                 if (string.IsNullOrEmpty(thumbnail) || File.Exists(thumbnail))
                 {
                     thumbnail = CallUploader(ImageToByteArray(imageset.ThumbNail), imageset.Name, "image/jpeg", true);
                 }
             }
             else
             {
                 MessageBox.Show(string.Format(Language.GetLocalizedText(-1, "Error: {0} not supported in client upload at the moment..."), target.GetType()));
                 return;
             }
         }
     }
     XmlDocument doc = new XmlDocument();
     XmlSerializer xml = new XmlSerializer(target.GetType());
     MemoryStream memStream = new MemoryStream();
     xml.Serialize(memStream, target);
     memStream.Seek(0, SeekOrigin.Begin);
     doc.Load(memStream);
     foreach (XmlNode x in doc.DocumentElement.Attributes)
     {
         bool isImage = (target is IPlace && ((IPlace)target).IsImage) ||
             x.Name == "Thumbnail" ||
             x.Name == "ThumbnailUrl";
         switch (x.Name)
         {
             case "Thumbnail":
             case "Url":
             case "TourUrl":
                 if (File.Exists(x.InnerText))
                 {
                     string contentType = FileContentType(x.InnerText);
                     if (contentType != null)
                         x.InnerText = CallUploader(x.InnerText, x.Name, contentType, isImage);
                 }
                 break;
             case "ThumbnailUrl":
                 x.InnerText = thumbnail;
                 break;
             case "AuthorImageUrl":
                 x.InnerText = authorThumbnail;
                 break;
         }
     }
     if (isUpdate)
     {
         api.Update(GetTokenFromId(), CommunityId, ComponentId.Value, name, thumbnail,
             doc.DocumentElement.OuterXml, true, null, null);
     }
     else
     {
         api.Create(GetTokenFromId(), CommunityId,
             CloudCommunityComponentsAPI.WWTComponentTypes.WWTSimpleComponent,
             ComponentId, name, thumbnail, doc.DocumentElement.OuterXml, null);
     }
     CloudCommunities.SetAvoidCache(CommunityId, ComponentId);
 }