コード例 #1
0
        protected virtual void CompileScenario(List <Pickle> pickles,
                                               Func <IEnumerable <PickleStep> > backgroundStepsFactory, Scenario scenario, IEnumerable <Tag> featureTags,
                                               string language, string gherkinDocumentUri)
        {
            var steps = new List <PickleStep>();

            if (scenario.Steps.Any())
            {
                steps.AddRange(backgroundStepsFactory());
            }

            var scenarioTags = new List <Tag>();

            scenarioTags.AddRange(featureTags);
            scenarioTags.AddRange(scenario.Tags);

            steps.AddRange(PickleSteps(scenario.Steps));

            Pickle pickle = new Pickle(
                _idGenerator.GetNewId(),
                gherkinDocumentUri,
                scenario.Name,
                language,
                steps,
                PickleTags(scenarioTags),
                new [] { scenario.Id }
                );

            pickles.Add(pickle);
        }
コード例 #2
0
        public Pickle Add(Pickle pickle)
        {
            //pickle.Id = _pickles.Max(x => x.Id) + 1;
            //_pickles.Add(pickle);

            var sql = @"insert into Pickle(NumberInStock,Price,Size, Type)
                        output inserted.*
                        values(@NumberInStock, @Price, @Size, @Type)";

            using (var db = new SqlConnection(ConnectionString))
            {
                var result = db.QueryFirstOrDefault <Pickle>(sql, pickle);
                return(result);

                //db.Open();

                //var cmd = db.CreateCommand();
                //cmd.CommandText = sql;

                //cmd.Parameters.AddWithValue("NumberInStock", pickle.NumberInStock);
                //cmd.Parameters.AddWithValue("Price", pickle.Price);
                //cmd.Parameters.AddWithValue("Size", pickle.Size);
                //cmd.Parameters.AddWithValue("Type", pickle.Type);

                //var reader = cmd.ExecuteReader();

                //if (reader.Read())
                //{
                //    var newPickle = MapReaderToPickle(reader);
                //    return newPickle;
                //}
                //return null;
            }
        }
コード例 #3
0
        private static void TryResolve <T>(Pickle pickle, PickleStep step, IStepResolver resolver, T context)
        {
            try
            {
                resolver.Resolve(step, context);
            }
            catch (Exception e)
            {
                var plocs = String.Join(",",
                                        pickle.Locations.Select(loc => $"{loc.Line}:{loc.Column}"));

                var slocs = String.Join(",",
                                        step.Locations.Select(loc => $"{loc.Line}:{loc.Column}"));

                var message = $@"

Scenario: ({plocs}) {pickle.Name}
    Step: ({slocs}) {step.Text}
   Error: {(e.InnerException ?? e).Message}

  Test Trace:
{(e.InnerException ?? e).StackTrace}

";
                throw new Exception(message);
            }
        }
コード例 #4
0
        public Pickle Add(Pickle pickle)
        {
            // using Max takes into account the possibility of repeats
            //pickle.Id = _pickles.Max(x => x.Id) + 1;
            //_pickles.Add(pickle);

            // Steps to Success
            // write a query in SQL Server Management Studio to see how it is going to work
            // copy it into C# as a string
            // create a connection, open a connection
            // create a command, set the command text
            // add any parameters you need to add
            // execute it
            // do something with the results
            // those are always going to be the steps

            var sql = @"INSERT INTO Pickle(NumberInStock, Price, Size, Type)
                        OUTPUT inserted.*
                        VALUES(@NumberInStock, @Price, @Size, @Type)";

            using (var db = new SqlConnection(ConnectionString))
            {
                // these two lines are the same as the commented out lines below
                var result = db.QueryFirstOrDefault <Pickle>(sql, pickle);
                return(result);
            }
        }
コード例 #5
0
        // descriptive name for method follows IActionResult
        // return type is IActionResult for flexibility ***What does that allow us, again?***
        public IActionResult AddPickle(Pickle pickleToAdd)
        {
            // the below if statement says if there are none in stock, make the current thing the stock;
            // otherwise, find the thing that exists and add the stock to this one
            // every class should have one thing that it does; single responsibility principle
            // controllers single responsibility is to take things in from the internet and return things to the internet; communication with http stuff
            // currently, this class both stores info AND communicates http stuff; something with two jobs means you need to break the thing up;
            // common interview question: one of the more common ways that people deal with storing data is with a pattern called the repository pattern;
            // some people love it, some hate it; it does perform the job; specifically for managing data and data storage;
            // INTERVIEW QUESTIONS
            // what's the difference between an abstract class and an interface?
            // what's the difference between a value type and a reference type?
            // can you describe the repository pattern OR can you describe a pattern that you have used in code?
            // Repository pattern is one of the more common in software development
            // patterns are more for the person reading the code than for being a software developer
            // the DataAccessLayer(DAL, DataAccess, Data) are the same as our data folder in React; this is a division of duty significance
            // if we reuse the below if/else, we can move that code to aits own method called AddOrUpdate
            var existingPickle = _repository.GetByType(pickleToAdd.Type);

            if (existingPickle == null)
            {
                var newPickle = _repository.Add(pickleToAdd);
                return(Created("", newPickle));
            }
            else
            {
                var updatedPickle = _repository.Update(pickleToAdd);
                return(Ok(pickleToAdd));
            }
            // created says "what is the rest url to get it; nothing yet, so here's an empty string;
            // when we add things, we want a 201 http response
        }
コード例 #6
0
        public Pickle Update(Pickle pickle)
        {
            var pickleToupdate = GetByType(pickle.Type);

            pickleToupdate.NumberInStock += pickle.NumberInStock;

            return(pickleToupdate);
        }
コード例 #7
0
        public void Run()
        {
            Sandwich sandwich = new SmallSandwich();
            sandwich = new Ham(sandwich);
            sandwich = new Pickle(sandwich);

            // sandwich.GetDescription() --> "Small sandwich, ham, pickle"
            // sandwich.GetPrice() --> 7.75
        }
コード例 #8
0
        public Pickle Add(Pickle pickle)
        {
            var sql = @"insert into Pickle(NumberInStock,Price,Size,Type)
                        output inserted.*
                        values(@NumberInStock,@Price,@Size,@Type)";

            using (var db = new SqlConnection(ConnectionString))
            {
                var result = db.QueryFirstOrDefault <Pickle>(sql, pickle);
                return(result);
            }
        }
コード例 #9
0
        protected virtual void CompileScenarioOutline(List <Pickle> pickles,
                                                      Func <IEnumerable <PickleStep> > backgroundStepsFactory, Scenario scenarioOutline,
                                                      IEnumerable <Tag> featureTags, string language, string gherkinDocumentUri)
        {
            foreach (var examples in scenarioOutline.Examples)
            {
                if (examples.TableHeader == null)
                {
                    continue;
                }
                var variableCells = examples.TableHeader.Cells;
                foreach (var values in examples.TableBody)
                {
                    var valueCells = values.Cells;

                    var steps = new List <PickleStep>();
                    if (scenarioOutline.Steps.Any())
                    {
                        steps.AddRange(backgroundStepsFactory());
                    }

                    var tags = new List <Tag>();
                    tags.AddRange(featureTags);
                    tags.AddRange(scenarioOutline.Tags);
                    tags.AddRange(examples.Tags);

                    foreach (var scenarioOutlineStep in scenarioOutline.Steps)
                    {
                        string stepText = Interpolate(scenarioOutlineStep.Text, variableCells, valueCells);

                        PickleStep pickleStep = CreatePickleStep(
                            scenarioOutlineStep,
                            stepText,
                            CreatePickleArgument(scenarioOutlineStep, variableCells, valueCells),
                            new[] { scenarioOutlineStep.Id, values.Id }
                            );
                        steps.Add(pickleStep);
                    }

                    Pickle pickle = new Pickle(
                        _idGenerator.GetNewId(),
                        gherkinDocumentUri,
                        Interpolate(scenarioOutline.Name, variableCells, valueCells),
                        language,
                        steps,
                        PickleTags(tags),
                        new[] { scenarioOutline.Id, values.Id }
                        );

                    pickles.Add(pickle);
                }
            }
        }
コード例 #10
0
        Pickle MapReaderToPickle(SqlDataReader reader)
        {
            var pickle = new Pickle
            {
                Id            = (int)reader["Id"],
                Type          = (string)reader["Type"],
                Price         = (decimal)reader["Price"],
                NumberInStock = (int)reader["NumberInStock"],
                Size          = (string)reader["Size"]
            };

            return(pickle);
        }
コード例 #11
0
ファイル: main.cs プロジェクト: Winnerhust/MyTool
 public List <int> getStorage()
 {
     if (isPickled() || needsReset() ||
         fullyQualifiedName() ==
         DEFAULT_NAME)
     {
         string file = storageFile();
         Pickle.load(file,
                     FLG_IMMEDIATE,
                     false);
     }
     return(m_payload);
 }
コード例 #12
0
        public IActionResult AddPickle(Pickle pickleToAdd)
        {
            var existingPickle = _repository.GetByType(pickleToAdd.Type);

            if (existingPickle == null)
            {
                _repository.Add(pickleToAdd);
                return(Created("", pickleToAdd));
            }
            else
            {
                var updatedPickle = _repository.Update(pickleToAdd);
                return(Ok(updatedPickle));
            }
        }
コード例 #13
0
        public Pickle Update(Pickle pickle)
        {
            var sql = @"update Pickle
                        set NumberInStock = NumberInStock + @NewStock
                        output inserted.*
                        where Id = @Id";

            using (var db = new SqlConnection(ConnectionString))
            {
                var parameters = new
                {
                    NewStock = pickle.NumberInStock,
                    Id       = pickle.Id
                };

                return(db.QueryFirstOrDefault <Pickle>(sql, parameters));
            }
        }
コード例 #14
0
        public Pickle Update(Pickle pickle)
        {
            //var pickleToUpdate = GetByType(pickle.Type);
            //pickleToUpdate.NumberInStock += pickle.NumberInStock;

            //return pickleToUpdate;

            var sql = @"update Pickle
                        set NumberInStock = NumberInStock + @NewStock
                        output inserted.*
                        where Id = @Id";

            using (var db = new SqlConnection(ConnectionString))
            {
                var parameters = new
                {
                    NewStock = pickle.NumberInStock,
                    Id       = pickle.Id
                };

                return(db.QueryFirstOrDefault <Pickle>(sql, parameters));

                //connection.Open();

                //var cmd = connection.CreateCommand();
                //cmd.CommandText = sql;

                //cmd.Parameters.AddWithValue("NewStock", pickle.NumberInStock);
                //cmd.Parameters.AddWithValue("Id", pickle.Id);

                //var reader = cmd.ExecuteReader();
                //if (reader.Read())
                //{
                //    var updatedPickle = MapReaderToPickle(reader);

                //    return updatedPickle;
                //}
                //return null;
            }
        }
コード例 #15
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (0x20302e33 != file.View.ReadUInt32(4))
            {
                return(null);
            }
            string index_offset_str = file.View.ReadString(8, 16, Encoding.ASCII);
            long   index_offset;

            if (!long.TryParse(index_offset_str, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out index_offset))
            {
                return(null);
            }
            if (index_offset >= file.MaxOffset)
            {
                return(null);
            }
            uint   key;
            string key_str = file.View.ReadString(0x19, 8, Encoding.ASCII);

            if (!uint.TryParse(key_str, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out key))
            {
                return(null);
            }

            IDictionary dict = null;

            using (var index = new ZLibStream(file.CreateStream(index_offset), CompressionMode.Decompress))
            {
                var pickle = new Pickle(index);
                dict = pickle.Load() as IDictionary;
            }
            if (null == dict)
            {
                return(null);
            }
            var dir = new List <Entry> (dict.Count);

            foreach (DictionaryEntry item in dict)
            {
                var name_raw = item.Key as byte[];
                var values   = item.Value as IList;
                if (null == name_raw || null == values || values.Count < 1)
                {
                    Trace.WriteLine("invalid index entry", "RpaOpener.TryOpen");
                    return(null);
                }
                string name = Encoding.UTF8.GetString(name_raw);
                if (string.IsNullOrEmpty(name))
                {
                    return(null);
                }
                var tuple = values[0] as IList;
                if (null == tuple || tuple.Count < 2)
                {
                    Trace.WriteLine("invalid index tuple", "RpaOpener.TryOpen");
                    return(null);
                }
                var entry = FormatCatalog.Instance.Create <RpaEntry> (name);
                entry.Offset       = (long)(Convert.ToInt64(tuple[0]) ^ key);
                entry.UnpackedSize = (uint)(Convert.ToInt32(tuple[1]) ^ key);
                entry.Size         = entry.UnpackedSize;
                if (tuple.Count > 2)
                {
                    entry.Header = tuple[2] as byte[];
                    if (null != entry.Header && entry.Header.Length > 0)
                    {
                        entry.Size    -= (uint)entry.Header.Length;
                        entry.IsPacked = true;
                    }
                }
                dir.Add(entry);
            }
            if (dir.Count > 0)
            {
                Trace.TraceInformation("[{0}] [{1:X8}] [{2}]", dir[0].Name, dir[0].Offset, dir[0].Size);
            }
            return(new ArcFile(file, this, dir));
        }
コード例 #16
0
        public override void Create(Stream output, IEnumerable <Entry> list, ResourceOptions options,
                                    EntryCallback callback)
        {
            var  rpa_options    = GetOptions <RpaOptions> (options);
            int  callback_count = 0;
            var  file_table     = new Dictionary <PyString, ArrayList>();
            long data_offset    = 0x22;

            output.Position = data_offset;
            foreach (var entry in list)
            {
                if (null != callback)
                {
                    callback(callback_count++, entry, arcStrings.MsgAddingFile);
                }

                string name      = entry.Name.Replace(@"\", "/");
                var    rpa_entry = new RpaEntry {
                    Name = name
                };
                using (var file = File.OpenRead(entry.Name))
                {
                    var size = file.Length;
                    if (size > uint.MaxValue)
                    {
                        throw new FileSizeException();
                    }
                    int header_size = (int)Math.Min(size, 0x10);
                    rpa_entry.Offset       = output.Position ^ rpa_options.Key;
                    rpa_entry.Header       = new byte[header_size];
                    rpa_entry.UnpackedSize = (uint)size ^ rpa_options.Key;
                    rpa_entry.Size         = (uint)(size - header_size);
                    file.Read(rpa_entry.Header, 0, header_size);
                    file.CopyTo(output);
                }
                var py_name = new PyString(name);
                if (file_table.ContainsKey(py_name))
                {
                    file_table[py_name].Add(rpa_entry);
                }
                else
                {
                    file_table[py_name] = new ArrayList {
                        rpa_entry
                    }
                };
            }
            long   index_pos = output.Position;
            string signature = string.Format(CultureInfo.InvariantCulture, "RPA-3.0 {0:x16} {1:x8}\n",
                                             index_pos, rpa_options.Key);
            var header = Encoding.ASCII.GetBytes(signature);

            if (header.Length > data_offset)
            {
                throw new ApplicationException("Signature serialization failed.");
            }

            if (null != callback)
            {
                callback(callback_count++, null, arcStrings.MsgWritingIndex);
            }

            using (var index = new ZLibStream(output, CompressionMode.Compress, CompressionLevel.Level9, true))
            {
                var pickle = new Pickle(index);
                if (!pickle.Dump(file_table))
                {
                    throw new ApplicationException("Archive index serialization failed.");
                }
            }
            output.Position = 0;
            output.Write(header, 0, header.Length);
        }
    }
コード例 #17
0
 public static Scenario Create(Pickle pickle) =>
 new Scenario(pickle);
コード例 #18
0
 public static bool HasTag(Pickle p, string tag) =>
 p.Tags
 .Select(PickleTags.Name)
 .Where(FuzzyString.Compare, tag)
 .Any();
コード例 #19
0
 public static void Deactivate(Pickle pickle)
 {
     pooledPickles.Push(pickle.gameObject);
     pickle.gameObject.SetActive(false);
 }
コード例 #20
0
 public PickleEvent(string uri, Pickle pickle)
 {
     this.uri    = uri;
     this.pickle = pickle;
 }
コード例 #21
0
 public void Add(Pickle pickle)
 {
     pickle.Id = _pickles.Max(x => x.Id) + 1;
     _pickles.Add(pickle);
 }
コード例 #22
0
 internal Scenario(Pickle pickle) => Pickle = pickle;