Exemplo n.º 1
0
        /// <summary>
        ///     Attempts
        /// This method is slow so lets not use it too much.
        /// </summary>
        /// <param name="job"></param>
        private static void CheckForInvalidCharacters(ref MongoJob job)
        {
            Dictionary <string, object> changedData =
                JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(job.Data));
            Dictionary <string, object> returnedData = CheckSectionForInvalidNames(changedData);


            dynamic thirdTime = JsonConvert.DeserializeObject <ExpandoObject>(JsonConvert.SerializeObject(returnedData));

            if (thirdTime != null)
            {
                job.Data = thirdTime;
            }
        }
Exemplo n.º 2
0
        /// <summary>Overloaded method to allow second attempt if job contains invalid names.</summary>
        /// <inheritdoc cref="BaseDatastore.Add" />
        /// <param name="secondAttempt">Is this the second attempt to queue job?</param>
#pragma warning disable 1573
        public void Add(string qid, Job job, bool secondAttempt)
        {
#pragma warning restore 1573
            MongoJob mongoJob = null;
            try {
                mongoJob = MongoJob.ConvertJob(job);
                IMongoCollection <MongoJob> collection = this.GetCollection(qid);
                // If mongoJob already exists we need to replace it
                FilterDefinition <MongoJob> filterDefinition =
                    Builders <MongoJob> .Filter.Eq("_id", mongoJob.JobId);

                collection.ReplaceOne(filterDefinition,
                                      mongoJob,
                                      new UpdateOptions {
                    IsUpsert = true
                });
            } catch (BsonSerializationException e) {
                if (secondAttempt)
                {
                    throw;
                }

                try {
                    if (e.Message.Contains("Element name"))
                    {
                        // Name probs contains '.'
                        if (mongoJob != null)
                        {
                            CheckForInvalidCharacters(ref mongoJob);
                            this.Add(qid, mongoJob, true);
                        }
                    }
                } catch (Exception) {
                    throw e;
                }
            } catch (Exception e) {
                Log.Error("Failed to add job data.", e);
                throw;
            }
        }