Exemplo n.º 1
0
 /// <summary>
 ///   Compiles the specified files and generates the output resource file.
 /// </summary>
 /// <param name="fileList">The enumeration of <see cref="FileInfo" /> objects.</param>
 /// <param name="output">The destination <see cref="DirectoryInfo" /> object.</param>
 /// <returns></returns>
 internal int Compile(IEnumerable<FileInfo> fileList, ResourceOutput output)
 {
     var database = new TzdbDatabase();
     ParseAllFiles(fileList, database);
     GenerateDateTimeZones(database, output);
     LogCounts(database);
     return 0;
 }
Exemplo n.º 2
0
 public int Execute(WindowsMapperCompilerOptions options)
 {
     log.Info("Starting compilation of {0}", options.SourceFileName);
     DateTimeZone.SetUtcOnly(true);
     var inputFile = new FileInfo(options.SourceFileName);
     if (!inputFile.Exists)
     {
         log.Error("Source file {0} does not exist", inputFile.FullName);
         return 2;
     }
     var mappings = ReadInput(inputFile);
     using (var output = new ResourceOutput(WindowsToPosixResource.WindowToPosixMapBase, options.OutputType))
     {
         log.Info("Compiling to {0}", output.OutputFileName);
         output.WriteDictionary(WindowsToPosixResource.WindowToPosixMapKey, mappings);
     }
     log.Info("Finished compiling.", options.SourceFileName);
     return 0;
 }
        public static ResourceOutput ProvisionOrUpdateResource(string subscriptionId, string cloudServiceName, string resourceType, string resourceName, ResourceInput resource)
        {
            ResourceOutput output;

            lock (theMassiveLock)
            {
                Subscription subscription;
                if (!allSubscriptions.TryGetValue(subscriptionId, out subscription))
                {
                    subscription = new Subscription() { Id = subscriptionId };
                    allSubscriptions[subscriptionId] = subscription;
                }

                CloudService theMatchingCloudService = subscription.CloudServices.SingleOrDefault<CloudService>(cs => String.CompareOrdinal(cs.Name, cloudServiceName) == 0);

                if (theMatchingCloudService == null)
                {
                    theMatchingCloudService = new CloudService() { Name = cloudServiceName };
                    subscription.CloudServices.Add(theMatchingCloudService);
                }

                ResourceOutput theMatchingResource = theMatchingCloudService.Resources.FirstOrDefault(r => String.Compare(r.Name, resourceName) == 0);

                if (theMatchingResource != null)
                {
                    // We can be called to provision / update a resource several time - Ignore the request if we have a record of the resource with the same incarnation id
                    if (theMatchingResource.ETag != resource.ETag)
                    {
                        theMatchingResource.CloudServiceSettings = resource.CloudServiceSettings;
                        theMatchingResource.ETag = resource.ETag;
                        theMatchingResource.IntrinsicSettings = resource.IntrinsicSettings;
                        theMatchingResource.Name = resourceName;
                        theMatchingResource.OperationStatus = new OperationStatus()
                        {
                            Error = new ErrorData() { HttpCode = 200, Message="OK" },
                            Result = OperationResult.Succeeded
                        };
                        theMatchingResource.Plan = resource.Plan;
                        theMatchingResource.SchemaVersion = resource.SchemaVersion;
                        theMatchingResource.State = ResourceState.Started.ToString();
                        theMatchingResource.SubState = "";
                        theMatchingResource.Type = resource.Type;
                    }

                    output = theMatchingResource;
                }
                else
                {
                    output = new ResourceOutput()
                    {
                        CloudServiceSettings = resource.CloudServiceSettings,
                        ETag = resource.ETag,
                        IntrinsicSettings = resource.IntrinsicSettings,
                        Name = resourceName,
                        OperationStatus = new OperationStatus()
                        {
                            Error = new ErrorData() { HttpCode = 200, Message="OK" },
                            Result = OperationResult.Succeeded
                        },
                        OutputItems = GenerateOutputItems(),
                        Plan = resource.Plan,
                        SchemaVersion = resource.SchemaVersion,
                        State = ResourceState.Started.ToString(),
                        SubState = "",
                        Type = resource.Type
                    };

                    theMatchingCloudService.Resources.Add(output);
                }
            }

            return output;
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Generates the date time zones from the given parsed time zone information object.
        /// </summary>
        /// <remarks>
        ///   <para>
        ///     First we go through the list of time zones and generate an <see cref="DateTimeZone" />
        ///     object for each one. We create a mapping between the time zone name and itself (for
        ///     writing out later). Then we write out the time zone as a resource to the current writer.
        ///   </para>
        ///   <para>
        ///     Second we go through all of the alias mappings and find the actual time zone that they
        ///     map to. we do this by redirecting through aliases until there are no more aliases. This
        ///     allows for on alias to refer to another. We add the alias mapping to the time zone
        ///     mapping created in the first step. When done, we write out the entire mapping as a
        ///     resource. The keys of the mapping can be used as the list of valid time zone ids
        ///     supported by this resource file.
        ///   </para>
        /// </remarks>
        /// <param name="database">The database of parsed zone info records.</param>
        /// <param name="output">The output file <see cref="ResourceOutput" />.</param>
        private static void GenerateDateTimeZones(TzdbDatabase database, ResourceOutput output)
        {
            var timeZoneMap = new Dictionary<string, string>();
            foreach (var zoneList in database.Zones)
            {
                var timeZone = CreateTimeZone(zoneList, database.Rules);
                timeZoneMap.Add(timeZone.Id, timeZone.Id);
                output.WriteTimeZone(timeZone.Id, timeZone);
            }

            foreach (var key in database.Aliases.Keys)
            {
                var value = database.Aliases[key];
                while (database.Aliases.ContainsKey(value))
                {
                    value = database.Aliases[value];
                }
                timeZoneMap.Add(key, value);
            }

            output.WriteDictionary(DateTimeZoneResourceProvider.IdMapKey, timeZoneMap);
        }
Exemplo n.º 5
0
        public int Execute(TzdbCompilerOptions options)
        {
            log.Info("Starting compilation of directory {0}", options.SourceDirectoryName);
            DateTimeZone.SetUtcOnly(true);
            var sourceDirectory = new DirectoryInfo(options.SourceDirectoryName);
            var outputFile = new FileInfo(options.OutputFileName);
            var files = options.InputFiles;
            var fileList = MakeFileList(sourceDirectory, files);
            ValidateArguments(sourceDirectory, fileList);
            using (var output = new ResourceOutput(outputFile.FullName, options.OutputType))
            {
                //// Using this conditional code makes debugging simpler in Visual Studio because exceptions will
                //// be caught by VS and shown with the exception visualizer.
#if DEBUG
                Compile(fileList, output);
#else
                try
                {
                    Compile(fileList, output);
                }
                catch (Exception e)
                {
                    log.Error("{0}", e.Message);
                    return 2;
                }
#endif
            }
            log.Info("Done compiling time zones.");
            return 0;
        }