public void WarnFormat(string format, object arg0) { LOGGER.WarnFormat(format, arg0); }
/// <summary> /// Logs the warning message. /// </summary> /// <param name="format">The format.</param> /// <param name="arg0">The arg0.</param> public void WarnFormat(string format, object arg0) { m_Log.WarnFormat(format, arg0); }
public void WarnFormat(string format, params object[] args) { _log.WarnFormat(format, args); }
public void testBlackBox() { Assert.IsFalse(testResults.Count == 0); IEnumerable <string> imageFiles = getImageFiles(); int testCount = testResults.Count; int[] passedCounts = new int[testCount]; int[] misreadCounts = new int[testCount]; int[] tryHarderCounts = new int[testCount]; int[] tryHarderMisreadCounts = new int[testCount]; foreach (var testImage in imageFiles) { var absPath = Path.GetFullPath(testImage); Log.InfoFormat("Starting {0}", absPath); var image = new Bitmap(Image.FromFile(testImage)); String expectedText; String expectedTextFile = Path.Combine(Path.GetDirectoryName(absPath), Path.GetFileNameWithoutExtension(absPath) + ".txt"); if (File.Exists(expectedTextFile)) { expectedText = File.ReadAllText(expectedTextFile, System.Text.Encoding.UTF8); } else { String expectedBinFile = Path.Combine(Path.GetDirectoryName(absPath), Path.GetFileNameWithoutExtension(absPath) + ".bin"); if (File.Exists(expectedBinFile)) { // it is only a dirty workaround for some special cases expectedText = File.ReadAllText(expectedBinFile, System.Text.Encoding.GetEncoding("ISO8859-1")); } else { throw new InvalidOperationException("Missing expected result file: " + expectedTextFile); } } String expectedMetadataFile = Path.Combine(Path.GetDirectoryName(absPath), Path.GetFileNameWithoutExtension(absPath) + ".metadata.txt"); var expectedMetadata = new Dictionary <string, string>(); if (File.Exists(expectedMetadataFile)) { foreach (var row in File.ReadLines(expectedMetadataFile)) { expectedMetadata.Add(row.Split('=')[0], string.Join("=", row.Split('=').Skip(1).ToArray())); } } for (int x = 0; x < testCount; x++) { var testResult = testResults[x]; float rotation = testResult.Rotation; var rotatedImage = rotateImage(image, rotation); LuminanceSource source = new BitmapLuminanceSource(rotatedImage); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) { passedCounts[x]++; Log.Info(" without try-hard ... ok."); } else { misreadCounts[x]++; Log.Info(" without try-hard ... fail."); } } catch (ReaderException) { // continue Log.Info(" without try-hard ... fail (exc)."); } try { if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) { tryHarderCounts[x]++; Log.Info(" with try-hard ... ok."); } else { tryHarderMisreadCounts[x]++; Log.Info(" with try-hard ... fail."); } } catch (ReaderException) { // continue Log.Info(" with try-hard ... fail (exc)."); } } } // Print the results of all tests first int totalFound = 0; int totalMustPass = 0; int totalMisread = 0; int totalMaxMisread = 0; var imageFilesCount = imageFiles.Count(); for (int x = 0; x < testResults.Count; x++) { TestResult testResult = testResults[x]; Log.InfoFormat("Rotation {0} degrees:", (int)testResult.Rotation); Log.InfoFormat(" {0} of {1} images passed ({2} required)", passedCounts[x], imageFilesCount, testResult.MustPassCount); int failed = imageFilesCount - passedCounts[x]; Log.InfoFormat(" {0} failed due to misreads, {1} not detected", misreadCounts[x], failed - misreadCounts[x]); Log.InfoFormat(" {0} of {1} images passed with try harder ({2} required)", tryHarderCounts[x], imageFilesCount, testResult.TryHarderCount); failed = imageFilesCount - tryHarderCounts[x]; Log.InfoFormat(" {0} failed due to misreads, {1} not detected", tryHarderMisreadCounts[x], failed - tryHarderMisreadCounts[x]); totalFound += passedCounts[x] + tryHarderCounts[x]; totalMustPass += testResult.MustPassCount + testResult.TryHarderCount; totalMisread += misreadCounts[x] + tryHarderMisreadCounts[x]; totalMaxMisread += testResult.MaxMisreads + testResult.MaxTryHarderMisreads; } int totalTests = imageFilesCount * testCount * 2; Log.InfoFormat("Decoded {0} images out of {1} ({2}%, {3} required)", totalFound, totalTests, totalFound * 100 / totalTests, totalMustPass); if (totalFound > totalMustPass) { Log.WarnFormat("+++ Test too lax by {0} images", totalFound - totalMustPass); } else if (totalFound < totalMustPass) { Log.WarnFormat("--- Test failed by {0} images", totalMustPass - totalFound); } if (totalMisread < totalMaxMisread) { Log.WarnFormat("+++ Test expects too many misreads by {0} images", totalMaxMisread - totalMisread); } else if (totalMisread > totalMaxMisread) { Log.WarnFormat("--- Test had too many misreads by {0} images", totalMisread - totalMaxMisread); } // Then run through again and assert if any failed for (int x = 0; x < testCount; x++) { TestResult testResult = testResults[x]; String label = "Rotation " + testResult.Rotation + " degrees: Too many images failed"; Assert.IsTrue(passedCounts[x] >= testResult.MustPassCount, label); Assert.IsTrue(tryHarderCounts[x] >= testResult.TryHarderCount, "Try harder, " + label); label = "Rotation " + testResult.Rotation + " degrees: Too many images misread"; Assert.IsTrue(misreadCounts[x] <= testResult.MaxMisreads, label); Assert.IsTrue(tryHarderMisreadCounts[x] <= testResult.MaxTryHarderMisreads, "Try harder, " + label); } }
public SummaryResults testPDF417BlackBoxCountingResults(bool assertOnFailure) { Assert.IsFalse(testResults.Count == 0); IDictionary <String, List <String> > imageFiles = getImageFileLists(); int testCount = testResults.Count; int[] passedCounts = new int[testCount]; int[] misreadCounts = new int[testCount]; int[] tryHarderCounts = new int[testCount]; int[] tryHaderMisreadCounts = new int[testCount]; foreach (KeyValuePair <String, List <String> > testImageGroup in imageFiles) { log.InfoFormat("Starting Image Group {0}", testImageGroup.Key); String fileBaseName = testImageGroup.Key; String expectedText; String expectedTextFile = fileBaseName + ".txt"; if (File.Exists(expectedTextFile)) { expectedText = File.ReadAllText(expectedTextFile, UTF8); } else { expectedTextFile = fileBaseName + ".bin"; Assert.IsTrue(File.Exists(expectedTextFile)); expectedText = File.ReadAllText(expectedTextFile, ISO88591); } for (int x = 0; x < testCount; x++) { List <Result> results = new List <Result>(); foreach (var imageFile in testImageGroup.Value) { #if !SILVERLIGHT var image = new Bitmap(Image.FromFile(imageFile)); #else var image = new WriteableBitmap(0, 0); image.SetSource(File.OpenRead(testImage)); #endif var rotation = testResults[x].Rotation; var rotatedImage = rotateImage(image, rotation); var source = new BitmapLuminanceSource(rotatedImage); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { results.AddRange(decode(bitmap, false)); } catch (ReaderException ignored) { // ignore } } results.Sort((arg0, arg1) => { PDF417ResultMetadata resultMetadata = getMeta(arg0); PDF417ResultMetadata otherResultMetadata = getMeta(arg1); return(resultMetadata.SegmentIndex - otherResultMetadata.SegmentIndex); }); var resultText = new StringBuilder(); String fileId = null; foreach (Result result in results) { PDF417ResultMetadata resultMetadata = getMeta(result); Assert.NotNull(resultMetadata, "resultMetadata"); if (fileId == null) { fileId = resultMetadata.FileId; } Assert.AreEqual(fileId, resultMetadata.FileId, "FileId"); resultText.Append(result.Text); } Assert.AreEqual(expectedText, resultText.ToString(), "ExpectedText"); passedCounts[x]++; tryHarderCounts[x]++; } } // Print the results of all tests first int totalFound = 0; int totalMustPass = 0; int totalMisread = 0; int totalMaxMisread = 0; int numberOfTests = imageFiles.Count; for (int x = 0; x < testResults.Count; x++) { TestResult testResult = testResults[x]; log.InfoFormat("Rotation {0} degrees:", (int)testResult.Rotation); log.InfoFormat(" {0} of {1} images passed ({2} required)", passedCounts[x], numberOfTests, testResult.MustPassCount); int failed = numberOfTests - passedCounts[x]; log.InfoFormat(" {0} failed due to misreads, {1} not detected", misreadCounts[x], failed - misreadCounts[x]); log.InfoFormat(" {0} of {1} images passed with try harder ({2} required)", tryHarderCounts[x], numberOfTests, testResult.TryHarderCount); failed = numberOfTests - tryHarderCounts[x]; log.InfoFormat(" {0} failed due to misreads, {1} not detected", tryHaderMisreadCounts[x], failed - tryHaderMisreadCounts[x]); totalFound += passedCounts[x] + tryHarderCounts[x]; totalMustPass += testResult.MustPassCount + testResult.TryHarderCount; totalMisread += misreadCounts[x] + tryHaderMisreadCounts[x]; totalMaxMisread += testResult.MaxMisreads + testResult.MaxTryHarderMisreads; } int totalTests = numberOfTests * testCount * 2; log.InfoFormat("Decoded {0} images out of {1} ({2}%, {3} required)", totalFound, totalTests, totalFound * 100 / totalTests, totalMustPass); if (totalFound > totalMustPass) { log.WarnFormat("+++ Test too lax by {0} images", totalFound - totalMustPass); } else if (totalFound < totalMustPass) { log.WarnFormat("--- Test failed by {0} images", totalMustPass - totalFound); } if (totalMisread < totalMaxMisread) { log.WarnFormat("+++ Test expects too many misreads by {0} images", totalMaxMisread - totalMisread); } else if (totalMisread > totalMaxMisread) { log.WarnFormat("--- Test had too many misreads by {0} images", totalMisread - totalMaxMisread); } // Then run through again and assert if any failed if (assertOnFailure) { for (int x = 0; x < testCount; x++) { TestResult testResult = testResults[x]; String label = "Rotation " + testResult.Rotation + " degrees: Too many images failed"; Assert.IsTrue(passedCounts[x] >= testResult.MustPassCount, label); Assert.IsTrue(tryHarderCounts[x] >= testResult.TryHarderCount, "Try harder, " + label); label = "Rotation " + testResult.Rotation + " degrees: Too many images misread"; Assert.IsTrue(misreadCounts[x] <= testResult.MaxMisreads, label); Assert.IsTrue(tryHaderMisreadCounts[x] <= testResult.MaxTryHarderMisreads, "Try harder, " + label); } } return(new SummaryResults(totalFound, totalMustPass, totalTests)); }
/// <summary> /// 记录warn /// </summary> /// <param name="t"></param> /// <param name="e"></param> #region public static void warn(Type t, Exception e) public static void warn(Type t, Exception e) { log4net.ILog logger = log4net.LogManager.GetLogger(t); logger.WarnFormat("Warn: {0}", e); }
/// <summary> /// Force get topic metadata and update /// </summary> public void UpdateInfo(short versionId, int correlationId, string clientId, string topic) { Logger.InfoFormat("Will update metadata for topic:{0}", topic); Guard.NotNullNorEmpty(topic, "topic"); var shuffledBrokers = this.syncProducerPool.GetShuffledProducers(); var i = 0; var hasFetchedInfo = false; while (i < shuffledBrokers.Count && !hasFetchedInfo) { ISyncProducer producer = shuffledBrokers[i++]; try { var topicMetadataRequest = TopicMetadataRequest.Create(new List <string>() { topic }, versionId, correlationId, clientId); var topicMetadataList = producer.Send(topicMetadataRequest); var topicMetadata = topicMetadataList.Any() ? topicMetadataList.First() : null; if (topicMetadata != null) { if (topicMetadata.Error != ErrorMapping.NoError) { Logger.WarnFormat("Try get metadata of topic {0} from {1}({2}) . Got error: {3}", topic, producer.Config.BrokerId, producer.Config.Host, topicMetadata.Error.ToString()); } else { this.topicPartitionInfo[topic] = topicMetadata; this.topicPartitionInfoLastUpdateTime[topic] = DateTime.UtcNow; Logger.InfoFormat("Will Update metadata info, topic {0} ", topic); //TODO: For all partitions which has metadata, here return the sorted list. //But sometimes kafka didn't return metadata for all topics. this.topicPartitionInfoList[topic] = topicMetadata.PartitionsMetadata.Select(m => { Partition partition = new Partition(topic, m.PartitionId); if (m.Leader != null) { var leaderReplica = new Replica(m.Leader.Id, topic); partition.Leader = leaderReplica; Logger.InfoFormat("Topic {0} partition {1} has leader {2}", topic, m.PartitionId, m.Leader.Id); return(partition); } Logger.WarnFormat("Topic {0} partition {1} does not have a leader yet", topic, m.PartitionId); return(partition); } ).OrderBy(x => x.PartId).ToList();; hasFetchedInfo = true; Logger.InfoFormat("Finish Update metadata info, topic {0} Partitions:{1} No leader:{2}", topic, this.topicPartitionInfoList[topic].Count, this.topicPartitionInfoList[topic].Where(r => r.Leader == null).Count()); //In very weired case, the kafka broker didn't return metadata of all broker. need break and retry. https://issues.apache.org/jira/browse/KAFKA-1998 // http://qnalist.com/questions/5899394/topicmetadata-response-miss-some-partitions-information-sometimes if (zkClient != null) { Dictionary <int, int[]> topicMetaDataInZookeeper = ZkUtils.GetTopicMetadataInzookeeper(this.zkClient, topic); if (topicMetaDataInZookeeper != null && topicMetaDataInZookeeper.Any()) { topicDataInZookeeper[topic] = topicMetaDataInZookeeper; if (this.topicPartitionInfoList[topic].Count != topicMetaDataInZookeeper.Count) { Logger.ErrorFormat("NOT all partition has metadata. Topic partition in zookeeper :{0} topics has partition metadata: {1}", topicMetaDataInZookeeper.Count, this.topicPartitionInfoList[topic].Count); throw new UnavailableProducerException(string.Format("Please make sure every partition at least has one broker running and retry again. NOT all partition has metadata. Topic partition in zookeeper :{0} topics has partition metadata: {1}", topicMetaDataInZookeeper.Count, this.topicPartitionInfoList[topic].Count)); } } } } } } catch (Exception e) { Logger.ErrorFormat("Try get metadata of topic {0} from {1}({2}) . Got error: {3}", topic, producer.Config.BrokerId, producer.Config.Host, e.FormatException()); } } }
internal void Consume() { // connects to zookeeper using (ZookeeperConsumerConnector connector = new ZookeeperConsumerConnector(configSettings, true)) { if (this.ThreadID == 0) { ConsumerGroupHelper.initialOffset = connector.GetOffset(cgOptions.Topic); //Logger.InfoFormat("======Original offset \r\n{0}", ConsumerGroupHelper.initialOffset == null ? "(NULL)" : ConsumeGroupMonitorHelper.GetComsumerGroupOffsetsAsLog(ConsumerGroupHelper.initialOffset)); } // defines collection of topics and number of threads to consume it with // ===============NOTE============================ // For example , if there is 80 partitions for one topic. // // Normally start more than 96 = 80*120% clients with same GroupId. ( the extra 20% are buffer for autopilot IMP). And set FetchThreadCountPerConsumer as 1. // Then 80 clients can lock partitions, can set MACHINENAME_ProcessID as ConsumerId, other 16 are idle. Strongly recomand take this method. // // If start 40 clients, and set FetchThreadCountPerConsumer as 1. then every client can lock 2 partitions at least. And if some client not available for autopilot // IMP reason, then some of the client maybe lock 3 partitions. // // If start 40 clients, and set FetchThreadCountPerConsumer as 2, you will get two IEnumerator<Message>:topicData[0].GetEnumerator(),topicData[1].GetEnumerator() // you need start TWO threads to process them in dependently. // If the client get 2 partitions, each thread will handle 1 partition, // If the client get 3 partitions, then one thread get 2 partitions, the other one get 1 partition. It will make the situaiton complex and the consume of partition not balance. //==================NOTE============================= IDictionary <string, int> topicMap = new Dictionary <string, int> { { cgOptions.Topic, cgOptions.FetchThreadCountPerConsumer } }; // get references to topic streams. IDictionary <string, IList <KafkaMessageStream <Message> > > streams = connector.CreateMessageStreams(topicMap, new DefaultDecoder()); IList <KafkaMessageStream <Message> > topicData = streams[cgOptions.Topic]; long latestTotalCount = 0; bool hitEndAndCommited = false; if (cgOptions.CancellationTimeoutMs == 5000) { // Get the message enumerator. IEnumerator <Message> messageEnumerator = topicData[0].GetEnumerator(); //TODO: the enumerator count equal with FetchThreadCountPerConsumer . For example, if that value is 5, then here should get 5 enumerator. //IF have 100 partitions, and only 20 consumers, need set this value to 5. and start 5 thread handle each one. // Add tuples until maximum receive message count is reached or no new messages read after consumer configured timeout. while (true) { bool noMoreMessage = false; try { messageEnumerator.MoveNext(); Message m = messageEnumerator.Current; latestTotalCount = Interlocked.Increment(ref ConsumerGroupHelper.totalCount); Logger.InfoFormat("Message {0} from Partition:{1}, Offset:{2}, key:{3}, value:{4}", latestTotalCount, m.PartitionId, m.Offset, m.Key == null ? "(null)" : Encoding.UTF8.GetString(m.Key), m.Payload == null ? "(null)" : Encoding.UTF8.GetString(m.Payload)); if (latestTotalCount == 1) { Logger.WarnFormat("Read FIRST message, it's offset: {0} PartitionID:{1}", m.Offset, ((ConsumerIterator <Message>)messageEnumerator).currentTopicInfo.PartitionId); } hitEndAndCommited = false; if (latestTotalCount % cgOptions.CommitBatchSize == 0) { //NOTE====== //Normally, just directly call .CommitOffsets() // CommitOffset(string topic, int partition, long offset) only used when customer has strong requirement for reprocess messages as few as possible. //Need tune the frequecy of calling .CommitOffsets(), it will directly increate zookeeper load and impact your overall performance if (cgOptions.CommitOffsetWithPartitionIDOffset) { connector.CommitOffset(cgOptions.Topic, m.PartitionId.Value, m.Offset); } else { connector.CommitOffsets(); } Console.WriteLine("\tRead some and commit once, LATEST message offset: {0}. PartitionID:{1} -- {2} Totally read {3} will commit offset. {4} FetchOffset:{5} ConsumeOffset:{6} CommitedOffset:{7}" , m.Offset, m.PartitionId.Value, ((ConsumerIterator <Message>)messageEnumerator).currentTopicInfo.PartitionId, latestTotalCount, DateTime.Now , ((ConsumerIterator <Message>)messageEnumerator).currentTopicInfo.FetchOffset , ((ConsumerIterator <Message>)messageEnumerator).currentTopicInfo.ConsumeOffset , ((ConsumerIterator <Message>)messageEnumerator).currentTopicInfo.CommitedOffset); } if (cgOptions.Count > 0 && latestTotalCount >= cgOptions.Count) { Logger.WarnFormat("Read LAST message, it's offset: {0}. PartitionID:{1} Totally read {2} want {3} will exit.", m.Offset, ((ConsumerIterator <Message>)messageEnumerator).currentTopicInfo.PartitionId, latestTotalCount, cgOptions.Count); break; } } catch (ConsumerTimeoutException) { if (!hitEndAndCommited) { Logger.WarnFormat("Totally Read {0} will commit offset. {1}", latestTotalCount, DateTime.Now); connector.CommitOffsets(); hitEndAndCommited = true; } // Thrown if no new messages read after consumer configured timeout. noMoreMessage = true; } if (noMoreMessage) { Logger.InfoFormat("No more message , hit end ,will Sleep(1), {0}", DateTime.Now); if (cgOptions.SleepTypeWhileAlwaysRead == 0) { Thread.Sleep(0); } else if (cgOptions.SleepTypeWhileAlwaysRead == 1) { Thread.Sleep(1); //Best choice is Thread.Sleep(1). Other 3 choice still make the CPU 100% } else if (cgOptions.SleepTypeWhileAlwaysRead == 2) { Thread.Yield(); } else { } } } } else { //Siphon scenario, repeatly take some messages and process. if no enough messages, will stop current batch after timeout. while (true) { #if NET45 bool noMoreMessage = false; Message lastMessage = null; int count = 0; KafkaMessageStream <Message> messagesStream = null; ConsumerIterator <Message> iterator = null; using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(cgOptions.CancellationTimeoutMs)) { lastMessage = null; IEnumerable <Message> messages = topicData[0].GetCancellable(cancellationTokenSource.Token); messagesStream = (KafkaMessageStream <Message>)messages; iterator = (ConsumerIterator <Message>)messagesStream.iterator; foreach (Message message in messages) { latestTotalCount = Interlocked.Increment(ref ConsumerGroupHelper.totalCount); lastMessage = message; if (latestTotalCount == 1) { PartitionTopicInfo p = iterator.currentTopicInfo; Logger.InfoFormat("Read FIRST message, it's offset: {0} PartitionID:{1}", lastMessage.Offset, p == null ? "null" : p.PartitionId.ToString()); } hitEndAndCommited = false; if (++count >= cgOptions.CommitBatchSize) { cancellationTokenSource.Cancel(); } } } if (count > 0) { connector.CommitOffsets(); consumedTotalCount += count; PartitionTopicInfo p = iterator.currentTopicInfo; Console.WriteLine("\tRead some and commit once, Thread: {8} consumedTotalCount:{9} Target:{10} LATEST message offset: {0}. PartitionID:{1} -- {2} Totally read {3} will commit offset. {4} FetchOffset:{5} ConsumeOffset:{6} CommitedOffset:{7}" , lastMessage.Offset, lastMessage.PartitionId.Value, p == null ? "null" : p.PartitionId.ToString(), latestTotalCount, DateTime.Now , p == null ? "null" : p.FetchOffset.ToString() , p == null ? "null" : p.ConsumeOffset.ToString() , p == null ? "null" : p.CommitedOffset.ToString() , this.ThreadID , this.consumedTotalCount , this.Count); } else { noMoreMessage = true; } if (this.Count > 0 && consumedTotalCount >= this.Count) { Logger.InfoFormat("Current thrad Read LAST message, Totally read {0} want {1} will exit current thread.", consumedTotalCount, this.Count); break; } if (noMoreMessage) { Logger.InfoFormat("No more message , hit end ,will Sleep(2000), {0}", DateTime.Now); if (cgOptions.SleepTypeWhileAlwaysRead == 0) { Thread.Sleep(0); } else if (cgOptions.SleepTypeWhileAlwaysRead == 1) { Thread.Sleep(2000); //Best choice is Thread.Sleep(1). Other 3 choice still make the CPU 100% } else if (cgOptions.SleepTypeWhileAlwaysRead == 2) { Thread.Yield(); } else { } } #endif #if NET4 throw new NotSupportedException("Please use .net45 to compile ."); #endif } } Logger.InfoFormat("Read {0} will commit offset. {1}", latestTotalCount, DateTime.Now); connector.CommitOffsets(); latestTotalCount = Interlocked.Read(ref ConsumerGroupHelper.totalCount); Logger.InfoFormat("Totally read {0} want {1} . ", latestTotalCount, cgOptions.Count); if (this.ThreadID == 0) { ConsumerGroupHelper.newOffset = connector.GetOffset(cgOptions.Topic); } } this.resetEvent.Set(); }
public void Warn(string message, params object[] args) { logger.WarnFormat(message, args); }
private EnvelopeType _export(Session xenSession, string targetPath, string ovfname, string vmUuid) { EnvelopeType ovfEnv; try { auditLog.DebugFormat("Export: {0}, {1}", ovfname, targetPath); #region GET VM Reference XenRef <VM> vmRef = null; try { vmRef = VM.get_by_uuid(xenSession, vmUuid); } catch { log.WarnFormat("VM not found as uuid: {0}, trying as name-label", vmUuid); vmRef = null; } if (vmRef == null) { try { List <XenRef <VM> > vmRefs = VM.get_by_name_label(xenSession, vmUuid); vmRef = vmRefs[0]; traceLog.DebugFormat("{0} VM(s) found by label {1}", vmRefs.Count, vmUuid); if (vmRefs.Count > 1) { log.WarnFormat("Only exporting FIRST VM with name {0}", vmUuid); } } catch { log.ErrorFormat(Messages.ERROR_VM_NOT_FOUND, vmUuid); throw; } } #endregion VM vm = VM.get_record(xenSession, vmRef); if (vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Suspended) { var message = string.Format(Messages.ERROR_VM_NOT_HALTED, vm.Name()); OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ExportProgress, "Export", message)); log.Info(message); throw new Exception(message); } #region CREATE ENVELOPE / ADD VIRTUAL SYSTEM ovfEnv = OVF.CreateEnvelope(ovfname); string vsId = OVF.AddVirtualSystem(ovfEnv, vm.name_label); string vhsId = OVF.AddVirtualHardwareSection(ovfEnv, vsId); #endregion #region TRY TO ID OS XenRef <VM_guest_metrics> vmgmRef = VM.get_guest_metrics(xenSession, vmRef); if (!vmgmRef.opaque_ref.ToUpper().Contains("NULL")) { VM_guest_metrics vmgm = VM_guest_metrics.get_record(xenSession, vmgmRef); //VM_metrics vmm = VM_metrics.get_record(xenSession, VM.get_metrics(xenSession, vmRef)); if (vmgm.os_version != null && vmgm.os_version.Count > 0) { foreach (string key in vmgm.os_version.Keys) { if (key.ToLower().Equals("name")) { ushort osid = ValueMaps.OperatingSystem(vmgm.os_version[key]); if (osid == 0xFFFF) { osid = 1; } // change to OTHER since search failed. string version = OVF.GetContentMessage("SECTION_OPERATINGSYSTEM_INFO"); if (vmgm.os_version.ContainsKey("major") && vmgm.os_version.ContainsKey("minor")) { version = string.Format(OVF.GetContentMessage("SECTION_OPERATINGSYSTEM_VERSION"), vmgm.os_version["major"], vmgm.os_version["minor"]); } string osname = (vmgm.os_version[key].Split(new [] { '|' }))[0]; OVF.UpdateOperatingSystemSection(ovfEnv, vsId, osname, version, osid); break; } } } } #endregion #region ADD VSSD // IS PV'd? for VirtualSystemType identification. string typeformat = @"{0}-{1}-{2}"; string vmtype = string.Format(typeformat, "hvm", "3.0", "unknown"); if (vm.HVM_boot_policy != null && vm.HVM_boot_policy == Properties.Settings.Default.xenBootOptions) { if (!string.IsNullOrEmpty(vm.domarch)) { vmtype = string.Format(typeformat, vm.domarch, "3.0", "unknown"); } } else { if (!string.IsNullOrEmpty(vm.domarch)) { vmtype = string.Format(typeformat, "xen", "3.0", vm.domarch); } else { vmtype = string.Format(typeformat, "xen", "3.0", "unknown"); } } OVF.AddVirtualSystemSettingData(ovfEnv, vsId, vhsId, vm.name_label, OVF.GetContentMessage("VSSD_CAPTION"), vm.name_description, Guid.NewGuid().ToString(), vmtype); #endregion #region ADD CPUS OVF.SetCPUs(ovfEnv, vsId, (ulong)vm.VCPUs_max); #endregion #region ADD MEMORY OVF.SetMemory(ovfEnv, vsId, (ulong)(vm.memory_dynamic_max / MB), "MB"); #endregion #region ADD NETWORKS List <XenRef <VIF> > vifs = VM.get_VIFs(xenSession, vmRef); foreach (XenRef <VIF> vifref in vifs) { VIF vif = VIF.get_record(xenSession, vifref); XenRef <Network> netRef = vif.network; Network net = Network.get_record(xenSession, netRef); // Why is the following call reference using name_label where other references use uuid? OVF.AddNetwork(ovfEnv, vsId, net.uuid, net.name_label, net.name_description, vif.MAC); } #endregion #region SET STARTUP OPTIONS OVF.AddStartupSection(ovfEnv, true, vsId, vm.order, vm.start_delay, vm.shutdown_delay); #endregion #region GET AND EXPORT DISKS using iSCSI List <XenRef <VBD> > vbdlist = VM.get_VBDs(xenSession, vmRef); _vdiRefs.Clear(); int diskIndex = 0; foreach (XenRef <VBD> vbdref in vbdlist) { VBD vbd = VBD.get_record(xenSession, vbdref); if (vbd.type == vbd_type.CD) { string rasdid = OVF.AddCDROM(ovfEnv, vsId, vbd.uuid, OVF.GetContentMessage("RASD_16_CAPTION"), OVF.GetContentMessage("RASD_16_DESCRIPTION")); OVF.SetTargetDeviceInRASD(ovfEnv, vsId, rasdid, vbd.userdevice); } else { try { XenRef <VDI> vdi = VBD.get_VDI(xenSession, vbdref); if (vdi != null && !string.IsNullOrEmpty(vdi.opaque_ref) && !(vdi.opaque_ref.ToLower().Contains("null"))) { _vdiRefs.Add(vdi); VDI lVdi = VDI.get_record(xenSession, vdi); string destinationFilename = Path.Combine(targetPath, string.Format(@"{0}.vhd", lVdi.uuid)); string diskid = Guid.NewGuid().ToString(); string diskName = lVdi.name_label; if (diskName == null) { diskName = string.Format("{0} {1}", OVF.GetContentMessage("RASD_19_CAPTION"), diskIndex); } OVF.AddDisk(ovfEnv, vsId, diskid, Path.GetFileName(destinationFilename), vbd.bootable, diskName, lVdi.name_description, (ulong)lVdi.physical_utilisation, (ulong)lVdi.virtual_size); OVF.SetTargetDeviceInRASD(ovfEnv, vsId, diskid, vbd.userdevice); diskIndex++; } } catch (Exception ex) { log.InfoFormat("Export: VBD Skipped: {0}: {1}", vbdref, ex.Message); } } } #endregion if (!MetaDataOnly) { _copydisks(ovfEnv, ovfname, targetPath); } #region ADD XEN SPECIFICS if (vm.HVM_boot_params != null) { Dictionary <string, string> _params = vm.HVM_boot_params; foreach (string key in _params.Keys) { if (key.ToLower().Equals("order")) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "HVM_boot_params", _params[key], OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } } } if (!string.IsNullOrEmpty(vm.HVM_boot_policy)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "HVM_boot_policy", vm.HVM_boot_policy, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_2")); } if (vm.HVM_shadow_multiplier != 1.0) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "HVM_shadow_multiplier", Convert.ToString(vm.HVM_shadow_multiplier), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (vm.platform != null) { Dictionary <string, string> platform = vm.platform; StringBuilder sb = new StringBuilder(); foreach (string key in platform.Keys) { sb.AppendFormat(@"{0}={1};", key, platform[key]); } OVF.AddOtherSystemSettingData(ovfEnv, vsId, "platform", sb.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_3")); } if (!string.IsNullOrEmpty(vm.PV_args)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_args", vm.PV_args, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (!string.IsNullOrEmpty(vm.PV_bootloader)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_bootloader", vm.PV_bootloader, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (!string.IsNullOrEmpty(vm.PV_bootloader_args)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_bootloader_args", vm.PV_bootloader_args, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (!string.IsNullOrEmpty(vm.PV_kernel)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_kernel", vm.PV_kernel, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (!string.IsNullOrEmpty(vm.PV_legacy_args)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_legacy_args", vm.PV_legacy_args, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (!string.IsNullOrEmpty(vm.PV_ramdisk)) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "PV_ramdisk", vm.PV_ramdisk, OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (vm.hardware_platform_version >= 0) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "hardware_platform_version", vm.hardware_platform_version.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (vm.HasSriovRecommendation()) { OVF.AddOtherSystemSettingData(ovfEnv, vsId, "allow_network_sriov", bool.TrueString.ToLowerInvariant(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (vm.has_vendor_device) { //serialise it with a different name to avoid it being deserialised automatically and getting the wrong type OVF.AddOtherSystemSettingData(ovfEnv, vsId, "VM_has_vendor_device", vm.has_vendor_device.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_1")); } if (vm.VGPUs.Count != 0) { VGPU vgpu = VGPU.get_record(xenSession, vm.VGPUs[0]); if (vgpu != null) { var vgpuGroup = GPU_group.get_record(xenSession, vgpu.GPU_group); var vgpuType = VGPU_type.get_record(xenSession, vgpu.type); var sb = new StringBuilder(); sb.AppendFormat("GPU_types={{{0}}};", vgpuGroup.GPU_types == null || vgpuGroup.GPU_types.Length < 1 ? "" : string.Join(";", vgpuGroup.GPU_types)); sb.AppendFormat("VGPU_type_vendor_name={0};", vgpuType.vendor_name ?? ""); sb.AppendFormat("VGPU_type_model_name={0};", vgpuType.model_name ?? ""); OVF.AddOtherSystemSettingData(ovfEnv, vsId, "vgpu", sb.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_4")); } } string pvsSiteUuid = string.Empty; var allProxies = xenSession.Connection.Cache.PVS_proxies; foreach (var p in allProxies.Where(p => p != null && p.VIF != null)) { var vif = xenSession.Connection.Resolve(p.VIF); if (vif != null) { var vmFromVif = xenSession.Connection.Resolve(vif.VM); if (vmFromVif != null && vmFromVif.uuid == vm.uuid) { var pvsSite = xenSession.Connection.Resolve(p.site); if (pvsSite != null) { pvsSiteUuid = pvsSite.uuid; } break; } } } if (!string.IsNullOrEmpty(pvsSiteUuid)) { var sb = new StringBuilder(); sb.AppendFormat("PVS_SITE={{{0}}};", string.Format("uuid={0}", pvsSiteUuid)); OVF.AddOtherSystemSettingData(ovfEnv, vsId, "pvssite", sb.ToString(), OVF.GetContentMessage("OTHER_SYSTEM_SETTING_DESCRIPTION_5")); } #endregion OVF.FinalizeEnvelope(ovfEnv); } catch (Exception ex) { if (ex is OperationCanceledException) { throw; } log.Error(Messages.ERROR_EXPORT_FAILED); throw new Exception(Messages.ERROR_EXPORT_FAILED, ex); } return(ovfEnv); }
public ForagerWindow(ForagerSettings settings) : base(settings.ScreenWidth, settings.ScreenHeight, GraphicsMode.Default, "Forager", settings.Fullscreen ? GameWindowFlags.Fullscreen : 0) { logger.Info("Initializing Forager game window"); this.Settings = settings; Keyboard.KeyDown += Keyboard_KeyDown; // Open data file if (!string.IsNullOrEmpty(Settings.DataFilePath)) { logger.DebugFormat("Opening data file at {0}", Settings.DataFilePath); dataWriter = new YAMLOutputStream(Settings.DataFilePath); } // Validate number of players var playerTextureBasePath = Path.Combine(basePath, Path.Combine("etc", "player_images")); var playerImageCount = Directory.GetFiles(playerTextureBasePath, "*.png").Length; if (Settings.Players > playerImageCount) { logger.WarnFormat("Too few player images are present, only allowing {0} players", playerImageCount); Settings.Players = playerImageCount; } players = Enumerable.Range(0, Settings.Players).Select(i => new Player(i)).ToArray(); playerShadows = players.Select(p => new PlayerShadow(p.Id)).ToArray(); // Load player textures logger.DebugFormat("Loading player textures from {0}", playerTextureBasePath); playerTextureIds = Textures.LoadPlayers(playerTextureBasePath, Settings.Players).ToArray(); playerGrayTextureIds = Textures.LoadPlayers(playerTextureBasePath, Settings.Players, (image) => Textures.MakeGrayScale(image)).ToArray(); // Load food textures var foodTextureBasePath = Path.Combine(basePath, Path.Combine("etc", "food_images")); var foodImageCount = Directory.GetFiles(foodTextureBasePath, "*.png").Length; logger.DebugFormat("Loading food textures from {0}", foodTextureBasePath); foodTextureIds = Textures.Load(foodTextureBasePath, "food", foodImageCount, x => x).ToArray(); plots = Enumerable.Range(0, Settings.Plots).Select(i => RectangleF.Empty).ToArray(); plotNumberOffsets = Enumerable.Range(0, Settings.Plots).Select(i => PointF.Empty).ToArray(); emptyPlotFood = Enumerable.Range(0, Settings.Plots).Select(i => new EmptyPlotFood()).ToArray(); CalculateSizesAndLoadFonts(); NormalizeProbabilities(); AssignPlayerPositions(); // Output settings if (dataWriter != null) { dataWriter.WriteStartDocument(); dataWriter.WriteHashSingle("Version", ForagerSettings.FileVersion); dataWriter.WriteLine(); dataWriter.WriteStartList("Settings"); dataWriter.WriteHashSingle("Description", Settings.GameDescription); dataWriter.WriteHashSingle("Players", Settings.Players); dataWriter.WriteStartList("Player Plots"); dataWriter.WriteComment("player, plot"); foreach (var player in players) { dataWriter.WriteText(string.Format("{0}, {1}", player.Id, player.PlotNumber + 1)); } // Player plots dataWriter.WriteEndList(); dataWriter.WriteHashSingle("Game Duration", Settings.GameSeconds); dataWriter.WriteHashSingle("Travel Time", Settings.TravelTime); dataWriter.WriteHashSingle("Food Rate", Settings.FoodRate); dataWriter.WriteHashSingle("Plots", Settings.Plots); if (Settings.ProbabilityShiftTimes.Count > 0) { dataWriter.WriteStartList("Probability Shift Times"); dataWriter.WriteComment("set, seconds from last shift"); int setIndex = 1; foreach (var shiftTime in settings.ProbabilityShiftTimes) { dataWriter.WriteText(string.Format("{0}, {1}", setIndex, shiftTime)); setIndex++; } // Probability Shift Times dataWriter.WriteEndList(); } dataWriter.WriteStartList("Plot Probabilities"); dataWriter.WriteComment("set, plot #, probability"); int probabilitySet = 1; double probabilitySum = 0; foreach (var probabilities in Settings.PlotProbabilities) { for (int plotIndex = 0; plotIndex < probabilities.Count; plotIndex++) { var plotProbability = probabilities[plotIndex] - probabilitySum; probabilitySum += plotProbability; dataWriter.WriteText(string.Format("{0}, {1}, {2:N2}", probabilitySet, plotIndex + 1, plotProbability)); } probabilitySet++; probabilitySum = 0; } // Plot probabilities dataWriter.WriteEndList(); // Settings dataWriter.WriteEndList(); dataWriter.WriteLine(); dataWriter.WriteStartList("Actions"); dataWriter.WriteComment("time in milliseconds, action, player, plot number"); } inputTimer.Start(); // Connect to input server if (Settings.Port > 0) { try { inputClient.Connect(IPAddress.Loopback, Settings.Port); inputClient.Client.BeginReceive(inputBuffer, 0, 2, SocketFlags.None, inputClient_DataReceived, null); } catch (Exception ex) { logger.Error("Failed to connect to input server", ex); } } gameSecondsLeft = Settings.GameSeconds; probabilitySecondsLeft = Settings.ProbabilityShiftTimes.FirstOrDefault(); UpdateStatusText(); roundTimer = new System.Timers.Timer(1000); roundTimer.Elapsed += roundTimer_Elapsed; roundTimer.Start(); }
public static void PostMessage(Exception ex) { logger.WarnFormat(ex.ToString()); Send(ex.Message); }
public void Warn(string format, params object[] args) { _innerLogger.WarnFormat(format, args); }
/// <summary> /// 添加WARN级别日志 /// </summary> /// <param name="msg">日志信息</param> public void Warn(string msg) { _log.WarnFormat(msg); }
public override int PlayFile(string fileURI) { if (!File.Exists(fileURI)) { logger.WarnFormat("文件不存在, {0}", fileURI); return(DotNETCode.FILE_NOT_FOUND); } try { this.fileStream = File.Open(fileURI, FileMode.Open); } catch (Exception ex) { logger.ErrorFormat("打开文件失败", ex); return(DotNETCode.OPEN_FILE_FAILED); } this.dsb8.SetCurrentPosition(0); uint error = this.dsb8.Play(0, 0, DSBPLAY.DSBPLAY_LOOPING); if (error != DSERR.DS_OK) { logger.ErrorFormat("Play失败, DSERR = {0}", error); return(DotNETCode.SYS_ERROR); } uint offset = (uint)this.BufferSize; while (true) { byte[] buffer = new byte[this.BufferSize]; if (this.fileStream.Read(buffer, 0, buffer.Length) == 0) { this.CloseFile(); this.dsb8.Stop(); logger.InfoFormat("文件播放完毕, 退出"); return(DotNETCode.SUCCESS); } IntPtr lpHandles = Marshal.UnsafeAddrOfPinnedArrayElement(this.notifyHwnd_close, 0); uint notifyIdx = Win32API.WaitForMultipleObjects(NotifyEvents, lpHandles, false, Win32API.INFINITE); if ((notifyIdx >= Win32API.WAIT_OBJECT_0) && (notifyIdx <= Win32API.WAIT_OBJECT_0 + NotifyEvents)) { if (this.WriteDataToBuffer(offset, buffer)) { } offset += (uint)this.BufferSize; offset %= (uint)(this.BufferSize * NotifyEvents); //Console.WriteLine("dwOffset = {0}, offset = {1}", this.rgdsbpn[notifyIdx].dwOffset, offset); } else if (notifyIdx == Win32API.WAIT_FAILED) { int winErr = Marshal.GetLastWin32Error(); logger.ErrorFormat("等待信号失败, 退出播放, LastWin32Error = {0}", winErr); this.dsb8.Stop(); this.CloseFile(); return(DotNETCode.SYS_ERROR); } } }
/// <summary> /// Checks, if the action is denied for the current windows user. /// </summary> /// <param name="action">The action.</param> /// <returns>True, in case the action cannot be performed successfully /// without user elevation.</returns> internal static bool Denied(ElevationRequiredAction action) { // check only once: if (_actions.ContainsKey(action)) { return(_actions[action] != null); } if (RssBanditApplication.PortableApplicationMode) { switch (action) { case ElevationRequiredAction.RunBanditAsWindowsUserLogon: _actions.Add(action, "Not applicable in portable mode."); return(true); case ElevationRequiredAction.MakeDefaultAggregator: _actions.Add(action, "Not applicable in portable mode."); return(true); default: Debug.Assert(false, "Unhandled ElevationRequiredAction: " + action); break; } } else { RegistryKey rk = null; switch (action) { case ElevationRequiredAction.RunBanditAsWindowsUserLogon: try { // this test will succeed on Vista, because of the silent redirect of write requests // to hives we can write. But it should work on older OS versions with defined restrictions. rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.CreateSubKey); rk.Close(); _actions.Add(action, null); } catch (SecurityException secEx) { _log.WarnFormat("ElevationRequiredAction: {0}, {1}", action, secEx); _actions.Add(action, secEx.Message); return(true); } break; case ElevationRequiredAction.MakeDefaultAggregator: try { // this test will succeed on Vista, because of the silent redirect of write requests // to hives we can write. But it should work on older OS versions with defined restrictions. rk = Win32.WindowsRegistry.ClassesRootKey(false).OpenSubKey(@"feed", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.CreateSubKey); rk.Close(); _actions.Add(action, null); } catch (SecurityException secEx) { _log.WarnFormat("ElevationRequiredAction: {0}, {1}", action, secEx); _actions.Add(action, secEx.Message); return(true); } break; default: Debug.Assert(false, "Unhandled ElevationRequiredAction: " + action); break; } } return(false); }
/// <summary> /// 记录warn /// </summary> /// <param name="t"></param> /// <param name="message"></param> #region public static void warn(Type t, String message) public static void warn(Type t, String message) { log4net.ILog logger = log4net.LogManager.GetLogger(t); logger.WarnFormat("Warn: {0}", message); }
public void LoadPlugins(MainForm mainForm, ICaptureHost captureHost) { // Copy ContextMenu mainMenu = mainForm.MainMenu; List <string> pluginFiles = new List <string>(); if (IniConfig.IsPortable && Directory.Exists(pafPath)) { foreach (string pluginFile in Directory.GetFiles(pafPath, "*.gsp", SearchOption.AllDirectories)) { pluginFiles.Add(pluginFile); } } else { if (Directory.Exists(pluginPath)) { foreach (string pluginFile in Directory.GetFiles(pluginPath, "*.gsp", SearchOption.AllDirectories)) { pluginFiles.Add(pluginFile); } } if (Directory.Exists(applicationPath)) { foreach (string pluginFile in Directory.GetFiles(applicationPath, "*.gsp", SearchOption.AllDirectories)) { pluginFiles.Add(pluginFile); } } } Dictionary <string, PluginAttribute> tmpAttributes = new Dictionary <string, PluginAttribute>(); Dictionary <string, Assembly> tmpAssemblies = new Dictionary <string, Assembly>(); // Loop over the list of available files and get the Plugin Attributes foreach (string pluginFile in pluginFiles) { LOG.DebugFormat("Checking the following file for plugins: {0}", pluginFile); try { Assembly assembly = Assembly.LoadFile(pluginFile); PluginAttribute[] pluginAttributes = assembly.GetCustomAttributes(typeof(PluginAttribute), false) as PluginAttribute[]; if (pluginAttributes.Length > 0) { PluginAttribute pluginAttribute = pluginAttributes[0]; AssemblyProductAttribute[] assemblyProductAttributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false) as AssemblyProductAttribute[]; if (assemblyProductAttributes.Length > 0) { pluginAttribute.Name = assemblyProductAttributes[0].Product; } else { continue; } pluginAttribute.Version = assembly.GetName().Version.ToString(); pluginAttribute.DllFile = pluginFile; // check if this plugin is already available PluginAttribute checkPluginAttribute = null; try { checkPluginAttribute = tmpAttributes[pluginAttribute.Name]; } catch { } if (checkPluginAttribute != null) { LOG.WarnFormat("Duplicate plugin {0} found", pluginAttribute.Name); if (isNewer(pluginAttribute.Version, checkPluginAttribute.Version)) { // Found is newer tmpAttributes[pluginAttribute.Name] = pluginAttribute; tmpAssemblies[pluginAttribute.Name] = assembly; LOG.InfoFormat("Loading the newer plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); } else { LOG.InfoFormat("Skipping (as the duplicate is newer or same version) the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); } continue; } else { if (conf.ExcludePlugins != null && conf.ExcludePlugins.Contains(pluginAttribute.Name)) { LOG.WarnFormat("Exclude list: {0}", conf.ExcludePlugins.ToArray()); LOG.WarnFormat("Skipping the excluded plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); continue; } if (conf.IncludePlugins != null && conf.IncludePlugins.Count > 0 && !conf.IncludePlugins.Contains(pluginAttribute.Name)) { // Whitelist is set LOG.WarnFormat("Include list: {0}", conf.IncludePlugins.ToArray()); LOG.WarnFormat("Skipping the not included plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); continue; } LOG.InfoFormat("Loading the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); tmpAttributes[pluginAttribute.Name] = pluginAttribute; tmpAssemblies[pluginAttribute.Name] = assembly; } } else { LOG.ErrorFormat("Can't find the needed Plugin Attribute ({0}) in the assembly of the file \"{1}\", skipping this file.", typeof(PluginAttribute), pluginFile); } } catch (Exception e) { LOG.Warn("Can't load file: " + pluginFile, e); } } foreach (string pluginName in tmpAttributes.Keys) { try { PluginAttribute pluginAttribute = tmpAttributes[pluginName]; Assembly assembly = tmpAssemblies[pluginName]; Type entryType = assembly.GetType(pluginAttribute.EntryType); if (entryType == null) { LOG.ErrorFormat("Can't find the in the PluginAttribute referenced type {0} in \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile); continue; } try { IGreenshotPlugin plugin = (IGreenshotPlugin)Activator.CreateInstance(entryType); if (plugin != null) { if (plugin.Initialize(this, captureHost, pluginAttribute)) { plugins.Add(pluginAttribute, plugin); } else { LOG.InfoFormat("Plugin {0} not initialized!", pluginAttribute.Name); } } else { LOG.ErrorFormat("Can't create an instance of the in the PluginAttribute referenced type {0} from \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile); } } catch (Exception e) { LOG.Error("Can't load Plugin: " + pluginAttribute.Name, e); } } catch (Exception e) { LOG.Error("Can't load Plugin: " + pluginName, e); } } }
private Yield GetCache(uint pageId, string wikiId, DateTime time, CultureInfo culture, Result <PageChangeCacheData> result) { // Note (arnec): going back 10 seconds before event, because timestamps in a request are not currently synced string keytime = time.ToString("yyyyMMddHHmm"); string since = time.Subtract(TimeSpan.FromSeconds(10)).ToString("yyyyMMddHHmmss"); PageChangeCacheData cacheData; string key = string.Format("{0}:{1}:{2}:{3}", pageId, wikiId, keytime, culture); _log.DebugFormat("getting data for key: {0}", key); lock (_cache) { if (_cache.TryGetValue(key, out cacheData)) { result.Return(cacheData); yield break; } } // fetch the page data Result <DreamMessage> pageResponse; yield return(pageResponse = _deki .At("pages", pageId.ToString()) .WithHeader("X-Deki-Site", "id=" + wikiId) .With("redirects", "0").GetAsync()); if (!pageResponse.Value.IsSuccessful) { _log.WarnFormat("Unable to fetch page '{0}' info: {1}", pageId, pageResponse.Value.Status); result.Return((PageChangeCacheData)null); yield break; } XDoc page = pageResponse.Value.ToDocument(); string title = page["title"].AsText; XUri pageUri = page["uri.ui"].AsUri; string pageUriString = CleanUriForEmail(pageUri); string unsubUri = CleanUriForEmail(pageUri .WithoutPathQueryFragment() .At("index.php") .With("title", "Special:PageAlerts") .With("id", pageId.ToString())); // fetch the revision history Result <DreamMessage> feedResponse; yield return(feedResponse = _deki .At("pages", pageId.ToString(), "feed") .WithHeader("X-Deki-Site", "id=" + wikiId) .With("redirects", "0") .With("format", "raw") .With("since", since) .GetAsync()); if (!feedResponse.Value.IsSuccessful) { _log.WarnFormat("Unable to fetch page '{0}' changes: {1}", pageId, feedResponse.Value.Status); result.Return((PageChangeCacheData)null); yield break; } // build the docs XDoc feed = feedResponse.Value.ToDocument()["change"]; if (feed.ListLength == 0) { _log.WarnFormat("Change feed is empty for page: {0}", pageId); result.Return((PageChangeCacheData)null); yield break; } string who = feed["rc_user_name"].AsText; string whoUri = CleanUriForEmail(pageUri.WithoutPathQueryFragment().At(XUri.EncodeSegment("User:"******"rc_comment"].AsText; string revisionUri = CleanUriForEmail(pageUri.With("revision", change["rc_revision"].AsText)); who = change["rc_user_name"].AsText; whoUri = CleanUriForEmail(pageUri.WithoutPathQueryFragment().At(XUri.EncodeSegment("User:"******"rc_timestamp"].AsText); cacheData.Items.Add(item); } lock (_cache) { // even though we override the entry if one was created in the meantime // we do the existence check so that we don't set up two expiration timers; if (!_cache.ContainsKey(key)) { _cacheItemCallback(key, () => { lock (_cache) { _cache.Remove(key); } }); } _cache[key] = cacheData; } result.Return(cacheData); yield break; }
private void Player_ImageChanged(object sender, EventArgs <Bitmap> e) { if (!active || !synching) { return; } PlayerScreen player = sender as PlayerScreen; if (player == null) { return; } PlayerScreen otherPlayer = GetOtherPlayer(player); if (dynamicSynching) { if (player.IsPlaying) { //log.DebugFormat("Received image from [{0}] ({1}).", GetPlayerIndex(player), player.LocalTime / 1000); currentTime = commonTimeline.GetCommonTime(player, player.LocalTime); if (otherPlayer.IsPlaying && resyncOperations < maxResyncOperations) { //---------------------------------------------------------------------------------- // Test for desync. // This is not the primary synchronization mechanism, videos should synchronize naturally from being started // at the right time, based on their time origin and the fact that their playback rate relative to real time should match. // // However, for videos started automatically, we can't guarantee that one isn't ahead of the other. // We allow ourselves one attempt at resync here. // This kind of resync can easily misfire and cause judder so it's only used very sparingly. //---------------------------------------------------------------------------------- long otherTime = commonTimeline.GetCommonTime(otherPlayer, otherPlayer.LocalTime); long divergence = Math.Abs(currentTime - otherTime); long frameTime = Math.Max(player.LocalFrameTime, otherPlayer.LocalFrameTime); if (divergence > frameTime) { resyncOperations++; log.WarnFormat("Synchronization divergence: [{0}]@{1} vs [{2}]@{3}. Resynchronizing.", GetPlayerIndex(player), currentTime / 1000, GetPlayerIndex(otherPlayer), otherTime / 1000); AlignPlayers(true); } } EnsureBothPlaying(); } else if (!otherPlayer.IsPlaying) { // Both players have completed a loop and are waiting. currentTime = 0; EnsureBothPlaying(); } } UpdateHairLines(); if (!view.Merging || e.Value == null) { return; } otherPlayer.SetSyncMergeImage(e.Value, !dualSaveInProgress); }
public MainWindow() { InitializeComponent(); #if !DEBUG this.SettingWindowState(ConfigurationManager.AppSettings["WindowState"]); #endif if (ConfigurationManager.AppSettings["UseLoggerWindow"] != null && Convert.ToBoolean(ConfigurationManager.AppSettings["UseLoggerWindow"])) { _ = new LoggerWindow(); } #region AForge Capture Device Arguments CaptureDeviceName = ConfigurationManager.AppSettings["CaptureDeviceName"]; String resolution = ConfigurationManager.AppSettings["CaptureDeviceResolution"]; if (!String.IsNullOrWhiteSpace(resolution)) { string[] arr = resolution.Split(','); if (arr.Length == 2) { int width, height; int.TryParse(arr[0], out width); int.TryParse(arr[1], out height); FrameSize = new System.Drawing.Size(width, height); } } String rectangle = ConfigurationManager.AppSettings["CaptureDeviceRectangle"]; if (!String.IsNullOrWhiteSpace(rectangle)) { string[] arr = rectangle.Split(','); if (arr.Length == 4) { int x, y, width, height; int.TryParse(arr[0], out x); int.TryParse(arr[1], out y); int.TryParse(arr[2], out width); int.TryParse(arr[3], out height); FrameRectangle = new Rectangle(x, y, width, height); } } Stretch stretch; if (Enum.TryParse <Stretch>(ConfigurationManager.AppSettings["CaptureImageStretch"], true, out stretch)) { ImageCapture.Stretch = stretch; } #endregion #region Video Arguments if (ConfigurationManager.AppSettings["VideoPath"] != null) { string paths = ConfigurationManager.AppSettings["VideoPath"]; if (!string.IsNullOrWhiteSpace(paths) || paths.ToLower().Trim() == "null") { VideoIndex = 0; VideoPaths = new List <string>(paths.Split(',')); MediaPlayer.Source = GetVideoSource(); } if (Enum.TryParse <Stretch>(ConfigurationManager.AppSettings["VideoStretch"], true, out stretch)) { MediaPlayer.Stretch = stretch; } } #endregion #region HPSocket Arguments if (MediaPlayer.Source != null) { if (ConfigurationManager.AppSettings["ListenPort"] != null) { ushort localPort; if (ushort.TryParse(ConfigurationManager.AppSettings["ListenPort"], out localPort)) { if (localPort >= 1024) { OnSocketInitialized(localPort); } else { Log.WarnFormat("禁用网络通信服务接口,端口参数设置不在范围:{0}", localPort); } } else { Log.WarnFormat("启用网络通信服务接口失败,端口参数设置错误:{0}", ConfigurationManager.AppSettings["ListenPort"]); } } } else { Log.Warn("无视频源,将不启动网络通信服务接口"); } #endregion Log.Info("MainWindow Read Config Complete."); }
public void ForwardTab() { logger.WarnFormat("未实现ForwardTab"); }
//--- Class Methods --- public static void RequestThread(int minRequired, Action <KeyValuePair <DispatchThread, Result <DispatchWorkItem> > > callback) { int consume; int create; lock (_syncRoot) { // reset idle time _idleTime = TimeSpan.Zero; // check if a guaranteed number of threads were requested if (minRequired > 0) { // check if we can supply the guaranteed number of threads; otherwise fail if (_allocatedThreads + minRequired > _maxThreads) { throw new InsufficientResourcesException("unable to obtain minium required threads"); } // consume all requested thread from thread reserve consume = minRequired; // recreate all requested threads sicne we won't see them back again create = minRequired; } else { // only consume one thread from thread reserve consume = 1; // only create new threads if the thread reserve has fallen below a minium level int count = _threadReserve.ItemCount; if ((count < _minThreadReserveCount) && (_allocatedThreads < MaxThreadCount)) { create = 1; } else { create = 0; } } // update number of allocated threads _allocatedThreads += create; // check if max number of threads has been reached if (_allocatedThreads >= _maxThreads) { _log.WarnFormat("RequestThread: reached max threads for app domain (max: {0}, allocated: {1})", _maxThreads, _allocatedThreads); } } // assign requested threads for (int i = 0; i < consume; ++i) { if (!_threadReserve.TryEnqueue(callback)) { throw new NotSupportedException("TryEnqueue failed"); } } // create new threads to replenish thread reserve CreateThreadAsync(create); }
public static void WarnFormat(string format, params object[] args) { Logger.WarnFormat(GetBefore() + format + GetAfter(), args); }
void FrameStarted(object source, FrameEventArgs e) { try { if (texture == null || !(texture is D3DTexture) || ((texture as D3DTexture).DXTexture) == null || ((texture as D3DTexture).DXTexture as D3D.Texture) == null) { return; } D3D.Surface d3dsurface = ((texture as D3DTexture).DXTexture as D3D.Texture).GetSurfaceLevel(0); if (ps == PLAY_STATE.BUFFERING) { if (browser == null) { browser = new Browser(); browser.SetObjectForScripting(scriptingObj); browser.SetSize(VideoSize()); CreateTexture(); bool ans = browser.Open(path); if (ans == false) { ps = PLAY_STATE.STOPPED; browser = null; } } if (browser.Loaded()) { Play(); } else { Graphics g = d3dsurface.GetGraphics(); string text; int pct = browser.LoadPercent(); if ((pct == 100) || (pct == 0)) { text = string.Format("Loading ({0}%)", pct); } else { text = string.Format("Loading ({0:d2}%)", pct); } switch ((count++ / 10) % 3) { case 0: text += "."; break; case 1: text += ".."; break; case 2: text += "..."; break; } g.Clear(Color.Black); g.DrawString(text, loadingFont, Brushes.White, loadingPoint); d3dsurface.ReleaseGraphics(); } } if (ps == PLAY_STATE.RUNNING) { Graphics g = d3dsurface.GetGraphics(); browser.RenderTo(g); d3dsurface.ReleaseGraphics(); } } catch (Exception exc) { log.WarnFormat("BrowserMovie.FrameStarted exception: {0}, stack trace {1}", exc.Message, exc.StackTrace); } }
internal static void HandleRequest(string destdir) { log.DebugFormat("Handling password request"); Process this_process = Process.GetCurrentProcess(); Process parent = Processes.FindParent(this_process); if (parent == null) { log.Warn("Cannot find parent process. Ignoring request."); return; } WindowsIdentity parent_user = Processes.GetWindowsIdentity(parent); WindowsIdentity this_user = Processes.GetWindowsIdentity(this_process); if (parent_user == null || this_user == null) { log.Warn("Cannot find user details. Ignoring request."); return; } if (parent_user.User != this_user.User) { log.Warn("Passwords requested from user different to us. Ignoring request."); return; } if (!Registry.AllowCredentialSave || !Properties.Settings.Default.SaveSession) { WriteXML(destdir, null, "nosession"); return; } string exepath = Processes.GetExePath(parent); string token; string token_exepath; string user_sid; if (ParseToken(destdir, out token, out token_exepath, out user_sid)) { // Valid token. if (token_exepath == exepath) { if (user_sid == this_user.User.ToString()) { CompleteRequest(destdir, token); return; } else { // Valid token, but for the wrong user. Fall through to reprompt. log.WarnFormat("Given token for user {0}, but running as {1}", user_sid, this_user.User); } } else { // Valid token, but for the wrong app. Fall through to reprompt. log.WarnFormat("Given token for {0}, but app is {1}", token_exepath, exepath); } } else { // Missing or invalid token. } using (var d = new PasswordsRequestDialog { Application = exepath }) switch (d.ShowDialog()) { case DialogResult.OK: // Give passwords this time. CompleteRequest(destdir, null); break; case DialogResult.Yes: // Give passwords always. CompleteRequest(destdir, GenerateToken(exepath, this_user.User.ToString())); break; case DialogResult.Cancel: WriteXML(destdir, null, "cancelled"); break; default: log.Error("Unexpected result from PasswordsRequestDialog!"); return; } }
private void BuildSetFreeBusyQuery( List <string> busyMonths, List <string> busyDailyData, List <string> tentativeMonths, List <string> tentativeDailyData, string startDate, string endDate, bool clearOOF) { if (busyMonths.Count != busyDailyData.Count) { log.WarnFormat("Mismatch between the busy months and daily data: {0} {1}", busyMonths.Count, busyDailyData.Count); } if (tentativeMonths.Count != tentativeDailyData.Count) { log.WarnFormat("Mismatch between the tentative months and daily data: {0} {1}", tentativeMonths.Count, tentativeDailyData.Count); } if (busyMonths.Count == 0) { webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.BusyMonths); webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.MergedMonths); } else { webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.BusyMonths, busyMonths); // Merged should be the union of busy and OOF, but since we don't have OOF, // it is exact copy of busy webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.MergedMonths, busyMonths); } if (busyDailyData.Count == 0) { webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.BusyEvents); webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.MergedEvents); } else { webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.BusyEvents, busyDailyData); // Merged should be the union of busy and OOF, but since we don't have OOF, // it is exact copy of busy webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.MergedEvents, busyDailyData); } if (tentativeMonths.Count == 0) { webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.TentativeMonths); } else { webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.TentativeMonths, tentativeMonths); } if (tentativeDailyData.Count == 0) { webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.TentativeEvents); } else { webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.TentativeEvents, tentativeDailyData); } if (clearOOF) { webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.OutOfOfficeEvents); webDavQueryBuilder.AddRemoveProperty(FreeBusyProperty.OutOfOfficeMonths); } webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.StartOfPublishedRange, startDate); webDavQueryBuilder.AddUpdateProperty(FreeBusyProperty.EndOfPublishedRange, endDate); }
protected virtual void AuditLogFailure() { AuditLog.WarnFormat("Operation failure: {0}", AuditDescription()); }
public void WarnFormat(string format, params object[] args) { log4netLogger.WarnFormat(CultureInfo.InvariantCulture, format, args); }
public static void WarnFormat(string format, params object[] args) { Logger.WarnFormat(GetPrefix() + format + GetSuffix(), args); }