Example #1
0
        public bool SaveUserConfiguration(UserConfiguration userConfiguration)
        {
            /*
             * <userID>1</userID>
             * <userLogPath>C:\Logs</userLogPath>
             * <userCheckInterval>5</userCheckInterval>
             * <userOpenOnStartUp>1</userOpenOnStartUp>
             */
            var confReader   = new ConfigurationReader();
            var serverConfig = confReader.GetServiceConfig();
            var confSaver    = new ConfigurationSaver(serverConfig.UserLogPath);

            if (!confSaver.AddAttribute("userID", userConfiguration.ID.ToString()) ||
                !confSaver.AddAttribute("userPCID", userConfiguration.PCID) ||
                !confSaver.AddAttribute("userPreviousPCID", userConfiguration.PreviousPCID) ||
                !confSaver.AddAttribute("userLogPath", userConfiguration.LogPath) ||
                !confSaver.AddAttribute("userCheckInterval", userConfiguration.CheckInterval) ||
                !confSaver.AddAttribute("userOpenOnStartup", userConfiguration.OpenOnStartup) ||
                !confSaver.AddAttribute("userMinimizedWhenClose", userConfiguration.MinimizedWhenClose))
            {
                return(false);
            }
            else
            {
                string userConfigFolder   = (serverConfig.UserConfigPath.Equals("ApplicationFolder")) ? AppDomain.CurrentDomain.BaseDirectory : serverConfig.UserConfigPath;
                string userConfigFullPath = Path.Combine(userConfigFolder, serverConfig.UserConfigFileName);
                return(confSaver.SaveXML(userConfigFullPath));
            }
        }
Example #2
0
        public bool SaveServiceConfiguration(ServiceConfiguration serviceConfiguration)
        {
            /*
             * <serviceName>minertracker</serviceName>
             * <servicePort>9988</servicePort>
             * <serverAddress>http://minertracker.com/api/fields</serverAddress>
             * <logPath>C:\Logs</logPath>
             * <checkInterval>60</checkInterval>
             * <userPCID>default</userPCID>
             * <userConfigPath>ApplicationFolder</userConfigPath>
             * <userConfigFileName>user.config</userConfigFileName>
             * <userID>1</userID>
             * <userLogPath>C:\Logs</userLogPath>
             * <userCheckInterval>5</userCheckInterval>
             * <userOpenOnStartup>1</userOpenOnStartup>
             * <userMinimizedWhenClose>1</userMinimizedWhenClose>
             */
            var confSaver = new ConfigurationSaver();

            if (
                !confSaver.AddAttribute("serviceName", serviceConfiguration.ServiceName) ||
                !confSaver.AddAttribute("servicePort", serviceConfiguration.ServicePort) ||
                !confSaver.AddAttribute("serverAddress", serviceConfiguration.ServerAddress) ||
                !confSaver.AddAttribute("serverUpdateIDAddress", serviceConfiguration.ServerUpdateIDAddress) ||
                !confSaver.AddAttribute("logPath", serviceConfiguration.LogPath) ||
                !confSaver.AddAttribute("checkInterval", serviceConfiguration.CheckInterval.ToString()) ||
                !confSaver.AddAttribute("userPCID", serviceConfiguration.UserPCID) ||
                !confSaver.AddAttribute("userConfigPath", serviceConfiguration.UserConfigPath) ||
                !confSaver.AddAttribute("userConfigFileName", serviceConfiguration.UserConfigFileName) ||
                !confSaver.AddAttribute("userID", serviceConfiguration.UserID.ToString()) ||
                !confSaver.AddAttribute("userLogPath", serviceConfiguration.UserLogPath) ||
                !confSaver.AddAttribute("userCheckInterval", serviceConfiguration.UserCheckInterval) ||
                !confSaver.AddAttribute("userOpenOnStartup", serviceConfiguration.UserOpenOnStartup) ||
                !confSaver.AddAttribute("userMinimizedWhenClose", serviceConfiguration.UserMinimizedWhenClose))
            {
                return(false);
            }
            else
            {
                string configFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "service.config");
                return(confSaver.SaveXML(configFullPath));
            }
        }