public static EventLog ExecuteOutputInDatabase(SqlConnection sqlConnection, string query)
        {
            EventLog eventLog = new EventLog();

            {
                try
                {
                    //sqlConnection.ConnectionString = TeamConfigurationSettings.ConnectionStringHstg;
                    using (var connection = sqlConnection)
                    {
                        var server = new Server(new ServerConnection(connection));
                        try
                        {
                            server.ConnectionContext.ExecuteNonQuery(query);

                            var localEvent = new Event
                            {
                                eventCode        = 0,
                                eventDescription = "The SQL statement was executed successfully.\r\n"
                            };

                            eventLog.Add(localEvent);
                        }
                        catch (Exception ex)
                        {
                            var localEvent = new Event
                            {
                                eventCode        = 1,
                                eventDescription = "Issues occurred executing the SQL statement.\r\n. SQL error: " +
                                                   ex.Message + "\r\n\r\n"
                            };

                            eventLog.Add(localEvent);
                        }
                    }
                }
                catch (Exception ex)
                {
                    var localEvent = new Event
                    {
                        eventCode        = 1,
                        eventDescription =
                            @"There was an issue executing the code against the database. The message is: " + ex
                    };

                    eventLog.Add(localEvent);
                }

                return(eventLog);
            }
        }
Пример #2
0
 private static void ThreadManager_ThreadForcedToClose(object sender, Shared.ThreadManagerEventArgs e)
 {
     EventLog.Add(String.Format("Thread forced to close: {0}, Unresponsive: {1}, Marked For Removal: {2}",
                                e.Thread.Name, e.Thread.UnResponsive.ToString(), e.Thread.MarkedForRemoval.ToString()));
     EventLog.Add(String.Format("Start Time: {0}", e.Thread.TimeStart.ToString("g")));
     EventLog.Add(String.Format("End Time: {0}", e.Thread.TimeFinish.ToString("g")));
 }
Пример #3
0
        /// <summary>
        /// Converts string array to message
        /// </summary>
        /// <param name="charArray"></param>
        /// <returns></returns>
        public static Message StringArrayToMessage(char[] charArray)
        {
#if DEBUG
            EventLog.Debug("Message.cs " + System.Reflection.MethodBase.GetCurrentMethod().Name);
#endif
            try
            {
                MessageType type = CharToMessageType(charArray[0]);

                string msgArray         = new string(charArray);
                int    sepCharsTitle    = msgArray.IndexOf("#A!");
                int    sepCharsClientID = msgArray.IndexOf("#B!");


                string title = msgArray.Substring(1, sepCharsTitle - 1);

                string  clientID = msgArray.Substring(sepCharsTitle + 3, sepCharsClientID - 3 - sepCharsTitle);
                string  contents = msgArray.Substring(sepCharsClientID + 3).TrimEnd('\0');
                Message Result   = new Message(title.Trim(), contents.Trim(), type);
                Result.SetClientID(clientID);
                return(Result);
            }
            catch (Exception err)
            {
#if DEBUG
                EventLog.Debug(err);
                EventLog.Debug("Message.cs " + System.Reflection.MethodBase.GetCurrentMethod().Name);
#endif
                EventLog.Add(err);
                return(new Message("Error", err.Message, MessageType.Error));
            }
        }
Пример #4
0
        /// <summary>
        /// Session is closing, are we saving any data from it?
        /// </summary>
        /// <param name="session">Session being removed</param>
        private void FinaliseSession(UserSession session)
        {
            try
            {
                if (session.SaveStatus == SaveStatus.Pending)
                {
                    session.SaveStatus = SaveStatus.RequiresSave;
                }

                foreach (PageViewData page in session.Pages)
                {
                    if (page.SaveStatus == SaveStatus.Pending)
                    {
                        page.SaveStatus = SaveStatus.RequiresSave;
                    }

                    System.Threading.Thread.Sleep(0);
                }

                RaiseSessionClosing(session);
            }
            catch (Exception err)
            {
                EventLog.Add(err);
                throw;
            }
            finally
            {
                session.Status = SessionStatus.Updated;
            }
        }
Пример #5
0
        /// <summary>
        /// Called in a seperate thread, updates thread with basic data to stop blocking
        /// </summary>
        /// <param name="session"></param>
        public void InitialiseSession(UserSession session)
        {
            if (session == null)
            {
                return;
            }

            try
            {
                RaiseGetIPDetails(session);

                // is it a bot
                session.IsBot = CheckIfBot(session);

                // referral type
                session.Referal = GetReferralType(session);

                session.SaveStatus = SaveStatus.RequiresSave;

                RaiseSessionCreated(session);
            }
            catch (Exception err)
            {
                EventLog.Add(err);
                throw;
            }
            finally
            {
                session.Status = SessionStatus.Updated;
            }
        }
        public static EventLog SaveOutputToDisk(string targetFile, string textContent)
        {
            EventLog eventLog = new EventLog();

            try
            {
                //Output to file
                using (var outfile = new StreamWriter(targetFile))
                {
                    outfile.Write(textContent);
                    outfile.Close();
                }
            }
            catch (Exception ex)
            {
                var localEvent = new Event
                {
                    eventCode        = 1,
                    eventDescription =
                        @"There was an issue saving the output to disk. The message is: " + ex
                };

                eventLog.Add(localEvent);
            }

            return(eventLog);
        }
Пример #7
0
 public void PropertyChangedHandler(object param)
 {
     if (SelectedValue != null)
     {
         EventLog.Add("Selection Changed : " + (SelectedValue as TaskBarItem).Name);
     }
 }
Пример #8
0
 /// <summary>
 /// Method used to add the event logs.
 /// </summary>
 /// <param name="param">Specifies the object parameter.</param>
 public void ExecuteEventLog(object param)
 {
     if (TaskBarSelectedItem != null)
     {
         EventLog.Add("Selection Changed : " + (TaskBarSelectedItem as TaskBarItem).Name);
     }
 }
Пример #9
0
        public Task HandleAsync(
            Event <TotalSet> e)
        {
            _log.Add($"Set Total to `{e.Data.Value}`");

            return(Task.CompletedTask);
        }
Пример #10
0
 public void PropertyChangedHandler(object param)
 {
     if (param != null)
     {
         EventLog.Add("Selection Changed:" + param.ToString());
     }
 }
Пример #11
0
    private void Update()
    {
        mJob.Complete();

        // copy connection state from native container
        mState = mConnection[0].GetState(mDriver);

        // copy received events from native container
        var decode = new DecodeEvent();

        for (var i = 0; i < mEvents.Length; i++)
        {
            mLog.Add(decode.Call(mEvents[i]));
            mEvents.RemoveAtSwapBack(i);
            --i;
        }

        // copy pending events to native container to send to host
        while (mLog.HasPending)
        {
            mEvents.Add(mLog.PopPending().Into());
        }

        // schedule next update
        var update = new UpdateJob(mDriver, mConnection, mEvents);

        mJob = mDriver.ScheduleUpdate();
        mJob = update.Schedule(mJob);
    }
Пример #12
0
 /// <summary>
 /// Removes a thread from list of threads being watched
 /// </summary>
 /// <param name="thread">Thread to stop watching</param>
 /// <param name="attempt">current attempt</param>
 private void ThreadRemoveInternal(ThreadManager thread, int attempt)
 {
     try
     {
         using (TimedLock.Lock(_lockObject))
         {
             foreach (ThreadManager watchedThread in _watchedThreads)
             {
                 if (watchedThread.ThreadID == thread.ThreadID)
                 {
                     _watchedThreads.Remove(watchedThread);
                     return;
                 }
             }
         }
     }
     catch (LockTimeoutException err)
     {
         if (attempt < 5)
         {
             EventLog.Add(err, String.Format("Watched Threads: {0}", _watchedThreads.Count));
             attempt++;
             ThreadRemoveInternal(thread, attempt);
         }
         else
         {
             EventLog.Add(err, String.Format("Watched Threads: {0}", _watchedThreads.Count));
             throw;
         }
     }
 }
Пример #13
0
 /// <summary>
 /// Handling the selected changed event.
 /// </summary>
 public void PropertyChangedHandler()
 {
     if (SelectedValue != null)
     {
         EventLog.Add("Selection Changed:" + (SelectedValue as Model).Content.ToString());
         ListBoxItems = (SelectedValue as Model).FolderItems;
     }
 }
Пример #14
0
 /// <summary>
 /// Handling the selected changed event.
 /// </summary>
 public void PropertyChangedHandler()
 {
     if (HierarchyItems != null)
     {
         EventLog.Add("Selection Changed:" + (HierarchyItems as HierarchyNavigatorModel).Content.ToString());
         ListBoxItems = (HierarchyItems as HierarchyNavigatorModel).FolderItems;
     }
 }
Пример #15
0
 public void PropertyChangedHandler(object param)
 {
     if (param != null)
     {
         Border    border = param as Border;
         TextBlock txt    = VisualUtils.FindDescendant(border, typeof(TextBlock)) as TextBlock;
         EventLog.Add("Selection Changed : " + txt.Text);
     }
 }
Пример #16
0
 public void KickChannelUser(string channel, string nick, string message = null)
 {
     EventLog.Add(new TestKick
     {
         Channel  = channel,
         Nickname = nick,
         Message  = message
     });
 }
Пример #17
0
 protected void LogMessage(MessageType messageType, string target, string body)
 {
     EventLog.Add(new TestMessage
     {
         Type   = messageType,
         Target = target,
         Body   = body
     });
 }
Пример #18
0
        /// <summary>
        /// Loads the layout for the listview
        /// </summary>
        public void LoadLayout()
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime || String.IsNullOrEmpty(this.Name))
            {
                return;
            }

            string file = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            file = Utilities.AddTrailingBackSlash(Utilities.AddTrailingBackSlash(file) + Application.ProductName) +
                   this.SaveName + this.Name + ".dat";

            if (System.IO.File.Exists(file))
            {
                try
                {
                    string sortOrder = XML.GetXMLValue("Settings", "SortOrder", "Ascending", file);
                    _lvColumnSorter.Order = (SortOrder)Enum.Parse(typeof(SortOrder), sortOrder);

                    _lvColumnSorter.SortColumn = XML.GetXMLValue("Settings", "SortColumn", 0, file);
                    _listSorted = XML.GetXMLValue("Settings", "Sorted", false, file);

                    foreach (ColumnHeader header in this.Columns)
                    {
                        string name = String.IsNullOrEmpty(header.Name) ? header.Text : header.Name;
                        name = Validation.Validate(name, ValidationTypes.AtoZ);

                        try
                        {
                            header.DisplayIndex = Utilities.CheckMinMax(XML.GetXMLValue("Settings",
                                                                                        String.Format("{0}DisplayIndex", name), header.DisplayIndex, file), 0, this.Columns.Count - 1);
                            header.Width = XML.GetXMLValue("Settings", String.Format("{0}Width", name), header.Width, file);
                        }
                        catch { } // ignore errors here
                    }

                    if (_listSorted)
                    {
                        Sort();
                    }
                }
                catch (Exception err)
                {
                    // any error here, delete the config file
                    EventLog.Add(err);

                    if (System.IO.File.Exists(file))
                    {
                        System.IO.File.Delete(file);
                    }
                }
            }
        }
Пример #19
0
 /// <summary>
 /// Forces a clean up of all caches, removing older items that have expired
 /// </summary>
 internal static void CleanAllCaches()
 {
     foreach (KeyValuePair <string, CacheManager> cManager in _allCaches)
     {
         try
         {
             cManager.Value.CleanCachedItems();
         }
         catch (Exception err)
         {
             EventLog.Add(err);
         }
     }
 }
Пример #20
0
        private void AccessRequested(ulong uid, Direction direction)
        {
            User = GetUser(uid);

            if (User != null)
            {
                if (direction == Domain.Direction.IN)
                {
                    var ws = new WorkShift()
                    {
                        ArrivalTime = DateTime.Now,
                        CardUid     = (long)uid
                    };
                    _ctx.WorkShifts.Add(ws);
                    _ctx.SaveChanges();
                }
                else
                {
                    long id   = (long)uid;
                    var  last = _ctx.WorkShifts.Where(x => x.CardUid == id).OrderByDescending(x => x.Id)
                                .FirstOrDefault();
                    if (last != null)
                    {
                        last.LeavingTime = DateTime.Now;
                        _ctx.SaveChanges();
                    }
                }

                Access    = AccessStatus.GRANTED;
                Direction = direction;
            }
            else
            {
                Access    = AccessStatus.DENIED;
                Direction = null;
            }

            EventLog.Add(new LogItemViewModel()
            {
                Date      = DateTime.Now,
                CardId    = uid,
                Fio       = User?.FIO,
                Direction = direction,
                Status    = Access.Value
            });

            ArduinoGateway.Instance.SendResponse(Access.Value);
        }
Пример #21
0
        public void SendWait(string p)
        {
            EventLog.Add(new Event(EventType.SendWait, p,
                                   NativeMethods.KeyboardUpDown.None));

            if (SendWaitLambda != null)
            {
                try
                {
                    SendWaitLambda?.Invoke();
                }
                catch (Exception ex)
                {
                    SendWaitLambdaExceptions.Add(ex);
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Initialises the client and starts listening for messages from the server
        /// </summary>
        public void StartListening()
        {
#if DEBUG
            EventLog.Debug("MessageClient.cs " + System.Reflection.MethodBase.GetCurrentMethod().Name);
#endif
            try
            {
                _timeout = false;

                using (TimedLock.Lock(_messageLockObject))
                {
                    string threadName = String.Format("Client Listening Thread {0}", _server);

                    if (ThreadManager.Exists(threadName))
                    {
                        return;
                    }

                    _tcpClient                = new TcpClient(_server, _port);
                    _tcpClient.SendTimeout    = 30000;
                    _tcpClient.ReceiveTimeout = 30000;
                    MessageClientListeningThread newListeningThread = new MessageClientListeningThread(this);
                    newListeningThread.MessageReceived += newListeningThread_MessageReceived;
                    ThreadManager.ThreadStart(newListeningThread, threadName, ThreadPriority.Lowest);
                }

                RaiseConnected();
            }
            catch (Exception err)
            {
#if DEBUG
                EventLog.Debug(err);
                EventLog.Debug("MessageClient.cs " + System.Reflection.MethodBase.GetCurrentMethod().Name);
#endif
                if (err.Message.Contains("A connection attempt failed because the connected party did not properly respond") ||
                    err.Message.Contains("No connection could be made because the target machine actively refused it"))
                {
                    RaiseConnectionRefused();
                }
                else if (!HandleClientException(err))
                {
                    EventLog.Add(err, String.Format("Server: {0}; Port: {1}", _server, _port));
                    throw;
                }
            }
        }
Пример #23
0
 /// <summary>
 /// Forces a clean up of all caches, removing all items
 /// </summary>
 internal static void ClearAllCaches()
 {
     foreach (KeyValuePair <string, CacheManager> cManager in _allCaches)
     {
         try
         {
             if (cManager.Value.AllowClearAll)
             {
                 cManager.Value.Clear();
             }
         }
         catch (Exception err)
         {
             EventLog.Add(err);
         }
     }
 }
Пример #24
0
        /// <summary>
        /// Removes a thread from list of threads being watched
        /// </summary>
        /// <param name="thread">Thread to stop watching</param>
        public void ThreadRemove(ThreadManager thread)
        {
            try
            {
                int attempt = 0;
                ThreadRemoveInternal(thread, attempt);

                if (_threadTimes.ContainsKey(thread.ID))
                {
                    _threadTimes.Remove(thread.ID);
                }
            }
            catch (Exception err)
            {
                EventLog.Add(err, String.Format("Watched Threads: {0}", _watchedThreads.Count));
            }
        }
Пример #25
0
        private static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
        {
            // for system assemblies and other 3rd party files,
            // anything else can be ignored here
            AssemblyName assyName = new AssemblyName(args.Name);

            EventLog.Add($"Assembly not found: {args.Name}");
            string filename = args.Name.ToLower().Split(',')[0];

            string assembly = System.IO.Path.Combine(Utils.GetPath(PathType.System), filename);

            if (!assembly.EndsWith(".dll"))
            {
                assembly += ".dll";
            }

            try
            {
                if (System.IO.File.Exists(assembly))
                {
                    return(Assembly.LoadFrom(assembly));
                }

                // has a path been passed in on the parameters?
                if (Parameters.OptionExists(Constants.Parameters.Path))
                {
                    assembly = Shared.Utilities.AddTrailingBackSlash(
                        Parameters.GetOption(Constants.Parameters.Path, String.Empty));

                    assembly += filename;

                    if (System.IO.File.Exists(assembly))
                    {
                        return(Assembly.LoadFrom(assembly));
                    }
                }
            }
            catch (Exception error)
            {
                Shared.EventLog.Add(error);
            }

            return(null);
        }
Пример #26
0
        /// <summary>
        /// Agrees the friend request.
        /// </summary>
        /// <param name="operaterId">The operater ID.</param>
        /// <param name="toId">To ID.</param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Agree(long operaterId, long toId, IUser user)
        {
            var    b    = Agree(operaterId, toId);
            string name = UserInfo.GetUserName(toId);

            EventLog.Add(new EventLog
            {
                OwnerId      = toId,
                ViewerId     = operaterId,
                TemplateName = "MakeFriend",
                AddTime      = DateTime.Now,
                ShowLevel    = 0,
                Json         =
                    JsonAdapter.Serialize(Dictionary.CreateFromArgs("ownername", name, "sendername", user.Name)
                                          )
            }
                         );
            return(b);
        }
Пример #27
0
        private void DeleteSelected()
        {
            if (MessageBox.Show(string.Format("Delete {0} files?", _selectedItems.Length), "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                foreach (var rawFileInfoViewModel in _selectedItems.ToArray())
                {
                    var error = rawFileInfoViewModel.DeleteFiles();
                    if (error == null)
                    {
                        RejectedFiles.Remove(rawFileInfoViewModel);
                    }
                    else
                    {
                        EventLog.Add(string.Format("Failed to delete file {0}: {1}", rawFileInfoViewModel.Path, error));
                    }
                }

                TotalSize = RejectedFiles.Sum(x => x.RawFileInfo.Size) / (1024 * 1024);
                RaisePropertyChanged("TotalSize");
            }
        }
Пример #28
0
        /// <summary>
        /// Thread run method
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        protected override bool Run(object parameters)
        {
            UserSession        session = (UserSession)parameters;
            UserSessionManager manager = (UserSessionManager)Parent;

            if (session == null || manager == null)
            {
                return(false);
            }

            try
            {
                manager.InitialiseSession(session);
            }
            catch (Exception err)
            {
                EventLog.Add(err);
            }

            return(false);
        }
Пример #29
0
        public FormMain()
        {
            InitializeComponent();

            // Instantiate the logging
            EventLog eventLog = new EventLog();

            // Set the version of the build for everything
            const string versionNumberForTeamApplication = "v1.6.0";

            Text = "TEAM - Taxonomy for ETL Automation Metadata " + versionNumberForTeamApplication;

            //richTextBoxInformation.AppendText("Starting from "+GlobalParameters.RootPath+"\r\n\r\n");
            //richTextBoxInformation.AppendText("Script path is " + GlobalParameters.ScriptPath + "\r\n\r\n");

            richTextBoxInformation.AppendText("Initialising the application.\r\n\r\n");

            // Make sure the application and custom location directories exist
            try
            {
                EnvironmentConfiguration.InitialiseRootPath();
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The TEAM directories are available and initialised.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "The directories required to operate TEAM are not available and can not be created. Do you have administrative priviliges in the installation directory to create these additional directories?"));
            }

            // Set the root path, to be able to locate the customisable configuration file
            try
            {
                EnvironmentConfiguration.LoadRootPathFile();
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The core configuration file has been loaded.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "The core configuration file could not be loaded. Is there a Configuration directory in the TEAM installation location?"));
            }

            // Make sure the configuration file is in memory
            try
            {
                EnvironmentConfiguration.InitialiseConfigurationPath();
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The user configuration paths are available.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered creating or detecting the configuration paths."));
            }

            // Load the available configuration file
            try
            {
                EnvironmentConfiguration.LoadConfigurationFile(GlobalParameters.ConfigurationPath + GlobalParameters.ConfigFileName + '_' + GlobalParameters.WorkingEnvironment + GlobalParameters.FileExtension);
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The user configuration settings (file) have been loaded.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered loading the user configuration file."));
            }

            // Load the pattern definition file
            try
            {
                ConfigurationSettings.patternDefinitionList = LoadPatternDefinition.DeserializeLoadPatternDefinition(GlobalParameters.LoadPatternPath + GlobalParameters.LoadPatternDefinitionFile);
                eventLog.Add(Event.CreateNewEvent(EventTypes.Information, "... The pattern definition file was loaded successfully.\r\n"));
            }
            catch
            {
                eventLog.Add(Event.CreateNewEvent(EventTypes.Error, "An issue was encountered loading the pattern definition file."));
            }


            // Report the events (including errors) back to the user
            int errorCounter = 0;

            foreach (Event individualEvent in eventLog)
            {
                if (individualEvent.eventCode == (int)EventTypes.Error)
                {
                    errorCounter++;
                }

                richTextBoxInformation.AppendText(individualEvent.eventDescription);
            }

            richTextBoxInformation.AppendText($"\r\n{errorCounter} error(s) have been found at startup.\r\n\r\n");


            TestConnections();

            //Startup information
            richTextBoxInformation.AppendText("\r\nApplication initialised - the Taxonomy of ETL Automation Metadata (TEAM). \r\n");
            richTextBoxInformation.AppendText("Welcome to version " + versionNumberForTeamApplication + ".\r\n\r\n");

            labelWorkingEnvironment.Text = "The working environment is: " + GlobalParameters.WorkingEnvironment;
        }
Пример #30
0
 public void PropertyChangedHandler(object param)
 {
     EventLog.Add("Color Changed:" + param.ToString());
 }