Esempio n. 1
0
        private static async Task MoveUsingFileSystem(IFile destination, IFile source, FileAttributes attributes)
        {
            if (SameVolume(destination.Path, source.Path))
            {
                await Task.Run(() =>
                {
                    // this is a guard clause for a bad bug I can't duplicate.  See issue # 79
                    MyDebug.Assert(source.Exists());
                    if (source.Exists())
                    {
                        File.Delete(destination.Path);
                        File.Move(source.Path, destination.Path);
                        if (attributes != FileAttributes.Normal)
                        {
                            File.SetAttributes(destination.Path, attributes);
                        }
                    }
                });

                return;
            }
            // else
            await FileSystemCopy(destination, source, attributes);

            source.Delete();
        }
Esempio n. 2
0
        private void getCookingStep(string food, ref FoodData destFood)
        {
            List <string> ingreidents = new List <string>();
            FoodData      fd          = GetFood(food);

            MyDebug.Assert(fd != null, "Food not found: " + food);
            foreach (string key in fd.ingredients)
            {
                FoodData keyFood = GetFood(key);
                if (keyFood != null && !IngredientDataManager.GetInstance().IsIngredientKey(key))
                {
                    getCookingStep(key, ref destFood);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(_ingMgr.GetIngredient(key) != null, "Ingredient not found for: " + key);
                    destFood.ingredient_set.Add(key);
                }
                ingreidents.Add(key);
            }

            CookingStep cs = new CookingStep();

            cs.canIgnore    = false;
            cs.id           = fd.id;
            cs.food         = fd.key;
            cs.price        = fd.price;
            cs.cookwareType = fd.cookware_type;
            cs.cookTime     = fd.cook_time;
            cs.ingredients  = ingreidents;

            destFood.cooking_step_list.Add(cs);
        }
        private List <CustomerOrder> ParseOrders(string orderStr)
        {
            List <CustomerOrder> orderList = new List <CustomerOrder>();
            var orderElements = orderStr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);;

            foreach (string element in orderElements)
            {
                //(Fried sausage,cowgirl,1.0);
                if (element.Length > 0)
                {
                    string sourceStr = element.Substring(1, element.Length - 2);

                    string[] infos = sourceStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (infos.Length >= 3 && infos.Length <= 4)
                    {
                        var order = new CustomerOrder();
                        if (infos[0].Contains("&"))
                        {
                            int pos = infos[0].IndexOf('&');
                            order.foods.Add(infos[0].Substring(0, pos));
                            order.foods.Add(infos[0].Substring(pos + 1, infos[0].Length - pos - 1));
                        }
                        else
                        {
                            order.foods.Add(infos[0]);
                        }
                        order.customer = infos[1];
                        //MyDebug.WriteLine(sourceStr + " ==== " + infos[2]);
                        order.weight = infos[2].ToFloat();

                        if (infos.Length == 4)
                        {
                            order.latestFirstCome = infos[3].ToInt32();
                        }
                        orderList.Add(order);

                        MyDebug.Assert(CustomerDataManager.GetInstance().IsCustomerKey(order.customer), "Error customer key : " + order.customer + ", Order :" + element);
                        m_customers.Add(order.customer);
                        if (order.foods.Count == 1)
                        {
                            MyDebug.Assert(FoodDataManager.GetInstance().IsFoodKey(order.foods[0]), "Error food key : " + order.foods[0] + ", Order :" + element);
                            m_foods.Add(order.foods[0]);
                        }
                        else
                        {
                            string combineFood = string.Format("{0}&{1}", order.foods[0], order.foods[1]);
                            MyDebug.Assert(FoodDataManager.GetInstance().IsFoodKey(combineFood), "Error food key : " + combineFood + ", Order :" + element);
                            m_foods.Add(combineFood);
                        }
                    }
                    else
                    {
                        MyDebug.Assert(false, element);
                    }
                }
            }
            return(orderList);
        }
        private List <CustomerOrder> ParseSpecialOrders(string orderStr)
        {
            List <CustomerOrder> orderList = new List <CustomerOrder>();
            var orderElements = orderStr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);;

            foreach (string element in orderElements)
            {
                //([7,8],Fried bread,ents);
                if (element.Length > 0)
                {
                    // 去掉括号
                    string sourceStr = element.Substring(2, element.Length - 3);

                    var order = new CustomerOrder();

                    int      index       = sourceStr.IndexOf(']');
                    string   intervalStr = sourceStr.Substring(0, index);
                    string[] interval    = intervalStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    MyDebug.Assert(interval.Length == 2, "");
                    order.interval.min = interval[0].ToInt32();
                    order.interval.max = interval[1].ToInt32();

                    int    lastIdx  = sourceStr.LastIndexOf(',');
                    string foodName = sourceStr.Substring(index + 2, lastIdx - index - 2);
                    if (foodName.Contains("&"))
                    {
                        int pos = foodName.IndexOf('&');
                        order.foods.Add(foodName.Substring(0, pos));
                        order.foods.Add(foodName.Substring(pos + 1, foodName.Length - pos - 1));
                    }
                    else
                    {
                        order.foods.Add(foodName);
                    }

                    string customerName = sourceStr.Substring(lastIdx + 1, sourceStr.Length - lastIdx - 1);
                    order.customer = customerName;

                    orderList.Add(order);

                    MyDebug.Assert(CustomerDataManager.GetInstance().IsCustomerKey(order.customer), "Error customer key : " + order.customer + ", Order :" + element);
                    m_customers.Add(order.customer);
                    if (order.foods.Count == 1)
                    {
                        MyDebug.Assert(FoodDataManager.GetInstance().IsFoodKey(order.foods[0]), "Error food key : " + order.foods[0] + ", Order :" + element);
                        m_foods.Add(order.foods[0]);
                    }
                    else
                    {
                        string combineFood = string.Format("{0}&{1}", order.foods[0], order.foods[1]);
                        MyDebug.Assert(FoodDataManager.GetInstance().IsFoodKey(combineFood), "Error food key : " + combineFood + ", Order :" + element);
                        m_foods.Add(combineFood);
                    }
                }
            }
            return(orderList);
        }
Esempio n. 5
0
 static ZebraPuzzle()
 {
     MyDebug.Assert(
         Color.All == Nationality.All &&
         Color.All == Pet.All &&
         Color.All == Drink.All &&
         Color.All == Smoke.All &&
         Color.All == Position.All
         );
 }
Esempio n. 6
0
    protected bool Equals(Clue other)
    {
        MyDebug.Assert(this.attributes.Length == other.attributes.Length);
        for (int ii = 0; ii < this.attributes.Length; ii++)
        {
            if (this.attributes[ii] != other.attributes[ii])
            {
                return(false);
            }
        }

        return(true);
    }
Esempio n. 7
0
        private static async Task MoveUsingStreams(IFile destination, IFile source, CancellationToken token,
                                                   FileAttributes attributes)
        {
            // this is a guard clause for a bad bug I can't duplicate.  See issue # 79
            MyDebug.Assert(source.Exists());
            if (!source.Exists())
            {
                return;
            }
            await CopyFrom(destination, source, token, attributes);

            source.Delete();
        }
Esempio n. 8
0
                public IFile CreateEnlistedFile(IDirectory untransactedDirectory, string name)
                {
                    var ret = new TransactedFile(untransactedDirectory.File(name), untransactedDirectory.
                                                 File(name + "." + transactionNumber.ToString() + ".txn"), untransactedDirectory);
                    var existingTransactedFile = items.FirstOrDefault(i => i.Path.Equals(ret.Path, StringComparison.Ordinal));

                    MyDebug.Assert(!items.Any(i => i.Path.Equals(ret.Path, StringComparison.Ordinal) &&
                                              i != existingTransactedFile));
                    if (existingTransactedFile != null)
                    {
                        return(existingTransactedFile);
                    }
                    items.Add(ret);
                    return(ret);
                }
        /// <summary>
        ///
        /// </summary>
        /// <param name="device"></param>
        public TagSetsDialog(DeviceRfidBoard device)
        {
            this.device = device;


            MyDebug.Assert(this.device != null);

            InitializeComponent();
            this.Text = string.Format("Tag Management [{0:X8}]", device.DeviceId);
            correlationThresholdLabel.Text = string.Format("Correlation Threshold ({0}-{1})",
                                                           DeviceRfidBoard.MIN_CorrelationThreshold, DeviceRfidBoard.MAX_CorrelationThreshold);

            // Set the Tag ID column to sort in ascending order.
            tagListDataGrid.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
        }
Esempio n. 10
0
        public static async Task <int> FillBufferAsync(this byte[] buffer, int offset, int count,
                                                       Stream s)
        {
            int totalRead = 0;
            int localRead = int.MaxValue;

            while (count - totalRead > 0 && localRead > 0)
            {
                localRead = await s.ReadAsync(buffer, offset + totalRead, count - totalRead);

                totalRead += localRead;
            }
            MyDebug.Assert(buffer.Length >= offset + totalRead);
            MyDebug.Assert(totalRead >= 0);
            MyDebug.Assert(totalRead <= count);
            return(totalRead);
        }
Esempio n. 11
0
        private void startSampling()
        {
            bSamplingRequested = true;

            if (!bSamplingActive)
            {
                ushort sampleCount = 0;

                if (autoUpdateCheckBox.Checked && (!ushort.TryParse(sampleCountTextBox.Text, out sampleCount) || (sampleCount == 0)))
                {
                    MessageBox.Show("Invalid sample count: '" + sampleCountTextBox.Text + "'.");
                }
                else if (deviceBoard.sampleCorrelationSeries(true, sampleCount))
                {
                    bSamplingActive = true;
                }
                else
                {
                    MyDebug.Assert(false);
                }
            }
        }
Esempio n. 12
0
        private Game MakeGame(string[] input)
        {
            ValidateInput(input);
            int  gameCellsDown   = input.Length;
            int  gameCellsAcross = input[0].Split(' ', StringSplitOptions.RemoveEmptyEntries).Length;
            Game game            = new Game(Side.Top, Side.Left, gameCellsAcross, gameCellsDown);

            for (int row = 0; row < input.Length; row++)
            {
                var cols = input[row].Split(' ', StringSplitOptions.RemoveEmptyEntries);
                for (int col = 0; col < cols.Length; col++)
                {
                    Cell cell = game[col, row];
                    MyDebug.Assert(cell.Status == CellStatus.Free);
                    cell.Status = Enum.Parse <CellStatus>(((int)cols[col][0]).ToString());
                    MyDebug.Assert(cell.Status == CellStatus.Free ||
                                   cell.Status == CellStatus.White ||
                                   cell.Status == CellStatus.Black);
                }
            }
            return(game);
        }
        private List <CustomerOrder> ParseAnyfoodOrders(string orderStr)
        {
            List <CustomerOrder> orderList = new List <CustomerOrder>();

            var orderElements = orderStr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);;

            foreach (string element in orderElements)
            {
                //([9,9],more3,mesmerizer)
                if (element.Length > 0)
                {
                    //Console.WriteLine(element);
                    // 去掉括号
                    string sourceStr = element.Substring(2, element.Length - 3);

                    var order = new CustomerOrder();

                    int      index       = sourceStr.IndexOf(']');
                    string   intervalStr = sourceStr.Substring(0, index);
                    string[] interval    = intervalStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    MyDebug.Assert(interval.Length == 2, "");
                    order.interval.min = interval[0].ToInt32();
                    order.interval.max = interval[1].ToInt32();

                    int lastIdx = sourceStr.LastIndexOf(',');
                    order.randomFoodRule = sourceStr.Substring(index + 2, lastIdx - index - 2);

                    string customerName = sourceStr.Substring(lastIdx + 1, sourceStr.Length - lastIdx - 1);
                    order.customer = customerName;

                    orderList.Add(order);

                    MyDebug.Assert(CustomerDataManager.GetInstance().IsCustomerKey(order.customer), "Error customer key : " + order.customer + ", Order :" + element);
                    m_customers.Add(order.customer);
                }
            }
            return(orderList);
        }
Esempio n. 14
0
    public int CompareTo(object obj)
    {
        if (obj == null)
        {
            return(1);
        }

        Clue other = obj as Clue;

        MyDebug.Assert(this.attributes.Length == other.attributes.Length);
        for (int ii = 0; ii < this.attributes.Length; ii++)
        {
            if (this.attributes[ii] < other.attributes[ii])
            {
                return(-1);
            }
            else if (this.attributes[ii] > other.attributes[ii])
            {
                return(1);
            }
        }
        return(0);
    }
Esempio n. 15
0
 public Token(TokenType tokenType, IList <Token> children)
 {
     MyDebug.Assert(tokenType != TokenType.Newline && tokenType != TokenType.Text);
     this.Type     = tokenType;
     this.Children = children;
 }
Esempio n. 16
0
 public Token(TokenType tokenType)
 {
     MyDebug.Assert(tokenType == TokenType.Newline);
     this.Type = tokenType;
 }
Esempio n. 17
0
    /// <summary>
    /// Two cases:
    ///   1) ToRightOf.  we can exclude the known left hand attribute from house 5 and the right hand attribute from house 1
    ///   2) NextTo.  If we get lucky and one of the neighbours has a known house we can fix the other
    /// TODO: ToRightOf should take advantage of similar logic to NextTo.
    /// </summary>
    /// <param name="clues">this will change if the method is called multiple times</param>
    /// <returns>a new cloned list of clues</returns>
    private static (bool, ISet <Clue>) InferNeighbours(ISet <Clue> clues)
    {
        var  cluesOut = new HashSet <Clue>();
        bool modified = false;

        foreach (var clue in clues)
        {
            var clueOut = clue.Clone();
            cluesOut.Add(clueOut);
        }
        foreach (var neighbour in Neighbour.neighbours)
        {
            // assert there are clues for all attributes
            // assert that setter is accustomed to a left-to-right culture
            Clue clueA, clueB;
            try
            {
                clueA = cluesOut.First(c => c.attributes[neighbour.attributeTypeA] == neighbour.attrivubuteValueA);
                clueB = cluesOut.First(c => c.attributes[neighbour.attributeTypeB] == neighbour.attrivubuteValueB);
            }
            catch (Exception e)
            {
                throw;
            }
            if (neighbour.Relation == Relation.ToRightOf)
            {
                var clueC = cluesOut.FirstOrDefault(c => c.attributes[AttributeType.Position] == Position.One);
                // left most house is to the right of nothing
                var clueD = cluesOut.FirstOrDefault(c => c.attributes[AttributeType.Position] == Position.Five);
                // right most house is to the left of nothing
                byte?oldC = clueC?.attributes[neighbour.attributeTypeA], oldD = clueD?.attributes[neighbour.attributeTypeB];
                if (clueC != null)
                {
                    clueC.attributes[neighbour.attributeTypeA]
                        = TurnOffBit(clueC.attributes[neighbour.attributeTypeA], neighbour.attrivubuteValueA);
                }

                if (clueD != null)
                {
                    clueD.attributes[neighbour.attributeTypeB]
                        = TurnOffBit(clueD.attributes[neighbour.attributeTypeB], neighbour.attrivubuteValueB);
                }
                modified = oldC != clueC?.attributes[neighbour.attributeTypeA] || oldD != clueD?.attributes[neighbour.attributeTypeB];
            }
            else if (neighbour.Relation == Relation.NextTo)
            {
                if (IsResolvedAttribute(clueA.attributes[AttributeType.Position]))
                {
                    // we know the position of clue A we may be able to infer the position of clue B
                    if (clueA.attributes[AttributeType.Position] == Position.One)
                    {
                        if (clueB.attributes[AttributeType.Position] != Position.Two)
                        {
                            MyDebug.Assert(!IsResolvedAttribute(clueB.attributes[AttributeType.Position]));
                            clueB.attributes[AttributeType.Position] = Position.Two;
                            modified = true;
                        }
                    }
                    else if (clueA.attributes[AttributeType.Position] == Position.Five)
                    {
                        if (clueB.attributes[AttributeType.Position] != Position.Four)
                        {
                            MyDebug.Assert(!IsResolvedAttribute(clueB.attributes[AttributeType.Position]));
                            clueB.attributes[AttributeType.Position] = Position.Four;
                            modified = true;
                        }
                    }
                }
                if (IsResolvedAttribute(clueB.attributes[AttributeType.Position]))
                {
                    // we know the position of clue B we may be able to infer the position of clue B
                    if (clueB.attributes[AttributeType.Position] == Position.One)
                    {
                        if (clueA.attributes[AttributeType.Position] != Position.Two)
                        {
                            MyDebug.Assert(!IsResolvedAttribute(clueA.attributes[AttributeType.Position]));
                            clueA.attributes[AttributeType.Position] = Position.Two;
                            modified = true;
                        }
                    }
                    else if (clueB.attributes[AttributeType.Position] == Position.Five)
                    {
                        if (clueA.attributes[AttributeType.Position] != Position.Four)
                        {
                            MyDebug.Assert(!IsResolvedAttribute(clueA.attributes[AttributeType.Position]));
                            clueA.attributes[AttributeType.Position] = Position.Four;
                            modified = true;
                        }
                    }
                }
            }
        }

        return(modified, cluesOut);
    }
 public int[] GetPhaseCorrelations(uint phase)
 {
     MyDebug.Assert(phase < 4);
     return(phaseCorrelations[phase]);
 }
Esempio n. 19
0
 public ITransactedDirectory BeginTransaction()
 {
     MyDebug.Assert(isRepaired);
     return(new TransactedDirectory(innerFileSystem));
 }