Example #1
0
            public bool Equals(DownloadMeta other)
            {
                if (ReferenceEquals(other, null))
                {
                    return(false);
                }

                if (ReferenceEquals(this, other))
                {
                    return(true);
                }

                if (!Size.Equals(other.Size))
                {
                    return(false);
                }

                if (!Sha1.Equals(other.Sha1))
                {
                    return(false);
                }

                return(Url.Equals(other.Url));
            }
Example #2
0
        public Boolean Execute()
        {
            //
            // Check Options
            //
            if (buildEngine == null)
            {
                throw new ArgumentNullException("BuildEngine");
            }

            if (inputFiles == null || inputFiles.Length <= 0)
            {
                LogError("Missing InputFiles");
                return(TaskFailed);
            }
            if (String.IsNullOrEmpty(outputFile))
            {
                LogError("Missing OutputFile");
                return(TaskFailed);
            }
            if (String.IsNullOrEmpty(@namespace))
            {
                LogError("Missing Namespace");
                return(TaskFailed);
            }

            //
            // Check that input files exist
            //
            Int32 missingInputFileCount = 0;

            for (int i = 0; i < inputFiles.Length; i++)
            {
                String inputFile = inputFiles[i];
                if (!File.Exists(inputFiles[i]))
                {
                    missingInputFileCount++;
                    LogError("Missing InputFile '{0}'", inputFile);
                }
            }
            if (missingInputFileCount > 0)
            {
                LogError("{0} of the input files {1} missing", missingInputFileCount, (missingInputFileCount == 1) ? "is" : "are");
                return(TaskFailed);
            }

            //
            // Load the input files
            //
            InputFileObject[] inputFileObjects = new InputFileObject[inputFiles.Length];

            Byte[]        fileBuffer      = new Byte[1024];
            Sha1Builder   inputShaBuilder = new Sha1Builder();
            StringBuilder builder         = new StringBuilder();

            for (int i = 0; i < inputFileObjects.Length; i++)
            {
                inputFileObjects[i] = new InputFileObject(inputFiles[i], fileBuffer, builder, inputShaBuilder, Encoding.UTF8);
            }
            Sha1   inputHash       = inputShaBuilder.Finish(false);
            String inputHashString = inputHash.ToString();

            if (forceCodeGeneration)
            {
                Log(MessageImportance.High, "Skipping the InputHash check because ForceCodeGeneration is set to true");
            }
            else
            {
                //
                // Try to get the saved hash from output file
                //
                Sha1   savedInputHash;
                String savedInputHashString = TryGetSavedInputHash(outputFile, out savedInputHash);
                if (savedInputHashString != null)
                {
                    if (inputHash.Equals(savedInputHash))
                    {
                        Log(MessageImportance.Normal, "Input hash matches saved input hash, no code generation done");
                        return(TaskSucceeded);
                    }
                }
            }

            //
            // Parse Pdl Files
            //
            PdlFile pdlFile = new PdlFile();

            for (int i = 0; i < inputFileObjects.Length; i++)
            {
                InputFileObject inputFileObject = inputFileObjects[i];
                PdlFileParser.ParsePdlFile(pdlFile, new LfdReader(new StringReader(inputFileObject.contents)));
            }

            //
            // Generate the code
            //
            StringBuilder outputStringBuilder = new StringBuilder();

            using (StringWriter outputStringWriter = new StringWriter(outputStringBuilder))
            {
                // Save the hash first
                outputStringWriter.WriteLine("// {0}{1}", PdlFile.InputShaPrefix, inputHashString);
                PdlCodeGenerator.GenerateCode(outputStringWriter, pdlFile, @namespace, generateStructs);
            }

            String outputContents = outputStringBuilder.ToString();

            FileExtensions.SaveStringToFile(outputFile, FileMode.Create, outputContents);

            return(TaskSucceeded);
        }