Exemplo n.º 1
0
        private async Task <string> UpdateMessage(EditModel model, int toUserId, bool NeedUser = false)
        {
            if (!NeedUser && toUserId == 0)
            {
                return(null);
            }
            using (MessagingDataProvider msgDP = new MessagingDataProvider()) {
                string toUser = await Resource.ResourceAccess.GetUserNameAsync(model.ToUserId);

                if (string.IsNullOrWhiteSpace(toUser))
                {
                    throw new Error(this.__ResStr("noUser", "User id {0} doesn't exist", model.ToUserId));
                }

                List <DataProviderFilterInfo> filters    = null;
                List <DataProviderFilterInfo> subFilters = null;
                subFilters = DataProviderFilterInfo.Join(subFilters, new DataProviderFilterInfo {
                    Field = "FromUser", Operator = "==", Value = Manager.UserId
                });
                subFilters = DataProviderFilterInfo.Join(subFilters, new DataProviderFilterInfo {
                    Field = "ToUser", Operator = "==", Value = toUserId
                });
                filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                    Logic = "||", Filters = subFilters
                });
                subFilters = null;
                subFilters = DataProviderFilterInfo.Join(subFilters, new DataProviderFilterInfo {
                    Field = "ToUser", Operator = "==", Value = Manager.UserId
                });
                subFilters = DataProviderFilterInfo.Join(subFilters, new DataProviderFilterInfo {
                    Field = "FromUser", Operator = "==", Value = toUserId
                });
                filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                    Logic = "||", Filters = subFilters
                });
                List <DataProviderSortInfo> sorts = null;
                sorts = DataProviderSortInfo.Join(sorts, new DataProviderSortInfo {
                    Field = "Sent", Order = DataProviderSortInfo.SortDirection.Descending
                });
                DataProviderGetRecords <Message> recs = await msgDP.GetItemsAsync(0, model.MaxMessages, sorts, filters);

                model.MessageData.Messages = recs.Data;
                model.MessageData.Messages.Reverse();
                model.MessageData.FromUser      = Manager.UserName;
                model.MessageData.ToUser        = toUser;
                model.MessageData.TotalMessages = recs.Total;
                return(toUser);
            }
        }
Exemplo n.º 2
0
        public async Task <List <string> > GetOnlineUsers()
        {
            YetaWFManager manager = await this.SetupSignalRAsync();

            using (ConnectionDataProvider connDP = new ConnectionDataProvider()) {
                //%%%%%%%%%%%%%%%%%%% limit scope to friend users
                List <DataProviderFilterInfo> filters = null;
                filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                    Field = "Name", Operator = "!=", Value = null
                });
                List <DataProviderSortInfo> sorts = null;
                sorts = DataProviderSortInfo.Join(sorts, new DataProviderSortInfo {
                    Field = "Name", Order = DataProviderSortInfo.SortDirection.Ascending
                });
                DataProviderGetRecords <Connection> conns = await connDP.GetItemsAsync(0, 0, sorts, filters);

                return((from c in conns.Data select c.Name).Distinct().ToList());
            }
        }
Exemplo n.º 3
0
            public async Task <List <PageDefinition> > GetPagesFromModuleAsync(Guid moduleGuid)
            {
                List <DataProviderSortInfo> sorts = DataProviderSortInfo.Join(null, new DataProviderSortInfo {
                    Field = nameof(PageDefinition.Url), Order = DataProviderSortInfo.SortDirection.Ascending
                });
                List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                    Field = nameof(PageDefinitionForModules.ModuleGuid), Operator = "==", Value = moduleGuid
                });

                using (DataProvider.PageDefinitionDataProvider pageDefDP = new DataProvider.PageDefinitionDataProvider()) {
                    using (PageDefinitionForModulesProvider pageDefForModDP = new PageDefinitionForModulesProvider()) {
                        List <JoinData> joins = new List <JoinData> {
                            new JoinData {
                                MainDP = pageDefDP, JoinDP = pageDefForModDP, MainColumn = nameof(PageDefinition.Identity), JoinColumn = SQLBase.SubTableKeyColumn, UseSite = false
                            },
                        };
                        DataProviderGetRecords <PageDefinition> recs = await GetRecordsAsync(0, 0, sorts, filters, Joins : joins);

                        return(recs.Data);
                    }
                }
            }
Exemplo n.º 4
0
        private async Task <TimeSpan> RunItemsAsync()
        {
            Logging.AddTraceLog("Scheduler event - checking scheduler items");

            using (SchedulerDataProvider schedDP = new SchedulerDataProvider()) {
                DateTime next = DateTime.UtcNow.Add(defaultTimeSpanNoTask);
                if (await schedDP.IsInstalledAsync())
                {
                    // run all items that are due now - Enabled == true and Next != null and Next < DateTime.UtcNow
                    List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                        new DataProviderFilterInfo {
                            Logic   = "&&",
                            Filters = new List <DataProviderFilterInfo> {
                                new DataProviderFilterInfo {
                                    Field = nameof(SchedulerItemData.Enabled), Operator = "==", Value = true,
                                },
                                new DataProviderFilterInfo {
                                    Field = nameof(SchedulerItemData.Next), Operator = "!=", Value = null,
                                },
                                new DataProviderFilterInfo {
                                    Field = nameof(SchedulerItemData.Next), Operator = "<=", Value = DateTime.UtcNow,
                                },
                            },
                        }
                    };
                    DataProviderGetRecords <SchedulerItemData> list = await schedDP.GetItemsAsync(filters);

                    foreach (SchedulerItemData item in list.Data)
                    {
                        await RunItemAsync(schedDP, item);
                    }

                    // Find the next startup time so we know how long to wait
                    List <DataProviderSortInfo> sorts = null;
                    sorts = DataProviderSortInfo.Join(sorts, new DataProviderSortInfo {
                        Field = nameof(SchedulerItemData.Next), Order = DataProviderSortInfo.SortDirection.Ascending
                    });
                    filters = new List <DataProviderFilterInfo> {
                        new DataProviderFilterInfo {
                            Logic   = "&&",
                            Filters = new List <DataProviderFilterInfo> {
                                new DataProviderFilterInfo {
                                    Field = nameof(SchedulerItemData.Enabled), Operator = "==", Value = true,
                                },
                                new DataProviderFilterInfo {
                                    Field = nameof(SchedulerItemData.Next), Operator = "!=", Value = null,
                                },
                            },
                        }
                    };
                    list = await schedDP.GetItemsAsync(0, 1, sorts, filters);

                    if (list.Data.Count > 0)
                    {
                        SchedulerItemData item = list.Data[0];
                        if (item.Next != null)
                        {
                            next = (DateTime)item.Next;
                        }
                    }
                }

                TimeSpan diff = next.Subtract(DateTime.UtcNow);
                if (diff < new TimeSpan(0, 0, 0))
                {
                    diff = new TimeSpan(0, 0, 1);
                }
                return(diff);
            }
        }
Exemplo n.º 5
0
        public async Task <string> RenderAsync(int model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            string type = PropData.GetAdditionalAttributeValue <string>("Force", null);

            if (type == "Grid" || (await IsLargeUserBaseAsync() && type != "DropDown"))
            {
                string hiddenId = UniqueId();
                string allId    = UniqueId();
                string nameId   = UniqueId();
                string noUser   = __ResStr("noUser", "(none)");

                bool header = PropData.GetAdditionalAttributeValue("Header", true);

                UserIdUI ui = new UserIdUI {
                    UserId = model,
                };
                using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) {
                    UserDefinition user = await userDP.GetItemByUserIdAsync(model);

                    if (user == null)
                    {
                        ui.UserName = __ResStr("noUser", "(none)");
                    }
                    else
                    {
                        ui.UserName = user.UserName;
                    }
                }

                ui.AllUsers    = GetGridAllUsersModel(header);
                ui.AllUsers.Id = allId;

                hb.Append($@"
<div class='yt_yetawf_identity_userid t_large t_edit' id='{DivId}'>
    {await HtmlHelper.ForEditComponentAsync(Container, PropertyName, model, "Hidden", HtmlAttributes: new { id = hiddenId, __NoTemplate = true })}");

                using (Manager.StartNestedComponent(FieldName)) {
                    hb.Append($@"
    <div class='t_name'>
        {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.UserName), HtmlAttributes: new { id = nameId })}
        {ImageHTML.BuildKnownIcon("#RemoveLight", title: __ResStr("ttClear", "Clear the current selection"), cssClass: "t_clear")}
    </div>
    {await HtmlHelper.ForLabelAsync(ui, nameof(ui.AllUsers))}
    {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.AllUsers))}");
                }
                hb.Append($@"
</div>");

                UserIdSetup setup = new UserIdSetup {
                    GridAllId = ui.AllUsers.Id,
                    HiddenId  = hiddenId,
                    NameId    = nameId,
                    NoUser    = noUser,
                };

                Manager.ScriptManager.AddLast($@"new YetaWF_Identity.UserIdEditComponent('{DivId}', {Utility.JsonSerialize(setup)});");
            }
            else
            {
                hb.Append($@"
<div class='yt_yetawf_identity_userid t_small t_edit'>");

                using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) {
                    List <DataProviderSortInfo> sorts = null;
                    DataProviderSortInfo.Join(sorts, new DataProviderSortInfo {
                        Field = nameof(UserDefinition.UserName), Order = DataProviderSortInfo.SortDirection.Ascending
                    });
                    DataProviderGetRecords <UserDefinition> recs = await userDP.GetItemsAsync(0, MAXUSERS, sorts, null);

                    List <SelectionItem <int> > list = (from u in recs.Data select new SelectionItem <int> {
                        Text = u.UserName,
                        Value = u.UserId,
                    }).ToList();
                    list.Insert(0, new SelectionItem <int> {
                        Text  = __ResStr("select", "(select)"),
                        Value = 0,
                    });
                    hb.Append(await DropDownListIntComponent.RenderDropDownListAsync(this, model, list, null));
                }

                hb.Append($@"
</div>");
            }
            return(hb.ToString());
        }