/// <summary>
        /// Updates the data for this node and triggers updates for any connected output nodes.
        /// </summary>
        internal override void Update()
        {
            var childFolderArrays = GetInputValues(nameof(_childFolders), new object[] { _childFolders })
                                    .OfType <FolderRef[]>()
                                    .ToArray();

            TempList.Clear();

            for (var i = 0; i < childFolderArrays.Length; i++)
            {
                var childFolderArray = childFolderArrays[i];
                for (var j = 0; j < childFolderArray.Length; j++)
                {
                    var childFolderRef = childFolderArray[j];
                    var newFolderRef   = new FolderRef
                    {
                        FolderName = Path.Combine(COCEditorConstants.ASSET_ROOT, childFolderRef.FolderName),
                        ShouldGenerateCodeToGetPath = childFolderRef.ShouldGenerateCodeToGetPath
                    };
                    TempList.Add(newFolderRef);
                }
            }

            TempList.Sort();

            _outputFolders = TempList.ToArray();

            // Make base call to trigger update on all output ports
            base.Update();
        }
        /// <summary>
        /// Updates the data for this node and triggers updates for any connected output nodes.
        /// </summary>
        internal override void Update()
        {
            var isFolderNameValid = !string.IsNullOrEmpty(_folderRef.FolderName);
            var childFolderArrays = GetInputValues(nameof(_childFolders), new object[0])
                                    .OfType <FolderRef[]>()
                                    .ToArray();
            var length = childFolderArrays.Sum(x => x.Length);

            // If there are not any child folders from other nodes present, return this folder as the
            // array of output folders.
            if (length == 0 && isFolderNameValid)
            {
                _outputFolders = new[]
                {
                    _folderRef
                };
            }
            else if (length > 0 && isFolderNameValid)
            {
                TempList.Clear();

                for (var i = 0; i < childFolderArrays.Length; i++)
                {
                    var childFolderArray = childFolderArrays[i];
                    for (var j = 0; j < childFolderArray.Length; j++)
                    {
                        var childFolderRef = childFolderArray[j];
                        var newFolderRef   = new FolderRef
                        {
                            FolderName = Path.Combine(_folderRef.FolderName, childFolderRef.FolderName),
                            ShouldGenerateCodeToGetPath = childFolderRef.ShouldGenerateCodeToGetPath
                        };

                        TempList.Add(newFolderRef);
                    }
                }

                if (_folderRef.ShouldGenerateCodeToGetPath)
                {
                    TempList.Add(_folderRef);
                }

                _outputFolders = TempList.ToArray();
            }
            else
            {
                _outputFolders = new FolderRef[0];
            }

            // Make base call to trigger update on all output ports
            base.Update();
        }
예제 #3
0
        //Fill the Window to the Right
        private void MoveElement(object sender, RoutedEventArgs e)
        {
            TempList.Clear();
            VM.ConfigurationList.Clear();
            VM.ParamConfigurationList.Clear();
            //
            foreach (var item in FirstList.SelectedItems)
            {
                TempList.Add(item.ToString());
                VM.ConfigurationList.Add(item.ToString());
            }
            foreach (var item in AlterFirstList.SelectedItems)
            {
                TempList.Add(item.ToString());
                VM.ParamConfigurationList.Add(item.ToString());
            }

            SecondList.ItemsSource = TempList;
        }
 public void NewRound() // this should tell the ui to clear (if everything works).
 {
     Scores.Clear();
     CardList.Clear();
     TempList.Clear();
 }
        /// <summary>
        /// Get information abount all available games
        /// </summary>
        public void GetAvailableGamesInfo()
        {
            var isContinueGames = _parseService.GetUserGamesInfo();

            _page.Dispatcher.Invoke(() =>
            {
                if (isContinueGames && UserName != null)
                {
                    foreach (var parsedItem in _parseService.UserGames)
                    {
                        UserGames.Add(parsedItem);
                    }
                }
                else
                {
                    MessageBox.Show("No entered user", "No user error");
                    return;
                }

                if (ViewModelHelper.DigGames.Count != 0)
                {
                    var tempList = ViewModelHelper.DigGames
                                   .Where(item => !UserGames.Contains(item))
                                   .ToList();

                    TempList = tempList;

                    var twmpList = new int[ViewModelHelper.DigGames.Count];

                    for (int i = 0; i < ViewModelHelper.DigGames.Count; i++)
                    {
                        if (!UserGames.Any(x => x == ViewModelHelper.DigGames[i]))
                        {
                            twmpList[i] = i;
                        }
                        else
                        {
                            twmpList[i] = 0;
                        }
                    }

                    PricesAll.Clear();
                    PricesAll.Add(0.05);
                    for (int i = 0; i < twmpList.Length; i++)
                    {
                        if (twmpList[i] != 0)
                        {
                            PricesAll.Add(ViewModelHelper.PricesAll[i]);
                        }
                    }

                    GamesAllSumm = Math.Round(PricesAll.Sum(), 3);

                    AmountGamesAll = TempList.Distinct().Count();

                    for (var i = 0; i < TempList.Count; i++)
                    {
                        if (!UserAllGamesDict.ContainsKey(TempList[i]))
                        {
                            UserAllGamesDict.Add(TempList[i], PricesAll[i]);
                        }
                    }

                    /// write user all info into helper class

                    ViewModelHelper.AllGamesUserHelper      = AmountGamesAll;
                    ViewModelHelper.AllGamesUserPriceHelper = GamesAllSumm;

                    ViewModelHelper.UserName = UserName;

                    TempList.Clear();
                    ListViewSourse.Clear();

                    foreach (var item in UserAllGamesDict)
                    {
                        ListViewSourse.Add($"Game: {item.Key} | Price: ${item.Value}");
                    }

                    CanCloseSaveAll = true;
                }

                else
                {
                    MessageBox.Show("No games from DIG", "No dig games error");
                    return;
                }

                CanCloseAvailableAllCards = true;
            });
        }
예제 #6
0
 private void ResetList()
 {
     TempList.Clear();
 }
예제 #7
0
파일: Program.cs 프로젝트: TaylorOne/Farkle
        static int ComputerTurn(List <int> diceRolls)
        {
            diceRolls.Clear();
            int PointsTurn = 0,
                Points     = 0,
                DiceRoll   = 0;
            List <int> TempList;
            var        rand = new Random();

            while (diceRolls.Count < 6)
            {
                if (diceRolls.Count == 0)
                {
                    diceRolls = new List <int>()
                    {
                        rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7)
                    };
                    Console.WriteLine($"The computer rolled: {diceRolls[0]}, {diceRolls[1]}, {diceRolls[2]}, {diceRolls[3]}, {diceRolls[4]}, {diceRolls[5]}");
                    TempList = PickNumbers(diceRolls);
                    Points   = ScoreNumbers(TempList);
                    diceRolls.Clear();

                    foreach (var number in TempList)
                    {
                        diceRolls.Add(number);
                    }

                    TempList.Clear();
                    Console.Write("The computer kept numbers ");
                    foreach (var number in diceRolls)
                    {
                        Console.Write(number + ", ");
                    }
                    Console.Write($"for a total of {Points} points.");
                    Console.WriteLine();

                    PointsTurn = Points;
                }
                else
                {
                    TempList = new List <int>();
                    Points   = 0;
                    Console.Write("The computer rolled: ");
                    for (int i = 0; i < 6 - diceRolls.Count; i++)
                    {
                        DiceRoll = rand.Next(1, 7);
                        TempList.Add(DiceRoll);
                        Console.Write(DiceRoll + ", ");
                    }

                    TempList = PickNumbers(TempList);
                    Points  += ScoreNumbers(TempList);

                    Console.Write("The computer kept numbers ");
                    foreach (var number in TempList)
                    {
                        Console.Write(number + ", ");
                        diceRolls.Add(number);
                    }
                    Console.Write($"for a total of {Points} points.");
                    Console.WriteLine();

                    PointsTurn += Points;
                }
            }

            Console.WriteLine($"The computer scored a total of {PointsTurn} points this turn");

            return(PointsTurn);
        }
예제 #8
0
        //  private void updateGraph(){
        //      double[] y_1 = null;
        //      double[] y_2 = null;
        //      double[] xs = null;
        //      double step = FrequencyManager.Frequency;
        //      lock (LockFinilizeUpdateData) {
        //          if (UnderSample < 1) UnderSample = 1;
        //          if (UnderSample >= _numOfPointsToPlot) UnderSample = (int)(_numOfPointsToPlot / 10);
        //          var newPoints = _workingPackets.Where((n,i)=>i%UnderSample==0).Select(
        //              data => new XY1Y2Point(
        //                  0,
        //                  ((Int16)((data[5] << 8) + data[4])) * Math.Pow(2, -15) * Multiply,
        //                  ((Int16)((data[7] << 8) + data[6])) * Math.Pow(2, -15) * Multiply2
        //                  ));

        //          _ploted.AddRange(newPoints);
        //          _workingPackets.Clear();

        //          //_working data may now be changed
        //          SemUpdateData.Release();
        //          if (_numOfPointsToPlot/UnderSample < _ploted.Count) {
        //              _ploted.RemoveRange(0, (int)(_ploted.Count - _numOfPointsToPlot/UnderSample));
        //          }



        //          y_1 = _ploted.Select(y1 => y1.Y1).ToArray();
        //          y_2 = _ploted.Select(y2 => y2.Y2).ToArray();
        //          xs = _ploted.Select((n, i) => i * step*UnderSample).ToArray();

        //          //_plotted may now be changed
        //      }
        //      lock(LockUpdateDataSeries){

        //        try {
        //            using (_series0.SuspendUpdates()) {
        //                using (_series1.SuspendUpdates()) {
        //                    _series0.Clear();
        //                    _series1.Clear();
        //                    _series0.Append(xs, y_1);
        //                    _series1.Append(xs, y_2);
        //                }
        //            }
        //        } catch (NullReferenceException) {
        //            //may happen when closing the window, we don't care for this one
        //        } catch (Exception e) { Debugger.Break(); }

        //    }//release lock


        //}

        //private void dataReceivedFT1__(byte[] data){

        //   if (Freeze) return;
        //   lock (MonitordataReceived) {

        //       _receivingPackets.Add(data);
        //       _receivedSinceLastUpdate++;
        //       if (_receivedSinceLastUpdate >= _numOfPointsToRefresh){
        //           lock (MonitorupdateSeries) {
        //               SemUpdateData.WaitOne();
        //               _workingPackets = _receivingPackets;
        //               int index = _receivedPackets.IndexOf(_receivingPackets);
        //               if (index == (_receivedPackets.Count - 1)) _receivingPackets = _receivedPackets[0];
        //               else _receivingPackets = _receivedPackets[index + 1];
        //               _receivingPackets.Clear();
        //               _receivedSinceLastUpdate = 0;
        //               IsScrollingVisible = false;
        //               Task.Factory.StartNew(action: updateGraph);
        //           }
        //       }
        //   }
        //}

        //  private void updateGraph__(){
        //      double[] y_1 = null;
        //      double[] y_2 = null;
        //      double[] xs = null;
        //      double step = FrequencyManager.Frequency;
        //      lock (LockFinilizeUpdateData) {
        //          if (UnderSample < 1) UnderSample = 1;
        //          if (UnderSample >= _numOfPointsToPlot) UnderSample = (int)(_numOfPointsToPlot / 10);
        //          var newPoints = _workingPackets.Where((n,i)=>i%UnderSample==0).Select(
        //              data => new XY1Y2Point(
        //                  0,
        //                  ((Int16)((data[5] << 8) + data[4])) * Math.Pow(2, -15) * Multiply,
        //                  ((Int16)((data[7] << 8) + data[6])) * Math.Pow(2, -15) * Multiply2
        //                  ));

        //          _ploted.AddRange(newPoints);
        //          _workingPackets.Clear();

        //          //_working data may now be changed
        //          SemUpdateData.Release();
        //          if (_numOfPointsToPlot/UnderSample < _ploted.Count) {
        //              _ploted.RemoveRange(0, (int)(_ploted.Count - _numOfPointsToPlot/UnderSample));
        //          }



        //          y_1 = _ploted.Select(y1 => y1.Y1).ToArray();
        //          y_2 = _ploted.Select(y2 => y2.Y2).ToArray();
        //          xs = _ploted.Select((n, i) => i * step*UnderSample).ToArray();

        //          //_plotted may now be changed
        //      }
        //      lock(LockUpdateDataSeries){

        //        try {
        //            using (_series0.SuspendUpdates()) {
        //                using (_series1.SuspendUpdates()) {
        //                    _series0.Clear();
        //                    _series1.Clear();
        //                    _series0.Append(xs, y_1);
        //                    _series1.Append(xs, y_2);
        //                }
        //            }
        //        } catch (NullReferenceException) {
        //            //may happen when closing the window, we don't care for this one
        //        } catch (Exception e) { Debugger.Break(); }

        //    }//release lock


        //}



        // private void dataReceivedFT1__(byte[] data){

        //    if (Freeze) return;
        //    lock (MonitordataReceived) {

        //        _receivingPackets.Add(data);
        //        _receivedSinceLastUpdate++;
        //        if (_receivedSinceLastUpdate >= _numOfPointsToRefresh) {
        //            lock (MonitorupdateSeries) {
        //                _workingPackets = _receivingPackets;
        //                int index = _receivedPackets.IndexOf(_receivingPackets);
        //                if (index == (_receivedPackets.Count - 1)) _receivingPackets = _receivedPackets[0];
        //                else _receivingPackets = _receivedPackets[index + 1];
        //                _receivingPackets.Clear();
        //                _receivedSinceLastUpdate = 0;
        //            }
        //            if (FrequencyManager.IsReadingHistory){
        //                //IsScrollingVisible = true;
        //                Task.Factory.StartNew(action:updateGraphHistory);

        //            } else{
        //                IsScrollingVisible = false;
        //                Task.Factory.StartNew(action: updateGraph);
        //            }
        //        }
        //    }
        // }

        //  private void updateGraph__(){

        //    double step = FrequencyManager.Frequency;
        //    double currx = 0;

        //    lock (MonitorupdateSeries){
        //        try {
        //            if (_workingPackets.Count == 0) return;
        //            uint availablePoints = (uint)(_ploted.Count + _workingPackets.Count);
        //            //prepare to receive new points
        //            if (availablePoints > _numOfPointsToPlot){
        //                if ((ulong)UnderSample >= _numOfPointsToPlot) UnderSample = (int)_numOfPointsToPlot/10;
        //                int removeRange = (int)(availablePoints - _numOfPointsToPlot) - (int)availablePoints%UnderSample;
        //                if (removeRange < 0) removeRange += (int)availablePoints % UnderSample;
        //                if (removeRange > _ploted.Count) {
        //                    removeRange -= _ploted.Count;
        //                    _ploted.Clear();
        //                    _workingPackets.RemoveRange(0, removeRange);
        //                } else {
        //                    _ploted.RemoveRange(0, removeRange);
        //                }

        //            }
        //            foreach (var point in _ploted) {
        //                point.X = currx;
        //                currx += step;
        //            }

        //            foreach (byte[] data in _workingPackets) {
        //                double readyNumber0 = ((Int16)((data[5] << 8) + data[4])) * Math.Pow(2, -15) * Multiply;
        //                double readyNumber1 = ((Int16)((data[7] << 8) + data[6])) * Math.Pow(2, -15) * Multiply2;
        //                _ploted.Add(new XY1Y2Point(currx, readyNumber0, readyNumber1));
        //                currx += step;
        //                if (IsRecording) {
        //                    //Tbl_History.addPoint(new[] { readyNumber0, readyNumber1, curr_x });
        //                    //curr_x += step;
        //                }

        //            }
        //            _workingPackets.Clear();
        //            using (_series0.SuspendUpdates()) {
        //                using (_series1.SuspendUpdates()) {
        //                    //if (_ploted.Count == 0) return;

        //                    _series0.Clear();
        //                    _series1.Clear();
        //                    if (UnderSample == 1) {
        //                        _series0.Append(_ploted.XData, _ploted.Y1Data);
        //                        _series1.Append(_ploted.XData, _ploted.Y2Data);
        //                    } else{
        //                        for (int i = 0; i < _ploted.Count; i++){
        //                            if (i % UnderSample == 0){
        //                                _series0.Append(_ploted[i].X, _ploted[i].Y1);
        //                                _series1.Append(_ploted[i].X, _ploted[i].Y2);
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        } catch (NullReferenceException){
        //         //may happen when closing the window, we don't care for this one
        //        }catch (Exception e) { Debugger.Break();}
        //    }//release lock

        //}

        #region ExcelFunction
        public void ToExcel <T>(List <T> list, string include = "", string exclude = "")
        {
            int count = 0;

            //Get property collection and set selected property list
            PropertyInfo[]      props    = typeof(T).GetProperties();
            List <PropertyInfo> propList = GetSelectedProperties(props, include, exclude);

            //Get simple type name
            string typeName = GetSimpleTypeName(list);

            //Convert list to array for selected properties
            object[,] listArray = new object[list.Count + 1, propList.Count];

            //Add property name to array as the first row
            int colIdx = 0;

            foreach (var prop in propList)
            {
                listArray[0, colIdx] = prop.Name;
                colIdx++;
            }
            //Iterate through data list collection for rows
            int rowIdx = 1;

            foreach (var item in list)
            {
                colIdx = 0;
                //Iterate through property collection for columns
                foreach (var prop in propList)
                {
                    //Do property value
                    listArray[rowIdx, colIdx] = prop.GetValue(item, null);
                    colIdx++;
                }
                rowIdx++;
            }
            int MaxRow = rowIdx;

            try
            {
                if (MaxRow > 1040000)
                {
                    List <T> TempList;
                    string   path = "\\Redler\\Charts\\" + DateTime.Now.ToString();
                    path = (path.Replace('-', ' ')).Replace(':', '_');

                    //Processing for Excel
                    object            oOpt = System.Reflection.Missing.Value;
                    Excel.Application oXL  = new Excel.Application();
                    Excel.Workbooks   oWBs = oXL.Workbooks;
                    Excel.Workbook    oWB  = oWBs.Add(Excel.XlWBATemplate.xlWBATWorksheet);
                    Excel.Worksheet   oSheet;

                    for (int i = 0, index = 0; i < MaxRow; i += 1040000, index++)
                    {
                        if ((i + 1040000) < MaxRow)
                        {
                            count = 1040000;
                        }
                        else
                        {
                            count = MaxRow - i - 2;
                        }

                        TempList = list.GetRange(i, count);

                        //Get property collection and set selected property list
                        props    = typeof(T).GetProperties();
                        propList = GetSelectedProperties(props, include, exclude);

                        //Get simple type name
                        typeName = GetSimpleTypeName(TempList);

                        //Convert list to array for selected properties
                        listArray = new object[TempList.Count + 1, propList.Count];

                        //Add property name to array as the first row
                        colIdx = 0;
                        foreach (var prop in propList)
                        {
                            listArray[0, colIdx] = prop.Name;
                            colIdx++;
                        }
                        //Iterate through data list collection for rows
                        rowIdx = 1;
                        foreach (var item in TempList)
                        {
                            colIdx = 0;
                            //Iterate through property collection for columns
                            foreach (var prop in propList)
                            {
                                //Do property value
                                listArray[rowIdx, colIdx] = prop.GetValue(item, null);
                                colIdx++;
                            }
                            rowIdx++;
                        }


                        oSheet      = (Excel.Worksheet)oWB.ActiveSheet;
                        oSheet.Name = typeName + '_' + index.ToString();

                        Excel.Range oRng = oSheet.get_Range("A1", oOpt).get_Resize(TempList.Count + 1, propList.Count);
                        oRng.set_Value(oOpt, listArray);

                        TempList.Clear();
                        oSheet = (Excel.Worksheet)oWB.Worksheets.Add();
                    }
                    //Open Excel
                    oXL.Visible = false;
                    //path += '_' + index.ToString() + '_';
                    path += ".xlsx";
                    path  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + path;
                    oWB.SaveAs(path, Excel.XlFileFormat.xlWorkbookDefault); //  - ,
                    oXL.Workbooks.Close();
                    oXL.Quit();

                    Process[] excelProcess;

                    excelProcess = Process.GetProcessesByName("Excel");
                    excelProcess[0].CloseMainWindow();
                    excelProcess[0].Refresh();
                    excelProcess[0].Kill();
                }
                else
                {
                    //Processing for Excel
                    object            oOpt   = System.Reflection.Missing.Value;
                    Excel.Application oXL    = new Excel.Application();
                    Excel.Workbooks   oWBs   = oXL.Workbooks;
                    Excel.Workbook    oWB    = oWBs.Add(Excel.XlWBATemplate.xlWBATWorksheet);
                    Excel.Worksheet   oSheet = (Excel.Worksheet)oWB.ActiveSheet;
                    oSheet.Name = typeName;

                    Excel.Range oRng = oSheet.get_Range("A1", oOpt).get_Resize(list.Count + 1, propList.Count);
                    oRng.set_Value(oOpt, listArray);
                    //Open Excel
                    oXL.Visible = false;

                    string path = "\\Redler\\Charts\\" + DateTime.Now.ToString();
                    path  = (path.Replace('-', ' ')).Replace(':', '_');
                    path += ".xlsx";
                    path  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + path;
                    oWB.SaveAs(path, Excel.XlFileFormat.xlWorkbookDefault); //  - ,
                    oXL.Workbooks.Close();
                    oXL.Quit();

                    Process[] excelProcess;

                    excelProcess = Process.GetProcessesByName("Excel");
                    excelProcess[0].CloseMainWindow();
                    excelProcess[0].Refresh();
                    excelProcess[0].Kill();
                }
            }
            catch
            {
                Process[] excelProcess;

                excelProcess = Process.GetProcessesByName("Excel");
                excelProcess[0].CloseMainWindow();
                excelProcess[0].Refresh();
                excelProcess[0].Kill();
            }

            chartPoints.Clear();
        }