Ejemplo n.º 1
0
 public void DeleteAllFrameEditsForFrame(long timestamp)
 {
     if (m_editsDictionary.ContainsKey(timestamp))
     {
         m_editsDictionary.Remove(timestamp);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes all values of a property from all projects
        /// (for a given configuration/platform)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        public void Move(string name, string val)
        {
            Parallel.ForEach(_allProjects, proj =>
            {
                ProjectProperty p = proj.GetProperty(name);
                if (p != null &&
                    !p.IsEnvironmentProperty &&
                    !p.IsGlobalProperty &&
                    !p.IsImported &&
                    !p.IsReservedProperty)
                {
                    proj.RemoveProperty(p);
                }
            });

            if (_allFoundProperties.ContainsKey(name))
            {
                ReferencedProperty refp = _allFoundProperties[name];
                refp.RemoveProjects(_allProjects);
                if (refp.UsedCount == 0)
                {
                    bool removed = _allFoundProperties.Remove(name);
                    Debug.Assert(removed, "Property was not removed from the list");
                }
            }

            UpdatePropertySheet(name, val);
        }
Ejemplo n.º 3
0
 public void UnregisterPlugin(string key)
 {
     if (_plugins.ContainsKey(key))
     {
         _plugins.Remove(key);
     }
 }
Ejemplo n.º 4
0
 protected void ClearProperties()
 {
     foreach (var propertyBagKey in PropertyBag.Keys)
     {
         PropertyBag.Remove(propertyBagKey);
     }
 }
Ejemplo n.º 5
0
        public async Task <bool> DeleteItemAsync(int index)
        {
            using (var doc = _db.GetDocument(CoreApp.DocId))
                using (var mdoc = doc.ToMutable())
                    using (MutableArrayObject listItems = mdoc.GetArray(CoreApp.ArrKey)) {
                        listItems.RemoveAt(index);
                        _db.Save(mdoc);
                    }

            _items.Remove(index);

            return(await Task.FromResult(true));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// This event is added to every new ObservableResults obj we create
 /// and we use it to add items to the listbox when we find results
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddedNewResult(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         if (e.NewItems != null)
         {
             foreach (KeyValuePair <Word.Range, string> item in e.NewItems)
             {
                 AddNewResultsToListbox(item);
                 // Keep the observableResults concurrent dict lean by removing
                 // the current item
                 _observableResults.Remove(item.Key);
             }
         }
     }
 }
Ejemplo n.º 7
0
        public bool DeleteCopy(uint CopyNo)
        {
            ItemCopy itemCopy;

            if (!_copies.TryGetValue(CopyNo, out itemCopy))
            {
                return(false);
            }

            if (_copies.Remove(itemCopy.CopyNo))
            {
                return(true);
            }

            return(false);
        }
 public TransmissionLossCalculatorService()
 {
     WorkQueue = new ObservableConcurrentDictionary<Guid, Radial>();
     var calculator = new ActionBlock<Radial>(radial =>
     {
         if (!radial.IsDeleted) Calculate(radial);
         WorkQueue.Remove(radial.Guid);
         _shadeFileProcessorQueue.Post(radial);
     }, new ExecutionDataflowBlockOptions { BoundedCapacity = -1, MaxDegreeOfParallelism = System.Environment.ProcessorCount });
     _calculatorQueue = new BufferBlock<Radial>(new DataflowBlockOptions { BoundedCapacity = -1 });
     _calculatorQueue.LinkTo(calculator);
     var shadeFileProcessor = new ActionBlock<Radial>(r =>
     {
         if (!r.IsDeleted && r.ExtractAxisData()) r.ReleaseAxisData();
     }, new ExecutionDataflowBlockOptions { BoundedCapacity = -1, MaxDegreeOfParallelism = System.Environment.ProcessorCount });
     _shadeFileProcessorQueue = new BufferBlock<Radial>(new DataflowBlockOptions { BoundedCapacity = -1 });
     _shadeFileProcessorQueue.LinkTo(shadeFileProcessor);
 }
        private async void StartUpdateTask()
        {
            if (_updateTask != null && _updateTask.Status == TaskStatus.Running)
            {
                return;
            }

            _ctsUpdate = new CancellationTokenSource();
            try
            {
                _updateTask = Task.Factory.StartNew(() =>
                {
                    Stopwatch sw = new Stopwatch();
                    while (!_ctsUpdate.Token.IsCancellationRequested)
                    {
                        sw.Restart();
                        foreach (MotionControllerModel mc in _camera.Controllers)
                        {
                            var mc1 = mc;
                            // update if the controller is selected for tracking
                            if (mc.Tracking.ContainsKey(_camera) && mc.Tracking[_camera])
                            {
                                // add if missing
                                if (!_controllerObjects.ContainsKey(mc))
                                {
                                    DispatcherHelper.UIDispatcher.Invoke(() =>
                                    {
                                        // convert color
                                        byte r      = (byte)(mc1.Color.r * 255 + 0.5);
                                        byte g      = (byte)(mc1.Color.g * 255 + 0.5);
                                        byte b      = (byte)(mc1.Color.b * 255 + 0.5);
                                        Color color = Color.FromRgb(r, g, b);

                                        SphereVisual3D sphere = new SphereVisual3D
                                        {
                                            Center = new Point3D(mc1.WorldPosition[_camera].x,
                                                                 mc1.WorldPosition[_camera].z,
                                                                 mc1.WorldPosition[_camera].y),
                                            Radius = ((int)((14.0 / Math.PI) * 100)) / 200.0,
                                            Fill   = new SolidColorBrush(color)
                                        };
                                        _controllerObjects.Add(mc1, sphere);
                                        _items.Add(sphere);
                                    });
                                }
                                // update position
                                if (mc.WorldPosition.ContainsKey(_camera))
                                {
                                    DispatcherHelper.UIDispatcher.Invoke((Action)(() => _controllerObjects[mc1].Center = new Point3D(
                                                                                      mc1.WorldPosition[_camera].x,
                                                                                      mc1.WorldPosition[_camera].z,
                                                                                      mc1.WorldPosition[_camera].y)));
                                }
                            }
                            // remove objects corresponding to unselected controllers
                            else
                            {
                                if (_controllerObjects.ContainsKey(mc))
                                {
                                    DispatcherHelper.UIDispatcher.Invoke((Action)(() => _items.Remove(_controllerObjects[mc1])));
                                    _controllerObjects.Remove(mc);
                                }
                            }
                        } // foreach
                        sw.Stop();
                        // taking the processing time of the task itself into account, pause the thread to approximately reach the given FPS
                        Thread.Sleep((int)(Math.Max((1000.0 / _camera.FPS) - sw.ElapsedMilliseconds, 0) + 0.5));
                    } // while
                }, _ctsUpdate.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
                await _updateTask;
            }
            catch (OperationCanceledException ex)
            {
                Console.WriteLine(ex.StackTrace);
                Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Stop();
            }
        }
        private async void Connect_Click(object sender, RoutedEventArgs e)
        {
            Connect.IsEnabled = false;

            if (_client != null)
            {
                try
                {
                    await _client.StopScanningAsync();
                }
                catch (Exception)
                {
                    // no-op: ignore failures, just stop if possible
                }

                await _client.DisconnectAsync();

                _client = null;

                var devs = Devices.Keys;
                foreach (var dev in devs)
                {
                    Devices.Remove(dev);
                }

                ButtplugConnType.IsEnabled = true;
                ButtplugConnType_SelectionChanged(this, null);
                Connect.Content   = "Connect";
                Connect.IsEnabled = true;
                Scan_Click(this, null);
                return;
            }

            try
            {
                switch (((ComboBoxItem)ButtplugConnType.SelectedValue).Content)
                {
                case "WebSocket":
                {
                    ButtplugTarget.IsEnabled   = false;
                    ButtplugConnType.IsEnabled = false;

                    ButtplugWebsocketConnectorOptions conn;
                    try
                    {
                        conn = new ButtplugWebsocketConnectorOptions(new Uri(ButtplugTarget.Text));
                    }
                    catch (UriFormatException e1)
                    {
                        MessageBox.Show($"Uri Error: {e1.Message}", "B******g Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        Connect.IsEnabled        = true;
                        ButtplugTarget.IsEnabled = true;
                        ButtplugConnType_SelectionChanged(this, null);
                        return;
                    }

                    _client                   = new ButtplugClient("NogasmChart");
                    _client.DeviceAdded      += ClientOnDeviceAdded;
                    _client.DeviceRemoved    += ClientOnDeviceRemoved;
                    _client.ServerDisconnect += ClientOnServerDisconnect;
                    _client.ErrorReceived    += ClientOnErrorReceived;
                    _client.ScanningFinished += ClientOnScanFinished;
                    await _client.ConnectAsync(conn);

                    break;
                }

                case "Embedded":
                {
                    ButtplugTarget.IsEnabled   = false;
                    ButtplugConnType.IsEnabled = false;

                    ButtplugEmbeddedConnectorOptions conn = new ButtplugEmbeddedConnectorOptions();
                    conn.ServerName = "NogasmChart";

                    _client                   = new ButtplugClient("NogasmChart");
                    _client.DeviceAdded      += ClientOnDeviceAdded;
                    _client.DeviceRemoved    += ClientOnDeviceRemoved;
                    _client.ServerDisconnect += ClientOnServerDisconnect;
                    _client.ErrorReceived    += ClientOnErrorReceived;
                    _client.ScanningFinished += ClientOnScanFinished;
                    await _client.ConnectAsync(conn);

                    break;
                }

                default:
                    MessageBox.Show("Invalid Connection type!", "B******g Error", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    Connect.IsEnabled = true;
                    return;
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show($"Something went wrong: {e1.Message}", "B******g Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                try
                {
                    if (_client != null)
                    {
                        await _client.DisconnectAsync();
                    }
                }
                catch (Exception)
                {
                    // no-op: cleanup only
                }

                _client = null;

                ButtplugConnType.IsEnabled = true;
                ButtplugConnType_SelectionChanged(this, null);
                Connect.Content   = "Connect";
                Connect.IsEnabled = true;
                Scan_Click(this, null);
                return;
            }

            Connect.Content   = "Disconnect";
            Connect.IsEnabled = true;

            try
            {
                Scan.IsEnabled = false;
                await _client.StartScanningAsync();

                Scan.Content   = "Stop Scanning";
                Scan.IsEnabled = true;
            }
            catch (Exception e1)
            {
                MessageBox.Show($"Something went wrong: {e1.Message}", "B******g Error", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 11
0
    private void OnSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        void Add(TKey key, TValue value)
        {
            _view[key] = _selector(value);
            if (value is INotifyPropertyChanged o)
            {
                o.PropertyChanged -= OnSourceItemPropertyChanged;
                o.PropertyChanged += OnSourceItemPropertyChanged;
            }
        }

        void AddRange(IEnumerable enumerable)
        {
            foreach (var(key, value) in enumerable.OfType <KeyValuePair <TKey, TValue> >())
            {
                Add(key, value);
            }
        }

        void Remove(TKey key, TValue value)
        {
            if (_view.ContainsKey(key))
            {
                _view.Remove(key);
            }

            if (value is INotifyPropertyChanged o)
            {
                o.PropertyChanged -= OnSourceItemPropertyChanged;
            }
        }

        void RemoveRange(IEnumerable enumerable)
        {
            foreach (var(key, value) in enumerable.OfType <KeyValuePair <TKey, TValue> >())
            {
                Remove(key, value);
            }
        }

        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            AddRange(e.NewItems);
        }
        else if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            RemoveRange(e.OldItems);
        }
        else if (e.Action == NotifyCollectionChangedAction.Replace)
        {
            RemoveRange(e.OldItems);
            AddRange(e.NewItems);
        }
        else if (e.Action == NotifyCollectionChangedAction.Reset)
        {
            foreach (var(key, value) in _dictionary)
            {
                Remove(key, _dictionary[key]);
            }

            _view.Clear();
        }
        else if (e.Action == NotifyCollectionChangedAction.Move)
        {
        }
    }