예제 #1
0
        private NSMenuItem CreateMenuItem(object sender, RepositoryAction action, ContextMenuArguments arguments)
        {
            var item = new NSMenuItem(action.Name, (s, e) => action.Action?.Invoke(s, e));

            item.Enabled = action.CanExecute;

            // this is a deferred submenu. We want to make sure that the context menu can pop up
            // fast, while submenus are not evaluated yet. We don't want to make the context menu
            // itself slow because the creation of the submenu items takes some time.
            if (action.DeferredSubActionsEnumerator != null)
            {
                var submenu = new NSMenu {
                    AutoEnablesItems = false
                };

                arguments.Initializers.Add(item, () =>
                {
                    foreach (var subAction in action.DeferredSubActionsEnumerator())
                    {
                        submenu.AddItem(CreateMenuItem(sender, subAction, arguments));
                    }

                    Console.WriteLine($"Added {submenu.Items.Length} deferred sub action(s).");
                });

                item.Submenu = submenu;
            }

            return(item);
        }
예제 #2
0
 public void Remove(Identity <WorkingTimeRange> identity)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         new WorkingTimeDao(c, t).Delete(identity.Value);
     });
 }
예제 #3
0
 public void RemoveByTaskId(Identity <WorkTask> taskId)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         new WorkingTimeDao(c, t).DeleteByTaskId(taskId.Value);
     });
 }
        public WorkingTimeForTimelineDto[] SelectByYmd(string ymd)
        {
            #region SQL
            const string sql = @"
SELECT
  time.id as WorkingTimeId
  , time.taskid as WorkTaskId
  , time.starttime as starttime
  , time.endtime as endtime
  , task.title as title
  , task.taskcategory as taskcategory
  , processes.title as workprocessname
FROM
  workingtimes time
INNER JOIN
  worktasks task ON task.id = time.taskid
INNER JOIN
  processes ON processes.id = task.processid
WHERE
  time.ymd = @ymd
";
            #endregion

            var list = new List <WorkingTimeForTimelineDto>();

            RepositoryAction.Query(c =>
            {
                var listRow = c.Query <WorkingTimeForTimelineTableRow>(sql, new { ymd });

                list.AddRange(listRow.Select(r => r.ConvertToDto()));
            });

            return(list.OrderBy(i => i.TimePeriod.StartDateTime).ToArray());
        }
예제 #5
0
 public static RepositoryEventArgs New(RepositoryAction action)
 {
     return(new RepositoryEventArgs
     {
         Action = action,
     });
 }
        /// <summary>
        /// Save data into database.
        /// </summary>
        /// <param name="entities">Entities to save.</param>c
        /// <param name="saveNestedProperties">Indicated repopsitory needs update nested properties</param>
        /// <returns>Entity saved.</returns>
        public virtual IEnumerable <TEntity> Save(IEnumerable <TEntity> entities, bool saveNestedProperties)
        {
            using (var context = CreateContext())
            {
                foreach (var entity in entities)
                {
                    // Identity primary key value.
                    int primaryKeyValue = IdentityPrimaryKeyValue(entity, context);

                    // Identify current action
                    this._currentAction = primaryKeyValue == 0 ? RepositoryAction.Inserting : RepositoryAction.Updating;

                    // Save entity to database.
                    SaveEntity(entity, context, primaryKeyValue);

                    // Update nested properties
                    UpdateNestedProperties(entity, context, saveNestedProperties);
                }

                // Commit changes to database
                context.SaveChanges();
            }

            return(entities);
        }
예제 #7
0
        /// <summary>
        /// Gets the modifications.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            // fetch latest changes from the remote repository
            RepositoryAction result = CreateUpateLocalRepository(to);

            Dictionary <string, string> revisionData = NameValuePair.ToDictionary(from.SourceControlData);
            ProcessResult logResult;
            string        lastCommit;

            if (revisionData.TryGetValue(COMMIT_KEY, out lastCommit))
            {
                logResult = GitLogHistory(GetBranchNameOrRevision(Branch, Revision), lastCommit, to);
            }
            else
            {
                Log.Debug(string.Concat("[Git] last integrated commit not found, using all ancestors of ",
                                        GetBranchNameOrRevision(Branch, Revision), " as the set of modifications."));
                logResult = GitLogHistory(GetBranchNameOrRevision(Branch, Revision), to);
            }

            // Get the hash of the origin head, and store it against the integration result.
            string originHeadHash = GitLogOriginHash(GetBranchNameOrRevision(Branch, Revision), to);

            revisionData[COMMIT_KEY] = originHeadHash;
            to.SourceControlData.Clear();
            NameValuePair.Copy(revisionData, to.SourceControlData);

            return(ParseModifications(logResult, lastCommit));
        }
예제 #8
0
 public virtual void SendNotify(object sender, RepositoryAction create, bool isSucceed)
 {
     if (this._mediator != null)
     {
         this._mediator.Notify(sender, RepositoryAction.Create, isSucceed);
     }
 }
 public void Delete(Identity <WorkTask> identity)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         new WorkTaskDao(c, t).Delete(identity.Value);
     });
 }
예제 #10
0
 /// <summary>
 /// 执行仓储操作之后
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="action"></param>
 protected void OnPersisted(IAggregateRoot obj, RepositoryAction action)
 {
     if (this.Persisted != null)
     {
         RepositoryPersistedEventArgs args = new RepositoryPersistedEventArgs(obj, action);
         this.Persisted(this, args);
     }
 }
예제 #11
0
 public void UpdateConfiguration(ConfigurationItem item)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         var dao = new ConfigDao(c, t);
         dao.DeleteInsert(ConfigTableRow.FromDomainObject(item));
     });
 }
예제 #12
0
 public static RepositoryEventArgs New(RepositoryAction action, IDataFileInfo info)
 {
     return(new RepositoryEventArgs
     {
         Action = action,
         Info = info,
     });
 }
예제 #13
0
 public void Edit(WorkingTimeRange workingTimeRange)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         var row = WorkingTimeTableRow.FromDomainObject(workingTimeRange);
         var dao = new WorkingTimeDao(c, t);
         dao.Update(row);
     });
 }
예제 #14
0
        private MenuItem CreateMenuItem(object sender, RepositoryAction action, IEnumerable <RepositoryView> affectedViews = null)
        {
            Action <object, object> clickAction = (object clickSender, object clickArgs) =>
            {
                if (action?.Action != null)
                {
                    var coords = new float[] { 0, 0 };

                    // run actions in the UI async to not block it
                    if (action.ExecutionCausesSynchronizing)
                    {
                        Task.Run(() => SetViewsSynchronizing(affectedViews, true))
                        .ContinueWith(t => action.Action(null, coords))
                        .ContinueWith(t => SetViewsSynchronizing(affectedViews, false));
                    }
                    else
                    {
                        Task.Run(() => action.Action(null, coords));
                    }
                }
            };

            var item = new AcrylicMenuItem()
            {
                Header    = action.Name,
                IsEnabled = action.CanExecute
            };

            item.Click += new RoutedEventHandler(clickAction);

            // this is a deferred submenu. We want to make sure that the context menu can pop up
            // fast, while submenus are not evaluated yet. We don't want to make the context menu
            // itself slow because the creation of the submenu items takes some time.
            if (action.DeferredSubActionsEnumerator != null)
            {
                // this is a template submenu item to enable submenus under the current
                // menu item. this item gets removed when the real subitems are created
                item.Items.Add("");

                void SelfDetachingEventHandler(object _, RoutedEventArgs __)
                {
                    item.SubmenuOpened -= SelfDetachingEventHandler;
                    item.Items.Clear();

                    foreach (var subAction in action.DeferredSubActionsEnumerator())
                    {
                        item.Items.Add(CreateMenuItem(sender, subAction));
                    }

                    Console.WriteLine($"Added {item.Items.Count} deferred sub action(s).");
                }

                item.SubmenuOpened += SelfDetachingEventHandler;
            }

            return(item);
        }
 public void Edit(WorkTask task)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         var row = WorkTaskTableRow.FromDomainObject(task);
         var dao = new WorkTaskDao(c, t);
         dao.Update(row);
     });
 }
예제 #16
0
 /// <summary>
 /// 执行仓储操作之前
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 protected bool OnPrePersist(IAggregateRoot obj, RepositoryAction action)
 {
     if (this.PrePersist != null)
     {
         RepositoryPrePersistEventArgs args = new RepositoryPrePersistEventArgs(obj, action);
         this.PrePersist(this, args);
         return(args.Allow);
     }
     return(true);
 }
        public WorkProcess[] SelectAll()
        {
            var list = new List <WorkProcess>();

            RepositoryAction.Query(c =>
            {
                var rows = new WorkProcessDao(c, null).SelectAll();
                list.AddRange(rows.Select(r => r.ToDomainObject()));
            });

            return(list.ToArray());
        }
        public Product[] SelectAll()
        {
            var list = new List <Product>();

            RepositoryAction.Query(c =>
            {
                var rows = new ProductDao(c, null).SelectAll();
                list.AddRange(rows.Select(r => r.ToDomainObject()));
            });

            return(list.ToArray());
        }
        public void Delete(TEntity entity)
        {
            this._currentAction = RepositoryAction.Deleting;

            using (var context = CreateContext())
            {
                context.Set <TEntity>().Attach(entity);
                context.Set <TEntity>().Remove(entity);

                context.SaveChanges();
            }
        }
예제 #20
0
        public WorkTaskWithTimesDto[] SelectByYmd(YmdString ymd, bool containsCompleted)
        {
            var list = new List <WorkTaskWithTimesDto>();

            RepositoryAction.Query(c =>
            {
                var workTaskDao    = new WorkTaskDao(c, null);
                var workingTimeDao = new WorkingTimeDao(c, null);
                var processes      = new WorkProcessDao(c, null).SelectAll();
                var products       = new ProductDao(c, null).SelectAll();
                var clients        = new ClientDao(c, null).SelectAll();
                var completedDao   = new WorkTaskCompletedDao(c, null);

                var tasks     = workTaskDao.SelectPlaned(ymd, containsCompleted);
                var times     = workingTimeDao.SelectByTaskIds(tasks.Select(t => t.Id).Distinct().ToArray());
                var completed = completedDao.SelectCompleted(tasks.Select(t => t.Id).Distinct().ToArray());

                foreach (var task in tasks)
                {
                    var dto = new WorkTaskWithTimesDto
                    {
                        TaskId       = new Identity <Domain.Domain.Tasks.WorkTask>(task.Id),
                        ClientName   = clients.FirstOrDefault(c => c.Id == task.ClientId)?.Name ?? "",
                        ProcessName  = processes.FirstOrDefault(p => p.Id == task.ProcessId)?.Title ?? "",
                        ProductName  = products.FirstOrDefault(p => p.Id == task.ProductId)?.Name ?? "",
                        TaskCategory = task.TaskCategory,
                        Title        = task.Title,
                        IsCompleted  = completed.Any(c => c == task.Id),
                        IsScheduled  = task.TaskSource == Domain.Domain.Tasks.TaskSource.Schedule,
                    };

                    dto.WorkingTimes = times.Where(t => t.TaskId == task.Id)
                                       .Select(t => t.ToDomainObject())
                                       .OrderBy(t => t.TimePeriod.StartDateTime)
                                       .ThenBy(t => t.Id)
                                       .ToArray();

                    list.Add(dto);
                }
            });

            try
            {
                return(list.OrderBy(i => i.WorkingTimes.Any(t => t.IsDoing) ? 0 : 1)
                       .ThenByDescending(i => i.WorkingTimes.Where(t => t.TimePeriod.IsFuture == false).Any() ? i.WorkingTimes.Where(t => t.TimePeriod.IsFuture == false).Max(t => t.TimePeriod.StartDateTime) : DateTime.MinValue)
                       .ThenBy(i => i.WorkingTimes.Where(t => t.TimePeriod.IsFuture).Any() ? i.WorkingTimes.Where(t => t.TimePeriod.IsFuture).Min(t => t.TimePeriod.StartDateTime) : DateTime.MaxValue)
                       .ThenBy(i => i.TaskId.Value).ToArray());
            }
            catch (Exception)
            {
                return(list.ToArray());
            }
        }
예제 #21
0
        public ConfigurationItem[] SelectAll()
        {
            ConfigurationItem[] results = null;

            RepositoryAction.Query(c =>
            {
                var dao = new ConfigDao(c, null);

                results = dao.SelectAll().Select(i => i.ConvertToDomainObject()).ToArray();
            });

            return(results);
        }
예제 #22
0
        public ImportedTask[] SelectByImportKeys(string[] importKeys)
        {
            ImportedTask[] results = null;

            RepositoryAction.Query(c =>
            {
                var dao = new ImportedTaskDao(c, null);

                results = dao.SelectByImportKeys(importKeys).Select(d => d.ConvertToDomainObject()).ToArray();
            });

            return(results);
        }
예제 #23
0
        public WorkingTimeRange SelectById(Identity <WorkingTimeRange> id)
        {
            WorkingTimeRange result = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkingTimeDao(c, null);

                result = dao.SelectId(id.Value)?.ToDomainObject();
            });

            return(result);
        }
        public WorkTask SelectById(Identity <WorkTask> identity)
        {
            WorkTask results = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkTaskDao(c, null);

                results = dao.SelectById(identity.Value)?.ConvertToDomainObject();
            });

            return(results);
        }
        public Client[] SelectAll()
        {
            var list = new List <Client>();

            RepositoryAction.Query(c =>
            {
                var listRow = new ClientDao(c, null).SelectAll();
                list.AddRange(listRow.Select(r => r.ToDomainObject()));
            });

            return(list.OrderBy(i => i.KanaName)
                   .ThenBy(i => i.Id.Value)
                   .ToArray());
        }
예제 #26
0
        public void AddRange(WorkingHour[] workingHours)
        {
            RepositoryAction.Transaction((c, t) =>
            {
                var dao = new WorkingHourDao(c, t);

                dao.Delete(workingHours.Select(w => w.Ymd.Value).Distinct().ToArray());

                foreach (var row in workingHours.Where(w => w.IsEmpty == false))
                {
                    dao.Insert(WorkingHourTableRow.FromDomainObjects(row));
                }
            });
        }
예제 #27
0
        public WorkingTimeRange Add(WorkingTimeRange workingTimeRange)
        {
            var row = WorkingTimeTableRow.FromDomainObject(workingTimeRange);

            RepositoryAction.Transaction((c, t) =>
            {
                var dao = new WorkingTimeDao(c, t);
                var id  = dao.Insert(row);

                // ID採番結果
                row.Id = id;
            });

            return(row.ToDomainObject());
        }
예제 #28
0
        public WorkingTimeRange[] SelectByTaskId(Identity <WorkTask> taskId)
        {
            WorkingTimeRange[] result = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkingTimeDao(c, null);

                result = dao.SelectByTaskIds(new int[] { taskId.Value })
                         .Select(t => t.ToDomainObject())
                         .ToArray();
            });

            return(result);
        }
예제 #29
0
        public WorkTask SelectById(Identity <WorkTask> identity)
        {
            WorkTask results = null;

            RepositoryAction.Query(c =>
            {
                var dao     = new WorkTaskDao(c, null);
                var compDao = new WorkTaskCompletedDao(c, null);
                var exist   = compDao.IsCompleted(identity.Value);

                results = WorkTaskFactory.Create(dao.SelectById(identity.Value), exist);
            });

            return(results);
        }
예제 #30
0
        public WorkingTimeRange[] SelectByYmd(string ymd)
        {
            WorkingTimeRange[] results = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkingTimeDao(c, null);

                results = dao.SelectYmd(ymd)
                          .Select(r => r.ToDomainObject())
                          .OrderBy(r => r.TimePeriod.StartDateTime)
                          .ToArray();
            });

            return(results);
        }
예제 #31
0
 // CONSTRUCTION
 static FactoryAction()
 {
     _repository = new RepositoryAction();
 }