Exemple #1
0
        /// <summary>
        /// Changes the import-to layer name to IMP_importFileName.
        /// If the importFileName is longer than  LayerNameLength, truncate it to LayerNameLength.
        /// If the importFileName contain characters other than alphabet, number, replace it with '_'
        /// </summary>
        /// <returns>Returns true if succeed.</returns>
        public bool ChangeLayerName(InputLayer layer, ref string layerName, bool isToLayer0)
        {
            LayerNameType layerNameType = LayerNameType.LayerNameDirect;

            try
            {
                if (isToLayer0)
                {
                    layerName = "0";
                }
                else
                {
                    string existingName = null;
                    // Truncate the layer name if it's too long
                    existingName = layer.Name;
                    // Replace illegal characters
                    foreach (Char tmp in existingName)
                    {
                        if (!(tmp >= 'A' && tmp <= 'Z'))
                        {
                            if (!(tmp >= 'a' && tmp <= 'z'))
                            {
                                if (!(tmp >='0' && tmp <='9'))
                                {
                                    existingName.Replace(tmp, '_');
                                }
                            }
                        }
                    }

                    // Prefix "IMP_"
                    layerName = string.Concat("IMP_", existingName);
                }

                layer.SetLayerName(layerNameType, layerName);

                return true;
            }
            catch
            {
                return false;
            }
        }