Beispiel #1
0
        static void Main(string[] args)
        {
            LoggerFactory factory = new LoggerFactory();
            AppLogger     logger  = factory.GetLogger(1);

            logger.Log("Message To File");
            logger = factory.GetLogger(3);
            logger.Log("Console Message");
            Console.ReadKey();
        }
Beispiel #2
0
        public void SetCanvas(PictureBoxObj pb)
        {
            lock (_canvasSync)
            {
                if (pb == null || pb.Image == null)
                {
                    return;
                }

                Width  = pb.Width;
                Height = pb.Height;

                _backPicture = pb;
                this.Controls.Add(_backPicture);
                _backPicture.SendToBack();
                _backPicture.Invalidate();


                _frontPicture = new PictureBoxObj(_backPicture.ClientID, _backPicture.UniqueID, PictureBoxStatus.Canvas);
                this.Controls.Add(_frontPicture);

                _frontPicture.Width  = pb.Width;
                _frontPicture.Height = pb.Width;
                _frontPicture.Image  = new Bitmap(Width, Height);
                _frontPicture.BringToFront();

                _editPBDrawObjects[0] = new DrawObjectList(0);
            }

            _isCleared = false;
            _needUpdateFrontPicture = true;
            AppLogger.Log("Picture loaded: width " + Width + ", height " + Height);
        }
        public static List <string> GetStringArrayValue(string text, string ArgName, List <string> DefaultValue = null)
        {
            string StringValue = GetStringValue(text, ArgName);

            if (string.IsNullOrEmpty(StringValue))
            {
                return(DefaultValue);
            }

            string[] Values = null;

            try
            {
                // Remove quotes
                char[] charsToTrim = { '\"' };
                StringValue = StringValue.Trim(charsToTrim);

                // Split value parameters
                Values = StringValue.Split(',');
            }
            catch (Exception e)
            {
                AppLogger.Log(string.Format("An error occurred while parsing {0} to array:\n{1}", ArgName, e.Message));
                return(DefaultValue);
            }

            return(Values.ToList());
        }
        private void ProcessCommandSendClusterEvent(Configuration Config, List <ClusterEvent> Events)
        {
            if (!File.Exists(SelectedConfig))
            {
                AppLogger.Log("No config file found: " + SelectedConfig);
                return;
            }

            EntityClusterNode MasterNode = Config.GetMasterNode();

            if (MasterNode == null)
            {
                AppLogger.Log("Master node not found");
                return;
            }

            if (Events == null || Events.Count == 0)
            {
                AppLogger.Log("Nothing to send");
                return;
            }

            foreach (ClusterEvent Event in Events)
            {
                SendClusterCommand(MasterNode.Addr, MasterNode.PortCE, Event.JsonData);
            }
        }
        private void ProcessCommandStartApp(Configuration Config)
        {
            if (!File.Exists(SelectedConfig))
            {
                AppLogger.Log("No config file found: " + SelectedConfig);
                return;
            }

            if (!File.Exists(SelectedApplication))
            {
                AppLogger.Log("No application found: " + SelectedApplication);
                return;
            }

            // Update config files before application start
            HashSet <string> NodesSent = new HashSet <string>();

            foreach (EntityClusterNode Node in Config.ClusterNodes.Values)
            {
                if (!NodesSent.Contains(Node.Addr))
                {
                    NodesSent.Add(Node.Addr);
                }
            }

            // Send start command to the listeners
            foreach (EntityClusterNode Node in Config.ClusterNodes.Values)
            {
                string cmd = GenerateStartCommand(Node, Config);
                SendDaemonCommand(Node.Addr, DefaultListenerPort, cmd);
            }
        }
Beispiel #6
0
        public bool Save()
        {
            string ip         = _TCPListenAddress.Address.ToString();
            string port       = _TCPListenAddress.Port.ToString();
            string updatePI_s = _pictureUpdateInterval.ToString();
            string maxCl_s    = _maxClients.ToString();
            string ping_s     = _pingInterval.ToString();

            try
            {
                IniFile ini = new IniFile(_iniName);
                ini.DefaultSection = _configSection;

                ini.Write(_ipIni, ip);
                ini.Write(_portIni, port);
                ini.Write(_updIntervalIni, updatePI_s);
                ini.Write(_maxClientIni, maxCl_s);
                ini.Write(_clPingIni, ping_s);

                ini.Save(Environment.CurrentDirectory);

                return(true);
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
                return(false);
            }
        }
Beispiel #7
0
 public static bool BulkInsert <T>(List <T> data, Dictionary <string, ColumnType> ColMap)
 {
     try
     {
         string DestTable = ((TableNameAttribute)typeof(T).GetCustomAttributes(true)[0]).TableName;
         using (_Connection = GetSQLConnection())
         {
             if (_Connection.State == System.Data.ConnectionState.Closed)
             {
                 _Connection.Open();
             }
             SqlBulkCopy copy = new SqlBulkCopy(_Connection);
             copy.DestinationTableName = DestTable;
             copy.BulkCopyTimeout      = 0;
             DataTable dt = data.ConvertToDatatable <T>(ColMap);
             copy.MapColumns(ColMap);
             copy.WriteToServer(dt);
         }
     }
     catch (Exception ex)
     {
         AppLogger.Log(ex);
         return(false);
     }
     return(true);
 }
Beispiel #8
0
        public static List <MetaValidation> LoadMetaDaata()
        {
            List <MetaValidation> mtadata = new List <MetaValidation>();

            try
            {
                using (_Connection = GetSQLConnection())
                {
                    if (_Connection.State == System.Data.ConnectionState.Closed)
                    {
                        _Connection.Open();
                    }
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = _Connection;
                    cmd.CommandText = "USP_LoadMetadata";
                    cmd.CommandType = CommandType.StoredProcedure;
                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        MetaValidation valid = new MetaValidation();
                        valid.DataSetName    = Convert.ToString(reader["DataSetName"]);
                        valid.Message        = Convert.ToString(reader["Message"]);
                        valid.ValidationType = Convert.ToString(reader["ValidationType"]);
                        valid.TypeName       = Convert.ToString(reader["TypeName"]);
                        valid.FieldOrder     = Convert.ToInt32(reader["FieldOrder"]);
                        mtadata.Add(valid);
                    }
                }
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
            }
            return(mtadata);
        }
Beispiel #9
0
        private void SendClusterCommand(string nodeAddress, int port, string cmd, bool bQuiet = false)
        {
            TcpClient nodeClient = new TcpClient();

            if (!bQuiet)
            {
                AppLogger.Log(string.Format("Sending command {0} to {1}...", cmd, nodeAddress));
            }

            try
            {
                // Connect to the listener
                nodeClient.Connect(nodeAddress, port);
                NetworkStream networkStream = nodeClient.GetStream();

                byte[] OutData = ASCIIEncoding.ASCII.GetBytes(cmd);
                byte[] OutSize = BitConverter.GetBytes((Int32)OutData.Length);

                networkStream.Write(OutSize, 0, OutSize.Length);
                networkStream.Write(OutData, 0, OutData.Length);
                AppLogger.Log("Event sent");
            }
            catch (Exception ex)
            {
                if (!bQuiet)
                {
                    AppLogger.Log("An error occurred while sending a command to " + nodeAddress + ". EXCEPTION: " + ex.Message);
                }
            }
            finally
            {
                nodeClient.Close();
            }
        }
Beispiel #10
0
        private void InitializeOptions()
        {
            InitializeTabLaunch();
            InitializeTabLog();

            AppLogger.Log("User setttings have been loaded successfulyy");
        }
Beispiel #11
0
        private bool TickCreateNewCanvas()
        {
            if (_incomingCanvas != null)
            {
                ArgNewPictureBox arg = _incomingCanvas;
                _incomingCanvas = null;

                _canvas.Clear();

                lock (_npbSync){
                    _newPB.Clear();
                    _clientServerPictureBoxID.Clear();
                }

                lock (_astSync){
                    _argsSendToAllClients.Clear();
                    _argsSendToAllClients = null;
                }

                PictureBoxObj pb = new PictureBoxObj(arg.ClientID, 0, PictureBoxStatus.Canvas);
                pb.BorderStyle = BorderStyle.FixedSingle;
                pb.Width       = arg.PBImage.Width;
                pb.Height      = arg.PBImage.Height;
                pb.Image       = arg.PBImage;
                _canvas.SetCanvas(pb);
                AppLogger.Log("New canvas created by " + arg.ClientID);

                lock (_astSync) { _argsSendToAllClients = new List <ICommandArg>(); }
                return(true);
            }
            return(false);
        }
Beispiel #12
0
 public void DeleteConfig()
 {
     Configs.Remove(SelectedConfig);
     RegistrySaver.RemoveRegistryValue(RegistrySaver.RegCategoryConfigList, SelectedConfig);
     AppLogger.Log("Configuration file [" + SelectedConfig + "] deleted");
     SelectedConfig = Configs.FirstOrDefault();
 }
Beispiel #13
0
        public override List <FileDiagnostics> ValidateData()
        {
            List <FileDiagnostics> diags = new List <FileDiagnostics>();

            try
            {
                var result = ReadData();
                DataValidator <FileModel> dataValidator = new DataValidator <FileModel>();
                diags = dataValidator.ValidateData(result);

                int RowNumber = 0;

                foreach (FileModel t in result)
                {
                    RowNumber++;
                    if (!string.IsNullOrEmpty(t.Status) && t.Status.ToString().ToLower() != Constants.APPROVED && t.Status.ToString().ToLower() != Constants.REJECTED && t.Status.ToString().ToLower() != Constants.DONE)
                    {
                        diags.Add(new FileDiagnostics()
                        {
                            Message   = "The property '" + nameof(t.Status) + "' is invalid(Should be Approved/Rejected/Done). Element.No: " + RowNumber,
                            FieldName = nameof(t.Status),
                            RowNo     = RowNumber,
                            severity  = Severity.Error
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
                throw ex;
            }
            return(diags);
        }
Beispiel #14
0
        public List <FileModel> ReadData()
        {
            List <FileModel> lstModel = new List <FileModel>();

            try
            {
                Stream        st         = _Stream;
                string        Tdata      = new StreamReader(st).ReadToEnd();
                XmlSerializer serializer = new XmlSerializer(typeof(Transactions));
                Transactions  result     = null;
                using (TextReader reader = new StringReader(Tdata))
                {
                    result = (Transactions)serializer.Deserialize(reader);
                }
                foreach (Transaction t in result.Transaction)
                {
                    FileModel model = new FileModel()
                    {
                        TransactionId   = t.Id.Replace("\"", "").TrimEnd().TrimStart(),
                        TransactionDate = t.TransactionDate.Replace("\"", "").TrimEnd().TrimStart(),
                        Amount          = t.PaymentDetails.Amount.Replace("\"", "").TrimEnd().TrimStart(),
                        CurrencyCode    = t.PaymentDetails.CurrencyCode.Replace("\"", "").TrimEnd().TrimStart(),
                        Status          = t.Status.Replace("\"", "").TrimEnd().TrimStart()
                    };
                    lstModel.Add(model);
                }
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
            }
            return(lstModel);
        }
        public bool Save()
        {
            string ip             = _remoteEndPoint.Address.ToString();
            string port           = _remoteEndPoint.Port.ToString();
            string updatePI_s     = _pictureUpdateInterval.ToString();
            string packSize_s     = _sendPacketSize.ToString();
            string packInterval_s = _sendPacketInterval.ToString();

            try
            {
                IniFile ini = new IniFile(_iniName);
                ini.DefaultSection = _configSection;

                ini.Write(_ipIni, ip);
                ini.Write(_portIni, port);
                ini.Write(_updIntervalIni, updatePI_s);
                ini.Write(_mspIntervalIni, packInterval_s);
                ini.Write(_mspSizeIni, packSize_s);

                ini.Save(Environment.CurrentDirectory);

                return(true);
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
                return(false);
            }
        }
Beispiel #16
0
    public static void Log(string element, string message)
    {
        string log = AppLogger.Log(AppManager.CurrentScreen, element, message);

        Text logText = Instantiate(Instance.LogText, Instance.LogList, false);

        logText.text = log;
    }
Beispiel #17
0
        public void DeleteApplication()
        {
            Applications.Remove(SelectedApplication);
            RegistrySaver.RemoveRegistryValue(RegistrySaver.RegCategoryAppList, SelectedApplication);
            AppLogger.Log("Application [" + SelectedApplication + "] removed from the list");

            SelectedApplication = null;
        }
Beispiel #18
0
        protected void Application_Error(object sender, EventArgs e)
        {
            try
            {
                Exception ex = Server.GetLastError();
                AppLogger.Log("Application_Error: " + ex.ToString());

                var httpContext       = ((MvcApplication)sender).Context;
                var currentController = " ";
                var currentAction     = " ";
                var currentRouteData  = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));

                if (currentRouteData != null)
                {
                    if (currentRouteData.Values["controller"] != null && !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
                    {
                        currentController = currentRouteData.Values["controller"].ToString();
                    }

                    if (currentRouteData.Values["action"] != null && !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
                    {
                        currentAction = currentRouteData.Values["action"].ToString();
                    }
                }

                var controller = new ErrorController();
                var routeData  = new RouteData();
                var action     = "DetailedError";

                //if (ex is HttpException)
                //{
                //    var httpEx = ex as HttpException;

                //    switch (httpEx.GetHttpCode())
                //    {
                //        case 404:
                //            action = "HttpError"; // not found
                //            break;

                //        case 401:
                //            action = "HttpError"; // "AccessDenied";
                //            break;
                //    }
                //}

                httpContext.ClearError();
                httpContext.Response.Clear();
                httpContext.Response.StatusCode             = ex is HttpException ? ((HttpException)ex).GetHttpCode() : 500;
                httpContext.Response.TrySkipIisCustomErrors = true;

                routeData.Values["controller"] = "Error";
                routeData.Values["action"]     = action;

                controller.ViewData.Model = new HandleErrorInfo(ex, currentController, currentAction);
                ((IController)controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));
            }
            catch { }
        }
Beispiel #19
0
        private void btnOptions_Click(object sender, EventArgs e)
        {
            SettingsForm options = new SettingsForm(_config);

            options.ShowDialog();
            if (options.DialogResult == DialogResult.OK)
            {
                AppLogger.Log("Apply team painter settings");
            }
        }
 public EntityViewport(string text)
 {
     try
     {
         InitializeFromText(text);
     }
     catch (Exception ex)
     {
         AppLogger.Log(ex.Message);
     }
 }
Beispiel #21
0
 private void LoadMetaData()
 {
     try
     {
         _validation = DBAccess.LoadMetaDaata();
     }
     catch (Exception ex)
     {
         AppLogger.Log(ex);
     }
 }
Beispiel #22
0
        public Tuple <bool, List <FileDiagnostics> > ProcessFile(Stream File, string FileName)
        {
            Tuple <bool, List <FileDiagnostics> > tpl = null;

            try
            {
                string FType = Path.GetExtension(FileName);

                if (FType == Constants.CSV)
                {
                    BaseFile baseFile = new CSVFile();
                    baseFile._Stream = File;
                    List <FileDiagnostics> ValidationMessage = baseFile.ValidateData();
                    if (ValidationMessage != null && ValidationMessage.Count > 0)
                    {
                        tpl = Tuple.Create(false, ValidationMessage);
                    }
                    else
                    {
                        tpl = Tuple.Create(baseFile.SaveData(), ValidationMessage);
                    }
                }
                else if (FType == Constants.XML)
                {
                    BaseFile baseFile = new XMLFile();
                    baseFile._Stream = File;
                    List <FileDiagnostics> ValidationMessage = baseFile.ValidateData();
                    if (ValidationMessage != null && ValidationMessage.Count > 0)
                    {
                        tpl = Tuple.Create(false, ValidationMessage);
                    }
                    else
                    {
                        tpl = Tuple.Create(baseFile.SaveData(), ValidationMessage);
                    }
                }
                else
                {
                    return(Tuple.Create(false, new List <FileDiagnostics>()
                    {
                        new FileDiagnostics()
                        {
                            FieldName = "File", Message = "Unknown file format"
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
            }
            return(tpl);
        }
Beispiel #23
0
 public void AddApplication(string appPath)
 {
     if (!Applications.Contains(appPath))
     {
         Applications.Add(appPath);
         RegistrySaver.AddRegistryValue(RegistrySaver.RegCategoryAppList, appPath);
         AppLogger.Log("Application [" + appPath + "] added to list");
     }
     else
     {
         AppLogger.Log("WARNING! Application [" + appPath + "] is already in the list");
     }
 }
Beispiel #24
0
 private void InitServer()
 {
     try
     {
         DBClientBase db   = new DBClientBase();
         var          user = db.GetAllList <BsHospital>();
         AppLogger.Log("首次请求完成:" + System.DateTime.Now.ToString());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #25
0
        public IActionResult DataView()
        {
            DataViewModel model = new DataViewModel();

            try
            {
                model = DBAccess.GetData(null);
            }
            catch (Exception ex)
            {
                AppLogger.Log(ex);
            }
            return(View(model));
        }
Beispiel #26
0
 public override bool SaveData()
 {
     try
     {
         var dataList = ReadData(out string Message);
         var Map      = Helper.GetPropColMapping <FileModel>();
         DBAccess.BulkInsert <FileModel>(dataList, Map);
     }
     catch (Exception ex)
     {
         AppLogger.Log(ex);
     }
     return(true);
 }
		private int SendClusterCommand(string nodeAddress, int port, string cmd, bool bQuiet = false)
		{
			int ResponseCode = 1;
			TcpClient nodeClient = new TcpClient();

			if (!bQuiet)
			{
				AppLogger.Log(string.Format("Sending command {0} to {1}...", cmd, nodeAddress));
			}

			try
			{
				// Connect to the listener
				nodeClient.Connect(nodeAddress, port);
				NetworkStream networkStream = nodeClient.GetStream();

				byte[] OutData = ASCIIEncoding.ASCII.GetBytes(cmd);
				byte[] OutSize = BitConverter.GetBytes((short)OutData.Length);

				networkStream.Write(OutSize, 0, OutSize.Length);
				networkStream.Write(OutData, 0, OutData.Length);
				AppLogger.Log("Event sent");

				byte[] InLength = new byte[2];
				int InBytesCount = networkStream.Read(InLength, 0, 2);
				AppLogger.Log("Received " + InBytesCount + " bytes");

				int MessageSize = InLength[0] + ((UInt16)InLength[1] << 8);
				byte[] InData = new byte[MessageSize];
				InBytesCount = networkStream.Read(InData, 0, MessageSize);
				AppLogger.Log("Received " + InBytesCount + " bytes");

				string Response = ASCIIEncoding.ASCII.GetString(InData, 0, InBytesCount);
				AppLogger.Log("Response " + Response);
			}
			catch (Exception ex)
			{
				if (!bQuiet)
				{
					AppLogger.Log("An error occurred while sending a command to " + nodeAddress + ". EXCEPTION: " + ex.Message);
				}
			}
			finally
			{
				nodeClient.Close();
			}

			return ResponseCode;
		}
Beispiel #28
0
 public void AddConfig(string configPath)
 {
     try
     {
         Configs.Add(configPath);
         SelectedConfig = Configs.Find(x => x == configPath);
         RegistrySaver.AddRegistryValue(RegistrySaver.RegCategoryConfigList, configPath);
         ChangeConfigSelection(configPath);
         AppLogger.Log("Configuration file [" + configPath + "] added to list");
     }
     catch (Exception)
     {
         AppLogger.Log("ERROR! Can not add configuration file [" + configPath + "] to list");
     }
 }
        private void ProcessCommandStartApp(Configuration Config)
        {
            if (!File.Exists(SelectedConfig))
            {
                AppLogger.Log("No config file found: " + SelectedConfig);
                return;
            }

            // Send start command to the listeners
            foreach (EntityClusterNode Node in Config.ClusterNodes.Values)
            {
                string cmd = GenerateStartCommand(Node, Config);
                SendDaemonCommand(Node.Addr, DefaultListenerPort, cmd);
            }
        }
Beispiel #30
0
        public static void Initialize()
        {
            var Logger = new AppLogger();

            I18N.Current
            .SetNotFoundSymbol("!!")                                             // Optional: when a key is not found, it will appear as $key$ (defaults to "$")
            .SetFallbackLocale("de")                                             // Optional but recommended: locale to load in case the system locale is not supported
            .SetThrowWhenKeyNotFound(true)                                       // Optional: Throw an exception when keys are not found (recommended only for debugging)
            .SetLogger(text => Logger.Log(text.Substring(7), typeof(I18N).Name)) // action to output traces
            .SetResourcesFolder("Locales")                                       // Optional: The directory containing the resource files (defaults to "Locales")
            .Init(typeof(App).GetTypeInfo().Assembly);                           // assembl

            Container = new StandardKernel();
            Container.Bind <ILogger>().To <AppLogger>();
            Container.Bind <MainViewModel>().ToSelf().InSingletonScope();
            Container.Bind <AppSettingsViewModel>().ToSelf().InSingletonScope();
            Container.Bind <MediDetailViewModel>().ToSelf().InSingletonScope();
            Container.Bind <NewMediViewModel>().ToSelf().InSingletonScope();
            Container.Bind <DependencyViewModel>().ToSelf().InSingletonScope();
            Container.Bind <DailyViewModel>().ToSelf().InSingletonScope();
            Container.Bind <StartViewModel>().ToSelf().InSingletonScope();
            Container.Bind <Medi>().ToSelf().InSingletonScope(); // Temp Medi
            Container.Bind <ISomeLogic>().To <SomeLogic>();

            if (UseMockDataStore)
            {
                Container.Bind <IDataStore <Medi> >().To <MediDataMock>().InSingletonScope();
                Container.Bind <IDataStore <Weekdays> >().To <WeekdaysDataMock>().InSingletonScope();
                Container.Bind <IDataStore <AppSettings> >().To <AppSettingsDataMock>().InSingletonScope();
                Container.Bind <IDataStore <DailyAppointment> >().To <DailyAppointmentDataMock>().InSingletonScope();
            }
            else
            {
                Container.Bind <IDataStore <Medi> >().To <MediDataStore>().WithConstructorArgument("backendUrl", App.URL);
                Container.Bind <IDataStore <Weekdays> >().To <WeekdaysDataStore>().WithConstructorArgument("backendUrl", App.URL);
                Container.Bind <IDataStore <AppSettings> >().To <AppSettingsDataStore>().WithConstructorArgument("backendUrl", App.URL);
                Container.Bind <IDataStore <DailyAppointment> >().To <DailyAppointmentDataStore>().WithConstructorArgument("backendUrl", App.URL);
            }

            //AppStore.Instance.User = new MediUser
            //{
            //    Id = MediDataMock.USER_ID,
            //    Created = DateTimeOffset.Now,
            //    Medis = new List<Medi>()
            //};

            Task.Run(() => FetchDataByUser());
        }