/// <summary>
        /// Function returns all Accounts stored in database
        /// </summary>
        /// <returns>List of IAccount object created based on specified type</returns>
        public List <IAccount> GetAccounts()
        {
            try
            {
                ////using var context = new DbEconomyContext();

                var accounts = new List <IAccount>();

                foreach (var a in context.Accounts.Where(a => !a.Deleted))
                {
                    var keys = context.Keys
                               .Where(k => !k.Deleted)
                               .Where(k => k.RelatedItemId == a.Id)
                               .ToList();

                    var bookmarks = context.Bookmarks
                                    .Where(b => !b.Deleted)
                                    .Where(b => b.RelatedItemId == a.Id)
                                    .ToList();

                    var acc = AccountFactory.GetAccount(new Guid(a.Id), (AccountTypes)a.Type, Guid.Empty, new Guid(a.WalletId), string.Empty, string.Empty, 0);

                    // load keys and key if exist
                    if (keys != null)
                    {
                        // this will load main account key for signing transactions
                        var key = keys.FirstOrDefault(k => k.Id == a.AccountKeyId);
                        if (key != null)
                        {
                            acc.AccountKey = key.Fill(new EncryptionKey(""));
                        }

                        // fill other account keys - messages, etc.
                        foreach (var k in keys)
                        {
                            acc.AccountKeys.Add(k.Fill(new EncryptionKey("")));
                        }
                    }

                    // load bookmarks
                    if (bookmarks != null)
                    {
                        // fill account bookmarks
                        foreach (var b in bookmarks)
                        {
                            acc.Bookmarks.Add(b.Fill(BookmarkFactory.GetBookmark((BookmarkTypes)b.Type, new Guid(b.Id), b.Name, b.Address)));
                        }
                    }

                    accounts.Add(a.Fill(acc));
                }

                return(accounts);
            }
            catch (Exception ex)
            {
                log.Error("Cannot get accounts list from Db", ex);
                return(null);
            }
        }
Example #2
0
 void DesignerItem_Loaded(object sender, RoutedEventArgs e)
 {
     if (base.Template != null)
     {
         ContentPresenter contentPresenter =
             this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter;
         if (contentPresenter != null)
         {
             UIElement contentVisual = VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
             if (contentVisual != null)
             {
                 DragThumb thumb = this.Template.FindName("PART_DragThumb", this) as DragThumb;
                 if (thumb != null)
                 {
                     ControlTemplate template =
                         DesignerItem.GetDragThumbTemplate(contentVisual) as ControlTemplate;
                     if (template != null)
                     {
                         thumb.Template = template;
                     }
                     if (this.BookmarkBase == null || this.BookmarkBase.NodeType == string.Empty)
                     {
                         this.BookmarkBase = BookmarkFactory.GetBookmark(EnumHelper.GetEnumByString <ActivityTypeEnum>((contentPresenter.Content is Grid) ? (contentPresenter.Content as Grid).Tag.ToString()
                         : (contentPresenter.Content as System.Windows.Shapes.Shape).Tag.ToString()));
                     }
                 }
             }
         }
     }
 }
Example #3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            if (this.dragStartPoint.HasValue)
            {
                ActivityTypeEnum typeEnum = Nsun.Workflow.Core.EnumExt.EnumHelper.GetEnumByString <ActivityTypeEnum>
                                                ((this.Content as ToolBoxItemExt).BookmarkType);

                BookmarkBase bookmark   = BookmarkFactory.GetBookmark(typeEnum);
                string       xamlString = XElement.Parse(bookmark.GetSerialContent()).Value;

                DragObject dataObject = new DragObject();
                dataObject.Xaml = xamlString;

                WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;
                if (panel != null)
                {
                    dataObject.DesiredSize = new Size(bookmark.Size.Key, bookmark.Size.Value);
                }

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);

                e.Handled = true;
            }
        }
Example #4
0
        public void SetUp()
        {
            _connection = new SqliteConnection("Data Source=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <StartPageContext>()
                          .UseSqlite(_connection)
                          .Options;

            _context = new StartPageContext(options);
            _factory = new BookmarkFactory(_context);
        }
        public override string UpdateBookmark(string wallet, string address, BookmarkTypes type, string bookmarkId, string name, string bookmarkAddress, IDbConnectorService dbservice)
        {
            try
            {
                if (EconomyMainContext.Wallets.TryGetValue(wallet, out var w))
                {
                    if (w.Accounts.TryGetValue(address, out var account))
                    {
                        IBookmark bkm = null;
                        bkm = account.Bookmarks.FirstOrDefault(b => b.Id.ToString() == bookmarkId);
                        if (bkm != null)
                        {
                            if (!string.IsNullOrEmpty(name))
                            {
                                bkm.Name = name;
                            }

                            if (!string.IsNullOrEmpty(bookmarkAddress))
                            {
                                bkm.Address = bookmarkAddress;
                            }

                            if (type != bkm.Type)
                            {
                                bkm.Type = type;
                            }
                        }
                        else
                        {
                            bkm = BookmarkFactory.GetBookmark(type, account.Id, name, bookmarkAddress);

                            bkm.Id = Guid.NewGuid();
                            account.Bookmarks.Add(bkm);
                        }

                        if (EconomyMainContext.WorkWithDb)
                        {
                            dbservice.SaveBookmark(bkm);
                        }

                        return("OK");
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Cannot add bookmark!", ex);
            }

            return("Add bookmark - ERROR");
        }
        /// <summary>
        /// Function returns Bookmark stored in database based on id
        /// </summary>
        /// <returns>IBookmark object created based on specified type</returns>
        public IBookmark GetBookmark(Guid id)
        {
            try
            {
                var bookmark = context.Bookmarks
                               .Where(b => !b.Deleted)
                               .Where(b => b.Id == id.ToString())
                               .FirstOrDefault();

                return(bookmark.Fill(BookmarkFactory.GetBookmark((BookmarkTypes)bookmark.Type, new Guid(bookmark.RelatedItemId), bookmark.Name, bookmark.Address)));
            }
            catch (Exception ex)
            {
                log.Error("Cannot get Bookmark from Db", ex);
                return(null);
            }
        }
Example #7
0
        /// <summary>
        /// 结束节点
        /// </summary>
        /// <param name="dto"></param>
        public void EndRouing(TransInfoDto dto)
        {
            IBookmark bookmarkInfo = BookmarkFactory.GetBookmark(dto.ActivityType);

            // 结束并发
            if (dto.SubmitType == SubmitTypeEnum._SP)
            {
                XElement parallelStart = null;
                // 获取对应的并发等待节点
                var doc = XElement.Parse(dto.TemplateXml);
                XmlHelper.GetFirstParalle(doc, dto.InstanceNodeId, ref parallelStart);

                if (parallelStart == null)
                {
                    throw new Exception("没有找到并发起始节点");
                }

                if (XmlHelper.HasValue(parallelStart, "GroupName"))
                {
                    HashSet <Guid>           parallelNodes = new HashSet <Guid>();
                    Dictionary <string, int> parallelCount = new Dictionary <string, int>();
                    var copyInfo = dto.GetCopyInfo();
                    copyInfo.InstanceNodeId = Guid.Parse(XmlHelper.GetSafeValue(parallelStart, ActivityConst.ID));
                    parallelCount.Add(copyInfo.TaskId + XmlHelper.GetSafeValue(parallelStart, "GroupName"), 1);
                    XmlHelper.TraversingGraphParallel(doc, parallelStart.ParseById(), null);
                    StopAll(parallelStart.Element("GroupName").Value, copyInfo, parallelNodes, ref parallelCount);
                    dto.Persistence.FinishActivityByNodeIds(copyInfo.InstanceId, parallelNodes.ToList(), RunStateConst.STOP);
                }

                return;
            }

            bookmarkInfo.Ending += (s, r) =>
            {
                var args = r as WFArgs;
                if (args.Parameter.NextActivities != null)
                {
                    RoutingFactory(args.Parameter.NextActivities, dto);
                }
            };
            bookmarkInfo.End(dto);
        }
        /// <summary>
        /// Function returns all Bookmarks stored in database
        /// </summary>
        /// <returns>List of IBookmark object created based on specified type</returns>
        public List <IBookmark> GetBookmarks()
        {
            try
            {
                var bookmarks = new List <IBookmark>();

                foreach (var bkm in context.Bookmarks.Where(b => !b.Deleted))
                {
                    if (bkm != null)
                    {
                        var bookmark = bkm.Fill(BookmarkFactory.GetBookmark((BookmarkTypes)bkm.Type, new Guid(bkm.RelatedItemId), bkm.Name, bkm.Address));
                        bookmarks.Add(bookmark);
                    }
                }

                return(bookmarks);
            }
            catch (Exception ex)
            {
                log.Error("Cannot get bookmarks list from Db", ex);
                return(null);
            }
        }
Example #9
0
        /// <summary>
        /// 路由工厂
        /// </summary>
        /// <param name="dto"></param>
        public void RoutingFactory(TransInfoDto dto)
        {
            IBookmark bookmarkInfo = BookmarkFactory.GetBookmark(dto.ActivityType);

            bookmarkInfo.Start(dto);
        }