/// <summary>Gets the score calculator.</summary>
 /// <param name="shred30Options">The shred30 options.</param>
 /// <param name="shred30Contacts">The shred30 contacts.</param>
 public static IShred30ScoreCalculator GetScoreCalculator(Shred30Options shred30Options, IEnumerable <IShred30Contact> shred30Contacts)
 {
     return(new StandardShred30ScoreCalculator(
                shred30Contacts,
                GetContactArrangers(shred30Options),
                GetValidators(),
                GetAddCalculator(shred30Options),
                GetUniqueCalculator(shred30Options)
                ));
 }
 /// <summary>Gets the unique calculator.</summary>
 /// <param name="shred30Options">The shred30 options.</param>
 private static IUniqueCalculator GetUniqueCalculator(Shred30Options shred30Options)
 {
     if (shred30Options.IsOpenLevel)
     {
         return(new OpenAddsBasedUniqueCalculator());
     }
     else
     {
         return(new IntermediateAddsBasedUniqueCalculator());
     }
 }
 /// <summary>Gets the add calculator.</summary>
 /// <param name="shred30Options">The shred30 options.</param>
 private static IAddCalculator GetAddCalculator(Shred30Options shred30Options)
 {
     if (shred30Options.UseXDex)
     {
         return(new StandardAddCalculator());
     }
     else
     {
         return(new NoXDexAddCalculator());
     }
 }
Ejemplo n.º 4
0
 /// <summary>Gets the shred30 options.</summary>
 /// <param name="options">The options.</param>
 private Shred30Options GetShred30Options(string options)
 {
     if (options == null)
     {
         return(Shred30Options.Default());
     }
     else
     {
         return(JsonConvert.DeserializeObject <Shred30Options>(options));
     }
 }
Ejemplo n.º 5
0
        public IHttpActionResult Index(string shred30, string options = null)
        {
            try
            {
                Shred30Options shred30Options = this.GetShred30Options(options);

                Shred30ContactsDeserializer   deserializer    = new Shred30ContactsDeserializer(shred30);
                IEnumerable <IShred30Contact> shred30Contacts = deserializer.Deserialize();

                IShred30ScoreCalculator scoreCalculator =
                    Shred30ScoreCalculatorFactory.GetScoreCalculator(shred30Options, shred30Contacts);

                Shred30ScoreResponse scoreResponse = new Shred30ScoreResponse
                {
                    Shred30String       = shred30Contacts.GetCollection().Format(),
                    Score               = scoreCalculator.CalculateScore(),
                    ScoreComponents     = scoreCalculator.GetScoreComponents(),
                    ContactExplanations = scoreCalculator.GetContactExplanations(),
                    Shred30Options      = shred30Options
                };

                return(Ok(scoreResponse));
            }
            catch (JsonException jsonException)
            {
                return(InternalServerError(jsonException));
            }
            catch (DeserializationException deserializationException)
            {
                return(Content(HttpStatusCode.PreconditionFailed, deserializationException));
            }
            catch (TrickNotFoundException trickNotFoundException)
            {
                return(Content(HttpStatusCode.NotFound, trickNotFoundException.Message));
            }
            catch (NotAllTricksSpecifySidesException notAllTricksSpecifySideException)
            {
                return(Content(HttpStatusCode.PreconditionFailed, notAllTricksSpecifySideException.Message));
            }
            catch (SurfacesDoNotLineUpException surfacesDoNotLineUpException)
            {
                return(Content(HttpStatusCode.PreconditionFailed, surfacesDoNotLineUpException.Message));
            }
            catch (TrickAfterDropDoesNotSpecifySideException trickAfterDropDoesNotSpecifySideException)
            {
                return(Content(HttpStatusCode.PreconditionFailed, trickAfterDropDoesNotSpecifySideException));
            }
            catch (Exception exception)
            {
                return(InternalServerError(exception));
            }
        }
        /// <summary>Gets the contact arrangers.</summary>
        private static IEnumerable <IShred30ContactArranger> GetContactArrangers(Shred30Options shred30Options)
        {
            IFootbagTrickService footbagTrickService;

            if (shred30Options.FootbagTrickService == "xml")
            {
                footbagTrickService = new XmlFootbagTrickService();
            }
            else
            {
                throw new System.Exception(
                          string.Format("Unsupported footbag trick service type: {0}", shred30Options.FootbagTrickService)
                          );
            }

            return(new List <IShred30ContactArranger>()
            {
                new FootbagTrickArranger(footbagTrickService),
                new StartSideArranger()
            });
        }