示例#1
0
 protected override void OnStop()
 {
     base.OnStop();
     CremaLog.Debug("service close");
     this.cremaService.Close();
     CremaLog.Debug("service closed.");
 }
示例#2
0
        static void RegisterLicense(string licenseName, Action <string> action)
        {
            var type = typeof(Program);
            var rm   = new ResourceManager($"{type.Namespace}.Properties.Resources", type.Assembly);
            var obj  = (byte[])rm.GetObject(licenseName);

            if (obj != null)
            {
                var license = Encoding.UTF8.GetString(obj);
                if (string.IsNullOrEmpty(license) == false)
                {
                    try
                    {
                        action(license);
                    }
                    catch (Exception e)
                    {
                        CremaLog.Error(new Exception($"register license failed : {licenseName}", e));
                    }
                    return;
                }
            }

            CremaLog.Warn($"license does not registered : {licenseName}");
        }
示例#3
0
文件: Program.cs 项目: sedrion/Crema
        static Program()
        {
            RegisterLicense($"{typeof(Program).Namespace}.Licenses.Newtonsoft.Json.Schema.license", item => Newtonsoft.Json.Schema.License.RegisterLicense(item));

            void RegisterLicense(string licenseName, Action <string> action)
            {
                try
                {
                    using (var stream = typeof(Program).Assembly.GetManifestResourceStream(licenseName))
                        using (var reader = new StreamReader(stream))
                        {
                            var license = reader.ReadToEnd();
                            if (license == string.Empty)
                            {
                                CremaLog.Warn($"license does not registered : {licenseName}");
                            }
                            else
                            {
                                action(license);
                            }
                        }
                }
                catch (Exception e)
                {
                    CremaLog.Error(new Exception($"register license failed : {licenseName}", e));
                }
            }
        }
示例#4
0
        public static async Task <LogViewModel> ShowDialogAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (descriptor.Target is IDataBase dataBase)
            {
                try
                {
                    var dialog = await dataBase.Dispatcher.InvokeAsync(() => new LogViewModel(authentication, dataBase));

                    if (dialog.ShowDialog() == true)
                    {
                        return(dialog);
                    }
                    return(null);
                }
                catch (Exception e)
                {
                    CremaLog.Error(e);
                    return(null);
                }
            }
            throw new NotImplementedException();
        }
示例#5
0
        static App()
        {
            CremaLog.RedirectionWriter = writer;

            RegisterLicense($"{typeof(App).Namespace}.Licenses.Newtonsoft.Json.Schema.license", item => Newtonsoft.Json.Schema.License.RegisterLicense(item));
            RegisterLicense($"{typeof(App).Namespace}.Licenses.Xceed.Wpf.DataGrid.license", item => Xceed.Wpf.DataGrid.Licenser.LicenseKey = item);
            RegisterLicense($"{typeof(App).Namespace}.Licenses.Xceed.Wpf.Toolkit.license", item => Xceed.Wpf.Toolkit.Licenser.LicenseKey   = item);

            void RegisterLicense(string licenseName, Action <string> action)
            {
                try
                {
                    using (var stream = typeof(App).Assembly.GetManifestResourceStream(licenseName))
                        using (var reader = new StreamReader(stream))
                        {
                            var license = reader.ReadToEnd();
                            if (license == string.Empty)
                            {
                                CremaLog.Warn($"license does not registered : {licenseName}");
                            }
                            else
                            {
                                action(license);
                            }
                        }
                }
                catch (Exception e)
                {
                    CremaLog.Error(new Exception($"register license failed : {licenseName}", e));
                }
            }
        }
示例#6
0
        protected async override void OnDeactivate(bool close)
        {
            base.OnDeactivate(close);

            try
            {
                if (this.template != null)
                {
                    await this.template.Dispatcher.InvokeAsync(() =>
                    {
                        this.template.CancelEdit(this.authentication);
                    });
                }
            }
            catch (Exception e)
            {
                CremaLog.Error(e);
            }
            finally
            {
                if (this.template != null)
                {
                    await this.template.Dispatcher.InvokeAsync(() =>
                    {
                        this.template.EditEnded    -= Template_EditEnded;
                        this.template.EditCanceled -= Template_EditCanceled;
                        this.template.Changed      -= Template_Changed;
                        this.template = null;
                    });
                }
            }
        }
示例#7
0
        public void RestoreState(CremaSettings settings)
        {
            if (settings.NoCache == false)
            {
                var stateCaches = this.ReadStateCaches();
                foreach (var item in this)
                {
                    if (stateCaches.ContainsKey($"{item.ID}") == true)
                    {
                        if (stateCaches[$"{item.ID}"] == DataBaseState.IsLoaded)
                        {
                            item.Load(Authentication.System);
                        }
                    }
                }
            }

            foreach (var item in settings.DataBaseList)
            {
                if (this.ContainsKey(item) == true)
                {
                    var dataBase = this[item];
                    if (dataBase.IsLoaded == false)
                    {
                        dataBase.Load(Authentication.System);
                    }
                }
                else
                {
                    CremaLog.Error(new DataBaseNotFoundException(item));
                }
            }
        }
示例#8
0
 private static string MessageSelector(object message)
 {
     if (message is Exception exception)
     {
         CremaLog.Error(exception);
     }
     return(AppMessageBox.DefaultMessageSelector(message));
 }
示例#9
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            var baseArgs = Environment.GetCommandLineArgs();
            var path     = baseArgs[1];
            var port     = int.Parse(baseArgs[2]);

            this.cremaService = new CremaService()
            {
                BasePath = path,
                Port     = port,
            };

            CremaLog.Debug("service base path : {0}", path);
            CremaLog.Debug("service port : {0}", port);

            try
            {
                CremaLog.Debug(args.Length);
                if (args.Any() == true)
                {
                    var settings = new Settings()
                    {
                        BasePath         = this.cremaService.BasePath,
                        Port             = this.cremaService.Port,
                        RepositoryModule = this.cremaService.RepositoryModule,
                        RepositoryName   = this.cremaService.RepositoryName,
                    };
                    var parser = new CommandLineParser("setting", settings);
                    parser.Parse(string.Join(" ", "setting", string.Join(" ", args)));

                    this.cremaService.BasePath         = settings.BasePath;
                    this.cremaService.Port             = settings.Port;
                    this.cremaService.RepositoryModule = settings.RepositoryModule;
                    this.cremaService.RepositoryName   = settings.RepositoryName;

                    CremaLog.Debug("=========================================================");
                    CremaLog.Debug("new settings");
                    CremaLog.Debug("service base path : {0}", settings.BasePath);
                    CremaLog.Debug("service port : {0}", settings.Port);
                    CremaLog.Debug("service repo name : {0}", settings.RepositoryName);
                    CremaLog.Debug("service repo module : {0}", settings.RepositoryModule);
                    CremaLog.Debug("=========================================================");
                }
            }
            catch (Exception e)
            {
                CremaLog.Error(e);
                throw e;
            }

            CremaLog.Debug("service open");
            this.cremaService.Open();
            this.cremaHost         = this.cremaService.CremaHost;
            this.cremaHost.Closed += CremaHost_Closed;
            CremaLog.Debug("service opened.");
        }
示例#10
0
        public async void Login(string address, string userID, SecureString password, string dataBaseName)
        {
            this.HasError = false;
            this.BeginProgress();

            try
            {
                this.ProgressMessage = Resources.Message_ConnectingToServer;
                if (await this.cremaHost.Dispatcher.InvokeAsync(() => CremaBootstrapper.IsOnline(address, userID, password)) == true)
                {
                    if (AppMessageBox.ShowQuestion(Resources.Message_SameIDConnected) == false)
                    {
                        this.ProgressMessage = string.Empty;
                        this.EndProgress();
                        this.HasError = false;
                        return;
                    }
                }
                await this.OpenAsync(address, userID, password);

                if (dataBaseName != string.Empty)
                {
                    await this.LoadAsync(dataBaseName);
                }
                else
                {
                    this.EndProgress();
                    this.dataBase     = null;
                    this.dataBaseName = null;
                    this.address      = null;
                    this.Refresh();
                    this.ProgressMessage = string.Empty;
                }
            }
            catch (TimeoutException e)
            {
                CremaLog.Error(e);
                this.ErrorMessage = Resources.Message_ConnectionFailed;
            }
            catch (EndpointNotFoundException e)
            {
                CremaLog.Error(e);
                this.ErrorMessage = Resources.Message_ConnectionFailed;
            }
            catch (Exception e)
            {
                CremaLog.Error(e);
                this.ErrorMessage = e.Message;
                if (this.IsOpened == true)
                {
                    AppMessageBox.ShowError(e.Message);
                }
            }
            finally
            {
                this.EndProgress(this.ProgressMessage);
            }
        }
示例#11
0
 private void CremaAppHost_Resetting(object sender, EventArgs e)
 {
     try
     {
         this.cremaAppHost.UserConfigs?.Commit(this);
     }
     catch (Exception ex)
     {
         CremaLog.Error(ex);
     }
 }
示例#12
0
        private void StopService()
        {
            CremaLog.Debug("service close");
            this.cremaService.Close();
            CremaLog.Debug("service closed.");

            if (IsMonoRuntime)
            {
                Environment.Exit(0);
            }
        }
示例#13
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main()
 {
     try
     {
         ServiceBase.Run(new WindowCremaService());
     }
     catch (Exception e)
     {
         CremaLog.Error(e);
         throw e;
     }
 }
示例#14
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            var baseArgs = Environment.GetCommandLineArgs();
            var path     = baseArgs[1];
            var port     = int.Parse(baseArgs[2]);

            this.cremaApp = new CremaApplication()
            {
                BasePath = path,
                Port     = port,
            };

            this.EventLog.WriteEntry($"service base path : {path}");
            this.EventLog.WriteEntry($"service port : {port}");

            try
            {
                this.EventLog.WriteEntry($"args length: {args.Length}");
                if (args.Any() == true)
                {
                    var settings = new Settings()
                    {
                        BasePath = this.cremaApp.BasePath,
                        Port     = this.cremaApp.Port,
                    };
                    var parser = new CommandLineParser("setting", settings);
                    parser.Parse(string.Join(" ", "setting", string.Join(" ", args)));

                    this.cremaApp.BasePath = settings.BasePath;
                    this.cremaApp.Port     = settings.Port;

                    this.EventLog.WriteEntry($"=========================================================");
                    this.EventLog.WriteEntry($"new settings");
                    this.EventLog.WriteEntry($"service base path : {settings.BasePath}");
                    this.EventLog.WriteEntry($"service port : {settings.Port}");
                    this.EventLog.WriteEntry($"service repo module : {settings.RepositoryModule}");
                    this.EventLog.WriteEntry($"=========================================================");
                }
            }
            catch (Exception e)
            {
                CremaLog.Error(e);
                throw e;
            }

            this.EventLog.WriteEntry("service open");
            this.cremaApp.Open();
            this.cremaHost        = this.cremaApp.GetService(typeof(ICremaHost)) as ICremaHost;
            this.cremaApp.Closed += CremaApp_Closed;
            this.EventLog.WriteEntry("service opened.");
        }
示例#15
0
        protected override void OnStop()
        {
            base.OnStop();
            CremaLog.Debug("service close");
            this.cremaService.Close();
            CremaLog.Debug("service closed.");

            if (IsMonoRuntime)
            {
                Environment.Exit(0);
            }
        }
示例#16
0
 private void CremaHost_Closed(object sender, ClosedEventArgs e)
 {
     CremaLog.Debug(nameof(CremaHost_Closed) + " " + e.Reason);
     if (e.Reason == CloseReason.Shutdown)
     {
         Task.Run(() =>
         {
             Thread.Sleep(1000);
             this.Stop();
         });
     }
 }
示例#17
0
        public void CreateRepository(string basePath, string repositoryPath)
        {
            var remotePath = Path.Combine(basePath, remoteName);
            var svnUri     = new Uri(remotePath);

            DirectoryUtility.Create(repositoryPath);
            DirectoryUtility.Prepare(repositoryPath, "tags");
            DirectoryUtility.Prepare(repositoryPath, "trunk");

            SvnServerHost.Run("create", remotePath.WrapQuot(), "--fs-type", "fsfs");
            SvnClientHost.Run("import", "-m", "first", repositoryPath.WrapQuot(), svnUri.ToString().WrapQuot());
            SvnClientHost.Run("checkout", svnUri.ToString().WrapQuot(), repositoryPath.WrapQuot(), "--force");

            CremaLog.Info("crema repository : \"{0}\"", repositoryPath);
            CremaLog.Info("  svn repository : \"{0}\"", remotePath);
        }
示例#18
0
 public ShellView(ICremaHost cremaHost, ConsoleCommandContext commandContext)
 {
     InitializeComponent();
     this.writer = new LogTextWriter()
     {
         TextBox = this.LogBox
     };
     this.cremaHost               = cremaHost;
     this.cremaHost.Opening      += CremaHost_Opening;
     this.cremaHost.Opened       += CremaHost_Opened;
     this.cremaHost.Closed       += CremaHost_Closed;
     this.commandContext          = commandContext;
     this.commandContext.Out      = new ConsoleWriter(this.terminal);
     this.terminal.CommandContext = this.commandContext;
     this.SetPrompt();
     CremaLog.AddRedirection(this.writer, LogLevel.Info);
 }
 public ConsoleConfiguration([ImportMany] IEnumerable <IConfigurationPropertyProvider> propertiesProvider)
     : base(propertiesProvider)
 {
     this.xmlPath        = AppUtility.GetDocumentFilename("configs") + ".xml";
     this.xsdPath        = AppUtility.GetDocumentFilename("configs") + ".xsd";
     this.SchemaLocation = UriUtility.MakeRelative(this.xmlPath, this.xsdPath);
     if (File.Exists(this.xmlPath) == true)
     {
         try
         {
             //this.Read(this.xmlPath);
         }
         catch (Exception e)
         {
             CremaLog.Error(e);
         }
     }
 }
 protected override void OnCommitted(System.Collections.IDictionary savedState)
 {
     CremaLog.Debug(serviceInstaller.ServiceName);
     CremaLog.Debug("commit");
     base.OnCommitted(savedState);
     CremaLog.Debug("committed");
     using ServiceController controller = new ServiceController(serviceInstaller.ServiceName);
     try
     {
         if (controller.Status != ServiceControllerStatus.Running)
         {
             controller.Start();
             controller.WaitForStatus(ServiceControllerStatus.Running);
         }
     }
     catch
     {
         throw;
     }
 }
示例#21
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (this.ParseCommandLine() == false)
            {
                this.Shutdown();
                return;
            }

            try
            {
                var splash = new SplashWindow()
                {
                    Title      = AppUtility.ProductName,
                    ThemeColor = Settings.Default.ThemeColor,
                    Background = Settings.Default.Background,
                    Foreground = Settings.Default.Foreground
                };
                splash.Show();

                if (this.FindResource("bootstrapper") is AppBootstrapper bootstrapper)
                {
                    bootstrapper.Initialize();
                }
                base.OnStartup(e);
                splash.Close();
            }
            catch (ConfigurationErrorsException cee)
            {
                foreach (var exception in cee.Errors)
                {
                    CremaLog.Error(exception);
                }

                Settings.Default.Reset();

                MessageBox.Show($"설정 파일을 초기화 하였습니다.\r\n응용 프로그램을 다시 시작하십시오.\r\n\r\n{cee}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                throw;
            }
        }
示例#22
0
        private void InitializeFromSettings()
        {
            if (this.FindResource("bootstrapper") is AppBootstrapper bootstrapper)
            {
                if (bootstrapper.Settings.Theme != string.Empty)
                {
                    this.cremaAppHost.Theme = bootstrapper.Settings.Theme;
                }

                if (bootstrapper.Settings.ThemeColor != string.Empty)
                {
                    try
                    {
                        var themeColor = (Color)ColorConverter.ConvertFromString(bootstrapper.Settings.ThemeColor);
                        this.cremaAppHost.ThemeColor = themeColor;
                    }
                    catch (Exception e)
                    {
                        CremaLog.Error(e);
                    }
                }
            }
        }
示例#23
0
 public void Warn(object message)
 {
     CremaLog.Warn(message);
 }
示例#24
0
 public void Error(object message)
 {
     CremaLog.Error(message);
 }
示例#25
0
 public void Fatal(object message)
 {
     CremaLog.Fatal(message);
 }
示例#26
0
 public void Info(object message)
 {
     CremaLog.Info(message);
 }
示例#27
0
 static App()
 {
     CremaLog.AddRedirection(Writer, LogLevel.Debug);
 }
示例#28
0
 public void RemoveRedirection(TextWriter writer)
 {
     CremaLog.RemoveRedirection(writer);
 }
示例#29
0
 protected override void OnExit(ExitEventArgs e)
 {
     CremaLog.RemoveRedirection(Writer);
     base.OnExit(e);
 }
示例#30
0
 public void AddRedirection(TextWriter writer, LogLevel verbose)
 {
     CremaLog.AddRedirection(writer, verbose);
 }