Exemplo n.º 1
0
        bool IsReadyToCreate(out string reason)
        {
            reason = "";

            if (selectedType == null)
            {
                return(false);
            }

            if (IsFileCreation())
            {
                if (string.IsNullOrEmpty(textBoxName.Text))
                {
                    reason = Translate("The file name is not specified.");
                    return(false);
                }

                if (textBoxName.Text.IndexOfAny(Path.GetInvalidPathChars()) != -1)
                {
                    reason = Translate("Invalid file name.");
                    return(false);
                }

                try
                {
                    if (textBoxName.Text.Contains('\\') || textBoxName.Text.Contains('/'))
                    {
                        if (Path.GetFileName(textBoxName.Text).IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
                        {
                            reason = Translate("Invalid file name.");
                            return(false);
                        }
                    }
                }
                catch { }

                var realPath = VirtualPathUtility.GetRealPathByVirtual(textBoxName.Text);
                if (File.Exists(realPath))
                {
                    reason = string.Format(Translate("A file with the name \'{0}\' already exists."), Path.GetFileName(realPath));
                    return(false);
                }
            }

            foreach (var c in tableLayoutPanel1.Controls)
            {
                NewObjectCell cell = c as NewObjectCell;
                if (cell != null)
                {
                    if (!cell.ReadyToCreate(out reason))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool ApplyCreationSettingsToObject(object createdObject, ref bool disableFileCreation)
        {
            var createdComponent         = createdObject as Component;
            var fileCreationRealFileName = GetFileCreationRealFileName();            // IsFileCreation() ? VirtualPathUtils.GetRealPathByVirtual( textBoxName.Text ) : "";

            if (!IsFileCreation() && createdComponent != null)
            {
                //!!!!!проверки
                createdComponent.Name = textBoxName.Text;
            }

            createdComponent?.NewObjectSetDefaultConfiguration(true);

            foreach (var c in tableLayoutPanel1.Controls)
            {
                NewObjectCell cell = c as NewObjectCell;
                if (cell != null)
                {
                    var context = new NewObjectCell.ObjectCreationContext();
                    context.newObject = createdObject;
                    context.fileCreationRealFileName = fileCreationRealFileName;
                    context.disableFileCreation      = disableFileCreation;

                    if (!cell.ObjectCreation(context))
                    //if( !cell.ObjectCreation( createdObject, fileCreationRealFileName, ref disableFileWriting ) )
                    {
                        //!!!!!

                        return(false);
                    }

                    disableFileCreation = context.disableFileCreation;
                }
            }

            return(true);
        }