Ejemplo n.º 1
0
    static void ArchiveToXML(LogStore logStore, string fileName)
    {
        LogArchiveSnapshot snapshot = logStore.CreateLogArchiveSnapshot();

        XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.ASCII);

        writer.WriteStartElement("logArchive");
        foreach (FileRegion region in snapshot.ArchiveRegions)
        {
            writer.WriteStartElement("fileRegion");
            writer.WriteElementString("path", region.Path);
            writer.WriteElementString("length", region.FileLength.ToString());
            writer.WriteElementString("offset", region.Offset.ToString());
            using (Stream dataStream = region.GetStream())
            {
                byte[] data = new byte[dataStream.Length];
                dataStream.Read(data, 0, data.Length);
                writer.WriteElementString("data", Convert.ToBase64String(data));
            }
            writer.WriteEndElement();
        }
        writer.WriteEndElement();
        writer.Close();
        logStore.SetArchiveTail(snapshot.LastSequenceNumber);
    }
Ejemplo n.º 2
0
    public void AddToUploadQueue(LogStore logStore, string targetLabel)
    {
        //gets the log dictionary from the logStore object
        SortedDictionary <string, List <string> > logDictionary =
            logStore.ExportAll <SortedDictionary <string, List <string> > >();

        if (logDictionary.Keys.Count == 0)
        {
            Debug.LogError("the logs " + targetLabel + " contain no columns!");
            logStore.RemoveSavingTarget(TargetType.MySql);
            return;
        }

        if (dataTargets.ContainsKey(targetLabel))
        {
            dataTargets[targetLabel].logstoreToUpload.Add(logStore);
            Debug.Log("Log Collection " + targetLabel + " with " + logDictionary.Keys.Count + " columns and " + logStore.RowCount + " rows prepared for upload.");
        }
        else
        {
            Debug.LogError("The targetLabel " + targetLabel + " does not match any of the loaded targets.");
            Debug.LogError("Aborting AddToUploadQueue..");
            logStore.RemoveSavingTarget(TargetType.MySql);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Terminate the result thread and apply any required exit procedures like sending final results.
        /// </summary>
        public override void Exit()
        {
            // Only process the logs once
            if (!ExitTriggered)
            {
                Log.Trace("BacktestingResultHandler.Exit(): starting...");
                List <LogEntry> copy;
                lock (LogStore)
                {
                    copy = LogStore.ToList();
                }
                ProcessSynchronousEvents(true);
                Log.Trace("BacktestingResultHandler.Exit(): Saving logs...");
                var logLocation = SaveLogs(_algorithmId, copy);
                SystemDebugMessage("Your log was successfully created and can be retrieved from: " + logLocation);

                // Set exit flag, update task will send any message before stopping
                ExitTriggered = true;
                ExitEvent.Set();

                StopUpdateRunner();

                SendFinalResult();

                base.Exit();
            }
        }
Ejemplo n.º 4
0
        public void UpdateLog(string path)
        {
            if (string.IsNullOrWhiteSpace(path) ||
                !path.Equals(this.currentPath, StringComparison.CurrentCultureIgnoreCase) || !this.settings.AutoRefreshOnFileChange)
            {
                return;
            }
            Action action = delegate
            {
                this.WaitRunningTasks();
                var f = new FileInfo(path);
                if (f.Length < this.logSize)
                {
                    this.currentPath = string.Empty;
                    this.logSize     = 0;
                    this.store.Do(logStore =>
                    {
                        logStore.Dispose();
                        this.store = null;
                    });
                }
                if (f.Length == this.logSize)
                {
                    return;
                }
                this.BeginLogReading();
            };

            Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
Ejemplo n.º 5
0
        // Demonstrates how to cleanup the log for FileRecordSequence and LogRecordSequence
        // Dispose the record sequence and cleanup the physical log
        static void Cleanup()
        {
            if (sequence != null)
            {
                sequence.Dispose();
            }

            try
            {
                if (usingFileLog)
                {
                    // Delete the the log file
                    File.Delete(logPath);
                }
                else
                {
                    // Delete the the base log file and all the associated extents
                    LogStore.Delete(logPath);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message);
            }
        }
Ejemplo n.º 6
0
 private void AddToLogstore(LogStore logStore, string columnLabel, object value)
 {
     logStore.Add(columnLabel, value);
     if (logStore.LogType == LogType.LogEachRow)
     {
         logStore.EndRow();
     }
 }
Ejemplo n.º 7
0
 public StatisticDlg(LogStore store, string size, string encoding)
 {
     this.InitializeComponent();
     this.store     = store;
     this.size      = size;
     this.encoding  = encoding;
     this.uiContext = TaskScheduler.FromCurrentSynchronizationContext();
     this.LoadStatistic();
 }
Ejemplo n.º 8
0
        public void GetLog(IRequest request, IResponse response, LogStore logStore)
        {
            var outputs = new WebConsoleOutputs();

            foreach (var log in logStore.GetUnloadEntrysByClientId(request.Get("clientId")))
            {
                outputs.WriteLine(log);
            }
            response.SetContext(outputs);
        }
Ejemplo n.º 9
0
        protected override void AddToLogStore(string message)
        {
            lock (LogStore)
            {
                var messageToLog = Algorithm != null
                    ? new LogEntry(Algorithm.Time.ToStringInvariant(DateFormat.UI) + " " + message)
                    : new LogEntry("Algorithm Initialization: " + message);

                LogStore.Add(messageToLog);
            }
        }
Ejemplo n.º 10
0
        public void LogContinueWithNoLogs()
        {
            var logStore = new LogStore();
            var logger1  = new Logger(logStore);

            logger1.LogContinued(null).Complete();

            var sut = new LogReader(logStore);

            Assert.Equal(null, sut.Get());
        }
Ejemplo n.º 11
0
    public void CreateLog(string collectionLabel, List <string> headers = null)
    {
        if (logsList.ContainsKey(collectionLabel))
        {
            Debug.LogWarning(collectionLabel + " already exists");
            return;
        }
        LogStore logStore = new LogStore(collectionLabel, email, sessionID, logStringOverTime, headers: headers);

        logsList.Add(collectionLabel, logStore);
    }
Ejemplo n.º 12
0
 private void AddToLogstore(LogStore logStore, Dictionary <string, object> logData)
 {
     foreach (KeyValuePair <string, object> pair in logData)
     {
         logStore.Add(pair.Key, pair.Value);
     }
     if (logStore.LogType == LogType.LogEachRow)
     {
         logStore.EndRow();
     }
 }
Ejemplo n.º 13
0
        public void OneLoggerWithOneLog()
        {
            var log1     = "abc";
            var logStore = new LogStore();
            var logger1  = new Logger(logStore);

            logger1.Log(log1);

            var sut = new LogReader(logStore);

            Assert.Equal(log1, sut.Get());
        }
Ejemplo n.º 14
0
    //returns true if the Meta log was created
    private bool AddMetaCollectionToList()
    {
        if (logsList.ContainsKey("Meta"))
        {
            return(false);
        }
        LogStore metaLog = new LogStore("Meta", email, sessionID, logStringOverTime, LogType.OneRowOverwrite);

        logsList.Add("Meta", metaLog);
        metaLog.Add("SessionID", sessionID);
        metaLog.Add("DeviceID", deviceID);
        return(true);
    }
Ejemplo n.º 15
0
        public void LogContinue()
        {
            var log1     = "abc";
            var log2     = "def";
            var logStore = new LogStore();
            var logger1  = new Logger(logStore);

            logger1.LogContinued(log1).LogContinued(log2).Complete();

            var sut = new LogReader(logStore);

            Assert.Equal(log1 + log2, sut.Get());
        }
Ejemplo n.º 16
0
        public void TestLogOverflow()
        {
            var store = new LogStore(new Logger());

            store.SetMaxStore(10);

            for (var i = 0; i < 20; i++)
            {
                store.Log(new LogEntry(LogLevels.Info, "hello", 0));
            }

            Assert.AreEqual(10, store.GetUnloadEntrysByClientId("test").Count);
        }
Ejemplo n.º 17
0
        public void LogContinueButNoCompletion()
        {
            var log1         = "abc";
            var log2         = "def";
            var logStore     = new LogStore();
            var logger1      = new Logger(logStore);
            var continuation = logger1.LogContinued(log1).LogContinued(log2);

            var sut = new LogReader(logStore);

            Assert.Null(sut.Get());

            continuation.Complete();
        }
Ejemplo n.º 18
0
 public void Log(string collectionLabel, string columnLabel, object value)
 {
     //checks if the log was created and creates it if not
     if (logsList.TryGetValue(collectionLabel, out LogStore logStore))
     {
         AddToLogstore(logStore, columnLabel, value);
     }
     //this will be executed only once if the log has not been created.
     else
     {
         LogStore newLogStore = new LogStore(collectionLabel, email, sessionID, logStringOverTime);
         logsList.Add(collectionLabel, newLogStore);
         AddToLogstore(newLogStore, columnLabel, value);
     }
 }
Ejemplo n.º 19
0
        public void OneLoggerWithTwoLogs()
        {
            var log1     = "abc";
            var log2     = "def";
            var logStore = new LogStore();
            var logger   = new Logger(logStore);

            logger.Log(log1);
            logger.Log(log2);

            var sut = new LogReader(logStore);

            Assert.Equal(log2, sut.Get());
            Assert.Equal(log1, sut.Get());
        }
Ejemplo n.º 20
0
        public void OneLoggerWithTwoLogsOfDifferentPriority()
        {
            var log1     = "abc";
            var log2     = "def";
            var logStore = new LogStore();
            var logger   = new Logger(logStore);

            logger.Log(3, log1);
            logger.Log(1, log2);

            var sut = new LogReader(logStore);

            Assert.Equal(log1, sut.Get());
            Assert.Equal(log2, sut.Get());
        }
Ejemplo n.º 21
0
        public void GivenTestCase()
        {
            var logStore = new LogStore();
            var logger   = new Logger(logStore);

            logger.Log(1, "abc");
            logger.Log(2, "def");
            logger.Log(1, "ghi");

            var sut = new LogReader(logStore);

            Assert.Equal("def", sut.Get());
            Assert.Equal("ghi", sut.Get());
            Assert.Equal("abc", sut.Get());
            Assert.Null(sut.Get());
        }
Ejemplo n.º 22
0
        public void EnumerateExtents()
        {
            LogStore store = sequence.LogStore;

            Console.WriteLine("Enumerating Log Extents...");
            Console.WriteLine("    Extent Count: {0} extents", store.Extents.Count);
            Console.WriteLine("    Extents Are...");
            foreach (LogExtent extent in store.Extents)
            {
                Console.WriteLine("      {0} ({1}, {2})",
                                  Path.GetFileName(extent.Path),
                                  extent.Size,
                                  extent.State);
            }
            Console.WriteLine("    Free Extents: {0} Free", store.Extents.FreeCount);
        }
Ejemplo n.º 23
0
        public void LogContinueWithIntermediateStep()
        {
            var log1         = "abc";
            var log2         = "def";
            var log3         = "ghi";
            var logStore     = new LogStore();
            var logger1      = new Logger(logStore);
            var continuation = logger1.LogContinued(log1);

            logger1.Log(log3);

            continuation.LogContinued(log2).Complete();

            var sut = new LogReader(logStore);

            Assert.Equal(log1 + log2, sut.Get());
            Assert.Equal(log3, sut.Get());
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Terminate the result thread and apply any required exit procedures.
        /// </summary>
        public virtual void Exit()
        {
            // Only process the logs once
            if (!ExitTriggered)
            {
                List <LogEntry> copy;
                lock (LogStore)
                {
                    copy = LogStore.ToList();
                }
                ProcessSynchronousEvents(true);
                var logLocation = SaveLogs(_algorithmId, copy);
                SystemDebugMessage("Your log was successfully created and can be retrieved from: " + logLocation);
            }

            //Set exit flag, and wait for the messages to send:
            ExitTriggered = true;
        }
Ejemplo n.º 25
0
        public void TwoLoggersWithOneLogEachOfDifferentPriority()
        {
            var log1     = "abc";
            var log2     = "def";
            var logStore = new LogStore();
            var logger1  = new Logger(logStore);

            logger1.Log(3, log1);

            var logger2 = new Logger(logStore);

            logger2.Log(1, log2);

            var sut = new LogReader(logStore);

            Assert.Equal(log1, sut.Get());
            Assert.Equal(log2, sut.Get());
        }
Ejemplo n.º 26
0
        // Dispose the record sequence and delete the log file.
        public void Cleanup()
        {
            // Dispose the sequence
            sequence.Dispose();

            // Delete the log file.
            if (delete)
            {
                try
                {
                    // This deletes the base log file and all the extents associated with the log.
                    LogStore.Delete(this.logName);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message);
                }
            }
        }
Ejemplo n.º 27
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            tapGestureLogStore      = new LogStore("SampleTapLogs.data");
            tapGestureLogStore.Name = "Taps";

            // Log screenshots
            var item = new UIBarButtonItem(UIBarButtonSystemItem.Camera);

            item.Clicked += delegate {
                Aardvark.LogScreenshot();
            };
            NavigationItem.RightBarButtonItem = item;

            // Ensure that the tap log store will only store tap logs.
            tapGestureLogStore.LogFilterBlock = logMessage => {
                if (logMessage?.UserInfo == null)
                {
                    return(false);
                }

                var val = (NSNumber)logMessage.UserInfo [SampleTapLogKey];
                return(val?.BoolValue == true);
            };

            // Do not log tap logs to the main tap log store.
            LogDistributor.DefaultDistributor.DefaultLogStore.LogFilterBlock = logMessage => {
                if (logMessage?.UserInfo == null)
                {
                    return(true);
                }

                var val = (NSNumber)logMessage.UserInfo [SampleTapLogKey];
                return(val?.BoolValue != true);
            };

            LogDistributor.DefaultDistributor.AddLogObserver(tapGestureLogStore);

            var appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;

            appDelegate.BugReporter.AddLogStores(new [] { tapGestureLogStore });
        }
Ejemplo n.º 28
0
    private void SaveCallback(LogStore logStore, bool clear)
    {
        if (!clear)
        {
            return;
        }

        //checks if all the targets have been saved, if not returns
        foreach (var targetType in targetsEnabled)
        {
            if (!logStore.TargetsSaved[targetType])
            {
                return;
            }
        }
        //All targets have been saved, we can clear the logs
        logStore.Clear();
        logStore.ResetTargetsSaved();
    }
Ejemplo n.º 29
0
        async Task MessageSender()
        {
            while (true)
            {
                await Task.Delay(500);

                if (MessageStore.Count != 0)
                {
                    await messageChannel?.SendMessageAsync(MessageStore[0]);

                    MessageStore.RemoveAt(0);
                }
                if (LogStore.Count != 0)
                {
                    await logChannel?.SendMessageAsync(LogStore[0]);

                    LogStore.RemoveAt(0);
                }
            }
        }
Ejemplo n.º 30
0
        public void TwoLoggersWithOneLogEachWithTwoReaders()
        {
            var log1     = "abc";
            var log2     = "def";
            var logStore = new LogStore();
            var logger1  = new Logger(logStore);

            logger1.Log(3, log1);

            var logger2 = new Logger(logStore);

            logger2.Log(1, log2);

            var sut1 = new LogReader(logStore);

            Assert.Equal(log1, sut1.Get());

            var sut2 = new LogReader(logStore);

            Assert.Equal(log2, sut2.Get());
        }
Ejemplo n.º 31
0
 internal LogPolicy(LogStore logStore)
 {
     this.store = logStore;
     Refresh();
 }