当前位置: 首页>>代码示例>>C#>>正文


C# IUser.RaiseMessage方法代码示例

本文整理汇总了C#中IUser.RaiseMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IUser.RaiseMessage方法的具体用法?C# IUser.RaiseMessage怎么用?C# IUser.RaiseMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUser的用法示例。


在下文中一共展示了IUser.RaiseMessage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormattedDownloads

 /// <summary>
 /// Only shows download report messages, and nothing else.
 /// </summary>
 public static void FormattedDownloads(string message, int progress, IUser user)
 {
     if (Regex.IsMatch(message, "download", RegexOptions.IgnoreCase))
     {
         user.RaiseMessage(
             // The \r at the front here causes download messages to *overwrite* each other.
             String.Format("\r{0} - {1}%           ", message, progress)
         );
     }
     else
     {
         // The percent looks weird on non-download messages.
         // The leading newline makes sure we don't end up with a mess from previous
         // download messages.
         user.RaiseMessage("\n{0}", message);
     }
 }
开发者ID:adamhomer88,项目名称:CKAN,代码行数:20,代码来源:ProgressReporter.cs

示例2: Download

        public static string Download(string url, string filename = null, IUser user = null)
        {
            user = user ?? new NullUser();
            user.RaiseMessage("Downloading {0}", url);

            // Generate a temporary file if none is provided.
            if (filename == null)
            {
                filename = FileTransaction.GetTempFileName();
            }

            Log.DebugFormat("Downloading {0} to {1}", url, filename);

            var agent = MakeDefaultHttpClient();
           
            try
            {
                agent.DownloadFile(url, filename);
            }
            catch (Exception ex)
            {
                Log.InfoFormat("Download failed, trying with curlsharp...");

                try
                {
                    Curl.Init();

                    using (FileStream stream = File.OpenWrite(filename))
                    using (var curl = Curl.CreateEasy(url, stream))
                    {
                        CurlCode result = curl.Perform();
                        if (result != CurlCode.Ok)
                        {
                            throw new Kraken("curl download of " + url + " failed with CurlCode " + result);
                        }
                        else
                        {
                            Log.Debug("curlsharp download successful");
                        }
                    }

                    Curl.CleanUp();
                    return filename;
                }
                catch
                {
                    // D'oh, failed again. Fall through to clean-up handling.
                }

                // Clean up our file, it's unlikely to be complete.
                // We do this even though we're using transactional files, as we may not be in a transaction.
                // It's okay if this fails.
                try
                {
                    Log.DebugFormat("Removing {0} after web error failure", filename);
                    FileTransaction.Delete(filename);
                }
                catch
                {
                    // Apparently we need a catch, even if we do nothing.
                }

                // Look for an exception regarding the authentication.
                if (Regex.IsMatch(ex.ToString(), "The authentication or decryption has failed."))
                {
                    throw new MissingCertificateKraken("Failed downloading " + url, ex);
                }

                // Not the exception we were looking for! Throw it further upwards!
                throw;
            }

            return filename;
        }
开发者ID:adamhomer88,项目名称:CKAN,代码行数:74,代码来源:Net.cs

示例3: UpdateRegistry

        /// <summary>
        /// Updates the supplied registry from the URL given.
        /// This does not *save* the registry. For that, you probably want Repo.Update
        /// </summary>
        internal static void UpdateRegistry(Uri repo, Registry registry, KSP ksp, IUser user, Boolean clear = true)
        {
            log.InfoFormat("Downloading {0}", repo);

            string repo_file = String.Empty;
            try
            {
                repo_file = Net.Download(repo);
            }
            catch (System.Net.WebException)
            {
                user.RaiseMessage("Connection to {0} could not be established.", repo);
                return;
            }

            // Clear our list of known modules.
            var old_available = registry.available_modules;
            if (clear)
            {
                registry.ClearAvailable();
            }

            // Check the filetype.
            FileType type = FileIdentifier.IdentifyFile(repo_file);

            switch (type)
            {
            case FileType.TarGz:
                UpdateRegistryFromTarGz (repo_file, registry);
                break;
            case FileType.Zip:
                UpdateRegistryFromZip (repo_file, registry);
                break;
            default:
                break;
            }

            List<CkanModule> metadataChanges = new List<CkanModule>();

            foreach (var identifierModulePair in old_available)
            {
                var identifier = identifierModulePair.Key;

                if (registry.IsInstalled(identifier))
                {
                    var installedVersion = registry.InstalledVersion(identifier);
                    if (!(registry.available_modules.ContainsKey(identifier)))
                    {
                        log.InfoFormat("UpdateRegistry, module {0}, version {1} not in repository ({2})", identifier, installedVersion, repo);
                        continue;
                    }

                    if (!registry.available_modules[identifier].module_version.ContainsKey(installedVersion))
                    {
                        continue;
                    }

                    // if the mod is installed and the metadata is different we have to reinstall it
                    var metadata = registry.available_modules[identifier].module_version[installedVersion];

                    if (!old_available.ContainsKey(identifier) ||
                        !old_available[identifier].module_version.ContainsKey(installedVersion))
                    {
                        continue;
                    }

                    var oldMetadata = old_available[identifier].module_version[installedVersion];

                    bool same = true;
                    if ((metadata.install == null) != (oldMetadata.install == null) ||
                        (metadata.install != null && metadata.install.Length != oldMetadata.install.Length))
                    {
                        same = false;
                    }
                    else
                    {
                        if(metadata.install != null)
                        for (int i = 0; i < metadata.install.Length; i++)
                        {
                            if (metadata.install[i].file != oldMetadata.install[i].file)
                            {
                                same = false;
                                break;
                            }

                            if (metadata.install[i].install_to != oldMetadata.install[i].install_to)
                            {
                                same = false;
                                break;
                            }

                            if ((metadata.install[i].filter == null) != (oldMetadata.install[i].filter == null))
                            {
                                same = false;
                                break;
                            }
//.........这里部分代码省略.........
开发者ID:adamhomer88,项目名称:CKAN,代码行数:101,代码来源:Repo.cs

示例4: Scan

        /// <summary>
        /// Scans the ksp instance. Detects installed mods to mark as auto-detected and checks the consistency
        /// </summary>
        /// <param name="ksp_instance">The instance to scan</param>
        /// <param name="user"></param>
        /// <param name="next_command">Changes the output message if set.</param>
        /// <returns>Exit.OK if instance is consistent, Exit.ERROR otherwise </returns>
        private static int Scan(CKAN.KSP ksp_instance, IUser user, string next_command=null)
        {
            try
            {
                ksp_instance.ScanGameData();
                return Exit.OK;
            }
            catch (InconsistentKraken kraken)
            {

                if (next_command==null)
                {
                    user.RaiseError(kraken.InconsistenciesPretty);
                    user.RaiseError("The repo has not been saved.");
                }
                else
                {
                    user.RaiseMessage("Preliminary scanning shows that the install is in a inconsistent state.");
                    user.RaiseMessage("Use ckan.exe scan for more details");
                    user.RaiseMessage("Proceeding with {0} in case it fixes it.\n", next_command);
                }

                return Exit.ERROR;
            }
        }
开发者ID:adamhomer88,项目名称:CKAN,代码行数:32,代码来源:Main.cs

示例5: HTTP

        internal static JObject HTTP(JObject orig_metadata, string remote_id, NetFileCache cache, IUser user)
        {
            var metadata = orig_metadata;

            // Check if we should auto-inflate.
            string kref = (string)metadata[expand_token];

            if (kref == (string)orig_metadata[expand_token] || kref == "#/ckan/http")
            {
                log.InfoFormat("Inflating from HTTP download... {0}", metadata[expand_token]);
                metadata["download"] = remote_id;
                metadata["version"] = "0.0.0"; // add a dummy version that will be replaced by the KSP-AVC parser later
                metadata.Remove(expand_token);

                var remote_uri = new Uri(remote_id);
                var downloaded_file = Net.Download(remote_uri);
                var module = CkanModule.FromJson(metadata.ToString());

                // Check the type of the downloaded file.
                FileType downloaded_file_type = FileIdentifier.IdentifyFile(downloaded_file);

                if (downloaded_file_type != FileType.Zip)
                {
                    // We assume the downloaded file is a zip file later on.
                    string error_message = String.Format("Downloaded file not identified as a zip. Got {0} instead.", downloaded_file_type.ToString());
                    throw new Kraken(error_message);
                }

                if (metadata[version_token] != null && (metadata[version_token].ToString()).StartsWith("#/ckan/ksp-avc"))
                {
                    // TODO pass the correct vref here...
                    var versionRemote = FindVersionRemote(metadata, metadata[version_token].ToString());
                    metadata.Remove(version_token);

                    try
                    {
                        AVC avc = AVC.FromZipFile(module, downloaded_file, versionRemote.id);
                        avc.InflateMetadata(metadata, null, null);
                        metadata["version"] = avc.version.ToString();
                        module.version = avc.version;
                    }
                    catch (JsonReaderException)
                    {
                        user.RaiseMessage("Bad embedded KSP-AVC file for {0}, halting.", module);
                        return null;
                    }

                    // If we've done this, we need to re-inflate our mod, too.
                    module = CkanModule.FromJson(metadata.ToString());
                }
                else
                {
                    throw new Kraken("No $vref specified, $kref HTTP method requires it, bailing out..");
                }

                ModuleInstaller.CachedOrDownload(module.identifier, module.version, module.download, cache);
            }
            else
            {
                log.WarnFormat("Not inflating metadata for {0}", orig_metadata["identifier"]);
            }

               // metadata["download"] = metadata["download"].ToString() + '#' + metadata["version"].ToString();
            return metadata;
        }
开发者ID:dexen,项目名称:CKAN,代码行数:65,代码来源:MainClass.cs

示例6: Available

        private static int Available(CKAN.KSP current_instance, IUser user)
        {
            List<CkanModule> available = RegistryManager.Instance(current_instance).registry.Available(current_instance.Version());

            user.RaiseMessage("Mods available for KSP {0}", current_instance.Version());
            user.RaiseMessage("");

            var width = user.WindowWidth;

            foreach (CkanModule module in available)
            {
                string entry = String.Format("* {0} ({1}) - {2}", module.identifier, module.version, module.name);
                user.RaiseMessage(width > 0 ? entry.PadRight(width).Substring(0, width - 1) : entry);
            }

            return Exit.OK;
        }
开发者ID:adamhomer88,项目名称:CKAN,代码行数:17,代码来源:Main.cs

示例7: Version

        private static int Version(IUser user)
        {
            user.RaiseMessage(Meta.Version());

            return Exit.OK;
        }
开发者ID:adamhomer88,项目名称:CKAN,代码行数:6,代码来源:Main.cs

示例8: CheckMonoVersion

        private static void CheckMonoVersion(IUser user, int rec_major, int rec_minor, int rec_patch)
        {
            try
            {
                Type type = Type.GetType("Mono.Runtime");
                if (type == null) return;

                MethodInfo display_name = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
                if (display_name != null)
                {
                    var version_string = (string) display_name.Invoke(null, null);
                    var match = Regex.Match(version_string, @"^\D*(?<major>[\d]+)\.(?<minor>\d+)\.(?<revision>\d+).*$");

                    if (match.Success)
                    {
                        int major = Int32.Parse(match.Groups["major"].Value);
                        int minor = Int32.Parse(match.Groups["minor"].Value);
                        int patch = Int32.Parse(match.Groups["revision"].Value);

                        if (major < rec_major || (major == rec_major && minor < rec_minor))
                        {
                            user.RaiseMessage(
                                "Warning. Detected mono runtime of {0} is less than the recommended version of {1}\n",
                                String.Join(".", major, minor, patch),
                                String.Join(".", rec_major, rec_minor, rec_patch)
                                );
                            user.RaiseMessage("Update recommend\n");
                        }
                    }
                }
            }
            catch (Exception)
            {
                // Ignored. This may be fragile and is just a warning method
            }
        }
开发者ID:adamhomer88,项目名称:CKAN,代码行数:36,代码来源:Main.cs

示例9: ShowUserInconsistencies

        private static void ShowUserInconsistencies(Registry registry, IUser user)
        {
            // However, if there are any sanity errors let's show them to the user so at least they're aware
            var sanityErrors = registry.GetSanityErrors();
            if (sanityErrors.Any())
            {
                var sanityMessage = new StringBuilder();

                sanityMessage.AppendLine("The following inconsistencies were found:");
                foreach (var sanityError in sanityErrors)
                {
                    sanityMessage.Append("- ");
                    sanityMessage.AppendLine(sanityError);
                }

                user.RaiseMessage(sanityMessage.ToString());
            }
        }
开发者ID:KSP-CKAN,项目名称:CKAN,代码行数:18,代码来源:Repo.cs

示例10: UpdateRegistry

        /// <summary>
        /// Updates the supplied registry from the URL given.
        /// This does not *save* the registry. For that, you probably want Repo.Update
        /// </summary>
        internal static void UpdateRegistry(Uri repo, Registry registry, KSP ksp, IUser user, Boolean clear = true)
        {
            // Use this opportunity to also update the build mappings... kind of hacky
            ServiceLocator.Container.Resolve<IKspBuildMap>().Refresh();

            log.InfoFormat("Downloading {0}", repo);

            string repo_file = String.Empty;
            try
            {
                repo_file = Net.Download(repo);
            }
            catch (System.Net.WebException)
            {
                user.RaiseMessage("Connection to {0} could not be established.", repo);
                return;
            }

            // Clear our list of known modules.
            if (clear)
            {
                registry.ClearAvailable();
            }

            // Check the filetype.
            FileType type = FileIdentifier.IdentifyFile(repo_file);

            switch (type)
            {
            case FileType.TarGz:
                UpdateRegistryFromTarGz (repo_file, registry);
                break;
            case FileType.Zip:
                UpdateRegistryFromZip (repo_file, registry);
                break;
            default:
                break;
            }

            List<CkanModule> metadataChanges = new List<CkanModule>();

            foreach (var installedModule in registry.InstalledModules)
            {
                var identifier = installedModule.identifier;

                var installedVersion = registry.InstalledVersion(identifier);
                if (!(registry.available_modules.ContainsKey(identifier)))
                {
                    log.InfoFormat("UpdateRegistry, module {0}, version {1} not in repository ({2})", identifier, installedVersion, repo);
                    continue;
                }

                if (!registry.available_modules[identifier].module_version.ContainsKey(installedVersion))
                {
                    continue;
                }

                // if the mod is installed and the metadata is different we have to reinstall it
                var metadata = registry.available_modules[identifier].module_version[installedVersion];

                var oldMetadata = registry.InstalledModule(identifier).Module;

                bool same = true;
                if ((metadata.install == null) != (oldMetadata.install == null) ||
                    (metadata.install != null && metadata.install.Length != oldMetadata.install.Length))
                {
                    same = false;
                }
                else
                {
                    if(metadata.install != null)
                    for (int i = 0; i < metadata.install.Length; i++)
                    {
                        if (metadata.install[i].file != oldMetadata.install[i].file)
                        {
                            same = false;
                            break;
                        }

                        if (metadata.install[i].install_to != oldMetadata.install[i].install_to)
                        {
                            same = false;
                            break;
                        }

                        if (metadata.install[i][email protected] != oldMetadata.install[i][email protected])
                        {
                            same = false;
                            break;
                        }

                        if ((metadata.install[i].filter == null) != (oldMetadata.install[i].filter == null))
                        {
                            same = false;
                            break;
                        }
//.........这里部分代码省略.........
开发者ID:KSP-CKAN,项目名称:CKAN,代码行数:101,代码来源:Repo.cs


注:本文中的IUser.RaiseMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。