示例#1
0
        public UnionAlternative AddAlternative(DataType dt)
        {
            var alt = new UnionAlternative(dt, Alternatives.Count);

            Alternatives.Add(alt);
            return(alt);
        }
示例#2
0
 public Experiment(string testName, params string[] alternatives)
     : this(testName)
 {
     foreach (string alt in alternatives)
     {
         Alternatives.Add(new ABAlternative(alt));
     }
 }
示例#3
0
文件: UnionType.cs 项目: mmyydd/reko
 public UnionType(string name, DataType preferredType, params DataType [] alternatives) : base(name)
 {
     this.PreferredType = preferredType;
     foreach (DataType dt in alternatives)
     {
         Alternatives.Add(new UnionAlternative(dt));
     }
 }
示例#4
0
文件: UnionType.cs 项目: mmyydd/reko
 public UnionType(string name, DataType preferredType, ICollection <DataType> alternatives) : base(name)
 {
     this.Name = name; this.PreferredType = preferredType;
     foreach (DataType dt in alternatives)
     {
         Alternatives.Add(new UnionAlternative(dt));
     }
 }
示例#5
0
        private void UpdateAlternatives(List <string> alternatives)
        {
            for (int index = 0; index < alternatives.Count; index++)
            {
                var label = _drawHelper.DrawLabel(index, alternatives[index]);

                Alternatives.Add(label);
            }
        }
示例#6
0
        private void LoadAlternatives(IEAElement element)
        {
            Alternatives.Clear();
            IEnumerable <IDecisionRelation> alternatives =
                element.FindConnectors(EAConstants.RelationMetaType, EAConstants.RelationAlternativeFor)
                .Select(a => (IDecisionRelation) new DecisionRelation(this, a));

            foreach (IDecisionRelation alternative in alternatives)
            {
                Alternatives.Add(alternative);
            }
        }
        public NonterminalSymbol(string name, string[][] alts)
        {
            Name = name;

            for (int i = 0; i < alts.Length; ++i)
            {
                var newAlt = new Alternative()
                {
                    NonterminalSymbolName = name
                };

                for (int j = 0; j < alts[i].Length; ++j)
                {
                    newAlt.Add(alts[i][j]);
                }

                Alternatives.Add(newAlt);
            }
        }
 public void Add(Alternative alt)
 {
     Alternatives.Add(alt);
 }
示例#9
0
        public void AddAlternative(string alternative, bool isCorrect)
        {
            Alternative alternative1 = new Alternative(alternative, isCorrect);

            Alternatives.Add(alternative1);
        }
示例#10
0
        private Stream CheckAcceptable(HttpRequest Request, HttpResponse Response, ref string ContentType, out bool Dynamic,
                                       string FullPath, string ResourceName)
        {
            HttpRequestHeader Header = Request.Header;

            Dynamic = false;

            if (Header.Accept != null)
            {
                bool Acceptable = Header.Accept.IsAcceptable(ContentType, out double Quality, out AcceptanceLevel TypeAcceptance, null);

                if ((!Acceptable || TypeAcceptance == AcceptanceLevel.Wildcard) && (this.allowTypeConversionFrom is null ||
                                                                                    (this.allowTypeConversionFrom.TryGetValue(ContentType, out bool Allowed) && Allowed)))
                {
                    IContentConverter Converter      = null;
                    string            NewContentType = null;

                    foreach (AcceptRecord AcceptRecord in Header.Accept.Records)
                    {
                        NewContentType = AcceptRecord.Item;
                        if (NewContentType.EndsWith("/*"))
                        {
                            NewContentType = null;
                            continue;
                        }

                        if (InternetContent.CanConvert(ContentType, NewContentType, out Converter))
                        {
                            Acceptable = true;
                            break;
                        }
                    }

                    if (Converter is null)
                    {
                        IContentConverter[] Converters = InternetContent.GetConverters(ContentType);

                        if (!(Converters is null))
                        {
                            string            BestContentType = null;
                            double            BestQuality     = 0;
                            IContentConverter Best            = null;
                            bool Found;

                            foreach (IContentConverter Converter2 in InternetContent.Converters)
                            {
                                Found = false;

                                foreach (string FromContentType in Converter2.FromContentTypes)
                                {
                                    if (ContentType == FromContentType)
                                    {
                                        Found = true;
                                        break;
                                    }
                                }

                                if (!Found)
                                {
                                    continue;
                                }

                                foreach (string ToContentType in Converter2.ToContentTypes)
                                {
                                    if (Header.Accept.IsAcceptable(ToContentType, out double Quality2) && Quality > BestQuality)
                                    {
                                        BestContentType = ToContentType;
                                        BestQuality     = Quality;
                                        Best            = Converter2;
                                    }
                                }
                            }

                            if (Best != null && (!Acceptable || BestQuality >= Quality))
                            {
                                Acceptable     = true;
                                Converter      = Best;
                                NewContentType = BestContentType;
                            }
                        }
                    }

                    if (Acceptable && Converter != null)
                    {
                        Stream f2 = null;
                        Stream f  = File.Open(FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        bool   Ok = false;

                        try
                        {
                            f2 = f.Length < HttpClientConnection.MaxInmemoryMessageSize ? (Stream) new MemoryStream() : new TemporaryFile();

                            if (Request.Session != null)
                            {
                                Request.Session["Request"]  = Request;
                                Request.Session["Response"] = Response;
                            }

                            List <string> Alternatives = null;
                            string[]      Range        = Converter.ToContentTypes;

                            foreach (AcceptRecord AcceptRecord in Header.Accept.Records)
                            {
                                if (AcceptRecord.Item.EndsWith("/*") || AcceptRecord.Item == NewContentType)
                                {
                                    continue;
                                }

                                if (Array.IndexOf <string>(Range, AcceptRecord.Item) >= 0)
                                {
                                    if (Alternatives is null)
                                    {
                                        Alternatives = new List <string>();
                                    }

                                    Alternatives.Add(AcceptRecord.Item);
                                }
                            }

                            if (Converter.Convert(ContentType, f, FullPath, ResourceName, Request.Header.GetURL(false, false),
                                                  ref NewContentType, f2, Request.Session, Alternatives?.ToArray()))
                            {
                                Dynamic = true;
                            }

                            ContentType = NewContentType;
                            Ok          = true;
                        }
                        finally
                        {
                            if (f2 is null)
                            {
                                f.Dispose();
                            }
                            else if (!Ok)
                            {
                                f2.Dispose();
                                f.Dispose();
                            }
                            else
                            {
                                f.Dispose();
                                f          = f2;
                                f.Position = 0;
                            }
                        }

                        return(f);
                    }
                }

                if (!Acceptable)
                {
                    throw new NotAcceptableException();
                }
            }

            return(null);
        }