public override void OnAfterSave(ISaveRequestHandler handler)
        {
            var newList = Target.AsObject(handler.Row) as List<NoteRow>;
            if (newList == null)
                return;

            var idField = (handler.Row as IIdRow).IdField;
            var entityId = idField[handler.Row].Value;

            if (handler.IsCreate)
            {
                foreach (var note in newList)
                    SaveNote(handler.UnitOfWork, note, handler.Row.Table, entityId, null);

                return;
            }

            var fld = NoteRow.Fields;
            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.List,
                EqualityFilter = new Dictionary<string, object>
                {
                    { fld.EntityType.PropertyName, handler.Row.Table },
                    { fld.EntityId.PropertyName, entityId }
                }
            };

            var oldList = new NoteRepository().List(handler.Connection, listRequest).Entities;
            NoteListSave(handler.UnitOfWork, handler.Row.Table, entityId, oldList, newList);
        }
Ejemplo n.º 2
0
 public ListRequestHandler(IContainerManager containerManager, Request request)
     : base(request)
 {
     if (containerManager == null)
     {
         throw new ArgumentNullException("containerManager");
     }
     this.containerManager = containerManager;
     this.request = (ListRequest)request;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes the custom page.
        /// </summary>
        /// <param name="uid">The uid.</param>
        public static void DeleteCustomPage(Guid uid)
        {
            FilterElementCollection filters = new FilterElementCollection();
            filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldUid, uid));

            ListRequest request = new ListRequest(CustomPageEntity.ClassName, filters.ToArray());
            request.Parameters.Add("CustomPageNormalizationPlugin", false);
            ListResponse response = (ListResponse)BusinessManager.Execute(request);

            foreach (CustomPageEntity page in response.EntityObjects)
            {
                if (!page.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName))
                    BusinessManager.Delete(page);
            }
        }
Ejemplo n.º 4
0
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (handler.Row as IIdRow).IdField;
            var fld = NoteRow.Fields;

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.List,
                EqualityFilter = new Dictionary<string, object>
                {
                    { fld.EntityType.PropertyName, handler.Row.Table },
                    { fld.EntityId.PropertyName, idField[handler.Row] ?? -1 }
                }
            };

            var notes = new NoteRepository().List(handler.Connection, listRequest).Entities;

            // users might be in another database, in another db server, so we can't simply use a join here
            var userIdList = notes.Where(x => x.InsertUserId != null).Select(x => x.InsertUserId.Value).Distinct();
            if (userIdList.Any())
            {
                var u = UserRow.Fields;
                IDictionary<int, string> userDisplayNames;
                using (var connection = SqlConnections.NewFor<UserRow>())
                    userDisplayNames = connection.Query(new SqlQuery()
                            .From(u)
                            .Select(u.UserId)
                            .Select(u.DisplayName)
                            .Where(u.UserId.In(userIdList)))
                        .ToDictionary(x => (int)x.UserId, x => (string)x.DisplayName);

                string s;
                foreach (var x in notes)
                    if (x.InsertUserId != null && userDisplayNames.TryGetValue(x.InsertUserId.Value, out s))
                        x.InsertUserDisplayName = s;
            }

            Target.AsObject(handler.Row, notes);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Resets the user settings by profile.
        /// </summary>
        /// <param name="uid">The page uid.</param>
        /// <param name="profileId">The profile id.</param>
        public static void ResetUserSettingsByProfile(Guid uid, int profileId)
        {
            List<string> users = new List<string>();

            if (profileId > 0)
            {
                FilterElementCollection fec = new FilterElementCollection();
                fec.Add(FilterElement.EqualElement(CustomizationProfileUserEntity.FieldProfileId, profileId));

                foreach (CustomizationProfileUserEntity entity in BusinessManager.List(CustomizationProfileUserEntity.ClassName, fec.ToArray()))
                    users.Add(entity.PrincipalId.ToString());
            }
            else // default profile
            {
                // 1. Get list all users
                using (IDataReader reader = Mediachase.IBN.Business.User.GetListAll())
                {
                    while (reader.Read())
                        users.Add(reader["UserId"].ToString());
                }

                // 2. Exclude users with non-default profile
                EntityObject[] entityList = BusinessManager.List(CustomizationProfileUserEntity.ClassName, (new FilterElementCollection()).ToArray());
                foreach (CustomizationProfileUserEntity puEntity in entityList)
                {
                    users.Remove(puEntity.PrincipalId.ToString());
                }
            }

            // O.R. [2010-10-05]. Don't process profile without users
            if (users.Count > 0)
            {
                // Remove CustomPages for all users in Profile
                FilterElementCollection filters = new FilterElementCollection();
                filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldUid, uid));

                OrBlockFilterElement orBlock = new OrBlockFilterElement();
                foreach (string userId in users)
                    orBlock.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldUserId, userId));
                filters.Add(orBlock);

                // Skip CustomPageNormalizationPlugin
                ListRequest request = new ListRequest(CustomPageEntity.ClassName, filters.ToArray());
                request.Parameters.Add("CustomPageNormalizationPlugin", false);
                ListResponse response = (ListResponse)BusinessManager.Execute(request);

                foreach (EntityObject page in response.EntityObjects)
                    BusinessManager.Delete(page);
            }
        }
Ejemplo n.º 6
0
 public static jQueryXmlHttpRequest List(ListRequest request, Action <ListResponse <UnitRow> > onSuccess, ServiceCallOptions options = null)
 {
     return(Q.ServiceRequest("TvHastanesi/Unit/List", request, onSuccess, options));
 }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.KeyOnly,
                IncludeColumns = new HashSet<string>
                {
                    itemKeyField.PropertyName ?? itemKeyField.Name
                },
                Criteria = thisKeyCriteria == new ValueCriteria(idField.AsObject(handler.Row)) & filterCriteria
            };

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = listFactory();
            foreach (Row item in response.Entities)
                list.Add(itemKeyField.AsObject(item));

            Target.AsObject(handler.Row, list);
        }
        public override void OnAfterSave(ISaveRequestHandler handler)
        {
            var newList = Target.AsObject(handler.Row) as IList;
            if (newList == null)
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);
            var masterId = idField.AsObject(handler.Row);

            if (handler.IsCreate)
            {
                foreach (Row entity in newList)
                    SaveDetail(handler.UnitOfWork, entity, masterId, null);

                return;
            }

            var oldList = new List<Row>();

            if (!attr.CheckChangesOnUpdate)
            {
                var row = rowFactory();
                var rowIdField = (row as IIdRow).IdField;

                // if we're not gonna compare old rows with new ones
                // no need to call list request handler

                new SqlQuery()
                        .Dialect(handler.Connection.GetDialect())
                        .From(row)
                        .Select((Field)rowIdField)
                        .Where(
                            foreignKeyField == new ValueCriteria(idField.AsObject(handler.Row)) &
                            filterCriteriaT0)
                        .ForEach(handler.Connection, () =>
                        {
                            oldList.Add(row.Clone());
                        });
            }
            else
            {
                var listRequest = new ListRequest
                {
                    ColumnSelection = ColumnSelection.List,
                    Criteria = foreignKeyCriteria == new ValueCriteria(idField.AsObject(handler.Row)) & filterCriteria
                };

                var listHandler = listHandlerFactory();
                var entities = listHandler.Process(handler.Connection, listRequest).Entities;
                foreach (Row entity in entities)
                    oldList.Add(entity);
            }

            DetailListSave(handler.UnitOfWork, masterId, oldList, newList);
        }
Ejemplo n.º 9
0
 public Result<ListResponse<MyRow>> List(ListRequest request)
 {
     return this.UseConnection("Default", (cnn) => new MyRepository().List(cnn, request));
 }
Ejemplo n.º 10
0
        private static Expression <Func <T, bool> > ParseExpStr <T>(ListRequest dto, string modelName,
                                                                    string strExp, out bool?isAnd) where T : class
        {
            Expression <Func <T, bool> > current = null;
            bool?isAnd_ = null;

            if (!string.IsNullOrEmpty(strExp))
            {
                var strExps = strExp.Trim().Split(' ');
                foreach (var expItem_ in strExps)
                {
                    var expItem = expItem_.Trim();
                    if (expItem == string.Empty)
                    {
                        continue;
                    }
                    if (expItem == "or")
                    {
                        isAnd_ = false;
                    }
                    else if (expItem == "and")
                    {
                        isAnd_ = true;
                    }
                    else if (dto.FieldFilters.ContainsKey(expItem))
                    {
                        var field     = dto.FieldFilters[expItem];
                        var valueType = field.ValueType;
                        try
                        {
                            if (!dto.FilterSettings.ContainsKey(field.FieldName) ||
                                !dto.FilterSettings[field.FieldName].IsAllowFilter)
                            {
                                throw new Exception("Field is not allowed.");
                            }
                            var fieldSetting = dto.FilterSettings[field.FieldName];
                            if (modelName != null && fieldSetting.ModelName != modelName)
                            {
                                continue;
                            }
                            if (valueType == null)
                            {
                                valueType = dto.FilterSettings[field.FieldName].ValueType;
                            }
                            if (current == null)
                            {
                                current = CreateFilter <T>(fieldSetting, field, ref valueType, dto.ToSql);
                            }
                            else if (isAnd_.Value)
                            {
                                current = current.And(CreateFilter <T>(fieldSetting, field, ref valueType, dto.ToSql));
                            }
                            else if (current != null && !isAnd_.Value)
                            {
                                current = current.Or(CreateFilter <T>(fieldSetting, field, ref valueType, dto.ToSql));
                            }
                        }
                        catch (Exception ex)
                        {
                            var details = new List <string>();
                            details.Add($"Expression: {field.Exp}");
                            details.Add($"Field: {field.FieldName}");
                            details.Add($"Operator: {field.Operator.ToString()}");
                            details.Add($"Value: {field.Value}");
                            details.Add($"ValueType: {valueType?.Name}");
                            throw new ErrorException(400, ex.Message, details);
                        }
                    }
                }
            }
            isAnd = isAnd_;
            return(current);
        }
Ejemplo n.º 11
0
        private static Expression <Func <T, bool> > ParseExpStrRecursive <T>(ListRequest dto, string modelName, int level,
                                                                             string filterExp, int startIndex, out int endIndex) where T : class
        {
            Expression <Func <T, bool> > current = null;
            string strExp     = null;
            var    i          = startIndex;
            var    startLevel = level;
            bool?  isAnd_;

            while (i <= filterExp.Length - 1)
            {
                if (filterExp[i] == '(')
                {
                    strExp = filterExp.Substring(startIndex, i - startIndex);
                    isAnd_ = null;
                    var tmp1 = ParseExpStr <T>(dto, modelName, strExp, out isAnd_);
                    if (tmp1 != null)
                    {
                        current = tmp1;
                    }
                    var tmp = ParseExpStrRecursive <T>(dto, modelName, level + 1, filterExp, i + 1, out endIndex);
                    if (isAnd_ != null && current != null && tmp != null)
                    {
                        if (isAnd_.Value)
                        {
                            current = current.And(tmp);
                        }
                        else if (!isAnd_.Value)
                        {
                            current = current.Or(tmp);
                        }
                    }
                    else if (tmp != null && current == null)
                    {
                        current = tmp;
                    }

                    i          = endIndex;
                    startIndex = endIndex;
                }
                else if (filterExp[i] == ')')
                {
                    strExp = filterExp.Substring(startIndex, i - startIndex);
                    isAnd_ = null;
                    var tmp = ParseExpStr <T>(dto, modelName, strExp, out isAnd_);
                    if (isAnd_ != null && current != null && tmp != null)
                    {
                        if (isAnd_.Value)
                        {
                            current = current.And(tmp);
                        }
                        else if (!isAnd_.Value)
                        {
                            current = current.Or(tmp);
                        }
                    }
                    else if (tmp != null && current == null)
                    {
                        current = tmp;
                    }
                    i++;
                    startLevel -= 1;
                    if (startLevel < level)
                    {
                        break;
                    }
                }
                else
                {
                    i++;
                }
            }
            endIndex = i;
            return(current);
        }
Ejemplo n.º 12
0
        public static Dictionary <string, FieldFilter> ParseFilterExp(ref string filterExp, ListRequest dto)
        {
            var groups       = Regex.Matches(filterExp, _regexGetFilterGroupDetails, RegexOptions.IgnoreCase);
            var fieldFilters = new Dictionary <string, FieldFilter>();

            for (var i = 0; i < groups.Count; i++)
            {
                //Log.Debug($@"A - {DateTime.Now.ToString("O")}");
                var g         = groups[i];
                var groupName = $"group{i}";
                var not       = g.Groups[1]?.Value == "not";
                var fieldName = g.Groups[2].Value;
                filterExp = filterExp.Replace(g.ToString(), $"({groupName})");
                var value = g.Groups[4]?.Value?.Trim();
                if (value == null)
                {
                    continue;
                }

                FilterOperator?operator_ = g.Groups[3].Value.ToEnum <FilterOperator>();

                // No need this anymore, cause auto gen exp already included default operator
                //if ((isFilterAutoGenerated || operator_ == null)
                //    && dto.FilterSettings != null
                //    && dto.FilterSettings.ContainsKey(fieldName))
                //{
                //    operator_ = dto.FilterSettings[fieldName].DefaultOperator;
                //}
                fieldFilters[groupName] = new FieldFilter
                {
                    Not             = not,
                    Exp             = g.Groups[0]?.Value,
                    FieldName       = fieldName,
                    Operator        = operator_.Value,
                    Value           = value,
                    ValueTypeString = g.Groups[5]?.Value
                };
            }
            return(fieldFilters);
        }
Ejemplo n.º 13
0
 public Result <ListResponse <MyRow> > List(ListRequest request)
 {
     return(this.UseConnection("Default", (cnn) => new MyRepository().List(cnn, request)));
 }
Ejemplo n.º 14
0
        public async Task <ListResponse <DistroListSummary> > GetDistroListsForOrgAsync(string orgId, ListRequest listRequest)
        {
            var lists = await QueryAsync(rec => rec.OwnerOrganization.Id == orgId, listRequest);

            return(new ListResponse <DistroListSummary>()
            {
                Model = lists.Model.Select(dls => dls.CreateSummary()),
                NextPartitionKey = lists.NextPartitionKey,
                NextRowKey = lists.NextRowKey,
                PageCount = lists.PageCount,
                PageIndex = lists.PageIndex,
                HasMoreRecords = lists.HasMoreRecords,
                PageSize = lists.PageSize,
                ResultId = lists.ResultId
            });
        }
Ejemplo n.º 15
0
        static void CheckPackage()
        {
            string filePath = Application.dataPath + "/../Library/PackageChecked";


            packageToAdd = new List <PackageEntry>();
            listRequest  = null;


            if (!File.Exists(filePath))
            {
                var packageListFile = Directory.GetFiles(Application.dataPath, "PackageImportList.txt", SearchOption.AllDirectories);
                if (packageListFile.Length == 0)
                {
                    Debug.LogError("[Auto Package] : Couldn't find the packages list. Be sure there is a file called PackageImportList in your project");
                }
                else
                {
                    string packageListPath = packageListFile[0];
                    packageToAdd = new List <PackageEntry>();
                    string[] content = File.ReadAllLines(packageListPath);
                    foreach (var line in content)
                    {
                        var          split = line.Split('@');
                        PackageEntry entry = new PackageEntry();

                        entry.name    = split[0];
                        entry.version = split.Length > 1 ? split[1] : null;

                        packageToAdd.Add(entry);
                    }

                    File.WriteAllText(filePath, "Delete this to trigger a new auto package check");

                    listRequest = Client.List();

                    while (!listRequest.IsCompleted)
                    {
                        if (listRequest.Status == StatusCode.Failure || listRequest.Error != null)
                        {
                            Debug.LogError(listRequest.Error.message);
                            break;
                        }
                    }

                    addRequests = new AddRequest[packageToAdd.Count];

                    installRequired = new bool[packageToAdd.Count];

                    for (int i = 0; i < installRequired.Length; i++)
                    {
                        installRequired[i] = true;
                    }



                    foreach (var package in listRequest.Result)
                    {
                        for (int i = 0; i < packageToAdd.Count; i++)
                        {
                            if (package.packageId.Contains(packageToAdd[i].name))
                            {
                                installRequired[i] = false;

                                if (package.versions.latestCompatible != "" && package.version != "")
                                {
                                    if (GreaterThan(package.versions.latestCompatible, package.version))
                                    {
                                        installRequired[i] = EditorUtility.DisplayDialog("Confirm Package Upgrade", string.Format("The version of \"{0}\" in this project is not the latest version. Would you like to upgrade it to the latest version? (Recommmended)", packageToAdd[i].name), "Yes", "No");

                                        if (installRequired[i])
                                        {
                                            packageToAdd[i].version = package.versions.latestCompatible;
                                        }
                                    }
                                }
                            }
                        }
                    }


                    for (int i = 0; i < packageToAdd.Count; i++)
                    {
                        if (installRequired[i])
                        {
                            addRequests[i] = InstallSelectedPackage(packageToAdd[i].name, packageToAdd[i].version);
                        }
                    }



                    ReimportPackagesByKeyword();
                }
            }
        }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (handler.Row as IIdRow).IdField;

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.List,
                EqualityFilter = new Dictionary<string, object>
                {
                    { foreignKeyField.PropertyName ?? foreignKeyField.Name, idField[handler.Row] }
                }
            };

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = rowListFactory();
            foreach (var item in response.Entities)
                list.Add(item);

            Target.AsObject(handler.Row, list);
        }
Ejemplo n.º 17
0
 public static jQueryXmlHttpRequest List(ListRequest request, Action <ListResponse <MeetingDecisionRow> > onSuccess, ServiceCallOptions options = null)
 {
     return(Q.ServiceRequest("Meeting/MeetingDecision/List", request, onSuccess, options));
 }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = this.attr.ColumnSelection,
                IncludeColumns = this.includeColumns,
                Criteria = foreignKeyCriteria == new ValueCriteria(idField.AsObject(handler.Row)) & filterCriteria
            };

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = rowListFactory();
            foreach (var item in response.Entities)
                list.Add(item);

            Target.AsObject(handler.Row, list);
        }
 public static jQueryXmlHttpRequest List(ListRequest request, Action <ListResponse <CategoryRow> > onSuccess, ServiceCallOptions options = null)
 {
     return(null);
 }
Ejemplo n.º 20
0
        public async Task <ListResponse <TicketStatusDefinitionSummary> > GetTicketStatusForOrgAsync(string orgId, ListRequest listRequest)
        {
            var response = await base.QueryAsync(attr => (attr.OwnerOrganization.Id == orgId || attr.IsPublic == true), listRequest);

            //TODO: This is a broken pattern to be fixed another day...sorry.
            var finalResponse = ListResponse <TicketStatusDefinitionSummary> .Create(response.Model.Select(mod => mod.CreateSummary()));

            finalResponse.NextPartitionKey = response.NextPartitionKey;
            finalResponse.NextRowKey       = response.NextRowKey;
            finalResponse.PageCount        = response.PageCount;
            finalResponse.PageCount        = response.PageIndex;
            finalResponse.PageSize         = response.PageSize;
            finalResponse.ResultId         = response.ResultId;
            return(finalResponse);
        }
Ejemplo n.º 21
0
 public ListResponse <MyRow> List(IDbConnection connection, ListRequest request)
 {
     return(new MyListHandler().Process(connection, request));
 }
        public void OnReturn(IListRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target) ||
                handler.Response.Entities.IsEmptyOrNull())
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.KeyOnly,
                IncludeColumns = new HashSet<string>
                {
                    itemKeyField.PropertyName ?? itemKeyField.Name,
                    thisKeyField.PropertyName ?? thisKeyField.Name
                }
            };

            var enumerator = handler.Response.Entities.Cast<Row>();
            while (true)
            {
                var part = enumerator.Take(1000);
                if (!part.Any())
                    break;

                enumerator = enumerator.Skip(1000);

                listRequest.Criteria = thisKeyCriteria.In(
                    part.Select(x => idField.AsObject(x))) & filterCriteria;

                IListResponse response = listHandler.Process(
                    handler.Connection, listRequest);

                var lookup = response.Entities.Cast<Row>()
                    .ToLookup(x => thisKeyField.AsObject(x).ToString());

                foreach (var row in part)
                {
                    var list = listFactory();
                    var matching = lookup[idField.AsObject(row).ToString()];
                    foreach (var x in matching)
                        list.Add(itemKeyField.AsObject(x));

                    Target.AsObject(row, list);
                }
            }
        }
Ejemplo n.º 23
0
 public ListResponse <MyRow> List(IDbConnection connection, ListRequest request)
 {
     return(new MyRepository().List(connection, request));
 }
 public ListResponse<MyRow> List(IDbConnection connection, ListRequest request)
 {
     return new MyRepository().List(connection, request);
 }
 // List of rows retrieve request
 public static IRestResponse <ListResponse <MyRow> > List <MyRow>(string baseUrl, string resource, ListRequest listRequest)
 {
     #region List Service Request
     IRestResponse <ListResponse <MyRow> > response = new RestResponse <ListResponse <MyRow> >();
     if (InternetConnection.IsConnectedToInternet() == true)
     {
         try
         {
             var restClient = new RestClient(baseUrl);
             var request    = new RestRequest(Method.POST);
             request.Resource = resource;
             request.AddHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
             request.AddHeader("Authorization", "Bearer " + VMMainModel.Instance.AuthToken);
             request.AddJsonBody(listRequest);
             request.RequestFormat = DataFormat.Json;
             response = restClient.Execute <ListResponse <MyRow> >(request);
         }
         catch (Exception ex)
         {
             response.ErrorMessage   = ex.Message;
             response.ErrorException = ex.InnerException;
             //MessageBox.Show(ex.Message);
         }
         return(response);
     }
     else
     {
         response.ErrorMessage = "Internet connection not available. Please check connection.";
         return(response);
     }
     #endregion
 }