Exemple #1
0
        private PublishResult PublishWithoutPreUpload(MapInfo mapInfo)
        {
            var service = new DOMAService();

            service.Url = WebServiceUrl;

            var request = new PublishMapRequest
            {
                Username = Username,
                Password = Password,
                MapInfo  = TranslateMapInfo(mapInfo),
            };

            try
            {
                request.MapInfo.BlankMapImageData = null; // this version of the webservice has not support for blank map images
                var response = service.PublishMap(request);
                return(new PublishResult
                {
                    Success = response.Success,
                    ErrorMessage = response.ErrorMessage,
                    URL = response.URL
                });
            }
            catch (Exception ex)
            {
                return(new PublishResult
                {
                    Success = false,
                    ErrorMessage = ex.Message
                });
            }
        }
Exemple #2
0
 public PublishResult Publish(MapInfo mapInfo)
 {
     if (version != null && version.CompareTo("3.0") >= 0)
     {
         return(PublishWithPreUpload(mapInfo));
     }
     return(PublishWithoutPreUpload(mapInfo));
 }
        private PublishResult PublishWithPreUpload(MapInfo mapInfo)
        {
            var service = new DOMAService();
              service.Url = WebServiceUrl;

              var request = new PublishPreUploadedMapRequest
              {
            Username = Username,
            Password = Password,
            MapInfo = TranslateMapInfo(mapInfo),
              };

              try
              {
            // use partial upload
            // map image
            FileUploadResult mapFileUploadResult = null;
            if (request.MapInfo.MapImageData != null) mapFileUploadResult = PartialFileUpload(request.MapInfo.MapImageData, request.MapInfo.MapImageFileExtension);
            // blank map image
            FileUploadResult blankMapFileUploadResult = null;
            if (request.MapInfo.BlankMapImageData != null) blankMapFileUploadResult = PartialFileUpload(request.MapInfo.BlankMapImageData, request.MapInfo.MapImageFileExtension);
            // thumbnail
            FileUploadResult thumbnailFileUploadResult = null;
            var thumbnailImageData = CreateThumbnailImageData(mapInfo);
            if (thumbnailImageData != null) thumbnailFileUploadResult = PartialFileUpload(thumbnailImageData, "jpg");

            if (!(mapFileUploadResult != null && !mapFileUploadResult.Success) && !(blankMapFileUploadResult != null && !blankMapFileUploadResult.Success) && !(thumbnailFileUploadResult != null && !thumbnailFileUploadResult.Success))
            {
              if (mapFileUploadResult != null) request.PreUploadedMapImageFileName = mapFileUploadResult.FileName;
              if (blankMapFileUploadResult != null) request.PreUploadedBlankMapImageFileName = blankMapFileUploadResult.FileName;
              if (thumbnailFileUploadResult != null) request.PreUploadedThumbnailImageFileName = thumbnailFileUploadResult.FileName;
            }

            // reset image data as it already has been uploaded
            request.MapInfo.MapImageData = null;
            request.MapInfo.BlankMapImageData = null;
            var response = service.PublishPreUploadedMap(request);
            return new PublishResult
            {
              Success = response.Success,
              ErrorMessage = response.ErrorMessage,
              URL = response.URL
            };
              }
              catch (Exception ex)
              {
            return new PublishResult
            {
              Success = false,
              ErrorMessage = ex.Message
            };
              }
        }
        private PublishResult PublishWithoutPreUpload(MapInfo mapInfo)
        {
            var service = new DOMAService();
              service.Url = WebServiceUrl;

              var request = new PublishMapRequest
              {
            Username = Username,
            Password = Password,
            MapInfo = TranslateMapInfo(mapInfo),
              };

              try
              {
            request.MapInfo.BlankMapImageData = null; // this version of the webservice has not support for blank map images
            var response = service.PublishMap(request);
            return new PublishResult
            {
              Success = response.Success,
              ErrorMessage = response.ErrorMessage,
              URL = response.URL
            };
              }
              catch (Exception ex)
              {
            return new PublishResult
            {
              Success = false,
              ErrorMessage = ex.Message
            };
              }
        }
        //, ThumbnailProperties tp)
        private static byte[] CreateThumbnailImageData(MapInfo mapInfo)
        {
            if (mapInfo.MapImageData == null && mapInfo.BlankMapImageData == null) return null;
              // get original image from byte array
              var ms = new MemoryStream(mapInfo.MapImageData ?? mapInfo.BlankMapImageData);
              var image = Image.FromStream(ms);
              ms.Close();
              ms.Dispose();

              // create blank thumbnail image
              // todo: get these values from webservice
              var thumbnailSize = new Size(400, 100);
              var thumbnailScale = 0.5;
              var thumbnailBitmap = new Bitmap(thumbnailSize.Width, thumbnailSize.Height);
              // the rectangle in the original image that corresponds to the thumbnail image
              var imageRectangle = new Rectangle((image.Width - thumbnailSize.Width) / 2, (image.Height - thumbnailSize.Height) / 2,
                                         Convert.ToInt32(thumbnailSize.Width / thumbnailScale), Convert.ToInt32(thumbnailSize.Height / thumbnailScale));
              // perform some resizing if the image is not large enough
              if (imageRectangle.Width > image.Width)
              {
            imageRectangle.X = 0;
            imageRectangle.Width = image.Width;
              }
              if (imageRectangle.Height > image.Height)
              {
            imageRectangle.Y = 0;
            imageRectangle.Height = image.Height;
              }

              // calculate actual thumbnail rectangle and draw the image to the thumbnail
              var thumbnailRectangle = new Rectangle(
            Convert.ToInt32((thumbnailSize.Width - thumbnailScale * imageRectangle.Width) / 2),
            Convert.ToInt32((thumbnailSize.Height - thumbnailScale * imageRectangle.Height) / 2),
            Convert.ToInt32(thumbnailScale * imageRectangle.Width),
            Convert.ToInt32(thumbnailScale * imageRectangle.Height));
              var thumbnailGraphics = Graphics.FromImage(thumbnailBitmap);
              thumbnailGraphics.SmoothingMode = SmoothingMode.AntiAlias;
              thumbnailGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
              using (var b = new SolidBrush(Color.White))
              {
            thumbnailGraphics.FillRectangle(b, new Rectangle(new Point(0, 0), thumbnailSize));
              }
              thumbnailGraphics.DrawImage(image, thumbnailRectangle, imageRectangle, GraphicsUnit.Pixel);
              thumbnailGraphics.Dispose();
              image.Dispose();

              // create byte array from image
              var thumbnailStream = new MemoryStream();
              thumbnailBitmap.Save(thumbnailStream, GetJpegEncoder(), GetJpegEncoderParams(0.8));
              thumbnailBitmap.Dispose();
              var data = thumbnailStream.ToArray();
              thumbnailStream.Dispose();

              return data;
        }
 public PublishResult Publish(MapInfo mapInfo)
 {
     if (version != null && version.CompareTo("3.0") >= 0)
       {
     return PublishWithPreUpload(mapInfo);
       }
       return PublishWithoutPreUpload(mapInfo);
 }
 private void SetControlValues(MapInfo mapInfo)
 {
     date.Value = mapInfo.Date.ToLocalTime();
       name.Text = mapInfo.Name;
       mapName.Text = mapInfo.MapName;
       foreach (var c in category.Items)
       {
     if (c is Category && (c as Category).ID == mapInfo.CategoryID) category.SelectedItem = c;
       }
       organiser.Text = mapInfo.Organiser;
       country.Text = mapInfo.Country;
       type.Text = mapInfo.Discipline;
       relayLeg.Text = mapInfo.RelayLeg;
       resultListUrl.Text = mapInfo.ResultListUrl;
       comment.Text = mapInfo.Comment;
 }
        private void map_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedMap = map.SelectedItem as MapInfo;
              if (!(selectedMap != null && selectedMap.ID != 0))
              {
            var defaultTime = DateTime.Now.ToLocalTime().Date;
            if (document.Sessions.Count > 0 && document.Sessions[0].Route.FirstWaypoint != null)
            {
              defaultTime = document.Sessions[0].Route.FirstWaypoint.Time.ToLocalTime();
            }
            selectedMap = new MapInfo
                        {
                          Date = defaultTime
                        };

              }
              SetControlValues(selectedMap);
        }
 private GetAllMapsResult GetAllMaps()
 {
     GetAllMapsResult getAllMapsResult = mapPublisher.GetAllMaps();
       if (getAllMapsResult.Success)
       {
     allMaps = getAllMapsResult.Maps;
     var newMap = new MapInfo
                {
                  ID = 0,
                  Name = string.Format("[{0}]", Strings.NewMap)
                };
     allMaps.Insert(0, newMap);
       }
       return getAllMapsResult;
 }
        private MapInfo CreateMapInfoFromControls()
        {
            MapInfo mapInfo = new MapInfo();
              var selectedMap = map.SelectedValue as MapInfo;
              if (selectedMap != null) mapInfo.ID = selectedMap.ID;
              mapInfo.Date = date.Value.ToUniversalTime();
              var selectedCategory = category.SelectedItem as Category;
              if (selectedCategory != null) mapInfo.CategoryID = selectedCategory.ID;
              mapInfo.Name = name.Text;
              mapInfo.MapName = mapName.Text;
              mapInfo.Organiser = organiser.Text;
              mapInfo.Country = country.Text;
              mapInfo.Discipline = type.Text;
              mapInfo.RelayLeg = relayLeg.Text;
              mapInfo.ResultListUrl = resultListUrl.Text;
              mapInfo.Comment = comment.Text;
              mapInfo.MapImageFileExtension = imageFormat.Text;

              IMapImageFileExporterDialog selector = null;
              switch (imageFormat.Text)
              {
            case "jpg":
              selector = new JpegPropertySelector
              {
            SizeCalculator = document.CalculateImageForExportSize
              };
              break;
            case "png":
            default:
              selector = new PngPropertySelector
              {
            SizeCalculator = document.CalculateImageForExportSize
              };
              break;
            //case "tiff":
            //  selector = new TiffPropertySelector
            //  {
            //    SizeCalculator = document.CalculateImageForExportSize
            //  };

            //  break;

              }

              if (selector.ShowPropertyDialog() == DialogResult.OK)
              {
            Application.DoEvents();

            // map image
            using (var ms = new MemoryStream())
            {
              var imageExporterProperties = new ImageExporterProperties()
              {
            EncodingInfo = selector.EncodingInfo,
            RouteDrawingMode = Document.RouteDrawingMode.Extended,
            ColorCodingAttribute = colorCodingAttribute,
            SecondaryColorCodingAttribute = secondaryColorCodingAttribute,
            PercentualSize = selector.PercentualImageSize,
            ColorRangeProperties = colorRangeProperties
              };
              var imageExporter = new ImageExporter(document, document.Sessions, ms)
              {
            Properties = imageExporterProperties
              };
              imageExporter.Export();
              mapInfo.MapImageData = ms.ToArray();
            }

            // blank map image
            using (var ms = new MemoryStream())
            {
              var imageExporterProperties = new ImageExporterProperties()
              {
            EncodingInfo = selector.EncodingInfo,
            RouteDrawingMode = Document.RouteDrawingMode.None,
            PercentualSize = selector.PercentualImageSize
              };
              var blankImageExporter = new ImageExporter(document, document.Sessions, ms)
              {
            Properties = imageExporterProperties
              };
              blankImageExporter.Export();
              mapInfo.BlankMapImageData = ms.ToArray();
            }
            return mapInfo;
              }
              return null;
        }
Exemple #11
0
        private static byte[] CreateThumbnailImageData(MapInfo mapInfo) //, ThumbnailProperties tp)
        {
            if (mapInfo.MapImageData == null && mapInfo.BlankMapImageData == null)
            {
                return(null);
            }
            // get original image from byte array
            var ms    = new MemoryStream(mapInfo.MapImageData ?? mapInfo.BlankMapImageData);
            var image = Image.FromStream(ms);

            ms.Close();
            ms.Dispose();

            // create blank thumbnail image
            // todo: get these values from webservice
            var thumbnailSize   = new Size(400, 100);
            var thumbnailScale  = 0.5;
            var thumbnailBitmap = new Bitmap(thumbnailSize.Width, thumbnailSize.Height);
            // the rectangle in the original image that corresponds to the thumbnail image
            var imageRectangle = new Rectangle((image.Width - thumbnailSize.Width) / 2, (image.Height - thumbnailSize.Height) / 2,
                                               Convert.ToInt32(thumbnailSize.Width / thumbnailScale), Convert.ToInt32(thumbnailSize.Height / thumbnailScale));

            // perform some resizing if the image is not large enough
            if (imageRectangle.Width > image.Width)
            {
                imageRectangle.X     = 0;
                imageRectangle.Width = image.Width;
            }
            if (imageRectangle.Height > image.Height)
            {
                imageRectangle.Y      = 0;
                imageRectangle.Height = image.Height;
            }

            // calculate actual thumbnail rectangle and draw the image to the thumbnail
            var thumbnailRectangle = new Rectangle(
                Convert.ToInt32((thumbnailSize.Width - thumbnailScale * imageRectangle.Width) / 2),
                Convert.ToInt32((thumbnailSize.Height - thumbnailScale * imageRectangle.Height) / 2),
                Convert.ToInt32(thumbnailScale * imageRectangle.Width),
                Convert.ToInt32(thumbnailScale * imageRectangle.Height));
            var thumbnailGraphics = Graphics.FromImage(thumbnailBitmap);

            thumbnailGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            thumbnailGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            using (var b = new SolidBrush(Color.White))
            {
                thumbnailGraphics.FillRectangle(b, new Rectangle(new Point(0, 0), thumbnailSize));
            }
            thumbnailGraphics.DrawImage(image, thumbnailRectangle, imageRectangle, GraphicsUnit.Pixel);
            thumbnailGraphics.Dispose();
            image.Dispose();

            // create byte array from image
            var thumbnailStream = new MemoryStream();

            thumbnailBitmap.Save(thumbnailStream, GetJpegEncoder(), GetJpegEncoderParams(0.8));
            thumbnailBitmap.Dispose();
            var data = thumbnailStream.ToArray();

            thumbnailStream.Dispose();

            return(data);
        }
Exemple #12
0
        private PublishResult PublishWithPreUpload(MapInfo mapInfo)
        {
            var service = new DOMAService();

            service.Url = WebServiceUrl;

            var request = new PublishPreUploadedMapRequest
            {
                Username = Username,
                Password = Password,
                MapInfo  = TranslateMapInfo(mapInfo),
            };

            try
            {
                // use partial upload
                // map image
                FileUploadResult mapFileUploadResult = null;
                if (request.MapInfo.MapImageData != null)
                {
                    mapFileUploadResult = PartialFileUpload(request.MapInfo.MapImageData, request.MapInfo.MapImageFileExtension);
                }
                // blank map image
                FileUploadResult blankMapFileUploadResult = null;
                if (request.MapInfo.BlankMapImageData != null)
                {
                    blankMapFileUploadResult = PartialFileUpload(request.MapInfo.BlankMapImageData, request.MapInfo.MapImageFileExtension);
                }
                // thumbnail
                FileUploadResult thumbnailFileUploadResult = null;
                var thumbnailImageData = CreateThumbnailImageData(mapInfo);
                if (thumbnailImageData != null)
                {
                    thumbnailFileUploadResult = PartialFileUpload(thumbnailImageData, "jpg");
                }

                if (!(mapFileUploadResult != null && !mapFileUploadResult.Success) && !(blankMapFileUploadResult != null && !blankMapFileUploadResult.Success) && !(thumbnailFileUploadResult != null && !thumbnailFileUploadResult.Success))
                {
                    if (mapFileUploadResult != null)
                    {
                        request.PreUploadedMapImageFileName = mapFileUploadResult.FileName;
                    }
                    if (blankMapFileUploadResult != null)
                    {
                        request.PreUploadedBlankMapImageFileName = blankMapFileUploadResult.FileName;
                    }
                    if (thumbnailFileUploadResult != null)
                    {
                        request.PreUploadedThumbnailImageFileName = thumbnailFileUploadResult.FileName;
                    }
                }

                // reset image data as it already has been uploaded
                request.MapInfo.MapImageData      = null;
                request.MapInfo.BlankMapImageData = null;
                var response = service.PublishPreUploadedMap(request);
                return(new PublishResult
                {
                    Success = response.Success,
                    ErrorMessage = response.ErrorMessage,
                    URL = response.URL
                });
            }
            catch (Exception ex)
            {
                return(new PublishResult
                {
                    Success = false,
                    ErrorMessage = ex.Message
                });
            }
        }