예제 #1
0
파일: Logger.cs 프로젝트: systemidx/Loki
 /// <summary>
 /// Informations the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Info(string message)
 {
     if (LogLevel <= LogLevel.Info)
     {
         OnInfo?.Invoke(this, new LokiInfoEventArgs(message));
     }
 }
예제 #2
0
        public static void AllLine(string format, params object[] objects)
        {
            string str = Format(format, objects) + "\n";

            OnInfo?.Invoke(str);
            OnError?.Invoke(str);
        }
예제 #3
0
 public void Info(string message)
 {
     if (OnInfo != null)
     {
         OnInfo.Invoke(message);
     }
 }
예제 #4
0
파일: _Logger.cs 프로젝트: semonpic/Warming
        public static void Info(string text)
        {
            Write("Info", text);
            var eventArgs = new LoggerLogEventArgs {
                Level = "Info", Message = text
            };

            OnInfo?.Invoke(eventArgs, eventArgs);
        }
예제 #5
0
 static public void SendInfo(string source, string level, string info)
 {
     OnInfo?.Invoke(new InfoArgs
     {
         source = source,
         level  = level,
         info   = info
     });
 }
예제 #6
0
        public File Parse(string fileAbsolutePath, UInt32 lastTagId = 0)
        {
            _lastTagId = lastTagId;

            var attributeSet = new AttributeSet();

            using (var file = System.IO.File.OpenRead(fileAbsolutePath)) {
                //Preamble
                var preamble = new byte[PREAMBLE_SIZE_BYTES];
                file.Read(preamble, 0, preamble.Length);

                //'DICM' Prefix
                var prefixRaw = new byte[PREFIX_SIZE_BYTES];
                file.Read(prefixRaw, 0, prefixRaw.Length);

                string prefixUTF8 = Encoding.UTF8.GetString(prefixRaw, 0, prefixRaw.Length);
                if (prefixUTF8.Equals(DICM_PREFIX, StringComparison.InvariantCultureIgnoreCase))
                {
                    OnInfo?.Invoke(this, $"Found '{DICM_PREFIX}' prefix.");
                }
                else
                {
                    OnWarning?.Invoke(this, $"Could not find '{DICM_PREFIX}' prefix.");
                }


                while (true)
                {
                    try {
                        var pos          = file.Position;
                        var newAttribute = ParseAttribute(file);
                        if (newAttribute == null)
                        {
                            OnWarning?.Invoke(this, $"Could not parse attribute at position: {pos}.");
                            continue;
                        }
                        attributeSet.Add(newAttribute.Tag.ID, newAttribute);
                        OnInfo?.Invoke(this, attributeSet.ToString());

                        if (_lastTagId > 0 && newAttribute.Tag.ID >= _lastTagId)
                        {
                            break;
                        }
                    }
                    catch (EndOfStreamException) {
                        break;
                    }
                }


                return(new File()
                {
                    IsVRExplicit = _isExplicitVr,
                    Attributes = attributeSet
                });
            }
        }
예제 #7
0
 static public void SendInfo(string source, string level, string info)
 {
     OnInfo?.Invoke(new InfoArgs
     {
         source = source,
         level  = level,
         info   = info
     });
     File.AppendAllText(CreateLog(), $"{DateTime.Now:HH:mm:ss} |{source}|[{level}] {info}\n");
 }
예제 #8
0
        public static void  SystemLog(string text)
        {
            Write("SystemLog", text);
            var eventArgs = new LoggerLogEventArgs {
                Level = "Info", Message = text
            };

            if (OnInfo != null)
            {
                OnInfo.Invoke(eventArgs, eventArgs);
            }
        }
예제 #9
0
 /// <summary>
 /// Log info
 /// </summary>
 /// <param name="args"></param>
 public static void Info(params object[] args)
 {
     if (IsInfoOn)
     {
         if (LogHandler != null)
         {
             LogHandler.Info(args);
         }
         if (OnInfo != null)
         {
             OnInfo.Invoke(LogHandler, args);
         }
     }
 }
예제 #10
0
        /// <summary>
        /// Create a new instance of <see cref="UnlocLoader"/>.
        /// </summary>
        public UnlocLoader()
        {
            var locationParser = new LocationParser();

            _countryLoader  = new CountryLoader();
            _locationLoader = new LocationLoader(locationParser);
            _fileDownloader = new FileDownloader();

            _countryLoader.OnInfo  += (sender, s) => OnInfo?.Invoke(sender, s);
            _countryLoader.OnWarn  += (sender, s) => OnWarn?.Invoke(sender, s);
            _countryLoader.OnTrace += (sender, s) => OnTrace?.Invoke(sender, s);

            _locationLoader.OnInfo  += (sender, s) => OnInfo?.Invoke(sender, s);
            _locationLoader.OnWarn  += (sender, s) => OnWarn?.Invoke(sender, s);
            _locationLoader.OnTrace += (sender, s) => OnTrace?.Invoke(sender, s);
        }
예제 #11
0
        private void InitListeners()
        {
            m_nativeEngine.OnInfo += (string message) =>
            {
                OnInfo?.Invoke(message);
            };

            m_nativeEngine.OnWarning += (string message) =>
            {
                OnWarning?.Invoke(message);
            };

            m_nativeEngine.OnError += (string message) =>
            {
                OnError?.Invoke(message);
            };
        }
예제 #12
0
        /// <summary>
        /// Creates a download able archive
        /// </summary>
        /// <param name="source">The file source</param>
        /// <param name="archiveName">The archive name</param>
        /// <returns>true if successful, otherwise false</returns>
        private static bool CreateArchive(string source, string archiveName)
        {
            try
            {
                // Calculates the percent
                string CalculatePercent(int step, int max)
                {
                    return($"{100d / max * step:N2}");
                }

                var archivePath = Path.Combine(source, archiveName);
                if (File.Exists(archivePath))
                {
                    File.Delete(archivePath);
                }

                var count = 1;
                using (var zipFile = new ZipFile())
                {
                    var files = GlobalHelper.GetImageFiles(source);

                    foreach (var file in files)
                    {
                        OnInfo?.Invoke(GlobalHelper.InfoType.Info, $"Create archive ({CalculatePercent(count++, files.Count)}%)");
                        OnProgress?.Invoke(GlobalHelper.CalculateCurrentProgress(count, files.Count), 100);
                        zipFile.AddFile(file.File.FullName);
                    }

                    zipFile.Save(archivePath);
                }

                return(true);
            }
            catch (Exception ex)
            {
                OnInfo?.Invoke(GlobalHelper.InfoType.Error, $"An error has occured while creating the archive. Message: {ex.Message}");
                return(false);
            }
        }
예제 #13
0
        /// <summary>
        /// Message received.
        /// </summary>
        /// <param name="json"></param>
        private void OnMessage(string json)
        {
            var jsonOptions = new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };
            var baseMessage = JsonSerializer.Deserialize <BaseMessage>(json, jsonOptions);

            switch (baseMessage?.Type)
            {
            case "info":
                _waitForInfo?.Set();
                var infoMessage = JsonSerializer.Deserialize <InfoMessage>(json, jsonOptions);
                //Can contain settings from 2.3...
                OnInfo?.Invoke(infoMessage);
                break;

            case "closePlugin":
                throw new IOException("Close Message Received");

            case "listChange":
                var listChangeMessage = JsonSerializer.Deserialize <ListChangeMessage>(json, jsonOptions);
                OnListChange?.Invoke(listChangeMessage);
                break;

            case "broadcast":
            case "settings":
            case "down":
            case "up":
                //Not needed for this plugin.
                break;

            case "action":
                var actionMessage = JsonSerializer.Deserialize <ActionMessage>(json, jsonOptions);
                OnActionEvent?.Invoke(actionMessage);
                break;
            }
        }
예제 #14
0
 private void OnEngineInfo(string message, uint messageLength)
 {
     OnInfo?.Invoke(message);
 }
예제 #15
0
파일: BTDebug.cs 프로젝트: nistck/Jx
 public static void Info(string message, params object[] args)
 {
     OnInfo?.Invoke(message, args);
     Print("Info", message, args);
 }
예제 #16
0
 public void Info(string tag, string msg)
 {
     OnInfo?.Invoke(tag, msg);
     Console.WriteLine($"[INFO]{msg}");
 }
예제 #17
0
파일: Log.cs 프로젝트: Bosek/pluginloader
 public static void Info(string message)
 {
     OnInfo?.Invoke(message);
 }
예제 #18
0
        public static void Info(string format, params object[] objects)
        {
            string str = Format(format, objects);

            OnInfo?.Invoke(str);
        }
예제 #19
0
 public static void Info(string message, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) =>
 OnInfo?.Invoke(message, file, line);
예제 #20
0
        protected override void OnMessage(MessageEventArgs e)
        {
            if (!e.IsText)
            {
                return;
            }

            var msg = e.Data;

            logger.Debug(new LogReceivedMessage
            {
                Message = msg,
                Session = ID
            }.ToJson());

            string msgType = null;

            try
            {
                msgType = JObject.Parse(msg)["type"]?.ToObject <string>();

                switch (msgType)
                {
                case "Authorization":
                    OnAuthorization?.Invoke(this, Authorization.FromJson(msg));
                    return;

                case "Client.Initialized":
                    OnClientInitialized?.Invoke(this, ClientInitialized.FromJson(msg));
                    return;

                case "Client.Register":
                    OnClientRegister?.Invoke(this, ClientRegister.FromJson(msg));
                    return;

                case "Config.Change":
                    if (Configurer)
                    {
                        OnConfigChange?.Invoke(this, ConfigChange.FromJson(msg));
                    }

                    return;

                case "Config.Register":
                    Configurer = true;
                    Subscriber = true;
                    OnConfigRegister?.Invoke(this);
                    return;

                case "Config.Start":
                    if (Configurer)
                    {
                        OnConfigStart?.Invoke(this);
                    }

                    return;

                case "Config.Stop":
                    if (Configurer)
                    {
                        OnConfigStop?.Invoke(this);
                    }

                    return;

                case "Execution.StartRequest":
                    OnExecutionRequest?.Invoke(this, ExecutionStartRequest.FromJson(msg));
                    return;

                case "Execution.Started":
                    OnExecutionStarted?.Invoke(this, ExecutionStarted.FromJson(msg));
                    return;

                case "Execution.Stopped":
                    OnExecutionStopped?.Invoke(this, ExecutionStopped.FromJson(msg));
                    return;

                case "Info.Message":
                    OnInfo?.Invoke(this, InfoMessage.FromJson(msg));
                    return;

                case "Info.Subscribe":
                    if (!Subscriber)
                    {
                        Subscriber = true;
                        OnSubscribe?.Invoke(this);
                    }

                    return;

                case "Info.Unsubscribe":
                    Subscriber = false;
                    return;

                default:
                    logger.Info(new LogReceivedUnknownMessageType
                    {
                        MessageType = msgType,
                        Session     = ID
                    }.ToJson());

                    return;
                }
            }
            catch (Exception ex)
            {
                //logger.Error()
                logger.Error(new LogMessageHandlingError
                {
                    Exception   = ex,
                    MessageType = msgType,
                    Session     = ID
                }.ToJson());
            }
        }
예제 #21
0
        /// <summary>
        /// Logging proxy interface for informational messages.
        /// </summary>
        /// <param name="msg">
        /// The message.
        /// </param>
        /// <param name="callerName">
        /// Courtesy of compiler services, the name of the function from which this method was invoked.
        /// </param>
        /// <param name="callerFilePath">
        /// Courtesy of compiler services, the source file containing the function from which this
        /// method was invoked.
        /// </param>
        /// <param name="callerSourceLineNumber">
        /// Courtesy of compiler services, the line number in the source file from which this method
        /// was invoked.
        /// </param>
        /// <remarks>
        /// Though this is a public function, this is designed to be used by plugins or other such
        /// things extending classes in this binary. Unfortunately this last minute design change has
        /// forced us to make this public.
        /// </remarks>
        public void Info(string msg, [CallerMemberName] string callerName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerSourceLineNumber = 0)
        {
            var formatted = string.Format("{0}\t {2}::{1}() #{3}", msg, callerName, Path.GetFileName(callerFilePath), callerSourceLineNumber);

            OnInfo?.Invoke(formatted);
        }
예제 #22
0
파일: EventLogger.cs 프로젝트: woweh/FlaUI
 protected override void GatedInfo(string message)
 {
     OnInfo?.Invoke(message);
     OnLog?.Invoke(LogLevel.Info, message);
 }
예제 #23
0
 public void Info(string tag, string msg)
 {
     OnInfo?.Invoke(tag, msg);
 }
예제 #24
0
 /// <summary>
 /// Occurs when the info message of the thumbnail creator was raised
 /// </summary>
 /// <param name="infoType">The info type</param>
 /// <param name="message">The message</param>
 private static void ThumbnailManagerOnOnNewInfo(GlobalHelper.InfoType infoType, string message)
 {
     OnInfo?.Invoke(infoType, message);
 }
예제 #25
0
        /// <summary>
        /// Creates the html table
        /// </summary>
        /// <param name="imageFiles">The image files</param>
        /// <param name="source">The path of the source folder</param>
        /// <param name="createThumbnails">The value which indicates if the user want to use thumbnails</param>
        /// <param name="thumbHeight">The height of the thumbnail</param>
        /// <param name="thumbWidth">The width of the thumbnail</param>
        /// <param name="keepRatio">The value which indicates if the ratio should be keeped</param>
        /// <param name="headerText">The headertext</param>
        /// <param name="blankTarget">true to use a blank target</param>
        /// <param name="columnCount">The column count</param>
        /// <param name="imageFooter">The image footer id</param>
        /// <param name="createArchive">true if the user wants to create a archive</param>
        /// <param name="archiveName">The name of the archive</param>
        /// <param name="openPage">true when the pages should be opened at the end</param>
        public static void CreateHtmlTable(List <ImageModel> imageFiles, string source, bool createThumbnails, int thumbHeight, int thumbWidth,
                                           bool keepRatio, string headerText, bool blankTarget, int columnCount, FooterType imageFooter, bool createArchive, string archiveName, bool openPage)
        {
            try
            {
                archiveName = CreateArchiveName(archiveName ?? "");

                var imageSizeList = new Dictionary <string, ImageSize>();
                if (createThumbnails)
                {
                    ThumbnailManager.OnNewInfo  += ThumbnailManagerOnOnNewInfo;
                    ThumbnailManager.OnProgress += ThumbnailManager_OnProgress;
                    imageSizeList = ThumbnailManager.CreateThumbnails(imageFiles, source, thumbWidth, thumbHeight, keepRatio);
                    ThumbnailManager.OnProgress -= ThumbnailManager_OnProgress;
                    ThumbnailManager.OnNewInfo  -= ThumbnailManagerOnOnNewInfo;
                }

                var htmlTable = new StringBuilder("");
                var target    = blankTarget ? "target=\"_blank\"" : "";

                var count      = 1;
                var totalCount = 1;

                foreach (var image in imageFiles)
                {
                    OnInfo?.Invoke(GlobalHelper.InfoType.Info, $"Create image entry {totalCount} of {imageFiles.Count}");
                    OnProgress?.Invoke(GlobalHelper.CalculateCurrentProgress(totalCount, imageFiles.Count), 100);
                    if (count == 1)
                    {
                        htmlTable.AppendLine("<tr>");
                    }


                    if (!imageSizeList.TryGetValue(image.File.Name, out var imgSize))
                    {
                        imgSize = ImageSize.CreateDefault();
                    }

                    // Create the tag for the size
                    var imgSizeHtml = $"width=\"{imgSize.Width}\" height=\"{imgSize.Height}\"";

                    // Create the image tag
                    var thumbnail = createThumbnails
                        ? $"<img src=\"thumbnails/{image.File.Name}\" {imgSizeHtml} alt=\"{image.File.Name}\" title=\"{image.File.Name}\">"
                        : $"<img src=\"{image.File.Name}\" {imgSizeHtml} alt=\"{image.File.Name}\" title=\"{image.File.Name}\">";

                    htmlTable.AppendLine(
                        $"<td><a href=\"{image.File.Name}\" {target}>{thumbnail}</a>{CreateImageFooter(image, imageFooter, totalCount, imageFiles.Count)}</td>");

                    count++;
                    totalCount++;

                    if (count <= columnCount)
                    {
                        continue;
                    }
                    count = 1;
                    htmlTable.AppendLine("</tr>");
                }

                var archiveHtml = "";
                if (createArchive)
                {
                    if (CreateArchive(source, archiveName))
                    {
                        archiveHtml = $"You can download all pictures here: <a href=\"{CreateArchiveName(archiveName)}\">{CreateArchiveName(archiveName)}</a><br /><br />";
                    }
                }

                OnInfo?.Invoke(GlobalHelper.InfoType.Info, "Write data into file.");
                var indexPath = Path.Combine(source, "index.html");
                File.WriteAllText(indexPath, CreateFinaleHtml(headerText, htmlTable.ToString(), archiveHtml));

                if (File.Exists(indexPath))
                {
                    OnInfo?.Invoke(GlobalHelper.InfoType.Info, "File created.");
                    if (openPage)
                    {
                        Process.Start(indexPath);
                    }
                }
                else
                {
                    OnInfo?.Invoke(GlobalHelper.InfoType.Error, "Can't create file.");
                }
            }
            catch (Exception ex)
            {
                OnInfo?.Invoke(GlobalHelper.InfoType.Error, $"An error has occured. Message: {ex.Message}");
            }
        }
예제 #26
0
 public static void Info(string category, string message)
 {
     OnInfo?.Invoke(category, message);
 }
예제 #27
0
 /// <summary>
 /// Information event
 /// </summary>
 /// <param name="message">message</param>
 private static void OnInfoHandle(string message)
 {
     //Invoke event
     OnInfo?.Invoke(message);
 }
예제 #28
0
 private void Transport_OnInfo(object sender, string info)
 {
     OnInfo?.Invoke(this, info);
 }
예제 #29
0
파일: Version.cs 프로젝트: nankeyu/biliroku
        private void Check()
        {
            Task.Run(() =>
            {
                OnInfo?.Invoke(this, "检查更新。");

                var ApiUrl = "https://api.github.com/repos/zyzsdy/biliroku/releases";
                var wc     = new WebClient();
                wc.Headers.Add("Accept: application/json;q=0.9,*/*;q=0.5");
                wc.Headers.Add("User-Agent: " + Ver.UA);
                wc.Headers.Add("Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4");

                //发送HTTP请求获取Release信息
                string releaseJson = null;

                try
                {
                    var releaseByte = wc.DownloadData(ApiUrl);
                    releaseJson     = System.Text.Encoding.GetEncoding("UTF-8").GetString(releaseByte);
                }
                catch (Exception e)
                {
                    OnInfo?.Invoke(this, "检查更新失败:" + e.Message);
                }

                //提取最新版的release信息
                if (releaseJson != null)
                {
                    try
                    {
                        var releaseObj  = JArray.Parse(releaseJson);
                        var releaseNote = releaseObj[0];
                        var tag         = releaseNote["tag_name"].ToString();
                        var url         = releaseNote["html_url"].ToString();
                        Version verCurrent, verNew;
                        verCurrent = Version.Parse(Ver.VER);
                        if (Version.TryParse(tag, out verNew))
                        {
                            if (verNew > verCurrent)
                            {
                                try
                                {
                                    OnResult?.Invoke(this, new UpdateResultArgs
                                    {
                                        version = tag,
                                        url     = url
                                    });
                                }catch (Exception e)
                                {
                                    OnInfo?.Invoke(this, "发现新版本,但是出了点罕见错误:" + e.Message);
                                }

                                OnInfo?.Invoke(this, "发现新版本" + tag + ",下载地址:" + url);
                            }
                            else
                            {
                                OnInfo?.Invoke(this, "当前已是最新版本。");
                            }
                        }
                        else
                        {
                            OnInfo?.Invoke(this, "版本信息无法解析。");
                        }
                    }
                    catch (Exception e)
                    {
                        OnInfo?.Invoke(this, "更新信息解析失败:" + e.Message);
                        OnInfo?.Invoke(this, releaseJson);
                    }
                }
            });
        }
예제 #30
0
파일: Log.cs 프로젝트: Bosek/pluginloader
 public void Info(string text = "")
 {
     OnInfo?.Invoke(text);
 }