public static void Swap(Span <byte> bytes, SwapMode swapMode)
        {
            if (bytes.Length % 2 != 0)
            {
                throw new ArgumentException("Swapping on odd number of bytes is not supported.");
            }

            switch (swapMode)
            {
            case SwapMode.BigEndian:
                break;

            case SwapMode.LittleEndian:
                bytes.Reverse();
                break;

            case SwapMode.BigEndianByteSwap:
                SwapBytes(bytes);
                break;

            case SwapMode.LittleEndianByteSwap:
                bytes.Reverse();
                SwapBytes(bytes);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(swapMode), swapMode, "Unsupported swap mode.");
            }
        }
示例#2
0
        public string Parse(string text, SwapMode swapmode)
        {
            char[] target = text.ToArray();

            for (int i = 0; i < target.Length; i++)
            {
                if (swapmode == SwapMode.ToLocal)
                {
                    if (srcSet.Contains(target[i]))
                    {
                        int x = Array.IndexOf(srcSet, target[i]);
                        target[i] = dstSet[x];
                    }
                }
                else
                {
                    if (dstSet.Contains(target[i]))
                    {
                        int x = Array.IndexOf(dstSet, target[i]);
                        target[i] = srcSet[x];
                    }
                }
            }

            return(new string(target));
        }
示例#3
0
        /* 入れ替え系 */
        public void Swap(SwapMode swapMode)
        {
            switch (swapMode)
            {
            case SwapMode.UpAndLeftUp:
                char UpAndLeftUp = Up;
                Up                = LeftUp;
                LeftUp            = UpAndLeftUp;
                swapedUpAndLeftUp = !swapedUpAndLeftUp;
                break;

            case SwapMode.UpAndRightUp:
                char UpAndRightUp = Up;
                Up                 = RightUp;
                RightUp            = UpAndRightUp;
                swapedUpAndRightUp = !swapedUpAndLeftUp;
                break;

            case SwapMode.LeftAndLeftUp:
                char LeftAndLeftUp = Left;
                Left   = LeftUp;
                LeftUp = LeftAndLeftUp;
                swapedLeftAndLeftUp = !swapedLeftAndLeftUp;
                break;

            case SwapMode.RightAndRightUp:
                char RightAndRightUp = Right;
                Right   = RightUp;
                RightUp = RightAndRightUp;
                swapedRightAndRightUp = !swapedRightAndRightUp;
                break;
            }
        }
            public void SwapsCorrectly(string expectedValue, SwapMode swapMode, string toConvert)
            {
                var bytes = toConvert.Select(c => (byte)c).ToArray().AsSpan();

                ByteSwapper.Swap(bytes, swapMode);

                var result = new string(bytes.ToArray().Select(b => (char)b).ToArray());

                Assert.AreEqual(expectedValue, result);
            }
示例#5
0
        private static string GetOperaionName(SwapMode mode)
        {
            switch (mode)
            {
            case SwapMode.Copy: return("копировать");

            case SwapMode.Swap: return("поменять местами");

            default: return("перемещение");
            }
        }
示例#6
0
        public SwapTableEntryControl(SwapMode swapMode)
        {
            InitializeComponent();

            swapRedCB.LoadEnum(typeof(SwapChannel));
            swapGreenCB.LoadEnum(typeof(SwapChannel));
            swapBlueCB.LoadEnum(typeof(SwapChannel));
            swapAlphaCB.LoadEnum(typeof(SwapChannel));

            LoadSwapMode(swapMode);
        }
示例#7
0
 internal SymbolInfo(MT4 conn, SDParser p)
 {
     //
     IsSelected       = p.popBoolean();
     IsFloatingSpread = p.popBoolean();
     //
     SessionDeals      = p.popLong();
     SessionBuyOrders  = p.popLong();
     SessionSellOrders = p.popLong();
     Volume            = p.popLong();
     VolumeHigh        = p.popLong();
     VolumeLow         = p.popLong();
     //
     Digits      = p.popInt();
     Spread      = p.popInt();
     StopsLevel  = p.popInt();
     FreezeLevel = p.popInt();
     //
     ContractPriceCalculationMode = ((PriceCalculationMode[])Enum.GetValues(typeof(PriceCalculationMode)))[p.popInt()];
     TradeMode          = ((TradeMode[])Enum.GetValues(typeof(TradeMode)))[p.popInt()];
     SwapMode           = ((SwapMode[])Enum.GetValues(typeof(SwapMode)))[p.popInt()];
     SwapRollover3Days  = ((DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)))[p.popInt()];
     TradeExecutionMode = ((TradeExecutionMode[])Enum.GetValues(typeof(TradeExecutionMode)))[p.popInt()];
     //
     Time           = conn.ToDate(p.popDouble());
     StartTime      = conn.ToDate(p.popDouble());
     ExpirationTime = conn.ToDate(p.popDouble());
     //
     ExpirationModes = ExpirationModeValues(p.popInt());
     FillingModes    = FillingModeValues(p.popInt());
     OrderModes      = OrderModeValues(p.popInt());
     //
     BaseCurrency   = p.pop();
     ProfitCurrency = p.pop();
     MarginCurrency = p.pop();
     Description    = p.pop();
     Path           = p.pop();
     //
     Bid                         = p.popDouble();
     BidHigh                     = p.popDouble();
     BidLow                      = p.popDouble();
     Ask                         = p.popDouble();
     AskHigh                     = p.popDouble();
     AskLow                      = p.popDouble();
     Last                        = p.popDouble();
     LastHigh                    = p.popDouble();
     LastLow                     = p.popDouble();
     Point                       = p.popDouble();
     TradeTickValue              = p.popDouble();
     TradeTickValueProfit        = p.popDouble();
     TradeTickValueLoss          = p.popDouble();
     TradeTickSize               = p.popDouble();
     TradeContractSize           = p.popDouble();
     MinVolume                   = p.popDouble();
     MaxVolume                   = p.popDouble();
     StepVolume                  = p.popDouble();
     LimitVolume                 = p.popDouble();
     LongSwap                    = p.popDouble();
     ShortSwap                   = p.popDouble();
     InitialMargin               = p.popDouble();
     MaintenanceMargin           = p.popDouble();
     LongMargin                  = p.popDouble();
     ShortMargin                 = p.popDouble();
     LimitMargin                 = p.popDouble();
     StopMargin                  = p.popDouble();
     StopLimitMargin             = p.popDouble();
     SessionVolume               = p.popDouble();
     SessionTurnover             = p.popDouble();
     SessionInterest             = p.popDouble();
     SessionBuyOrdersVolume      = p.popDouble();
     SessionSellOrdersVolume     = p.popDouble();
     SessionOpenPrice            = p.popDouble();
     SessionClosePrice           = p.popDouble();
     SessionAverageWeightedPrice = p.popDouble();
     SessionSettlementPrice      = p.popDouble();
     SessionMinLimitPrice        = p.popDouble();
     SessionMaxLimitPrice        = p.popDouble();
 }
示例#8
0
 public void LoadSwapMode(SwapMode swapMode)
 {
     SwapMode = swapMode;
     Reload();
 }
 private void SwapRowsForAssociatedGrids(SwapMode mode,int iSelected)
 {
     for (int i = 0;i< AssociatedGrids.Length; i++)
     {
         swapRows(AssociatedGrids[i], iSelected, mode);
     }
 }
示例#10
0
        private void swapRows(clsWritableGrid _Grid, int iSelectedRow, SwapMode range)
        {
            try
            {
                SetFreezedRows();
                //int iSelectedRow = -1;
                //for (int iTmp = 0; iTmp <= _ParentGrid.Rows.Count - 1; iTmp++)
                //{
                //    if (_ParentGrid.Rows[iTmp].Selected)
                //    {
                //        if (listFreezedRows.Contains(iTmp))
                //            return;
                //        iSelectedRow = iTmp;
                //        if (range == SwapMode.Up)
                //            iSelectedRow--;
                //        else
                //            iSelectedRow++;
                //        break; // TODO: might not be correct. Was : Exit For
                //    }
                //}

                if (iSelectedRow != -1)
                {
                    string[] sTmp = new string[_Grid.dvSource.Table.Columns.Count];
                    for (int iTmp = 0; iTmp <= _Grid.dvSource.Table.Columns.Count - 1; iTmp++)
                    {
                        //sTmp[iTmp] = _Grid.Rows[iSelectedRow].Cells[iTmp].Value.ToString();
                        sTmp[iTmp] = _Grid.dvSource[iSelectedRow][iTmp].ToString();
                    }

                    int iNewRow = 0;
                    if (range == SwapMode.Down)
                    {
                        iNewRow = iSelectedRow + 1;
                    }
                    else if (range == SwapMode.Up)
                    {
                        iNewRow = iSelectedRow - 1;
                        if (listFreezedRows.Contains(iNewRow))
                            iNewRow = -1;
                    }

                    if (iNewRow > -1)
                    {
                        if (range == SwapMode.Up | range == SwapMode.Down)
                        {
                            _Grid.dvSource.BeginInit();
                            for (int iTmp = 0; iTmp <= _Grid.dvSource.Table.Columns.Count - 1; iTmp++)
                            {

                                //this.Rows[iSelectedRow].Cells[iTmp].Value = this.Rows[iNewRow].Cells[iTmp].Value;
                                _Grid.dvSource[iSelectedRow][iTmp] = _Grid.dvSource[iNewRow][iTmp];
                                //this.Rows[iNewRow].Cells[iTmp].Value = sTmp[iTmp];
                                _Grid.dvSource[iNewRow][iTmp] = sTmp[iTmp];
                            }
                            _Grid.dvSource.EndInit();
                            _Grid.dvSource.Table.AcceptChanges();
                            _Grid.DataSource = _Grid.dvSource.Table;
                            _Grid.Update();

                            for (int i = 0; i < _Grid.Rows.Count - 1; i++)
                            {
                                _Grid.Rows[i].Selected = false;
                            }
                            _Grid.Rows[iNewRow].Selected = true;
                        }
                        else if (range == SwapMode.Top | range == SwapMode.Bottom)
                        {
                            reshuffleRows(sTmp, iSelectedRow, range);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
示例#11
0
        private void swapRows(SwapMode range, ref int SelectedIndex)
        {
            try
            {
                SetFreezedRows();
                //if (listFreezedRows.Count > 0)
                //{
                //    listFreezedRows.Clear();

                //}
                //listFreezedRows.Add(0);
                //listFreezedRows.Add(1);
                int iSelectedRow = -1;
                for (int iTmp = 0; iTmp <= this.Rows.Count - 1; iTmp++)
                {
                    if (this.Rows[iTmp].Selected)
                    {
                        if (listFreezedRows.Contains(iTmp))
                            return;
                        iSelectedRow = iTmp;
                        SelectedIndex = iSelectedRow;
                        break; // TODO: might not be correct. Was : Exit For
                    }
                }

                if (iSelectedRow != -1)
                {
                    string[] sTmp = new string[this.dvSource.Table.Columns.Count];
                    for (int iTmp = 0; iTmp <= this.dvSource.Table.Columns.Count - 1; iTmp++)
                    {
                        //sTmp[iTmp] = this.Rows[iSelectedRow].Cells[iTmp].Value.ToString();
                        sTmp[iTmp] = this.dvSource[iSelectedRow][iTmp].ToString();
                    }

                    int iNewRow = 0;
                    if (range == SwapMode.Down)
                    {
                        iNewRow = iSelectedRow + 1;
                    }
                    else if (range == SwapMode.Up)
                    {
                        iNewRow = iSelectedRow - 1;
                        if (listFreezedRows.Contains(iNewRow))
                            iNewRow = -1;
                    }

                    if (iNewRow > -1)
                    {
                        if (range == SwapMode.Up | range == SwapMode.Down)
                        {
                            this.dvSource.BeginInit();
                            for (int iTmp = 0; iTmp <= this.dvSource.Table.Columns.Count - 1; iTmp++)
                            {

                                //this.Rows[iSelectedRow].Cells[iTmp].Value = this.Rows[iNewRow].Cells[iTmp].Value;
                                this.dvSource[iSelectedRow][iTmp] = this.dvSource[iNewRow][iTmp];
                                //this.Rows[iNewRow].Cells[iTmp].Value = sTmp[iTmp];
                                this.dvSource[iNewRow][iTmp] = sTmp[iTmp];
                            }
                            this.dvSource.EndInit();
                            dvSource.Table.AcceptChanges();
                            this.DataSource = dvSource.Table;
                            this.Update();

                            toSelect(iNewRow);
                        }
                        else if (range == SwapMode.Top | range == SwapMode.Bottom)
                        {
                            reshuffleRows(sTmp, iSelectedRow, range);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
示例#12
0
        private void reshuffleRows(string[] sTmp, int iSelectedRow, SwapMode Range)
        {
            if (Range == SwapMode.Top)
            {
                //int iFirstRow = 0;
                int iFirstRow = 2;
                if (iSelectedRow > iFirstRow)
                {
                    for (int iTmp = iSelectedRow; iTmp >= 1; iTmp += -1)
                    {
                        for (int iCol = 0; iCol <= this.Columns.Count - 1; iCol++)
                        {
                            if (listFreezedRows.Contains(iTmp))
                                continue;
                            this.Rows[iTmp].Cells[iCol].Value = this.Rows[iTmp - 1].Cells[iCol].Value;
                        }
                    }
                    for (int iCol = 0; iCol <= this.Columns.Count - 1; iCol++)
                    {
                        this.Rows[iFirstRow].Cells[iCol].Value = sTmp[iCol].ToString();
                    }
                    toSelect(iFirstRow);
                }
            }
            else
            {
                int iLastRow = this.Rows.Count - 1;
                if (iSelectedRow < iLastRow)
                {
                    for (int iTmp = iSelectedRow; iTmp <= iLastRow - 1; iTmp++)
                    {
                        for (int iCol = 0; iCol <= this.Columns.Count - 1; iCol++)
                        {

                            this.Rows[iTmp].Cells[iCol].Value = this.Rows[iTmp + 1].Cells[iCol].Value;
                        }
                    }
                    for (int iCol = 0; iCol <= this.Columns.Count - 1; iCol++)
                    {
                        this.Rows[iLastRow].Cells[iCol].Value = sTmp[iCol].ToString();
                    }
                    toSelect(iLastRow);
                }
            }
        }
示例#13
0
 private void CreatePanel(string name, int index, SwapMode swapMode)
 {
 }
示例#14
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Source: ", EditorStyles.boldLabel);
            previousSource = source;
            source         = (Texture2D)EditorGUILayout.ObjectField(source, typeof(Texture2D), false, GUILayout.Width(220));
            GUILayout.EndHorizontal();

            //float imageDistance = 0f;

            GUILayout.Space(10f);
            if (source)
            {
                //imageDistance = source.height * zoom;
                //GUILayout.Space(imageDistance + 25f);
                previousMode = mode;
                mode         = (ColorSwapperWindow.SwapMode)EditorGUILayout.EnumPopup(mode);
                if (mode == SwapMode.HueChange)
                {
                    hueChange        = EditorGUILayout.Slider("Hue", hueChange, -1f, 1f);
                    saturationChange = EditorGUILayout.Slider("Saturation", saturationChange, -1f, 1f);
                    valueChange      = EditorGUILayout.Slider("Value", valueChange, -1f, 1f);
                }
                if (mode == SwapMode.SingleColors)
                {
                    if (targetColors.Count > 8)
                    {
                        colorScrollPosition = EditorGUILayout.BeginScrollView(colorScrollPosition, GUILayout.Height(160));
                    }
                    for (int i = 0; i < targetColors.Count; i++)
                    {
                        targetColors[i] = EditorGUILayout.ColorField(targetColors[i]);
                    }
                    if (targetColors.Count > 8)
                    {
                        EditorGUILayout.EndScrollView();
                    }
                }
                //------swap
                if (GUI.changed == true || recoloredImage == null)
                {
                    if (sourceColors?.Count == 0 || colorMap == null || recoloredImage == null || source != previousSource)
                    {
                        GetColors();
                    }
                    // if (zoom != previousZoom || source != previousSource || mode != previousMode) ResizeToContent();
                    SwapColors();
                }
                EditorGUILayout.Separator();
                previousZoom = zoom;
                zoom         = EditorGUILayout.Slider("Zoom", zoom, 0.1f, 10f);
                GUILayout.Space(10f);
                if (GUILayout.Button("Save Duplicate"))
                {
                    //Debug.Log("Implement Save");
                    SaveTex(source, recoloredImage);
                }
                recoloredImageScroll = EditorGUILayout.BeginScrollView(recoloredImageScroll,
                                                                       GUILayout.MaxWidth(position.width),
                                                                       GUILayout.MaxHeight(position.height - 60f));
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(recoloredImage.width * zoom), GUILayout.Height(recoloredImage.height * zoom));
                EditorGUI.DrawTextureTransparent(rect, recoloredImage);
                EditorGUILayout.EndScrollView();
                //GUILayout.EndHorizontal();
            }
        }