示例#1
0
 protected override void init()
 {
     FilePath = EwlStatics.CombinePaths(ConfigurationStatics.FilesFolderPath, FileName + FileExtensions.Xsd);
     if (!File.Exists(FilePath))
     {
         throw new ApplicationException("File does not exist.");
     }
 }
 // NOTE: We do have the power to add and remove web sites here, and we can list just the stopped or just the started sites.
 // NOTE: When we add web sites with the ISU, we should NOT support host headers since WCF services have some restrictions with these. See http://stackoverflow.com/questions/561823/wcf-error-this-collection-already-contains-an-address-with-scheme-http
 private bool siteExistsInIis(string webSiteName)
 {
     if (!File.Exists(appCmdPath))
     {
         return(false);
     }
     return(EwlStatics.RunProgram(appCmdPath, "list sites", "", true).Contains("\"" + webSiteName + "\""));
 }
示例#3
0
 public static string GetBuildFilePath(int systemId)
 {
     return(EwlStatics.CombinePaths(
                DataPackageRepositoryPath
                /*NOTE: Make this the generic web-site-accessible folder and change this and DataPackageRepositoryPath to be a subfolder of that.*/,
                "Latest Builds",
                systemId.ToString()));
 }
        private string getNamespaceFromFilePath(string projectNamespace, string filePathRelativeToProject)
        {
            var tokens = filePathRelativeToProject.Separate(System.IO.Path.DirectorySeparatorChar.ToString(), false);

            tokens = tokens.Take(tokens.Count - 1).ToList();
            return(StaticFileHandler.CombineNamespacesAndProcessEwfIfNecessary(
                       projectNamespace,
                       StringTools.ConcatenateWithDelimiter(".", tokens.Select(i => EwlStatics.GetCSharpIdentifier(i.CapitalizeString())).ToArray())));
        }
示例#5
0
 private static void writeColumnProperty(TextWriter writer, Column column)
 {
     CodeGenerationStatics.AddSummaryDocComment(
         writer,
         "This object will " + (column.AllowsNull && !column.NullValueExpression.Any() ? "sometimes" : "never") + " be null.");
     writer.WriteLine(
         "public " + column.DataTypeName + " " + EwlStatics.GetCSharpIdentifier(column.PascalCasedNameExceptForOracle) + " { get { return __basicRow." +
         EwlStatics.GetCSharpIdentifier(column.PascalCasedName) + "; } }");
 }
        void Operation.Execute(Installation genericInstallation, OperationResult operationResult)
        {
            var installation             = genericInstallation as RecognizedDevelopmentInstallation;
            var localNuGetFeedFolderPath = EwlStatics.CombinePaths(ConfigurationStatics.RedStaplerFolderPath, "Local NuGet Feed");

            // NuGet.exe has problems if the folder doesn't exist.
            Directory.CreateDirectory(localNuGetFeedFolderPath);

            ExportLogic.CreateEwlNuGetPackage(installation, true, localNuGetFeedFolderPath, null);
        }
        public int CompareTo(DbParameterValue other)
        {
            if (other == null)
            {
                return(1);
            }
            var valueResult = EwlStatics.Compare(value, other.value);

            return(valueResult != 0 ? valueResult : EwlStatics.Compare(dbTypeString, other.dbTypeString, comparer: StringComparer.InvariantCulture));
        }
示例#8
0
        public int CompareTo(InlineDbCommandColumnValue other)
        {
            if (other == null)
            {
                return(1);
            }
            var nameResult = EwlStatics.Compare(columnName, other.columnName, comparer: StringComparer.InvariantCulture);

            return(nameResult != 0 ? nameResult : EwlStatics.Compare(value, other.value));
        }
        private void generateWindowsServiceCode(DevelopmentInstallation installation, WindowsService service)
        {
            var serviceProjectGeneratedCodeFolderPath = EwlStatics.CombinePaths(installation.GeneralLogic.Path, service.Name, generatedCodeFolderName);

            Directory.CreateDirectory(serviceProjectGeneratedCodeFolderPath);
            var isuFilePath = EwlStatics.CombinePaths(serviceProjectGeneratedCodeFolderPath, "ISU.cs");

            IoMethods.DeleteFile(isuFilePath);
            using (TextWriter writer = new StreamWriter(isuFilePath)) {
                writer.WriteLine("using System;");
                writer.WriteLine("using System.ComponentModel;");
                writer.WriteLine("using System.Reflection;");
                writer.WriteLine("using System.Runtime.InteropServices;");
                writer.WriteLine("using System.ServiceProcess;");
                writer.WriteLine("using System.Threading;");
                writer.WriteLine("using EnterpriseWebLibrary;");
                writer.WriteLine("using EnterpriseWebLibrary.DataAccess;");
                writer.WriteLine("using EnterpriseWebLibrary.WindowsServiceFramework;");
                writer.WriteLine();
                writeAssemblyInfo(writer, installation, service.Name);
                writer.WriteLine();
                writer.WriteLine("namespace " + service.NamespaceAndAssemblyName + " {");

                writer.WriteLine("internal static partial class Program {");

                writer.WriteLine("[ MTAThread ]");
                writer.WriteLine("private static void Main() {");
                writer.WriteLine("SystemInitializer globalInitializer = null;");
                writer.WriteLine("initGlobalInitializer( ref globalInitializer );");
                writer.WriteLine("var dataAccessState = new ThreadLocal<DataAccessState>( () => new DataAccessState() );");
                writer.WriteLine(
                    "GlobalInitializationOps.InitStatics( globalInitializer, \"{0}\", false, mainDataAccessStateGetter: () => dataAccessState.Value, useLongDatabaseTimeouts: true );"
                    .FormatWith(service.Name));
                writer.WriteLine("try {");
                writer.WriteLine(
                    "TelemetryStatics.ExecuteBlockWithStandardExceptionHandling( () => ServiceBase.Run( new ServiceBaseAdapter( new " + service.Name.EnglishToPascal() +
                    "() ) ) );");
                writer.WriteLine("}");
                writer.WriteLine("finally {");
                writer.WriteLine("GlobalInitializationOps.CleanUpStatics();");
                writer.WriteLine("}");
                writer.WriteLine("}");

                writer.WriteLine("static partial void initGlobalInitializer( ref SystemInitializer globalInitializer );");

                writer.WriteLine("}");

                writer.WriteLine("internal partial class " + service.Name.EnglishToPascal() + ": WindowsServiceBase {");
                writer.WriteLine("internal " + service.Name.EnglishToPascal() + "() {}");
                writer.WriteLine("string WindowsServiceBase.Name { get { return \"" + service.Name + "\"; } }");
                writer.WriteLine("}");

                writer.WriteLine("}");
            }
        }
        /// <summary>
        /// Gets a new system list.
        /// </summary>
        public static void RefreshSystemList()
        {
            // Do not perform schema validation since we don't want to be forced into redeploying Program Runner after every schema change. We also don't have access
            // to the schema on non-development machines.
            var cacheFilePath = EwlStatics.CombinePaths(ConfigurationStatics.EwlFolderPath, "System List.xml");
            var cacheUsed     = false;

            try {
                ConfigurationLogic.ExecuteWithSystemManagerClient(
                    client => {
                    Task.Run(
                        async() => {
                        using (var response = await client.GetAsync("system-list", HttpCompletionOption.ResponseHeadersRead)) {
                            response.EnsureSuccessStatusCode();
                            using (var stream = await response.Content.ReadAsStreamAsync())
                                RsisSystemList = XmlOps.DeserializeFromStream <SystemList>(stream, false);
                        }
                    })
                    .Wait();
                });
            }
            catch (Exception e) {
                // Use the cached version of the system list if it is available.
                if (File.Exists(cacheFilePath))
                {
                    RsisSystemList = XmlOps.DeserializeFromFile <SystemList>(cacheFilePath, false);
                    cacheUsed      = true;
                }
                else
                {
                    throw new UserCorrectableException("Failed to download the system list and a cached version is not available.", e);
                }
            }

            StatusStatics.SetStatus(
                cacheUsed ? "Failed to download the system list; loaded a cached version from \"{0}\".".FormatWith(cacheFilePath) : "Downloaded the system list.");

            // Cache the system list so something is available in the future if the machine is offline.
            try {
                XmlOps.SerializeIntoFile(RsisSystemList, cacheFilePath);
            }
            catch (Exception e) {
                const string generalMessage = "Failed to cache the system list on disk.";
                if (e is UnauthorizedAccessException)
                {
                    throw new UserCorrectableException(generalMessage + " If the program is running as a non built in administrator, you may need to disable UAC.", e);
                }

                // An IOException probably means the file is locked. In this case we want to ignore the problem and move on.
                if (!(e is IOException))
                {
                    throw new UserCorrectableException(generalMessage, e);
                }
            }
        }
        internal static void Generate(string rootPath, string nameSpace, TextWriter writer)
        {
            var cssClasses = new HashSet <string>();

            foreach (var fileInfo in new DirectoryInfo(rootPath).GetFiles("*.css", SearchOption.AllDirectories))
            {
                new FileReader(fileInfo.FullName).ExecuteInStreamReader(
                    delegate(StreamReader reader) {
                    // Remove comments and styles.
                    // NOTE: We need to find a way to also throw out media query expressions.
                    var text = reader.ReadToEnd().RemoveTextBetweenStrings("/*", "*/").RemoveTextBetweenStrings("{", "}");

                    foreach (Match match in Regex.Matches(text, @"\.(\w+)"))
                    {
                        cssClasses.Add(match.Groups[1].Value);
                    }
                });
            }

            if (cssClasses.Any())
            {
                writer.WriteLine("namespace " + nameSpace + " {");

                CodeGenerationStatics.AddSummaryDocComment(writer, "This class provides typesafe access to css classes present in *.css files.");
                writer.WriteLine("public class ElementClasses {");

                var identifiers = new HashSet <string>();
                foreach (var elementClass in cssClasses)
                {
                    writer.WriteLine("/// <summary>");
                    writer.WriteLine("/// Constant for the '{0}' class.".FormatWith(elementClass));
                    writer.WriteLine("/// </summary>");
                    var identifier = EwlStatics.GetCSharpIdentifier(elementClass.CapitalizeString());
                    if (identifiers.Contains(identifier))
                    {
                        var uniqueIdentifier = identifier;
                        var i = 0;
                        while (identifiers.Contains(uniqueIdentifier))
                        {
                            uniqueIdentifier = identifier + i++;
                        }
                        identifier = uniqueIdentifier;
                    }
                    identifiers.Add(identifier);
                    writer.WriteLine("public static readonly ElementClass {0} = new ElementClass( \"{1}\" );".FormatWith(identifier, elementClass));
                }

                writer.WriteLine("}");                   // class
                writer.WriteLine("}");                   // namespace
            }

            // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
            generateLegacy(rootPath, nameSpace, writer);
        }
示例#12
0
        private static void writeGenericGetterWithoutValueParams(TextWriter writer, ModificationField field, bool?includeValidationMethodReturnValue)
        {
            var controlGetter = "( v, ls ) => controlGetter( v" + (field.TypeName != field.NullableTypeName ? ".Value" : "") + ", ls )";
            var body          = "return " + EwlStatics.GetCSharpIdentifierSimple("Get" + field.PascalCasedName + "FormItem") + "( false, " + controlGetter +
                                (includeValidationMethodReturnValue.HasValue ? ", validationMethod" : "") +
                                ", labelAndSubject: labelAndSubject, labelOverride: labelOverride, cellSpan: cellSpan, textAlignment: textAlignment" +
                                (includeValidationMethodReturnValue.HasValue
                                             ? ", validationPredicate: validationPredicate, validationErrorNotifier: validationErrorNotifier, additionalValidationMethod: additionalValidationMethod, validationList: validationList"
                                             : "") + " );";

            writeGenericGetter(writer, field, false, includeValidationMethodReturnValue, body);
        }
示例#13
0
        private static string getValidationGetter(ModificationField field, bool includeValidationMethodReturnValue)
        {
            var fieldPropertyName = EwlStatics.GetCSharpIdentifierSimple(field.PropertyName);
            var statements        = new[]
            {
                "if( validationPredicate != null && !validationPredicate() ) return;",
                (includeValidationMethodReturnValue ? fieldPropertyName + " = " : "") + "validationMethod( control, postBackValues, labelAndSubject, validator );",
                "if( validator.ErrorsOccurred && validationErrorNotifier != null ) validationErrorNotifier();",
                "if( !validator.ErrorsOccurred && additionalValidationMethod != null ) additionalValidationMethod( labelAndSubject, validator );"
            };

            return("control => new EwfValidation( ( postBackValues, validator ) => { " + StringTools.ConcatenateWithDelimiter(" ", statements) +
                   " }, validationList ?? EwfPage.Instance.DataUpdate )");
        }