Inheritance: ViewModelBase
Exemple #1
0
        protected override void OnSessionUpdated(PersistentObject session)
        {
            base.OnSessionUpdated(session);

            if (channel != null)
                session.SetAttributeValue("ChannelUri", channel.Uri);
        }
        internal PersistentObjectAttribute(JObject model, PersistentObject parent)
            : base(model)
        {
            Parent = parent;
            clrType = new Lazy<Type>(() => Service.GetClrType(Type));

            UpdateOptions();
            HasValue = ValueDirect != null;
        }
        internal PersistentObjectAttributeWithReference(JObject model, PersistentObject parent)
            : base(model, parent)
        {
            propertiesToBackup = new[] { "value", "isReadOnly", "isValueChanged", "options", "objectId", "validationError" };

            var lookup = (JObject)model["lookup"];
            if (lookup != null)
                Lookup = Service.Current.Hooks.OnConstruct(lookup, null, false);
        }
Exemple #4
0
        public async Task<JObject> ExecuteQueryAsync(Query query, PersistentObject parent = null, string filterName = null, bool asLookup = false)
        {
            try
            {
                IsBusy = true;

                var data = CreateData();
                data["query"] = query.ToServiceObject();
                data["parent"] = parent != null ? parent.ToServiceObject() : null;
                data["filterName"] = filterName;
                data["asLookup"] = asLookup;

                var response = await PostAsync("ExecuteQuery", data);

                var ex = (string)response["exception"] ?? (string)response["ExceptionMessage"];
                if (!string.IsNullOrEmpty(ex))
                    throw new Exception(ex);

                AuthToken = (string)response["authToken"];
                await UpdateSession(response);

                return (JObject)response["result"];
            }
            finally
            {
                IsBusy = false;
            }
        }
 protected virtual PersistentObjectTabAttributes CreateAttributesTab(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
 {
     return new PersistentObjectTabAttributes(attributes, title, parent);
 }
Exemple #6
0
 internal virtual void OnOpen(PersistentObject po)
 {
 }
Exemple #7
0
 internal virtual Query OnConstruct(JObject model, PersistentObject parent, bool asLookup)
 {
     return new Query(model, parent, asLookup);
 }
Exemple #8
0
 internal override void OnConstruct(PersistentObject po)
 {
     OnConstruct((PhonePersistentObject)po);
 }
 protected PersistentObjectTab(string title, PersistentObject parent)
 {
     IsActionBarVisible = true;
     Title = title;
     Parent = parent;
 }
 protected PersistentObjectTab(string title, PersistentObject parent)
 {
     IsActionBarVisible = true;
     Title  = title;
     Parent = parent;
 }
Exemple #11
0
 internal StoreQuery(JObject model, PersistentObject parent = null, bool asLookup = false)
     : base(model, parent, asLookup)
 {
 }
 public StorePersistentObjectTabAttributes(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     :
         base(attributes, title, parent)
 {
     Navigate = new Navigate();
 }
 internal PersistentObjectTabAttributes(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     : base(title, parent)
 {
     Attributes = attributes;
     Groups = Attributes.Where(a => a.IsVisible).GroupBy(a => a.Group).Select(g => g.Key).ToArray();
 }
Exemple #14
0
        public async Task<PersistentObject> ExecuteActionAsync(string action, PersistentObject parent = null, Query query = null, QueryResultItem[] selectedItems = null, Dictionary<string, string> parameters = null, bool skipHooks = false)
        {
            var isObjectAction = action.StartsWith("PersistentObject.") || query == null;

            try
            {
                IsBusy = true;

                if (!skipHooks)
                {
                    string fullTypeName;
                    if (!isObjectAction)
                    {
                        query.SetNotification(null);
                        fullTypeName = query.PersistentObject.FullTypeName;
                    }
                    else
                    {
                        parent.SetNotification(null);
                        fullTypeName = parent.FullTypeName;
                    }

                    var args = new ExecuteActionArgs(action) { Parameters = parameters, PersistentObject = parent, Query = query, SelectedItems = selectedItems };
                    await Hooks.OnAction(args);

                    if (args.IsHandled)
                        return args.Result;

                    args.IsHandled = ClientActions.Get(fullTypeName).OnAction(args);
                    if (args.IsHandled)
                        return args.Result;
                }

                var data = CreateData();
                data["action"] = action;
                data["query"] = query != null ? query.ToServiceObject() : null;
                data["parent"] = parent != null ? parent.ToServiceObject() : null;
                data["selectedItems"] = selectedItems != null ? JArray.FromObject(selectedItems.Select(i => i != null ? i.ToServiceObject() : null)) : null;
                data["parameters"] = parameters != null ? JToken.FromObject(parameters) : null;

                var response = await PostAsync("ExecuteAction", data);

                var ex = (string)response["exception"] ?? (string)response["ExceptionMessage"];
                if (!string.IsNullOrEmpty(ex))
                {
                    if (isObjectAction)
                        parent.SetNotification(ex);
                    else
                        query.SetNotification(ex);

                    return null;
                }

                AuthToken = (string)response["authToken"];
                await UpdateSession(response);

                var jPo = (JObject)response["result"];
                return jPo != null ? Hooks.OnConstruct(jPo) : null;
            }
            catch (Exception e)
            {
                if (isObjectAction)
                    parent.SetNotification(e.Message);
                else
                    query.SetNotification(e.Message);

                return null;
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #15
0
        public async Task<Tuple<Stream, string>> GetStreamAsync(PersistentObject registeredStream) //, string action = null, PersistentObject parent = null, Query query = null, QueryResultItem[] selectedItems = null, Dictionary<string, string> parameters = null)
        {
            try
            {
                IsBusy = true;

                var data = CreateData();
                if (registeredStream != null)
                    data["id"] = registeredStream.ObjectId;

                var req = new MultipartFormDataContent("VidyanoBoundary");
                req.Add(new StringContent(data.ToString(Formatting.None)), "data");

                var responseMsg = await httpClient.PostAsync(new Uri(Uri) + "GetStream", req);

                var stream = await responseMsg.Content.ReadAsStreamAsync();
                return Tuple.Create(stream, responseMsg.Content.Headers.ContentDisposition.FileName ?? responseMsg.Content.Headers.ContentDisposition.FileNameStar);
            }
            finally
            {
                IsBusy = false;
            }
        }
 internal ReceivePersistentObjectArgs(PersistentObject obj)
 {
     PersistentObject = obj;
 }
        internal PersistentObjectAttributeWithReference(Client client, JObject model, PersistentObject parent)
            : base(client, model, parent)
        {
            propertiesToBackup = new[] { "value", "isReadOnly", "isValueChanged", "options", "objectId", "validationError" };

            var lookup = (JObject)model["lookup"];

            if (lookup != null)
            {
                Lookup = client.Hooks.OnConstruct(client, lookup, parent, false);
            }
        }
Exemple #18
0
        internal Query(Client client, JObject model, PersistentObject parent = null, bool asLookup = false)
            : base(client, model)
        {
            Parent   = parent;
            AsLookup = asLookup;

            var po = (JObject)model["persistentObject"];

            if (po != null)
            {
                PersistentObject = client.Hooks.OnConstruct(client, po);
            }

            if (model.TryGetValue("columns", out var columnsToken))
            {
                var columns = (JArray)columnsToken;
                Columns = columns.Select(jCol => new QueryColumn((JObject)jCol, this)).ToArray();
            }
            else
            {
                Columns = new QueryColumn[0];
            }

            if (model.TryGetValue("actions", out var actionsToken))
            {
                var actions = ActionBase.GetActions(client, actionsToken, parent, this);
                CanFilter = actions.Any(a => a.Name == "Filter");

                Actions       = actions.Where(a => !a.IsPinned).OfType <QueryAction>().ToArray();
                PinnedActions = actions.Where(a => a.IsPinned).OfType <QueryAction>().ToArray();
            }
            else
            {
                PinnedActions = Actions = new QueryAction[0];
            }

            var newAction = Actions.OfType <New>().FirstOrDefault();
            var addAction = Actions.FirstOrDefault(a => a.Name == "AddReference");

            if (newAction != null && addAction != null)
            {
                Actions = EnumerableEx.Return(new AddAndNewAction(newAction, addAction)).Concat(Actions).ToArray();
            }

            var result = (JObject)model["result"];

            if (result != null)
            {
                SetResult(result);
                model.Remove("result");
            }

            if (model["isZoomedIn"] == null)
            {
                IsZoomedIn = true;
            }

            SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
            HasTextSearch   = !string.IsNullOrEmpty(TextSearch);
            HasNotification = !string.IsNullOrWhiteSpace(Notification);

            client.Hooks.OnConstruct(this);
        }
Exemple #19
0
 internal override void OnOpen(PersistentObject po)
 {
     OnOpen(po as PhonePersistentObject);
 }
Exemple #20
0
 protected virtual PersistentObjectTabAttributes CreateAttributesTab(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
 {
     return(new PersistentObjectTabAttributes(attributes, title, parent));
 }
Exemple #21
0
 internal override Query OnConstruct(JObject model, PersistentObject parent, bool asLookup)
 {
     return new PhoneQuery(model, parent, asLookup);
 }
Exemple #22
0
        public async Task RefreshFromResult(PersistentObject result)
        {
            SetNotification(result.Notification, result.NotificationType);

            if (Attributes != null && result.Attributes != null)
            {
                foreach (var attr in Attributes)
                {
                    var serviceAttribute = result.Attributes.FirstOrDefault(a => a.Id == attr.Id);
                    if (serviceAttribute != null)
                    {
                        attr.OptionsDirect = serviceAttribute.OptionsDirect;
                        attr.IsReadOnly    = serviceAttribute.IsReadOnly;
                        attr.IsRequired    = serviceAttribute.IsRequired;

                        if (attr.IsVisible != serviceAttribute.IsVisible)
                        {
                            attr.Visibility = serviceAttribute.Visibility;
                        }

                        attr.ValueDirect = serviceAttribute.ValueDirect;
                        var attrWithRef        = attr as PersistentObjectAttributeWithReference;
                        var serviceAttrWithRef = serviceAttribute as PersistentObjectAttributeWithReference;
                        if (attrWithRef != null && serviceAttrWithRef != null)
                        {
                            attrWithRef.ObjectId = serviceAttrWithRef.ObjectId;
                        }

                        var attrAsDetail        = attr as PersistentObjectAttributeAsDetail;
                        var serviceAttrAsDetail = serviceAttribute as PersistentObjectAttributeAsDetail;
                        if (attrAsDetail != null && serviceAttrAsDetail != null)
                        {
                            attrAsDetail.Objects = serviceAttrAsDetail.Objects != null
                                ? serviceAttrAsDetail.Objects.Select(obj =>
                            {
                                obj.Parent = this;
                                obj.OwnerDetailAttribute = attrAsDetail;
                                obj.IsInEdit             = IsInEdit;
                                return(obj);
                            }).ToArray()
                                : new PersistentObject[0];
                        }

                        attr.TriggersRefresh = serviceAttribute.TriggersRefresh;
                        attr.IsValueChanged  = serviceAttribute.IsValueChanged;
                        attr.ValidationError = serviceAttribute.ValidationError;
                    }
                }

                if (IsNew)
                {
                    ObjectId = result.ObjectId;
                    IsNew    = result.IsNew;
                }

                SecurityToken = result.SecurityToken;
                IsDirty       = Attributes.Any(a => a.IsValueChanged);

                if (result.Breadcrumb != null)
                {
                    Breadcrumb = result.Breadcrumb;
                }

                if (result.QueriesToRefresh != null && Queries != null)
                {
                    foreach (var id in result.QueriesToRefresh)
                    {
                        Query query = null;

                        if (Guid.TryParse(id, out var guid))
                        {
                            query = Queries.FirstOrDefault(q => q.Value.Id == id).Value;
                        }

                        if (query == null)
                        {
                            query = Queries[id];
                        }

                        if (query != null && query.HasSearched)
                        {
                            await query.RefreshQueryAsync().ConfigureAwait(false);
                        }
                    }
                }
            }
        }
Exemple #23
0
 protected internal virtual void OnSessionUpdated(PersistentObject session)
 {
 }
Exemple #24
0
 internal PersistentObjectTabAttributes(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     : base(title, parent)
 {
     Attributes = attributes;
     Groups     = Attributes.Where(a => a.IsVisible).GroupBy(a => a.Group).Select(g => g.Key).ToArray();
 }
Exemple #25
0
 internal virtual void OnConstruct(PersistentObject po)
 {
 }
 protected override PersistentObjectTabAttributes CreateAttributesTab(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
 {
     return new PhonePersistentObjectTabAttributes(this, attributes, title, parent);
 }
Exemple #27
0
 internal PhoneQuery(JObject model, PersistentObject parent, bool asLookup)
     : base(model, parent, asLookup)
 {
     ContextMenuActions = new List<ActionBase>(Actions.Where(a => a.HasSelectionRule));
     ContextMenuActions.AddRange(PinnedActions.Where(a => a.HasSelectionRule));
 }
 public PhonePersistentObjectTabAttributes(PhonePersistentObject phoneParent, PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     : base(attributes, title, parent)
 {
     this.phoneParent = phoneParent;
 }
        public async Task RefreshFromResult(PersistentObject result)
        {
            SetNotification(result.Notification, result.NotificationType);

            if (Attributes != null && result.Attributes != null)
            {
                foreach (var attr in Attributes)
                {
                    var serviceAttribute = result.Attributes.FirstOrDefault(a => a.Id == attr.Id);
                    if (serviceAttribute != null)
                    {
                        attr.OptionsDirect = serviceAttribute.OptionsDirect;
                        attr.IsReadOnly = serviceAttribute.IsReadOnly;
                        attr.IsRequired = serviceAttribute.IsRequired;

                        if (attr.IsVisible != serviceAttribute.IsVisible)
                            attr.Visibility = serviceAttribute.Visibility;

                        attr.ValueDirect = serviceAttribute.ValueDirect;
                        var attrWithRef = attr as PersistentObjectAttributeWithReference;
                        var serviceAttrWithRef = serviceAttribute as PersistentObjectAttributeWithReference;
                        if (attrWithRef != null && serviceAttrWithRef != null)
                            attrWithRef.ObjectId = serviceAttrWithRef.ObjectId;

                        attr.TriggersRefresh = serviceAttribute.TriggersRefresh;
                        attr.IsValueChanged = serviceAttribute.IsValueChanged;
                        attr.ValidationError = serviceAttribute.ValidationError;
                    }
                }

                if (IsNew)
                {
                    ObjectId = result.ObjectId;
                    IsNew = result.IsNew;
                }

                SecurityToken = result.SecurityToken;
                IsDirty = Attributes.Any(a => a.IsValueChanged);

                if (result.Breadcrumb != null)
                    Breadcrumb = result.Breadcrumb;

                if (result.QueriesToRefresh != null && Queries != null)
                {
                    foreach (var id in result.QueriesToRefresh)
                    {
                        Query query = null;

                        Guid guid;
                        if (Guid.TryParse(id, out guid))
                            query = Queries.FirstOrDefault(q => q.Value.Id == id).Value;

                        if (query == null)
                            query = Queries[id];

                        if (query != null && query.HasSearched)
                            await query.RefreshQueryAsync();
                    }
                }
            }
        }
Exemple #30
0
 internal override void OnOpen(PersistentObject po)
 {
     ((Frame)Window.Current.Content).Navigate(typeof(PersistentObjectPage), Client.CurrentClient.AddCachedObject(po));
 }