Example #1
0
        private void FormServer_Load(object sender, EventArgs e)
        {
            AppendString = new AppendDelegate(AppendMethod);
            Addfriend    = new AddDelegate(AddMethod);
            Removefriend = new RemoveDelegate(RemoveMethod);
            //getting local IPv4 address
            List <string> listIP = getIP();

            if (listIP.Count == 0)
            {
                this.comboBoxIP.Items.Clear();
                this.comboBoxIP.Text = "Can not get IP address";
            }
            else if (listIP.Count == 1)
            {
                this.comboBoxIP.Items.Add(listIP[0]);
                this.comboBoxIP.SelectedIndex = 0;
            }
            else
            {
                foreach (string str in listIP)
                {
                    this.comboBoxIP.Items.Add(str);
                }
                this.comboBoxIP.Text = "Pls select or enter a IP address";
            }
            //default port
            textBoxServerPort.Text = "6000";
        }
        public override void Insert(string cacheKey, object itemToCache, string scope = null, DateTimeOffset?absoluteExpiration = null, TimeSpan?slidingExpiration = null, FileCacheDependency dependency = null,
                                    RemoveDelegate onRemoveCallback = null)
        {
            var options = new MemoryCacheEntryOptions()
            {
                SlidingExpiration  = slidingExpiration,
                AbsoluteExpiration = absoluteExpiration
            };

            if (onRemoveCallback != null)
            {
                options.RegisterPostEvictionCallback((key, value, reason, state) =>
                {
                    onRemoveCallback(key, value, (RemoveReason)Enum.Parse(typeof(RemoveReason), reason.ToString()), state);
                });
            }

            if (dependency != null)
            {
                options.AddExpirationToken(dependency.GetChangeToken());
            }

            if (scope != null)
            {
                var ctsScope = UniqueObject.GetUniqueObject <CancellationTokenSource>(GetCacheKeyPrefix(scope));
                options.AddExpirationToken(new CancellationChangeToken(ctsScope.Token));
            }
            var ctsDefault = UniqueObject.GetUniqueObject <CancellationTokenSource>(GetCacheKeyPrefix(_defaultScopeName));

            options.AddExpirationToken(new CancellationChangeToken(ctsDefault.Token));

            string strKey = GetCacheKey(cacheKey, scope);

            _cache.Set(strKey, itemToCache, options);
        }
            public object Set(string name, object instance, Type type, object value, params object[] arguments)
            {
                EventInfo ei = type.GetEvent(name, PropertyFilter);

                if (ei == null)
                {
                    return(NoResult);
                }
                if (!CanBind(ei))
                {
                    return(NoResult);
                }

                RemoveDelegate remove_delegate = value as RemoveDelegate;

                if (remove_delegate == null)
                {
                    EventBroker.AssignEvent(ei, instance, (IInvokable)value);
                }
                else
                {
                    EventBroker.RemoveEvent(ei, instance, remove_delegate.OriginalMethod);
                }

                return(value);
            }
Example #4
0
        //初始化加载
        private void FormServer_Load(object sender, EventArgs e)
        {
            //实例化委托对象,与委托方法关联
            AppendString = new AppendDelegate(AppendMethod);
            Addfriend = new AddDelegate(AddMethod);
            Removefriend = new RemoveDelegate(RemoveMethod);
            //获取本机IPv4地址
            List<string> listIP = getIP();
            if (listIP.Count == 0)
            {
                this.comboBoxIP.Items.Clear();
                this.comboBoxIP.Text = "未能获取IP!";
            }
            else if (listIP.Count == 1)
            {
                this.comboBoxIP.Items.Add(listIP[0]);
                this.comboBoxIP.SelectedIndex = 0;
            }
            else
            {
                foreach (string str in listIP)
                {
                    this.comboBoxIP.Items.Add(str);
                }
                this.comboBoxIP.Text = "请选择IP!";
            }
            //设置默认端口号
            textBoxServerPort.Text = "8899";

            buttonStop.Enabled = false;
        }
Example #5
0
        public override void Insert(string cacheKey, object itemToCache, string scope = null, DateTimeOffset?absoluteExpiration = null, TimeSpan?slidingExpiration = null, FileCacheDependency dependency = null,
                                    RemoveDelegate onRemoveCallback = null)
        {
            if (dependency != null)
            {
                throw new NotSupportedException("RedisCacheProvider does not support file dependency.");
            }
            var key = GetCacheKey(cacheKey, scope);

            using (var redisClient = this.GetRedisClient())
            {
                if (absoluteExpiration != null)
                {
                    redisClient.Add(key, itemToCache, absoluteExpiration.Value);
                }
                else if (slidingExpiration != null)
                {
                    redisClient.Add(key, itemToCache, slidingExpiration.Value);
                }
                else
                {
                    redisClient.Add(key, itemToCache);
                }
            }
        }
Example #6
0
        void Remove(ToastAdorner toast)
        {
            var index = _adorners.IndexOf(toast) - 1;

            if (!_adorners.Remove(toast))
            {
                return;
            }

            RemoveDelegate del = _adornerLayer.Remove;

            Application.Current?.Dispatcher?.Invoke(del, toast);

            if (!_adorners.Any())
            {
                IsEmpty?.Invoke(this, new EventArgs());
                return;
            }

            if (index < 0)
            {
                return;
            }

            MoveBackwards(index);
        }
Example #7
0
 private void RemoveAllCoins_Click(object sender, EventArgs e)
 {
     //Remove coin configs
     _coinConfigs = new List<CoinConfig>();
     RemoveDelegate remove = new RemoveDelegate(Remove);
     BeginInvoke(remove);
 }
Example #8
0
        private void RemoveCoin_Click(object sender, EventArgs e)
        {
            //Get coin to remove
            InputForm form = new InputForm("Remove", _coinConfigs.OrderBy(c => c.coin).Select(c => c.coin).ToList());

            if (form.ShowDialog() != DialogResult.OK)
                return;

            //Check if coin exists
            if (_coinConfigs.Any(a => a.coin.Equals(form.InputText.ToUpper())))
            {
                //Update coin configs based on changed values
                foreach (var coinGuiLine in _coinGuiLines)
                {
                    var coinConfig = _coinConfigs.Single(c => c.coin == coinGuiLine.CoinName);
                    coinConfig.bought = Convert.ToDecimal(coinGuiLine.BoughtTextBox.Text);
                    coinConfig.paid = Convert.ToDecimal(coinGuiLine.PaidTextBox.Text);
                    coinConfig.SetStartupPrice = false;
                }

                //Remove coin config
                _coinConfigs.RemoveAll(a => a.coin.Equals(form.InputText.ToUpper()));

                RemoveDelegate remove = new RemoveDelegate(Remove);
                BeginInvoke(remove);
            }
            else
            {
                MessageBox.Show("Coin does not exist.");
            }
        }
Example #9
0
        public FishyNote(int fishyNoteID, RemoveDelegate deleteMe, TextUpdate noteTextUpdate, RetriveText retriveNoteText)
        {
            InitializeComponent();
            _fishyNoteID = fishyNoteID;

            _deleteMe        += deleteMe;
            _noteTextUpdate  += noteTextUpdate;
            _retriveNoteText += retriveNoteText;
        }
Example #10
0
        private void AddCoin_Click(object sender, EventArgs e)
        {
            //Check if coin list has been downloaded
            while(_coinNames.Count <= 0)
            {
                if (MessageBox.Show("Please wait while coin list is being downloaded.", "Loading", MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
                    return;
            }

            try
            {
                using (var webClient = new WebClient())
                {
                    //Get coin to add
                    InputForm form = new InputForm("Add", _coinNames.Except(_coinConfigs.Select(c => c.coin).ToList()).ToList());

                    if (form.ShowDialog() != DialogResult.OK)
                        return;

                    if (!_coinNames.Contains(form.InputText.ToUpper()))
                    {
                        MessageBox.Show("Coin does not exist.");
                        return;
                    }

                    //Check if coin exists
                    if (!_coinConfigs.Any(a => a.coin.Equals(form.InputText.ToUpper())))
                    {
                        //Update coin configs based on changed values
                        foreach (var coinGuiLine in _coinGuiLines)
                        {
                            var coinConfig = _coinConfigs.Single(c => c.coin == coinGuiLine.CoinName);
                            coinConfig.bought = Convert.ToDecimal(coinGuiLine.BoughtTextBox.Text);
                            coinConfig.paid = Convert.ToDecimal(coinGuiLine.PaidTextBox.Text);
                            coinConfig.SetStartupPrice = false;
                        }

                        //Add config
                        _coinConfigs.Add(new CoinConfig { coin = form.InputText.ToUpper(), bought = 0, paid = 0, StartupPrice = 0, SetStartupPrice = true });

                        RemoveDelegate remove = new RemoveDelegate(Remove);
                        BeginInvoke(remove);
                    }
                    else
                    {
                        MessageBox.Show("Coin already added.");
                    }
                }
            }
            catch (WebException)
            {
                //Update status
                UpdateStatusDelegate updateStatus = new UpdateStatusDelegate(UpdateStatus);
                BeginInvoke(updateStatus, "No internet connection");
            }
        }
Example #11
0
 /// <summary>
 /// Creates a <see cref="CollectionChangedEventHandler{T}"/> from the specified delegates.
 /// </summary>
 /// <param name="add"> If null is specified, nothing is performed on addition of an element. </param>
 /// <param name="move"> If null is specified, nothing is performed on removal of an element. </param>
 /// <param name="remove"> If null is specified, nothing is performed on removal of an element. </param>
 /// <param name="replace"> If null is specified, the default action is performed, which is to first remove and then add the changes. </param>
 /// <param name="reset"> If null is specified, the default action is performed, which is to remove all elements. </param>
 public static CollectionChangedEventHandler <T> Create <TCollection>(
     AddDelegate <TCollection> add         = null,
     RemoveDelegate <TCollection> remove   = null,
     ReplaceDelegate <TCollection> replace = null,
     MoveDelegate <TCollection> move       = null,
     ResetDelegate <TCollection> reset     = null
     ) where TCollection : INotifyCollectionChanged
 {
     return(new DelegatedCollectionChangedEventHandler <TCollection>(move, add, reset, replace, remove));
 }
Example #12
0
        private void LoadPortfolio(string portfolio)
        {
            if (!File.Exists(portfolio))
                return;

            //Load portfolio from file
            _coinConfigs = JsonConvert.DeserializeObject<List<CoinConfig>>(File.ReadAllText(portfolio) ?? string.Empty);
            _selectedPortfolio = portfolio;

            RemoveDelegate remove = new RemoveDelegate(Remove);
            BeginInvoke(remove);
        }
Example #13
0
 public void SetCache(string CacheKey, object objObject, string Scope = null, DateTimeOffset?AbsoluteExpiration = null, TimeSpan?SlidingExpiration = null, ProviderLevel level = ProviderLevel.Normal,
                      FileCacheDependency objDependency = null, RemoveDelegate OnRemoveCallback = null)
 {
     if (objObject != null)
     {
         //if no OnRemoveCallback value is specified, use the default method
         if (OnRemoveCallback == null)
         {
             OnRemoveCallback = ItemRemovedCallback;
         }
         CachingProvider.Instance(level).Insert(CacheKey, objObject, Scope, AbsoluteExpiration, SlidingExpiration, objDependency, OnRemoveCallback);
     }
 }
Example #14
0
 /// <summary>
 ///     初始化线程安全类
 /// </summary>
 /// <param name="ctrl">需要进行线程安全的控件</param>
 public ThreadSafeSetter(Control ctrl)
 {
     target          = ctrl;
     setText         = SetText;
     setAppendText   = SetAppendText;
     getText         = GetText;
     add             = Add;
     remove          = Remove;
     removeAll       = RemoveAll;
     setEnabled      = SetEnabled;
     getEnabled      = GetEnabled;
     getSelectedItem = GetSelectedItem;
 }
Example #15
0
        /// <summary>
        /// 条件に合致した要素を削除
        /// </summary>
        /// <param name="t"></param>
        public void Remove(RemoveDelegate rd)
        {
            LinkedListNode <T> node = this.First;

            while (node != null)
            {
                LinkedListNode <T> next = node.Next;
                if (rd(node.Value))
                {
                    base.Remove(node);
                }
                node = next;
            }
        }
Example #16
0
 public DelegatedCollectionChangedEventHandler(
     MoveDelegate <TCollection> move,
     AddDelegate <TCollection> add,
     ResetDelegate <TCollection> reset,
     ReplaceDelegate <TCollection> replace,
     RemoveDelegate <TCollection> remove
     )
 {
     this.move    = move;
     this.add     = add;
     this.reset   = reset;
     this.replace = replace;
     this.remove  = remove;
 }
Example #17
0
        private void AddCoin_Click(object sender, EventArgs e)
        {
            //Check if coin list has been downloaded
            while (_coinNames.Count <= 0)
            {
                if (MessageBox.Show("Please wait while coin list is being downloaded.", "Loading", MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
                {
                    return;
                }
            }

            //Get coin to add
            InputForm form = new InputForm("Add", _coinNames.ToList());

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //Check if coin exists
            if (!_coinNames.Contains(form.InputText.ToUpper()))
            {
                MessageBox.Show("Coin does not exist.");
                return;
            }

            //Update coin config bought and paid values
            foreach (var coinGuiLine in _coinGuiLines)
            {
                var coinConfig = _coinConfigs.Single(c => c.coin == coinGuiLine.CoinName && c.coinIndex == coinGuiLine.CoinIndex);
                coinConfig.bought          = Convert.ToDecimal(coinGuiLine.BoughtTextBox.Text);
                coinConfig.paid            = Convert.ToDecimal(coinGuiLine.PaidTextBox.Text);
                coinConfig.SetStartupPrice = false;
            }

            //Add coin config
            _coinConfigs.Add(new CoinConfig {
                coin = form.InputText.ToUpper(), coinIndex = _coinConfigs.Count(c => c.coin.Equals(form.InputText.ToUpper())), bought = 0, paid = 0, StartupPrice = 0, SetStartupPrice = true
            });

            RemoveDelegate remove = new RemoveDelegate(Remove);

            BeginInvoke(remove);
        }
Example #18
0
        private void rfidMain_Load(object sender, EventArgs e)
        {
            MaximizeBox = false;
            //实例化委托对象,与委托方法关联
            AppendString = new AppendDelegate(AppendMethod);
            Addfriend    = new AddDelegate(AddMethod);
            Removefriend = new RemoveDelegate(RemoveMethod);
            //获取本机IPv4地址
            List <string> listIP = getIP();

            if (listIP.Count == 0)
            {
                this.comboBoxIP.Items.Clear();
                this.comboBoxIP.Text = "未能获取IP!";
            }
            else if (listIP.Count == 1)
            {
                this.comboBoxIP.Items.Add(listIP[0]);
                this.comboBoxIP.SelectedIndex = 0;
            }
            else
            {
                foreach (string str in listIP)
                {
                    this.comboBoxIP.Items.Add(str);
                }
                this.comboBoxIP.Text = "请选择IP!";
            }
            //设置默认端口号
            textBoxServerPort.Text = "9600";
            System.Timers.Timer pTimer = new System.Timers.Timer(1000); //每隔1秒执行一次,没用winfrom自带的
            pTimer.Elapsed  += pTimer_Elapsed;                          //委托,要执行的方法
            pTimer.AutoReset = true;                                    //获取该定时器自动执行
            pTimer.Enabled   = true;                                    //这个一定要写,要不然定时器不会执行的
            Control.CheckForIllegalCrossThreadCalls = false;            //这个不太懂,有待研究

            startListen();                                              //开始监听
        }
Example #19
0
        private void RemoveCoin_Click(object sender, EventArgs e)
        {
            //Get coin to remove
            InputForm form = new InputForm("Remove", _coinConfigs);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //Check if coin exists
            if (!_coinConfigs.Any(a => a.coin.Equals(form.InputText.ToUpper()) && a.coinIndex == form.CoinIndex))
            {
                MessageBox.Show("Coin does not exist.");
                return;
            }

            //Update coin config bought and paid values
            foreach (var coinGuiLine in _coinGuiLines)
            {
                var coinConfig = _coinConfigs.Single(c => c.coin == coinGuiLine.CoinName && c.coinIndex == coinGuiLine.CoinIndex);
                coinConfig.bought          = Convert.ToDecimal(coinGuiLine.BoughtTextBox.Text);
                coinConfig.paid            = Convert.ToDecimal(coinGuiLine.PaidTextBox.Text);
                coinConfig.SetStartupPrice = false;
            }

            //Remove coin config
            _coinConfigs.RemoveAll(a => a.coin.Equals(form.InputText.ToUpper()) && a.coinIndex == form.CoinIndex);

            //Reset coin indexes
            ResetCoinIndex();

            RemoveDelegate remove = new RemoveDelegate(Remove);

            BeginInvoke(remove);
        }
Example #20
0
        public void UpdateCoins(string response)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateCoinDelegates(UpdateCoins), response);
                return;
            }

            //Overall values
            decimal totalPaid            = 0;
            decimal overallTotal         = 0;
            decimal totalNegativeProfits = 0;
            decimal totalPostivieProfits = 0;

            //Index of coin gui line
            int index = 0;

            //Deserialize settings
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            //Deserialize response and map to generic coin
            List <CoinData> coins = new List <CoinData>();

            switch (_api)
            {
            case API_COIN_MARKET_CAP:
                var coinsCoinMarketCap = JsonConvert.DeserializeObject <List <ApiCoinMarketCap> >(response, settings);
                coins = coinsCoinMarketCap.Select(c => Mappings.MapCoinMarketCap(c)).ToList();
                break;

            case API_COIN_CAP:
                var coinsCoinCap = JsonConvert.DeserializeObject <List <ApiCoinCap> >(response, settings);
                coins = coinsCoinCap.Select(c => Mappings.MapCoinCap(c)).ToList();
                break;
            }

            //Create list of coin names
            _coinNames = coins.OrderBy(c => c.ShortName).Select(c => c.ShortName).ToList();

            //Loop through all coins from config
            foreach (CoinConfig coin in _coinConfigs)
            {
                CoinData downloadedCoin;

                //Parse coins, if coin doesnt exist set to 0
                downloadedCoin = coins.Any(c => c.ShortName == coin.coin)
                    ? coins.Single(c => c.ShortName == coin.coin)
                    : new CoinData {
                    ShortName = coin.coin, CoinIndex = coin.coinIndex, Change1HourPercent = 0, Change24HourPercent = 0, Price = 0
                };

                //Check if gui lines need to be loaded
                if (_loadGuiLines)
                {
                    AddCoin(coin, downloadedCoin, index);
                }

                //Incremenet coin line index
                index++;

                //Check if coinguiline exists for coinConfig
                if (!_coinGuiLines.Any(cg => cg.CoinName.Equals(downloadedCoin.ShortName)))
                {
                    RemoveDelegate remove = new RemoveDelegate(Remove);
                    BeginInvoke(remove);
                    return;
                }

                //Get the gui line for coin
                CoinGuiLine line = (from c in _coinGuiLines where c.CoinName.Equals(downloadedCoin.ShortName) && c.CoinIndex == coin.coinIndex select c).First();

                //Calculate
                decimal bought        = Convert.ToDecimal(line.BoughtTextBox.Text);
                decimal paid          = Convert.ToDecimal(line.PaidTextBox.Text);
                decimal boughtPrice   = bought == 0 ? 0 : paid / bought;
                decimal total         = bought * downloadedCoin.Price;
                decimal profit        = total - paid;
                decimal changeDollar  = downloadedCoin.Price - coin.StartupPrice;
                decimal changePercent = coin.StartupPrice == 0 ? 0 : ((downloadedCoin.Price - coin.StartupPrice) / coin.StartupPrice) * 100;

                //Update total profits
                if (profit >= 0)
                {
                    totalPostivieProfits += profit;
                }
                else
                {
                    totalNegativeProfits += profit;
                }

                //Add to totals
                totalPaid    += paid;
                overallTotal += paid + profit;

                //Update gui
                line.CoinLabel.Show();
                line.CoinIndexLabel.Text         = _coinConfigs.Count(c => c.coin.Equals(coin.coin)) > 1 ? $"[{coin.coinIndex + 1}]" : string.Empty;
                line.CoinLabel.Text              = downloadedCoin.ShortName;
                line.PriceLabel.Text             = $"${downloadedCoin.Price}";
                line.BoughtPriceLabel.Text       = $"${boughtPrice:0.000000}";
                line.TotalLabel.Text             = $"${total:0.00}";
                line.ProfitLabel.Text            = $"${profit:0.00}";
                line.ChangeDollarLabel.Text      = $"${changeDollar:0.000000}";
                line.ChangePercentLabel.Text     = $"{changePercent:0.00}%";
                line.Change1HrPercentLabel.Text  = $"{downloadedCoin.Change1HourPercent:0.00}%";
                line.Change24HrPercentLabel.Text = $"{downloadedCoin.Change24HourPercent:0.00}%";
            }

            //Update gui
            lblOverallTotal.Text        = $"${overallTotal:0.00}";
            lblTotalProfit.ForeColor    = overallTotal - totalPaid >= 0 ? Color.Green : Color.Red;
            lblTotalProfit.Text         = $"${overallTotal - totalPaid:0.00}";
            lblTotalNegativeProfit.Text = $"${totalNegativeProfits:0.00}";
            lblTotalPositiveProfit.Text = $"${totalPostivieProfits:0.00}";
            lblStatus.Text = "Status: Sleeping";
            _refreshTime   = DateTime.Now;

            //Sleep and rerun
            _loadGuiLines = false;
        }
Example #21
0
 /// <summary>
 /// Inserts the specified cache key.
 /// </summary>
 /// <param name="cacheKey">The cache key.</param>
 /// <param name="itemToCache">The value.</param>
 /// <param name="scope">The value in which scope.</param>
 /// <param name="absoluteExpiration">The absolute expiration.</param>
 /// <param name="slidingExpiration">The sliding expiration.</param>
 /// <param name="dependency">The dependency.</param>
 /// <param name="onRemoveCallback">The on remove callback.</param>
 public abstract void Insert(string cacheKey, object itemToCache, string scope = null, DateTimeOffset?absoluteExpiration = null, TimeSpan?slidingExpiration = null, FileCacheDependency dependency = null,
                             RemoveDelegate onRemoveCallback = null);
Example #22
0
 /// <summary>
 /// [async]条件に合致した要素を削除
 /// </summary>
 /// <param name="t"></param>
 public new void Remove(RemoveDelegate rd)
 {
     lock (SyncObject)
         base.Remove(rd);
 }