Exemplo n.º 1
0
 /// <summary>
 /// Returns true if another instance represents logically the same regional entity: has the same type and path, regardless of path extensions ('.r','.noc',...).
 /// Use this as a test as Equals() is not overriden by this class and does instance-based comparison by default
 /// </summary>
 public bool IsLogicallyTheSame(SectionRegionBase other)
 {
     if (other == null)
     {
         return(false);
     }
     if (GetType() != other.GetType())
     {
         return(false);
     }
     if (!this.RegionPath.IsSameRegionPath(other.RegionPath))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
                                      internal SectionRegionBase(RegCatalog catalog, SectionRegionBase parentSection, string name, string path, FileSystemSession session) : base(catalog, name, path, session)
                                      {
                                          ParentSection = parentSection;

                                          var gc = this.LevelConfig.AttrByName(Metabank.CONFIG_GEO_CENTER_ATTR).Value;

                                          if (gc.IsNotNullOrWhiteSpace())
                                          {
                                              try
                                              {
                                                  GeoCenter = new LatLng(gc);
                                              }
                                              catch (Exception error)
                                              {
                                                  throw new MetabaseException(StringConsts.METABASE_REG_GEO_CENTER_ERROR.Args(GetType().Name, name, gc, error.ToMessageWithType()));
                                              }
                                          }
                                      }
Exemplo n.º 3
0
                                  /// <summary>
                                  /// Tries to navigate to region path as far as possible and returns the deepest section or null.
                                  /// This method is needed to obtain root paths from detailed paths with wild cards.
                                  /// Method also returns how deep it could navigate(how many path levels resolved).
                                  /// For example:
                                  ///  '/Us/East/Clev.noc/{1}/{2}' - Clev.noc with depth=3 will be returned.
                                  /// </summary>
                                  public SectionRegionBase TryNavigateAsFarAsPossible(string path, out int depth)
                                  {
                                      depth = 0;
                                      if (path == null)
                                      {
                                          return(null);
                                      }
                                      var segs = path.Split('/').Where(s => s.IsNotNullOrWhiteSpace()).Select(s => s.Trim());
                                      SectionRegionBase existing = null;
                                      SectionRegionBase current  = null;
                                      var first = true;

                                      foreach (var seg in (segs))
                                      {
                                          if (first)
                                          {
                                              first = false;
                                              if (seg.EndsWith(RegCatalog.REG_EXT))
                                              {
                                                  current = Regions[seg.Substring(0, seg.LastIndexOf(RegCatalog.REG_EXT))];
                                              }
                                              else
                                              {
                                                  current = Regions[seg];
                                              }
                                          }
                                          else
                                          {
                                              current = current[seg];
                                          }

                                          if (current == null)
                                          {
                                              break;
                                          }
                                          depth++;
                                          existing = current;
                                      }
                                      return(existing);
                                  }
Exemplo n.º 4
0
                                  /// <summary>
                                  /// Tries to navigate to NOC section in the specified absolute path and returns it or null if path is invalid/does not lead to NOC.
                                  /// Ignores anything after the NOC section (zones, hosts etc..). For example '/world/us/east/CLE.noc/a/ii/x' will return 'CLE.noc' section,
                                  ///  but '/world/us/east' will return null as there is no NOC in the path
                                  /// </summary>
                                  public SectionNOC GetNOCofPath(string path)
                                  {
                                      if (path == null)
                                      {
                                          return(null);
                                      }
                                      var segs = path.Split('/').Where(s => s.IsNotNullOrWhiteSpace());
                                      SectionRegionBase current = null;
                                      var first = true;

                                      foreach (var seg in (segs))
                                      {
                                          if (first)
                                          {
                                              first = false;
                                              if (seg.EndsWith(RegCatalog.REG_EXT))
                                              {
                                                  current = Regions[seg.Substring(0, seg.LastIndexOf(RegCatalog.REG_EXT))];
                                              }
                                              else
                                              {
                                                  current = Regions[seg];
                                              }
                                          }
                                          else
                                          {
                                              if (current == null)
                                              {
                                                  return(null);
                                              }
                                              current = current[seg];
                                          }
                                          if (current is SectionNOC)
                                          {
                                              return((SectionNOC)current);
                                          }
                                      }
                                      return(null);
                                  }
Exemplo n.º 5
0
                                  /// <summary>
                                  /// Counts the number of matching region path segments that resolve to the same section in the region catalog.
                                  /// Example:  /US/East/CLE/A/I and /US/East/JFK/A/I returns 2
                                  /// </summary>
                                  public int CountMatchingPathSegments(SectionRegionBase sect1, SectionRegionBase sect2)
                                  {
                                      if (sect1 == null || sect2 == null)
                                      {
                                          return(0);
                                      }

                                      var chain1 = sect1.SectionsOnPath.ToList();
                                      var chain2 = sect2.SectionsOnPath.ToList();

                                      var i = 0;//count number of matching segments

                                      for (; i < chain1.Count && i < chain2.Count; i++)
                                      {
                                          if (!chain1[i].IsLogicallyTheSame(chain2[i]))
                                          {
                                              break;
                                          }
                                      }

                                      return(i);
                                  }
Exemplo n.º 6
0
                                  /// <summary>
                                  /// Navigates to region path and returns the corresponding section or null.
                                  /// The path root starts at region catalog level i.e.: '/Us/East/Clev.noc/A/IV/wlarge0001' -
                                  ///   a path to a host called 'wlarge0001' located in zone A-IV in Cleveland network center etc.
                                  /// NOTE: may omit the '.r', '.noc', and '.z' region/noc and zone designators.
                                  /// The navigation is done using case-insensitive name comparison, however
                                  ///  the underlying file system may be case-sensitive and must be supplied the exact name
                                  /// </summary>
                                  public SectionRegionBase this[string path]
                                  {
                                      get
                                      {
                                          if (path == null)
                                          {
                                              return(null);
                                          }
                                          var segs = path.Split('/').Where(s => s.IsNotNullOrWhiteSpace()).Select(s => s.Trim());
                                          SectionRegionBase result = null;
                                          var first = true;
                                          foreach (var seg in (segs))
                                          {
                                              if (first)
                                              {
                                                  first = false;
                                                  if (seg.EndsWith(RegCatalog.REG_EXT))
                                                  {
                                                      result = Regions[seg.Substring(0, seg.LastIndexOf(RegCatalog.REG_EXT))];
                                                  }
                                                  else
                                                  {
                                                      result = Regions[seg];
                                                  }
                                              }
                                              else
                                              {
                                                  result = result[seg];
                                              }

                                              if (result == null)
                                              {
                                                  break;
                                              }
                                          }
                                          return(result);
                                      }
                                  }