Exemple #1
0
        protected override Task Init()
        {
            _collection = new ObjectRepositoryServerObservableCollection <MoneyColumnMetadataModel, MoneyColumnMetadataStream>(
                ObjectRepository,
                SendUpdate,
                (x, i) => new MoneyColumnMetadataStream {
                Added = ToStream(x)
            },
                (x, i) => new MoneyColumnMetadataStream {
                Removed = ToStream(x)
            },
                (x, i) => new MoneyColumnMetadataStream {
                Updated = ToStream(x)
            },
                list =>
            {
                var model = new MoneyColumnMetadataStream {
                    Snapshot = new MoneyColumnMetadataList()
                };
                model.Snapshot.MoneyColumnMetadatas.AddRange(list.Select(ToStream).ToList());
                return(model);
            });

            Anchors.Add(() => _collection.Dispose());

            return(Task.CompletedTask);
        }
Exemple #2
0
        public UpdateService()
        {
            _gitHubClient = new GitHubClient(new ProductHeaderValue("DiverOfDark_BudgetTracker", Startup.CommmitHash));
            _timer        = new Timer(TimerCallback, null, TimeSpan.FromSeconds(1), TimeSpan.FromHours(1));

            Anchors.Add(_timer.Dispose);
        }
        protected override Task Init()
        {
            _collection = new ObjectRepositoryServerObservableCollection <SpentCategoryModel, SpentCategoriesStream>(
                ObjectRepository,
                SendUpdate,
                (x, i) => new SpentCategoriesStream {
                Added = ToSpentCategory(x)
            },
                (x, i) => new SpentCategoriesStream {
                Removed = ToSpentCategory(x)
            },
                (x, i) => new SpentCategoriesStream {
                Updated = ToSpentCategory(x)
            },
                list =>
            {
                var model = new SpentCategoriesStream {
                    Snapshot = new SpentCategoryList()
                };
                model.Snapshot.SpentCategories.AddRange(list.Select(ToSpentCategory).ToList());
                return(model);
            });

            Anchors.Add(() => _collection.Dispose());

            return(Task.CompletedTask);
        }
Exemple #4
0
 protected override Task Init()
 {
     _collection = new ObjectRepositoryServerObservableCollection <DebtModel, DebtsStream>(
         ObjectRepository,
         SendUpdate,
         (x, i) => new DebtsStream {
         Added = ToDebtView(x)
     },
         (x, i) => new DebtsStream {
         Removed = ToDebtView(x)
     },
         (x, i) => new DebtsStream {
         Updated = ToDebtView(x)
     },
         list =>
     {
         var model = new DebtsStream {
             Snapshot = new DebtsList()
         };
         model.Snapshot.Debts.AddRange(list.Select(ToDebtView).ToList());
         return(model);
     });
     Anchors.Add(_collection.Dispose);
     return(Task.CompletedTask);
 }
Exemple #5
0
        public async Task Send(IServerStreamWriter <T> writer, ServerCallContext context)
        {
            await Init();

            ObjectRepository.ModelChanged += OnModelRepositoryChanged;
            Anchors.Add(() => ObjectRepository.ModelChanged -= OnModelRepositoryChanged);
            try
            {
                while (!context.CancellationToken.IsCancellationRequested && !IsDisposed)
                {
                    if (_sendModelEvent.IsSet)
                    {
                        _sendModelEvent.Reset();
                        while (_queue.TryDequeue(out var item))
                        {
                            await writer.WriteAsync(item);
                        }
                    }

                    await _sendModelEvent.WaitAsync(context.CancellationToken);
                }
            } catch (Exception ex) when(ex is RpcException exception && exception.StatusCode == StatusCode.Cancelled || ex is TaskCanceledException)
            {
                // cancelled, not an issue
            }
        }
        private void AnalyseBoardTileAtCoordinatesAndAddIfItIsAnAnchor(int X, int Y)
        {
            BoardTile tile = Board.GetBoardTileAtCoordinates(X, Y);

            if (tile == null || tile.CharTile != null || AddedAnchors.Contains(tile))
            {
                return;
            }
            Anchors.Add(tile);
            AddedAnchors.Add(tile);
        }
        protected override Task Init()
        {
            var timer = new Timer(1000);

            timer.Elapsed += SendScrenshot;
            timer.Start();
            SendScrenshot(null, null);
            Anchors.Add(timer.Dispose);
            Anchors.Add(() => timer.Elapsed -= SendScrenshot);
            return(Task.CompletedTask);
        }
Exemple #8
0
        public GrpcViewModelBase(ObjectRepository objectRepository, ILogger logger)
        {
            ObjectRepository = objectRepository;
            logger.LogInformation($"Creating {GetType().Name}.");

            Anchors.Add(() =>
            {
                logger.LogInformation($"Disposing {GetType().Name}.");
                _sendModelEvent.Set();
            });
        }
Exemple #9
0
        protected void InitializeDefaultAnchor(RectangleF rect, IPrimitiveProvider provider)
        {
            var a = new AnchorHandle(rect.GetCornerPoint(CornerType.Top), this, TOP_ANCHOR, provider);

            Anchors.Add(a);
            a = new AnchorHandle(rect.GetCornerPoint(CornerType.LeftMiddle), this, LEFT_ANCHOR, provider);
            Anchors.Add(a);
            a = new AnchorHandle(rect.GetCornerPoint(CornerType.RightMiddle), this, RIGHT_ANCHOR, provider);
            Anchors.Add(a);
            a = new AnchorHandle(rect.GetCornerPoint(CornerType.Bottom), this, BOTTOM_ANCHOR, provider);
            Anchors.Add(a);
        }
        public UnitTest1()
        {
            CommandAssemblysLoader.EntryAssembly = Assembly.GetAssembly(typeof(UnitTestMef));
            Anchors.Add(ProgramsCommand.Anchor.FullName);
            var root       = Assembly.GetAssembly(typeof(UnitTestMef)).Location;
            var dir        = Path.GetDirectoryName(root);
            var components = dir;
            var dd         = Programs.ProgramsRepository;

            //  var components = Path.Combine(dir, "components");
            CommandCompositionHelper = new CommandCompositionHelper(components);
            CommandCompositionHelper.AssembleCommandComponents();
            CommandCompositionHelper.Initialize();
        }
    // A realtime database transaction receives MutableData which can be modified
    // and returns a TransactionResult which is either TransactionResult.Success(data) with
    // modified data or TransactionResult.Abort() which stops the transaction with no changes.
    TransactionResult AddAnchorTransaction(MutableData mutableData)
    {
        List <object> Anchors = mutableData.Value as List <object>;

        if (Anchors == null)
        {
            Anchors = new List <object>();
        }
        //else if (mutableData.ChildrenCount >= MaxScores)
        //{
        //    // If the current list of scores is greater or equal to our maximum allowed number,
        //    // we see if the new score should be added and remove the lowest existing score.
        //    long minScore = long.MaxValue;
        //    object minVal = null;
        //    foreach (var child in users)
        //    {
        //        if (!(child is Dictionary<string, object>))
        //            continue;
        //        long childScore = (long)((Dictionary<string, object>)child)["hitCounter"];
        //        if (childScore < minScore)
        //        {
        //            minScore = childScore;
        //            minVal = child;
        //        }
        //    }
        //    // If the new score is lower than the current minimum, we abort.
        //    if (minScore > hitCounter)
        //    {
        //        return TransactionResult.Abort();
        //    }
        //    // Otherwise, we remove the current lowest to be replaced with the new score.
        //    users.Remove(minVal);
        //}

        // Now we add the new score as a new entry that contains the email address and score.

        //newNameMap["hitCounter"] =hitCounter;

        //newNameMap["scale"] = treeScale;
        newNameMap["Room"]       = roomNumber;
        newNameMap["IP"]         = IPAddress;
        newNameMap["playerName"] = playerName;

        Anchors.Add(newNameMap);

        // You must set the Value to indicate data at that location has changed.
        mutableData.Value = Anchors;
        return(TransactionResult.Success(mutableData));
    }
        protected override Task Init()
        {
            _updateService.PropertyChanged += UpdateServiceChanged;
            _timer = new Timer(100)
            {
                AutoReset = false
            };
            _timer.Elapsed += SendStatsUpdate;

            Anchors.Add(() =>
            {
                _updateService.PropertyChanged -= UpdateServiceChanged;
                _timer.Elapsed -= SendStatsUpdate;
            });
            Anchors.Add(_timer.Dispose);
            SendUpdate(_model);

            return(Task.CompletedTask);
        }
Exemple #13
0
 public Road(GameObject mySelf, int direction, bool reverse)
 {
     MySelf = mySelf;
     if (mySelf.transform.Find("AnchorN") != null)
     {
         Anchors.Add(new AnchorParameter(mySelf.transform.Find("AnchorN").gameObject, direction, 'N', reverse));
     }
     if (mySelf.transform.Find("AnchorE") != null)
     {
         Anchors.Add(new AnchorParameter(mySelf.transform.Find("AnchorE").gameObject, direction, 'E', reverse));
     }
     if (mySelf.transform.Find("AnchorS") != null)
     {
         Anchors.Add(new AnchorParameter(mySelf.transform.Find("AnchorS").gameObject, direction, 'S', reverse));
     }
     if (mySelf.transform.Find("AnchorW") != null)
     {
         Anchors.Add(new AnchorParameter(mySelf.transform.Find("AnchorW").gameObject, direction, 'W', reverse));
     }
 }
Exemple #14
0
        public void Initialize()
        {
            if (CommandCompositionHelper == null)
            {
                Anchors.Add(ProgramsCommand.Anchor.FullName);
                Anchors.Add(CommandFileLoader.Anchor.FullName);
                Anchors.Add(CommandPOCCallbacks.Anchor.FullName);
                Anchors.Add(SimpleCommands.Anchor.FullName);
                Anchors.Add(CommandGraphQL.Anchor.FullName);

                P7.GraphQLCore.Global.EntryAssembly  = Assembly.GetAssembly(typeof(Local));
                CommandAssemblysLoader.EntryAssembly = P7.GraphQLCore.Global.EntryAssembly;

                var builder = new ContainerBuilder();

                // Register individual components
                var assemblies = TypeHelper <Local> .GetReferencingAssemblies(P7.GraphQLCore.Global.EntryAssembly);

                builder.RegisterAssemblyModules(assemblies.ToArray());

                TheContainer = builder.Build();
                CommandGraphQL.GraphQLCommands.TheContainer = TheContainer;



                //            var dd = ProgramsCommand.Anchor.Name;
                var root       = Assembly.GetAssembly(typeof(Local)).Location;
                var dir        = Path.GetDirectoryName(root);
                var components = dir;
                //      var dd = ProgramsCommand.Programs.ProgramsRepository;
                //  var components = Path.Combine(dir, "components");
                CommandCompositionHelper = new CommandCompositionHelper(components);
                CommandCompositionHelper.AssembleCommandComponents();
                CommandCompositionHelper.Initialize();


                //       JsonFile.RootFolder = ""; // just making sure that the dll gets copied
            }
        }
Exemple #15
0
 public void AddAnchor(GSplineAnchor a)
 {
     Anchors.Add(a);
 }
 public Task RecordAnchor(LedgerAnchor anchor)
 {
     Anchors.Add(anchor);
     return(Task.FromResult(0));
 }
Exemple #17
0
        /// <summary>
        /// Add one component to the board
        /// </summary>
        /// <param name="position">The component position</param>
        /// <param name="boardGrid">The canvas on which to display the component</param>
        /// <param name="xmlElement">The XML Element with the component data</param>
        public Component(Point position, BoardGrid boardGrid, XElement xmlElement)
        {
            // Save parameters
            BoardGrid = boardGrid as BoardGrid;
            _Name     = xmlElement.Element("name").Value;

            // Display the image
            ImageSource    = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, Properties.Settings.Default.ResourcesFolder, xmlElement.Element("image").Value));
            ComponentImage = new Image
            {
                Source = new BitmapImage(ImageSource) // Image to display
            };

            GraphicalComponent = new Border
            {
                Width           = 2 * BoardGrid.GridSpacing + 2 * BoardGrid.GridThickness, // The component covers 2 grid cells
                Height          = 2 * BoardGrid.GridSpacing + 2 * BoardGrid.GridThickness,
                Child           = ComponentImage,
                BorderBrush     = new SolidColorBrush(Colors.Black),
                BorderThickness = new Thickness(0),
                ToolTip         = Name
            };
            ImageSize = new Vector(GraphicalComponent.Width, GraphicalComponent.Height);
            Scale     = GraphicalComponent.Width / (double)xmlElement.Element("width");

            Position = position;
            // Add the component to the BoardGrid
            BoardGrid.ComponentsOnBoard.Add(this);
            BoardGrid.Children.Add(GraphicalComponent);

            // Rotation
            Rotation = new RotateTransform(0);
            GraphicalComponent.RenderTransform = Rotation;

            // Anchors
            IEnumerable <XElement> xmlAnchors = xmlElement.Element("anchors").Elements("anchor"); // Get all the anchors present in the XML

            foreach (XElement xmlAnchor in xmlAnchors)
            {
                // Parse each anchor's position
                Vector anchor = new Vector
                {
                    X = (double)xmlAnchor.Element("posX") * Scale + GraphicalComponent.BorderThickness.Left,
                    Y = (double)xmlAnchor.Element("posY") * Scale + GraphicalComponent.BorderThickness.Top
                };
                anchor.X = Math.Round(anchor.X, 0); // Round the anchor composants
                anchor.Y = Math.Round(anchor.Y, 0);
                Anchors.Add(anchor);
            }

            // Attributes
            Attributes      = new Dictionary <string, double?>();
            AttributesUnits = new Dictionary <string, Dictionary <string, double> >();
            if (xmlElement.Element("attributes") != null)                                                      // Check if there are attributes
            {
                IEnumerable <XElement> xmlAttributes = xmlElement.Element("attributes").Elements("attribute"); // Get all the attributes present in the XML
                foreach (XElement xmlAttribute in xmlAttributes)                                               // Parse each attribute's name and available units
                {
                    Attributes.Add((string)xmlAttribute.Element("name"), null);                                // The value is undefined for now
                    AttributesUnits.Add((string)xmlAttribute.Element("name"), new Dictionary <string, double>());

                    foreach (XElement xmlUnit in xmlAttribute.Element("units").Elements("unit"))
                    {
                        AttributesUnits[(string)xmlAttribute.Element("name")].Add((string)xmlUnit.Element("symbol"), (double)xmlUnit.Element("value"));
                    }
                }
            }

            // Event handlers
            GraphicalComponent.MouseLeftButtonDown += Component_MouseLeftButtonDown; // Event handler to trigger selection or properties editing
            GraphicalComponent.MouseLeftButtonUp   += Component_MouseLeftButtonUp;   // Event handler to trigger selection or properties editing
            GraphicalComponent.MouseMove           += Component_MouseMove;           // Event handler to trigger drag&drop
        }