Example #1
0
    private static CommonHost GetHost(Configuration.MapTabRow mapTab, string type)
    {
        string userName = mapTab.IsUserNameNull() ? "" : mapTab.UserName;
        string password = mapTab.IsPasswordNull() ? "" : mapTab.Password;

        CommonHost host = null;

        try
        {
            switch (type)
            {
            case "AGS":
                if (String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(password))
                {
                    host = new AgsHost(mapTab.MapHost);
                }
                else
                {
                    try
                    {
                        host = new AgsHost(mapTab.MapHost, userName, password, true);
                    }
                    catch { }

                    if (host == null)
                    {
                        host = new AgsHost(mapTab.MapHost, userName, password, false);
                    }
                }
                break;

            case "ArcIMS":
                host = new ArcImsHost(mapTab.MapHost, userName, password);
                break;
            }
        }
        catch { }

        return(host);
    }
Example #2
0
  private void ValidateMapServices()
  {
    Dictionary<String, CommonHost> mapHosts = new Dictionary<String, CommonHost>();
    Dictionary<String, CommonMapService> mapServices = new Dictionary<String, CommonMapService>();
    Dictionary<String, CommonDataFrame> mapDataFrames = new Dictionary<String, CommonDataFrame>();

    // === MapTab ===

    // load the map hosts

    foreach (Configuration.MapTabRow mapTab in MapTab)
    {
      string userName = mapTab.IsUserNameNull() ? null : mapTab.UserName;
      string password = mapTab.IsPasswordNull() ? null : mapTab.Password;

      string agsHostKey = mapTab.GetHostKey("AGS");

      if (!mapHosts.ContainsKey(agsHostKey))
      {
        AgsHost agsHost = null;

        try
        {
          agsHost = new AgsHost(mapTab.MapHost, userName, password);
        }
        catch { }

        mapHosts.Add(agsHostKey, agsHost);
      }

      string arcImsHostKey = mapTab.GetHostKey("ArcIMS");

      if (!mapHosts.ContainsKey(arcImsHostKey))
      {
        ArcImsHost arcImsHost = null;

        try
        {
          arcImsHost = new ArcImsHost(mapTab.MapHost, userName, password);
        }
        catch { }

        mapHosts.Add(arcImsHostKey, arcImsHost);
      }

      if (mapHosts[agsHostKey] == null && mapHosts[arcImsHostKey] == null)
      {
        mapTab.ValidationError = "Could not connect to the server";
      }
    }

    // load the map services

    foreach (Configuration.MapTabRow mapTab in MapTab.Where(o => o.IsValidationErrorNull()))
    {
      string agsServiceKey = mapTab.GetServiceKey("AGS");

      if (!mapServices.ContainsKey(agsServiceKey))
      {
        AgsMapService agsService = null;
        string agsHostKey = mapTab.GetHostKey("AGS");

        if (mapHosts[agsHostKey] != null)
        {
          try
          {
            agsService = mapHosts[agsHostKey].GetMapService(mapTab.MapService) as AgsMapService;
          }
          catch { }
        }

        mapServices.Add(agsServiceKey, agsService);
      }

      string arcImsServiceKey = mapTab.GetServiceKey("ArcIMS");

      if (!mapServices.ContainsKey(arcImsServiceKey))
      {
        ArcImsService arcImsService = null;
        string arcImsHostKey = mapTab.GetHostKey("ArcIMS");

        if (mapHosts[arcImsHostKey] != null)
        {
          try
          {
            arcImsService = mapHosts[arcImsHostKey].GetMapService(mapTab.MapService) as ArcImsService;
          }
          catch { }
        }

        mapServices.Add(arcImsServiceKey, arcImsService);
      }

      if (mapServices[agsServiceKey] == null && mapServices[arcImsServiceKey] == null)
      {
        mapTab.ValidationError = "Could not find the specified map service on the server";
      }
    }

    // load the dataframes

    foreach (Configuration.MapTabRow mapTab in MapTab.Where(o => o.IsValidationErrorNull()))
    {
      string dataFrameKey = mapTab.GetDataFrameKey();

      if (!mapDataFrames.ContainsKey(dataFrameKey))
      {
        CommonDataFrame dataFrame = null;

        foreach (string type in new string[] { "AGS", "ArcIMS" })
        {
          CommonMapService mapService = mapServices[mapTab.GetServiceKey(type)];

          if (dataFrame == null && mapService != null)
          {
            dataFrame = mapTab.IsDataFrameNull() ? mapService.DefaultDataFrame : mapService.DataFrames.FirstOrDefault(o => String.Compare(o.Name, mapTab.DataFrame, true) == 0);
          }
        }

        mapDataFrames.Add(dataFrameKey, dataFrame);
      }

      if (mapDataFrames[dataFrameKey] == null)
      {
        mapTab.ValidationError = "Could not find the specified data frame in the map service";
      }
    }

    // === Layer ===

    foreach (Configuration.LayerRow layer in Layer)
    {
      // for each valid MapTab linked through MapTabLayer

      foreach (Configuration.MapTabLayerRow link in layer.GetMapTabLayerRows().Where(o => o.MapTabRow.IsValidationErrorNull()))
      {
        // a single layer with the specified name must be present in the MapTab dataframe

        CommonLayer[] commonLayers = mapDataFrames[link.MapTabRow.GetDataFrameKey()].Layers.Where(o => String.Compare(o.Name, layer.LayerName, true) == 0).ToArray();

        if (commonLayers.Length == 0)
        {
          link.ValidationError = String.Format("'{0}' is not a layer in the service/dataframe for map tab '{1}'", layer.LayerName, link.MapTabID);
        }
        else if (commonLayers.Length > 1)
        {
          link.ValidationError = String.Format("More than one layer named '{0}' in the service/dataframe for map tab '{1}'", layer.LayerName, link.MapTabID);
        }
        else
        {
          CommonLayer commonLayer = commonLayers[0];

          if (commonLayer.Type == CommonLayerType.Feature)
          {
            bool needsGeometryField = false;

            // for selectable layers

            if (!layer.IsKeyFieldNull())
            {
              // KeyField must exist in the layer 

              if (commonLayer.Fields == null || commonLayer.FindField(layer.KeyField) == null)
              {
                link.ValidationError = String.Format("Layer '{0}' in the service/dataframe for map tab '{1}' does not contain the key field '{2}'", layer.LayerName, link.MapTabID, layer.KeyField);
              }

              needsGeometryField = true;
            }

            // for zones and levels, the specified fields must be available

            if (!layer.IsZoneFieldNull())
            {
              if (commonLayer.Fields == null || commonLayer.FindField(layer.ZoneField) == null)
              {
                link.ValidationError = String.Format("Layer '{0}' in the service/dataframe for map tab '{1}' does not contain the zone field '{2}'", layer.LayerName, link.MapTabID, layer.ZoneField);
              }

              needsGeometryField = true;
            }

            if (!layer.IsLevelFieldNull() && (commonLayer.Fields == null || commonLayer.FindField(layer.LevelField) == null))
            {
              link.ValidationError = String.Format("Layer '{0}' in the service/dataframe for map tab '{1}' does not contain the level field '{2}'", layer.LayerName, link.MapTabID, layer.LevelField);
            }

            if (needsGeometryField && commonLayer.GeometryField == null)
            {
              link.ValidationError = String.Format("Layer '{0}' in the service/dataframe for map tab '{1}' does not provide a shape field (may be set to hidden in the MXD)", layer.LayerName, link.MapTabID);
            }
          }

          if (commonLayer.Type == CommonLayerType.Image)
          {
            if (!layer.IsKeyFieldNull() && commonLayer is ArcImsLayer)
            {
              link.ValidationError = String.Format("KeyField cannot be set for raster layers in ArcIMS", layer.LayerName, link.MapTabID);
            }
            else
            {
              string[] invalidFunctions = new string[] { "mailinglabel", "export", "targetparams" };

              foreach (Configuration.LayerFunctionRow layerFunction in LayerFunction.Where(o => o.LayerID == link.LayerID && o.IsValidationErrorNull() && invalidFunctions.Contains(o.FunctionName.ToLower())))
              {
                layerFunction.ValidationError = String.Format("Function '{0}' cannot be applied to a raster layer", layerFunction.FunctionName);
              }
            }
          }
        }
      }

      // for each valid MapTab linked via BaseMapID a single layer with the specified name must be present in the MapTab dataframe

      if (!layer.IsBaseMapIDNull())
      {
        foreach (Configuration.MapTabRow mapTab in MapTab.Where(o => o.IsValidationErrorNull() && !o.IsBaseMapIDNull() && o.BaseMapID == layer.BaseMapID))
        {
          int n = mapDataFrames[mapTab.GetDataFrameKey()].Layers.Count<CommonLayer>(o => String.Compare(o.Name, layer.LayerName, true) == 0);

          if (n == 0)
          {
            layer.ValidationError = String.Format("'{0}' is not a layer in the service/dataframe for map tab '{1}'", layer.LayerName, mapTab.MapTabID);
          }
          else if (n > 1)
          {
            layer.ValidationError = String.Format("More than one layer named '{0}' in the service/dataframe for map tab '{1}'", layer.LayerName, mapTab.MapTabID);
          }
        }
      }
    }
  }
Example #3
0
  private static CommonHost GetHost(Configuration.MapTabRow mapTab, string type)
  {
    string userName = mapTab.IsUserNameNull() ? "" : mapTab.UserName;
    string password = mapTab.IsPasswordNull() ? "" : mapTab.Password;

    CommonHost host = null;
    
    try
    {
      switch (type)
      {
        case "AGS":
          if (String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(password))
          {
            host = new AgsHost(mapTab.MapHost);
          }
          else
          {
            try
            {
              host = new AgsHost(mapTab.MapHost, userName, password, true);
            }
            catch { }

            if (host == null)
            {
              host = new AgsHost(mapTab.MapHost, userName, password, false);
            }
          }
          break;

        case "ArcIMS": 
          host = new ArcImsHost(mapTab.MapHost, userName, password); 
          break;
      }
    }
    catch { }

    return host;
  }