Esempio n. 1
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// The <see cref="ResultFieldOptions"/>.
        /// </returns>
        public static ResultFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = new ResultFieldOptions();

            result.ChoiceList = new ChoiceModel[0];

            var listProperty = model.GetType().GetProperty(string.Format(CultureInfo.InvariantCulture, "{0}{1}", property.Name, Constants.ResultListPostfix));
            if (listProperty != null)
            {
                var listValue = listProperty.GetValue(model, null);
                if (listValue != null)
                {
                    result.ChoiceList = ((IEnumerable<ChoiceInfo>)listValue).Select(i => new ChoiceModel(i));
                }
                else
                {
                    result.IsEditable = true;
                }
            }
            
            return result;
        }
        /// <summary>
        /// Executes the specified item.
        /// </summary>
        /// <param name="item">The target item.</param>
        /// <param name="oldItem">The old item.</param>
        public override void Execute(IEditableRoot item, IEditableRoot oldItem)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var approval = item.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName);

            if (approval == null)
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Approval field \"{0}\" not found in item \"{1}\" or you don't have access. Action will not run.", ApprovalFieldName, item.GetType()), "item");

            var membersFound = new HashSet<int>();

            foreach (var member in approval.MemberResults.Where(am => am.ApprovalLevel == approval.CurrentLevel))
            {
                if (member.GetApprovalMemberResult() != ApprovalMemberResults.Undecided)
                    continue;

                if (!member.Person.HasValue || !member.OriginalApprover.HasValue || membersFound.Contains(member.OriginalApprover.Value))
                    continue;

                membersFound.Add(member.OriginalApprover.Value);

                var person = PersonManager.GetPerson(member.Person.Value);
                if (person == null)
                    continue;

                var basePersonId = member.OriginalApprover.Value;
                var actionItem = DynamicTypeManager.NewActionItem();
                actionItem.ActionGuid = Guid.ToString();
                actionItem.Process = item.ProcessName;
                actionItem.PersonId = person.Id;
                actionItem.BasePersonId = basePersonId;
                actionItem.ItemId = item.Id;
                actionItem.IsActionNew = true;

                var supportStates = item as ISupportStates;
                if (supportStates != null)
                    actionItem.ItemStateId = supportStates.CurrentState;

                actionItem.Save();
                CommunicationService.NotifyActionsChanged(person.Id);

                if (SendEmail && !string.IsNullOrWhiteSpace(person.Email))
                {
                    SendMessage(item, person);
                }
            }

            if (SendEmail && !string.IsNullOrWhiteSpace(EmailFieldName))
            {
                var email = item.ReadValueByPropertyName<string>(EmailFieldName);

                if (!string.IsNullOrWhiteSpace(email))
                {
                    SendMessage(item, email);
                }
            }

            base.Execute(item, oldItem);
        }
Esempio n. 3
0
 private static bool IsTabbedUI(IEditableRoot editableRoot)
 {
     var tabbedUiAttribute =
         editableRoot.GetType()
             .GetCustomAttributes(typeof(TabbedUIAttribute), false)
             .OfType<TabbedUIAttribute>()
             .FirstOrDefault();
     return tabbedUiAttribute != null && tabbedUiAttribute.IsTabbedUI;
 }
Esempio n. 4
0
 private static object GetValue(PropertyInfo prop, IEditableRoot editableRoot)
 {
     if (editableRoot == null) throw new ArgumentNullException("editableRoot");
     if (editableRoot.GetType().GetProperty(prop.Name) != null)
         return prop.GetValue(editableRoot);
     return GetValue(prop, editableRoot.GetBaseEdit());
 }
        private static ChartPanel GetChartDescriptor(IEditableRoot instance, string exprFieldName, string spcFieldName, ChartTypesEnum chartType, int subgroupSize, int dataPoints = 0)
        {
            ChartPanel chartDescriptor = null;

            MobileDictionary<string, ChartPanel> dict = null;
            if (!exprFieldName.Contains("_Rule"))
            {
                dict = instance.GetValueByPropertyName("ChartDescriptorExp") as MobileDictionary<string, ChartPanel>;
                if (dict != null)
                    dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartDescriptor);
                else
                    dict = new MobileDictionary<string, ChartPanel>();
            }

            if (chartDescriptor == null)
            {
                chartDescriptor = SpcManager.CreateChartDescriptor(chartType);
                chartDescriptor.DataPoints = dataPoints;
                chartDescriptor.SubgroupSize = subgroupSize;

                chartDescriptor = MethodCaller.CallFactoryMethod(instance.GetType(), "GetSampleDataForSPC", spcFieldName, instance, chartType, chartDescriptor, true) as ChartPanel;

                if (!exprFieldName.Contains("_Rule"))
                {
                    ChartPanel chartPanel;
                    if (dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartPanel))
                        dict[string.Format("{0}{1}", exprFieldName, spcFieldName)] = chartDescriptor;
                    else
                        dict.Add(string.Format("{0}{1}", exprFieldName, spcFieldName), chartDescriptor);

                    instance.LoadValueByPropertyName("ChartDescriptorExp", dict);
                }
            }
            else
            {
                chartDescriptor.DataPoints = dataPoints;
                chartDescriptor.SubgroupSize = subgroupSize;

                chartDescriptor = MethodCaller.CallFactoryMethod(instance.GetType(), "GetSampleDataForSPC", spcFieldName, instance, chartType, chartDescriptor, true) as ChartPanel;
            }

            return chartDescriptor;
        }        
        private static Task<ChartPanel> GetChartDescriptorAsync(IEditableRoot instance, string exprFieldName, string spcFieldName, ChartTypesEnum chartType, int subgroupSize, int dataPoints = 0)
        {
            ChartPanel chartDescriptor = null;

            var dict = instance.GetValueByPropertyName("ChartDescriptorExp") as MobileDictionary<string, ChartPanel>;
            if (dict != null)
                dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartDescriptor);
            else
                dict = new MobileDictionary<string, ChartPanel>();

            if (chartDescriptor == null)
            {
                return SpcManager.CreateChartDescriptorAsync(chartType)
                    .ContinueWith(async task =>
                    {
                        if (task.Result != null)
                        {
                            chartDescriptor = task.Result;
                            chartDescriptor.DataPoints = dataPoints;
                            chartDescriptor.SubgroupSize = subgroupSize;

                            var getDataTask = MethodCaller.CallFactoryMethod(
                                instance.GetType(), "GetSampleDataForSPCAsync", instance, spcFieldName, chartType, chartDescriptor, true) as Task<ChartPanel>;
                            chartDescriptor = await getDataTask;

                            ChartPanel chartPanel;
                            if (dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartPanel))
                                dict[string.Format("{0}{1}", exprFieldName, spcFieldName)] = chartDescriptor;
                            else
                                dict.Add(string.Format("{0}{1}", exprFieldName, spcFieldName), chartDescriptor);

                            instance.LoadValueByPropertyName("ChartDescriptorExp", dict);

                            return chartDescriptor;
                        }

                        return task.Result;
                    }
                    , CancellationToken.None, TaskContinuationOptions.NotOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap();
            }

            chartDescriptor.DataPoints = dataPoints;
            chartDescriptor.SubgroupSize = subgroupSize;

            var getSamplesTask = MethodCaller.CallFactoryMethod(
                instance.GetType(), "GetSampleDataForSPCAsync", instance, spcFieldName, chartType, chartDescriptor, true) as Task<ChartPanel>;
            return getSamplesTask;
        }
Esempio n. 7
0
        /// <summary>
        /// Sets the current state.
        /// </summary>
        /// <param name="item">The editable root.</param>
        /// <param name="stateGuid">The state unique identifier.</param>
        public static void SetCurrentState(IEditableRoot item, Guid stateGuid)
        {
            using (new ThreadLocalBypassPropertyCheckContext())
            {
                if (stateGuid.Equals(Guid.Empty))
                    return;

                var supportStates = item as ISupportStates;
                if (supportStates == null)
                    return;

                var stateToSet = supportStates.StateManager.States.FirstOrDefault(s => s.Guid.Equals(stateGuid));
                if (stateToSet != null)
                    item.GetType().GetProperty(Constants.CurrentStateColumnName).SetValue(item, stateToSet.Id, null);
            }
        }
Esempio n. 8
0
        private static List<FieldInfo> GetFields(IEditableRoot editableRoot, ICollection<string> visibleFields, IList<FieldVisibilityRule> visibilityRules = null)
        {
            var props =
                editableRoot.GetType()
                            .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

            var fields = new List<FieldInfo>();

            var baseEdit = props.FirstOrDefault(p => p.Name == Constants.BaseEditPropertyName);
            if (baseEdit != null && baseEdit.DeclaringType != null)
            {
                var baseEditValue = baseEdit.DeclaringType.InvokeMember(Constants.BaseEditPropertyName, BindingFlags.GetProperty, null, editableRoot, null);

                if (baseEditValue != null)
                    fields.AddRange(GetFields((IEditableRoot)baseEditValue, visibleFields, visibilityRules));
            }

            foreach (var prop in props)
            {
                if (prop == baseEdit)
                    continue;

                if (!visibleFields.Contains(prop.Name))
                    continue;

                var field = new FieldInfo();//TheFieldFactory.Value.CreateField(prop, _detailsModel, model, this);
                field.Model = editableRoot;
                field.SystemName = prop.Name;
                var commonAttr = prop.GetCustomAttributes(typeof(CommonSettingsAttribute), false).FirstOrDefault() as CommonSettingsAttribute;
                field.Name = commonAttr.Name;

                var fieldEditorAttr =
                    prop.GetCustomAttributes(typeof (FieldEditorAttribute), false).FirstOrDefault() as
                    FieldEditorAttribute;
                if (fieldEditorAttr != null)
                    field.FieldEditor = fieldEditorAttr.DataType;
                
                fields.Add(field);
            }

            return fields;
        }
Esempio n. 9
0
        /// <summary>
        /// Extracts and returns field Default or Calculated expression, if specified. 
        /// </summary>
        /// <param name="baseModel">Editable root model.</param>
        /// <param name="property">Field property.</param>
        /// <returns>
        /// Expression definition in JSON format.
        /// </returns>
        private static string GetExpression(IEditableRoot baseModel, PropertyInfo property)
        {
            if (baseModel == null)
            {
                throw new ArgumentNullException("baseModel");
            }

            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var expressionFieldName = property.Name + "ExpressionXml";

            var expressionProperty = baseModel.GetType().GetField(expressionFieldName);
            if (expressionProperty != null)
            {
                var expressionXml = (string) expressionProperty.GetRawConstantValue();

                var expressionService = new ExpressionServiceBase();
                Ioc.SatisfyImportsOnce(expressionService);

                var expressionSerializer = expressionService.ExpressionsSerializer;
                var expressionContainer = expressionSerializer.Deserialize(expressionXml);

                var expressionNodeFactory = expressionService.ExpressionNodeFactory;
                var destinationNode = expressionNodeFactory.CreateExpressionNodes(expressionContainer.Expressions);

                var expressionTranslator = new ExpressionsTranslator();

                var expression = expressionTranslator.ConvertNodeToExpression(destinationNode);
                expression.Source = new ExpressionSource
                {
                    Out =
                        expressionService.GetExpressionSourceFieldsList(expressionXml, true)
                            .Select(
                                f => new ExpressionSourcePoint {Key = f.SystemName, DataType = f.DataType.ToString()})
                };

                var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
                return JsonConvert.SerializeObject(expression, Formatting.Indented, jsonSerializerSettings);
            }

            return null;
        }