示例#1
0
 private CkanModule ApplyVersionsCheckbox(CkanModule input)
 {
     if (IncludeVersionsCheckbox.Checked)
     {
         return(input);
     }
     else
     {
         // We want to return the relationships without the version properties,
         // BUT we don't want to purge them from the main module object
         // in case the user changes the checkbox after cancelling out of the
         // save popup. So we create a new CkanModule instead.
         var newMod = CkanModule.FromJson(CkanModule.ToJson(input));
         foreach (var rels in new List <List <RelationshipDescriptor> >()
         {
             newMod.depends,
             newMod.recommends,
             newMod.suggests
         })
         {
             if (rels != null)
             {
                 foreach (var rel in rels
                          .Select(rel => rel as ModuleRelationshipDescriptor)
                          .Where(rel => rel != null))
                 {
                     rel.version     = null;
                     rel.min_version = null;
                     rel.max_version = null;
                 }
             }
         }
         return(newMod);
     }
 }
示例#2
0
文件: Repo.cs 项目: fei090620/CKAN
        private static CkanModule ProcessRegistryMetadataFromJSON(string metadata, string filename)
        {
            log.DebugFormat("Converting metadata from JSON.");

            try
            {
                CkanModule module = CkanModule.FromJson(metadata);
                log.DebugFormat("Found {0} version {1}", module.identifier, module.version);
                return(module);
            }
            catch (Exception exception)
            {
                // Alas, we can get exceptions which *wrap* our exceptions,
                // because json.net seems to enjoy wrapping rather than propagating.
                // See KSP-CKAN/CKAN-meta#182 as to why we need to walk the whole
                // exception stack.

                bool handled = false;

                while (exception != null)
                {
                    if (exception is UnsupportedKraken || exception is BadMetadataKraken)
                    {
                        // Either of these can be caused by data meant for future
                        // clients, so they're not really warnings, they're just
                        // informational.

                        log.InfoFormat("Skipping {0} : {1}", filename, exception.Message);

                        // I'd *love a way to "return" from the catch block.
                        handled = true;
                        break;
                    }

                    // Look further down the stack.
                    exception = exception.InnerException;
                }

                // If we haven't handled our exception, then it really was exceptional.
                if (handled == false)
                {
                    if (exception == null)
                    {
                        // Had exception, walked exception tree, reached leaf, got stuck.
                        log.ErrorFormat("Error processing {0} (exception tree leaf)", filename);
                    }
                    else
                    {
                        // In case whatever's calling us is lazy in error reporting, we'll
                        // report that we've got an issue here.
                        log.ErrorFormat("Error processing {0} : {1}", filename, exception.Message);
                    }

                    throw;
                }
                return(null);
            }
        }
示例#3
0
文件: Repo.cs 项目: CodingWoes/CKAN
        /// <summary>
        /// Updates the supplied registry from the URL given.
        /// This will *clear* the registry of available modules first.
        /// This does not *save* the registry. For that, you probably want Repo.Update
        /// </summary>
        internal static void UpdateRegistry(Uri repo, Registry registry)
        {
            log.InfoFormat("Downloading {0}", repo);

            string repo_file = Net.Download(repo);

            using (var zipfile = new ZipFile(repo_file))
            {
                // Clear our list of known modules.
                registry.ClearAvailable();

                // Walk the archive, looking for .ckan files.
                string filter = @"\.ckan$";

                foreach (ZipEntry entry in zipfile)
                {
                    string filename = entry.Name;

                    // Skip things we don't want.
                    if (!Regex.IsMatch(filename, filter))
                    {
                        log.DebugFormat("Skipping archive entry {0}", filename);
                        continue;
                    }

                    log.DebugFormat("Reading CKAN data from {0}", filename);

                    // Read each file into a string.
                    string metadata_json;
                    using (var stream = new StreamReader(zipfile.GetInputStream(entry)))
                    {
                        metadata_json = stream.ReadToEnd();
                        stream.Close();
                    }

                    log.Debug("Converting from JSON...");

                    try
                    {
                        CkanModule module = CkanModule.FromJson(metadata_json);
                        log.InfoFormat("Found {0} version {1}", module.identifier, module.version);
                        registry.AddAvailable(module);
                    }
                    catch (Kraken kraken)
                    {
                        if (kraken is UnsupportedKraken || kraken is BadMetadataKraken)
                        {
                            // Either of these can be caused by data meant for future
                            // clients, so they're not really warnings, they're just
                            // informational.

                            log.InfoFormat("Skipping {0} : {1}", filename, kraken.Message);
                        }

                        // This is not the kraken we're looking for.
                        throw;
                    }
                }

                zipfile.Close();
            }

            // Remove our downloaded meta-data now we've processed it.
            // Seems weird to do this as part of a transaction, but Net.Download uses them, so let's be consistent.
            file_transaction.Delete(repo_file);
        }