示例#1
0
        public static async Task <ScopedList <TResult> > GetList <TResult>(
            this IListable <TResult> resource,
            int?offset     = null,
            int?limit      = null,
            DateTime?from  = null,
            DateTime?to    = null,
            Ordering?order = null
            ) where TResult : ModelBase
        {
            var opts = new ListOptions
            {
                Offset = offset,
                Limit  = limit,
                From   = from,
                To     = to,
                Order  = order
            };

            var path = resource.BasePath;

            if (!opts.IsEmpty())
            {
                var content = serializer.ExtractFormValues(opts);
                path += $"?{await content.ReadAsStringAsync().ConfigureAwait(false)}";
            }

            // TODO: Actual list container type that can be re-requested and supports paging as well.
            return(await resource.Requester.Request <ScopedList <TResult> >(
                       resource.Endpoint,
                       "GET",
                       path
                       ).ConfigureAwait(false));
        }
示例#2
0
        private static INumerable BuildCount(List <Token> tokens)
        {
            List <Token> laterTokens = tokens.Skip(1).ToList();

            if (laterTokens.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Expression 'count' do not contain all necessary information.");
            }

            if (TokenGroups.ContainsTokenOutsideBrackets(laterTokens, TokenType.Inside))
            {
                return(BuildCountInside(laterTokens));
            }
            else
            {
                IListable ilist = ListableBuilder.Build(laterTokens);
                if (ilist.IsNull())
                {
                    return(null);
                }
                else
                {
                    return(new Count(ilist));
                }
            }
        }
示例#3
0
        private static INumerable BuildCountInside(List <Token> tokens)
        {
            int index = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.Inside);

            if (index == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Expression 'count inside' do not contain information about referent location.");
            }

            if (index == 0)
            {
                throw new SyntaxErrorException("ERROR! Expression 'count inside' do not contain information about referent list of elements.");
            }

            IListable ilist = ListableBuilder.Build(tokens.Take(index).ToList());

            if (ilist.IsNull())
            {
                return(null);
            }

            IStringable istr = StringableBuilder.Build(tokens.Skip(index + 1).ToList());

            if (istr.IsNull())
            {
                return(null);
            }

            return(new CountInside(ilist, istr));
        }
示例#4
0
        public static IStringable BuildLis(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 list argument.");
            }

            IListable ilis = ListableBuilder.Build(args[0].tokens);

            if (ilis.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as list.");
            }

            if (name.Equals("commonbeginning"))
            {
                return(new FuncCommonbeginning(ilis));
            }
            else if (name.Equals("commonending"))
            {
                return(new FuncCommonending(ilis));
            }
            else if (name.Equals("concatenate") || name.Equals("concatenated"))
            {
                return(new FuncConcatenate(ilis));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
示例#5
0
 internal virtual void SubmitForReview(IListable entity)
 {
     entity.AssignedToOrgId = submitter.OrgId;
     entity.StatusId = referenceRepository.GetStatus(StatusType.PENDING_REVIEW).StatusId;
     entity.AssignedToUserId = null;
     entity.AssignedAt = null;
 }
示例#6
0
        public static IBoolable BuildLisStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: one list and one text.");
            }

            IListable   ilis = ListableBuilder.Build(args[0].tokens);
            IStringable istr = StringableBuilder.Build(args[1].tokens);

            if (ilis.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as list.");
            }
            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("contain") || name.Equals("contains"))
            {
                return(new FuncContain(ilis, istr));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
示例#7
0
 public MoveToAs(IListable list, IStringable destination, IStringable newName, bool forced)
 {
     this.list        = list;
     this.destination = destination;
     this.newName     = newName;
     this.forced      = forced;
 }
示例#8
0
        public static IBoolable BuildIn(List <Token> tokens)
        {
            int index = tokens.TakeWhile(x => !x.GetTokenType().Equals(TokenType.In)).Count();

            if (index == 0 || index == tokens.Count - 1)
            {
                return(null);
            }

            List <Token> leftTokens  = tokens.GetRange(0, index);
            List <Token> rightTokens = tokens.GetRange(index + 1, tokens.Count - index - 1);

            IStringable istr = StringableBuilder.Build(leftTokens);

            if (istr.IsNull())
            {
                return(null);
            }

            IListable ilis = ListableBuilder.Build(rightTokens);

            if (ilis.IsNull())
            {
                return(null);
            }

            return(new In(istr, ilis));
        }
示例#9
0
        public void GetInfo(object item, ItemInfo info)
        {
            IListable listable = item.As <IListable>();

            if (listable != null)
            {
                listable.GetInfo(info);
                return;
            }

            IResource resource = item.As <IResource>();

            if (resource != null && !item.Is <Game>())
            {
                info.Label      = Path.GetFileName(resource.Uri.LocalPath);
                info.ImageIndex = info.GetImageList().Images.IndexOfKey(Sce.Atf.Resources.ResourceImage);
                return;
            }

            // If the object has a name use it as the label (overriding whatever may have been set previously)
            INameable nameable = Adapters.As <INameable>(item);

            if (nameable != null)
            {
                info.Label = nameable.Name;
            }
        }
示例#10
0
        public static ICommand BuildCreateUsual(List <Token> tokens, bool forced, bool directory)
        {
            if (tokens.Count == 0)
            {
                if (directory)
                {
                    return(new CreateDirectory(new StringVariableRefer("this"), forced));
                }
                else
                {
                    return(new CreateFile(new StringVariableRefer("this"), forced));
                }
            }
            IListable ilist = ListableBuilder.Build(tokens);


            if (ilist.IsNull())
            {
                throw new SyntaxErrorException("ERROR! There are is something wrong with " + (directory ? "directory" : "file")
                                               + " creation command syntax.");
            }
            if (directory)
            {
                return(new CreateDirectory(ilist, forced));
            }
            else
            {
                return(new CreateFile(ilist, forced));
            }
        }
示例#11
0
        public static ICommand Build(List <Token> tokens, bool forced)
        {
            TokenType type = tokens[0].GetTokenType();

            tokens.RemoveAt(0);

            if (tokens.Where(t => t.GetTokenType().Equals(TokenType.To)).Count() > 1)
            {
                throw new SyntaxErrorException("ERROR! In " + GetName(type) + " command keyword 'to' occurs too many times.");
            }

            List <Token> part1  = new List <Token>();
            List <Token> part2  = new List <Token>();
            bool         pastTo = false;

            foreach (Token tok in tokens)
            {
                if (tok.GetTokenType().Equals(TokenType.To))
                {
                    pastTo = true;
                }
                else
                {
                    if (pastTo)
                    {
                        part2.Add(tok);
                    }
                    else
                    {
                        part1.Add(tok);
                    }
                }
            }

            if (part2.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " is too short and do not contain all necessary information.");
            }

            IStringable expression2 = StringableBuilder.Build(part2);

            if (expression2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second part of command " + GetName(type) + " cannot be read as text.");
            }

            if (part1.Count == 0)
            {
                return(BuildSimple(type, expression2, forced));
            }
            else
            {
                IListable expression1 = ListableBuilder.Build(part1);
                if (expression1.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! First part of command " + GetName(type) + " cannot be read as list.");
                }
                return(BuildComplex(type, expression1, expression2, forced));
            }
        }
示例#12
0
 public static void Check(IListable obj)
 {
     if (obj == null)
     {
         return;
     }
 }
示例#13
0
        private static ICommand BuildComplex(TokenType type, IListable ilist)
        {
            switch (type)
            {
            case TokenType.Copy:
                return(new Copy(ilist));

            case TokenType.Cut:
                return(new Cut(ilist));

            case TokenType.Delete:
                return(new Delete(ilist));

            case TokenType.Drop:
                return(new Drop(ilist));

            case TokenType.Hide:
                return(new Hide(ilist));

            case TokenType.Lock:
                return(new Lock(ilist));

            case TokenType.Open:
                return(new Open(ilist));

            case TokenType.Unhide:
                return(new Unhide(ilist));

            case TokenType.Unlock:
                return(new Unlock(ilist));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
示例#14
0
        public void GetInfo(object item, ItemInfo info)
        {
            ILayer layer = Adapters.As <ILayer>(item);

            if (layer != null)
            {
                info.Label    = layer.Name;
                info.HasCheck = true;
                info.SetCheckState(GetCheckState(layer));
            }
            else
            {
                IReference <IGameObject> reference = Adapters.As <IReference <IGameObject> >(item);
                if (reference != null)
                {
                    IListable listable = reference.As <IListable>();
                    listable.GetInfo(info);
                    //INameable nameable = Adapters.As<INameable>(reference.Target);
                    //if (nameable != null && !string.IsNullOrEmpty(nameable.Name))
                    //    info.Label = nameable.Name;

                    info.IsLeaf = true;
                    IVisible iVisible = GetIVisible(item);
                    if (iVisible != null)
                    {
                        info.HasCheck = true;
                        info.Checked  = iVisible.Visible;
                    }
                }
            }
        }
示例#15
0
        public static IListable BuildListTernary(List <Token> tokens)
        {
            IBoolable condition = BoolableBuilder.Build(GetTernaryCondition(tokens));

            if (condition.IsNull())
            {
                return(null);
            }

            IListable confirmationCase = ListableBuilder.Build(GetTernaryConfirmation(tokens));

            if (confirmationCase.IsNull())
            {
                return(null);
            }

            IListable negationCase = ListableBuilder.Build(GetTernaryNegation(tokens));

            if (negationCase.IsNull())
            {
                return(null);
            }

            return(new ListTernary(condition, confirmationCase, negationCase));
        }
示例#16
0
        internal void AssignToUser(IListable entity)
        {

            entity.StatusId = referenceRepository.GetStatus(StatusType.ASSIGNED).StatusId;            
            entity.AssignedAt = DateTime.Now;
            entity.AssignedByUserId = submitter.UserId;
            entity.AssignedToOrgId = submitter.OrgId;
        }
示例#17
0
 internal void SaveAsDraft(IListable entity)
 {
     entity.StatusId = referenceRepository.GetStatus(StatusType.DRAFT).StatusId;
     entity.AssignedAt = null;
     entity.AssignedByUserId = null;
     entity.AssignedToUserId = null;
     entity.AssignedToOrgId = submitter.OrgId;
 }    
示例#18
0
 internal void Reroute(IListable entity)
 {
     entity.StatusId = referenceRepository.GetStatus(StatusType.REROUTED).StatusId;            
     entity.AssignedAt = null;
     entity.AssignedToUserId = null;
     entity.AssignedByUserId = null;
     entity.AssignedToOrgId = getOrg(RBCCode).OrgId;
 }
示例#19
0
 internal void WithdrawItem(IListable entity)
 {
     entity.AssignedToUserId = submitter.UserId;
     entity.AssignedToOrgId = submitter.OrgId;
     entity.AssignedByUserId = submitter.UserId;
     entity.StatusId = referenceRepository.GetStatus(StatusType.DRAFT).StatusId;            
     entity.AssignedAt = null;
     entity.ResolvedAt = null;
 }  
示例#20
0
 internal void createWorkItemHistory(IListable entity)
 {
     itemHistory = new QmsWorkitemhistory();
     itemHistory.ActionTakenByUserId = submitter.UserId;
     itemHistory.CreatedAt = DateTime.Now;
     itemHistory.WorkItemId = entity.Id;
     itemHistory.ActionTakenByUserId = submitter.UserId;
     itemHistory.WorkItemTypeCode = entity.WorkItemType;
     itemHistory.ActionDescription = ActionDescription;
     referenceRepository.context.Add(itemHistory);
 }        
示例#21
0
 internal void ReOpen(IListable entity,User reopenedBy, User assignedTo)
 {
     entity.StatusId = referenceRepository.GetStatus(StatusType.ASSIGNED).StatusId;            
     entity.AssignedByUserId = reopenedBy.UserId;
     entity.AssignedToUserId = assignedTo.UserId;
     entity.AssignedToOrgId = assignedTo.OrgId;
     entity.AssignedAt = DateTime.Now;
     entity.UpdatedAt = DateTime.Now;
     entity.ResolvedAt = null;
     entity.DeletedAt = null;
 }
示例#22
0
        public static ICommand Build(List <Token> tokens, bool forced)
        {
            TokenType type = tokens[0].GetTokenType();

            tokens.RemoveAt(0);

            int toIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.To);
            int asIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.As);

            if (asIndex < toIndex)
            {
                return(null);
            }
            if (toIndex == asIndex - 1)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " do not have definition of destination directory.");
            }
            if (asIndex == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " do not have definition of new name for file/directory.");
            }

            List <Token> listTokens        = tokens.Take(toIndex).ToList();
            List <Token> destinationTokens = tokens.GetRange(toIndex + 1, asIndex - toIndex - 1);
            List <Token> nameTokens        = tokens.Skip(asIndex + 1).ToList();

            IStringable destination = StringableBuilder.Build(destinationTokens);

            if (destination.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of destination directory cannot be read as text.");
            }
            IStringable name = StringableBuilder.Build(nameTokens);

            if (name.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of new name for file/directory cannot be read as text.");
            }

            if (listTokens.Count == 0)
            {
                return(BuildSimple(type, destination, name, forced));
            }
            else
            {
                IListable list = ListableBuilder.Build(listTokens);
                if (list.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of list of files and directories is not correct.");
                }
                return(BuildComplex(type, list, destination, name, forced));
            }
        }
示例#23
0
        /// <summary>
        /// Update操作前的数据检查,确保数据不会误导ID,CreateTime, ModifyTime,比如 PUT /asset/105  但是提供的数据里面id=106。
        /// </summary>
        /// <param name="accid"></param>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        async Task <bool> UpdateProtectListableEntityAsync(string accid, IListable value)
        {
            var src = await GetAsync(accid, value.Id) as IListable;

            if (src == null)
            {
                return(false);
            }
            value.CreatedTime  = src.CreatedTime;
            value.ModifiedTime = DateTime.UtcNow;
            return(true);
        }
示例#24
0
        internal void Return(IListable entity)
        {
            
            SecUser originator = this.referenceRepository.context.SecUser.Where(u => u.UserId == entity.CreatedByUserId).SingleOrDefault();

            entity.AssignedToUserId = null;
            entity.AssignedToOrgId = originator.OrgId.Value;
            entity.AssignedByUserId = null;
            entity.StatusId = referenceRepository.GetStatus(StatusType.RETURNED).StatusId;            
            entity.AssignedAt = null;
            entity.ResolvedAt = null;
        }
示例#25
0
 private void GetPropertyValuesForComponent(IListable selectedItem)
 {
     foreach (var item in selectedItem.GetType().GetProperties())
     {
         Type pt = item.PropertyType;
         if (pt == typeof(bool))
         {
             CheckBox checkBox = (CheckBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, item.Name);
             item.SetValue(selectedItem, checkBox.IsChecked);
         }
         else if (pt == typeof(int))
         {
             TextBox textBox = (TextBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, item.Name);
             item.SetValue(selectedItem, Convert.ToInt32(textBox.Text));
         }
         else if (pt == typeof(double))
         {
             if (item.Name != "Width" && item.Name != "Height")
             {
                 TextBox textBox = (TextBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, item.Name);
                 item.SetValue(selectedItem, Convert.ToDouble(textBox.Text));
             }
         }
         else if (pt == typeof(decimal))
         {
             TextBox textBox = (TextBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, item.Name);
             item.SetValue(selectedItem, Convert.ToDecimal(textBox.Text));
         }
         else if (pt == typeof(Color))
         {
             TextBox  textBox  = (TextBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, "tb" + item.Name);
             ComboBox comboBox = (ComboBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, "cb" + item.Name);
             if (textBox.Text != "#00000000" || string.IsNullOrWhiteSpace(textBox.Text))
             {
                 item.SetValue(selectedItem, (Color)ColorConverter.ConvertFromString(textBox.Text));
             }
             else if (comboBox.SelectedIndex != 0)
             {
                 item.SetValue(selectedItem, (Color)(comboBox.SelectedItem as PropertyInfo).GetValue(1));
             }
         }
         else if (pt == typeof(string))
         {
             if (item.Name != "ImagePath" && item.Name != "Name")
             {
                 TextBox textBox = (TextBox)LogicalTreeHelper.FindLogicalNode(PropertiesPanel, item.Name);
                 item.SetValue(selectedItem, textBox.Text);
             }
         }
     }
 }
示例#26
0
        public static ISubcommand BuildWith(List <Token> tokens, bool negated)
        {
            string name = negated ? "without" : "with";

            IListable ilis = ListableBuilder.Build(tokens);

            if (ilis.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In list declaration there is something wrong with expression: " + name + ".");
            }
            else
            {
                return(new With(ilis, negated));
            }
        }
        private static ICommand BuildComplex(TokenType type, IListable list, ITimeable time)
        {
            switch (type)
            {
            case TokenType.Recreate:
                return(new RecreateTo(list, time));

            case TokenType.Remodify:
                return(new RemodifyTo(list, time));

            case TokenType.Reaccess:
                return(new ReaccessTo(list, time));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
示例#28
0
        private static ICommand BuildComplex(TokenType type, IListable ilist, IStringable destination, IStringable newName, bool forced)
        {
            switch (type)
            {
            case TokenType.Copy:
                return(new CopyToAs(ilist, destination, newName, forced));

            case TokenType.Cut:
                return(new MoveToAs(ilist, destination, newName, forced));

            case TokenType.Move:
                return(new MoveToAs(ilist, destination, newName, forced));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
示例#29
0
        private string formatMessage(IListable ca, QmsWorkitemcomment comment)
        {
            string retval = ca.Message;
            string commentTemplate = "Latest Comment:{0}<br/> by {1} on {2}";            
            if(comment != null)
            {
                string commentText = string.Format(commentTemplate,comment.Message,comment.Author.DisplayName,comment.CreatedAt.ToShortDateString());
                retval += commentText;
            }
            else
            {
                retval += "No comments have been made.";
            }

            return retval;
        }
示例#30
0
        private void sendIndividualMessage(IListable entity, NtfNotificationevent ne, User submitter, QmsWorkitemcomment comment)
        {
            if(submitter.UserId != entity.CreatedByUserId.Value) // if the person doing the action is the originator they don't get a message since they did the action
            {
                NtfNotification notification = new NtfNotification();
                notification.CreatedAt = DateTime.Now;
                notification.HasBeenRead = 0;
                notification.Title = string.Format(ne.TitleTemplate,entity.Id);
                notification.WorkitemId = entity.Id;
                notification.WorkItemTypeCode = WorkItemTypeEnum.CorrectiveActionRequest;
                notification.SendAsEmail = 1;
                notification.NotificationEventId = ne.NotificationEventId;
                notification.Message = entity.Message;
                switch(ne.NotificationEventCode)
                {
                    case CorrectiveActionNotificationType.CA_Assigned:
                        notification.UserId = entity.AssignedToUserId.Value;
//                        notification.Message = string.Format(ne.MessageTemplate,ca.Id, ca.AssignedAt.Value.ToShortDateString(),ca.EmplId,ca.Employee.FullName);
                        break;
                    case CorrectiveActionNotificationType.CA_Created:
                        notification.UserId = entity.CreatedByUserId.Value;
//                        notification.Message = string.Format(ne.MessageTemplate,ca.Id, ca.CreatedAt.ToShortDateString(),ca.EmplId,ca.Employee.FullName);
                        break;
                    case CorrectiveActionNotificationType.CA_Returned:
                        notification.UserId = entity.CreatedByUserId.Value;
//                        notification.Message = string.Format(ne.MessageTemplate,ca.Id, ca.UpdatedAt.Value.ToShortDateString(),ca.EmplId,ca.Employee.FullName);
                        break;
                    case CorrectiveActionNotificationType.CA_Closed:
                        notification.UserId = entity.CreatedByUserId.Value;
//                        notification.Message = string.Format(ne.MessageTemplate,ca.Id, ca.ResolvedAt.Value.ToShortDateString(),ca.EmplId,ca.Employee.FullName);
                        break;                    
                    case CorrectiveActionNotificationType.CA_Withdrawn:
                        notification.UserId = entity.AssignedToUserId.Value;
//                        notification.Message = string.Format(ne.MessageTemplate,ca.Id,  ca.UpdatedAt.Value.ToShortDateString(), ca.EmplId, ca.Employee.FullName);
                        break;
                    default:
                        //not a indivual message type
                        break;
                }
        
                context.Add(notification);
                context.SaveChanges();
            }


            
        }
        public static void List(string[] headers, IListable[] items)
        {
            int[] columnWidths = DisplayHeaders(headers);

            for(int count = 0; count < items.Length; count++)
            {
                string[] values = items[count].ColumnValues;
                DisplayItemRow(columnWidths, values);
            }
        }