Ejemplo n.º 1
0
        /// <summary>
        /// Loads configuration dictionary from files or returns empty configuration.
        /// </summary>
        /// <param name="xmlConfigFilePath">Path of the configuration XML file.</param>
        /// <param name="xmlSchemaConfigFilePath">Path of the configuration XML Schema file.</param>
        /// <returns>Configuration dictionary.</returns>
        /// <exception cref="InvalidDataException">Invalid data.</exception>
        /// <exception cref="XmlException">Error occured when parsing the XML.</exception>
        private static Dictionary <string, FileWatcherConfigurationSet> LoadConfiguration(string xmlConfigFilePath,
                                                                                          string xmlSchemaConfigFilePath)
        {
            Dictionary <string, FileWatcherConfigurationSet> tempConfigurationDictionary =
                new Dictionary <string, FileWatcherConfigurationSet>();

            try
            {
                // Check files.
                if (CheckFiles(xmlConfigFilePath,
                               xmlSchemaConfigFilePath))
                {
                    // Load configuration.
                    tempConfigurationDictionary =
                        XmlConfigurationLoader.LoadConfiguration(xmlConfigFilePath,
                                                                 xmlSchemaConfigFilePath);
                }
            }
            catch (InvalidDataException ex)
            {
                throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture,
                                                             @Resources.MessageFileWatcherConfigurationError,
                                                             @ex.Message), ex);
            }
            catch (XmlException ex)
            {
                throw new XmlException(String.Format(CultureInfo.CurrentCulture,
                                                     @Resources.MessageFileWatcherConfigurationError,
                                                     @ex.Message), ex);
            }
            return(tempConfigurationDictionary);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the server with the embedded configuration.
        /// </summary>
        /// <param name="taskInstance">Instance of the background task associated with the application</param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            stopTokenSource = new CancellationTokenSource();

            taskInstance.Canceled += Stop;

            var deferral = taskInstance.GetDeferral();

            try
            {
                EnsureSystemNet();

                var configurationXml =
                    await FileIO.ReadTextAsync(
                        await ApplicationData.Current.LocalFolder.GetFileAsync(ConfigurationFile));

                using (var serverHost =
                           new XmlConfigurationLoader().Load <ServerHost>(configurationXml))
                {
                    try
                    {
                        await Task.Delay(-1, stopTokenSource.Token);
                    }
                    catch (OperationCanceledException)
                    {
                        // Stop requested
                    }
                }
            }
            catch (Exception error)
            {
                // Log any initialization errors
                var logFile =
                    await ApplicationData.Current.TemporaryFolder.CreateFileAsync(
                        $"{DateTime.Now:ddMMyyyy-hhmmss}.txt",
                        CreationCollisionOption.ReplaceExisting);

                await FileIO.AppendTextAsync(logFile, error.ToString() + Environment.NewLine);
            }

            stopTokenSource.Dispose();
            taskInstance.Canceled -= Stop;

            deferral.Complete();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //var configLoader = new AttributeConfigurationLoader();
            var configLoader = new XmlConfigurationLoader("configs\\test.config.xml");
            var reader       = new ExcelDataReader("testdata.xlsx", configLoader);

            try
            {
                var users = reader.ReadData <User>();

                foreach (var u in users)
                {
                    Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", u.ID, u.Name, u.Age, u.Email, u.Birthday);
                }
            }
            catch (DataReaderException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        /// <param name="cancelToken">Cancellation token to signal stop request</param>
        /// <returns>A <see cref="Task"/> that represents asyncrhonous hosting.</returns>
        public async Task Run(CancellationToken cancelToken)
        {
            var configSection =
                ConfigurationManager.GetSection(ZeptoServerConfigurationSectionName)
                as ZeptoServerConfigurationSection;

            if (configSection == null)
            {
                throw Errors.MissingConfigurationSection(ZeptoServerConfigurationSectionName);
            }

            using (var serverHost =
                       new XmlConfigurationLoader().Load <ServerHost>(configSection.ServerHostConfiguration))
            {
                try
                {
                    await Task.Delay(-1, cancelToken);
                }
                catch (OperationCanceledException)
                {
                    // Stop requested
                }
            }
        }