Beispiel #1
0
        private void LoadFromFile(string pathToFile)
        {
            string         json   = File.ReadAllText(pathToFile);
            JsonTextReader reader = new JsonTextReader(new StringReader(json));
            bool           rv;

            //file must start with an array opener
            rv = reader.Read();
            while (rv && reader.TokenType != JsonToken.StartArray)
            {
                rv = reader.Read();
            }

            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                // object detected
                if (reader.TokenType == JsonToken.StartObject)
                {
                    Dictionary <string, string> properties = new Dictionary <string, string>();
                    //read stuff until we detect the end of the object
                    while (reader.TokenType != JsonToken.EndObject)
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            string propertyName = reader.Value.ToString();
                            //this means that the next read should have a property value
                            rv = reader.Read();

                            if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Integer || reader.TokenType == JsonToken.Float || reader.TokenType == JsonToken.Boolean || reader.TokenType == JsonToken.Date)
                            {
                                properties[propertyName] = reader.Value.ToString();
                            }
                        }
                        rv = reader.Read();
                    }

                    //test if the jobid exists on the database
                    SqlAgentJob jobHandler = Database.CreateSqlAgentJobHandler(properties["jobid"]);
                    if (jobHandler == null)
                    {
                        Logger.Log("Job Id \"" + properties["jobid"] + "\" from file \"" + properties["name"] + "\" at folder \"" + properties["folder"] + "\" was not found on server " + Database.Datasource + ". Job was ignored.", System.Diagnostics.EventLogEntryType.Warning);
                    }


                    FileWatcher watcher = new FileWatcher(properties["folder"], properties["name"], properties["jobid"]);
                    watcher.OnFileReadyForProcessing += OnFileReadyForProcessing;
                    watcher.OnFileRemovedFromFolder  += OnFileRemoved;
                    _watchers.Add(watcher);
                }
            }
            Logger.Log("files.json load complete. Listening to " + _watchers.Count.ToString() + " files.");
        }
Beispiel #2
0
        public FileWatcher(string path, string fileName, string jobId)
        {
            _path     = path;
            _fileName = fileName;
            _jobId    = jobId;

            JobHandler = Database.CreateSqlAgentJobHandler(_jobId);

            _watcher        = new FileSystemWatcher();
            _watcher.Path   = _path;
            _watcher.Filter = _fileName;

            _watcher.NotifyFilter = NOTIFY_FILTERS;

            _watcher.Changed += new FileSystemEventHandler(OnFileChanged);
            _watcher.Created += new FileSystemEventHandler(OnFileChanged);
            _watcher.Deleted += new FileSystemEventHandler(OnFileRemoved);
            _watcher.Renamed += new RenamedEventHandler(OnFileRenamed);

            //Do not start listening inmediatly.
            _watcher.EnableRaisingEvents = false;
        }