Ejemplo n.º 1
0
        public ApiCollectionModel(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection)
            : base(mainWindow, parent, apiCollection)
        {
            Model = apiCollection;

            if (apiCollection.Items != null)
                Items.AddRange(apiCollection.Items.Select(x => x.Type == ApiItemType.Collection ?
                    (ApiItemModel)new ApiCollectionModel(mainWindow, this, (ApiCollection)x) :
                    new ApiModel(mainWindow, this, (Api)x)));

            Items.SetUpSync(
                MainWindow.Repository,
                Model.Items,
                x => x.ItemModel);
        }
Ejemplo n.º 2
0
        public ApiCollectionModel(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection) : base(mainWindow, parent, apiCollection)
        {
            Model = apiCollection;

            if (apiCollection.Items != null)
            {
                Items.AddRange(apiCollection.Items.Select(x => x.Type == ApiItemType.Collection ?
                                                          (ApiItemModel) new ApiCollectionModel(mainWindow, this, (ApiCollection)x) :
                                                          new ApiModel(mainWindow, this, (Api)x)));
            }

            Items.SetUpSync(
                MainWindow.Repository,
                Model.Items,
                x => x.ItemModel);
        }
Ejemplo n.º 3
0
 public static ApiItemModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, ApiItem item)
 {
     ApiItemModel result;
     switch (item.Type)
     {
         case ApiItemType.Api:
             result = ApiModel.Import(mainWindow, parent, (Api)item);
             break;
         case ApiItemType.Collection:
             result = ApiCollectionModel.Import(mainWindow, parent, (ApiCollection)item);
             break;
         default:
             throw new Exception();
     }
     return result;
 }
Ejemplo n.º 4
0
        public static ApiItemModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, ApiItem item)
        {
            ApiItemModel result;

            switch (item.Type)
            {
            case ApiItemType.Api:
                result = ApiModel.Import(mainWindow, parent, (Api)item);
                break;

            case ApiItemType.Collection:
                result = ApiCollectionModel.Import(mainWindow, parent, (ApiCollection)item);
                break;

            default:
                throw new Exception();
            }
            return(result);
        }
Ejemplo n.º 5
0
        protected ApiItemModel(MainWindowModel mainWindow, ApiCollectionModel parent, ApiItem item)
        {
            MainWindow = mainWindow;
            Parent = parent;
            ItemModel = item;
            Items = new RxList<ApiItemModel>();

            this.ObservePropertyChange(x => x.IsSelected).Subscribe(x =>
            {
                if (x)
                {
                    var current = Parent;
                    while (current != null)
                    {
                        current.IsExpanded = true;
                        current = current.Parent;
                    }
                    MainWindow.SelectedItem = this;
                }
            });
        }
Ejemplo n.º 6
0
        protected ApiItemModel(MainWindowModel mainWindow, ApiCollectionModel parent, ApiItem item)
        {
            MainWindow = mainWindow;
            Parent     = parent;
            ItemModel  = item;
            Items      = new RxList <ApiItemModel>();

            this.ObservePropertyChange(x => x.IsSelected).Subscribe(x =>
            {
                if (x)
                {
                    var current = Parent;
                    while (current != null)
                    {
                        current.IsExpanded = true;
                        current            = current.Parent;
                    }
                    MainWindow.SelectedItem = this;
                }
            });
        }
Ejemplo n.º 7
0
        public ApiModel(MainWindowModel mainWindow, ApiCollectionModel parent, Api api) : base(mainWindow, parent, api)
        {
            Inputs  = new RxList <ApiInputModel>();
            Outputs = new RxList <ApiOutputModel>();
            Headers = new RxList <ApiHeaderModel>();

            SubscribeForInputs(this.ObservePropertyChange(x => x.Model.Url), () => Model.Url, ApiInputType.Url);
            SubscribeForInputs(this.ObservePropertyChange(x => x.Model.Body).Where(x => ContentTypes.IsText(ContentType)), () => Model.Body, ApiInputType.Body);
            SubscribeForInputs(this.ObservePropertyChange(x => x.Headers).SelectMany(x => x.ObserveElementProperty(y => y.Name)).Merge(this.ObservePropertyChange(x => x.Headers).SelectMany(x => x.ObserveElementProperty(y => y.Value))), () => string.Join("\n", Headers.Select(x => x.Name + "=" + x.Value)), ApiInputType.Header);

            Model = api;
            if (api.Inputs != null)
            {
                Inputs.AddRange(api.Inputs.Select(x => new ApiInputModel
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    DefaultValue = x.DefaultValue,
                    InputType    = x.InputType
                }));
            }
            if (api.Outputs != null)
            {
                Outputs.AddRange(api.Outputs.Select(x => new ApiOutputModel
                {
                    Id         = x.Id,
                    Name       = x.Name,
                    Expression = x.Expression,
                    Type       = x.Type
                }));
            }
            if (api.Headers != null)
            {
                Headers.AddRange(api.Headers.Select(x => new ApiHeaderModel
                {
                    Id    = x.Id,
                    Name  = x.Name,
                    Value = x.Value
                }));
            }
            Send  = RxCommand.CreateAsync(OnSend);
            Reset = RxCommand.Create(OnReset);

            Inputs.SetUpSync(
                MainWindow.Repository,
                Model.Inputs,
                x => new ApiInput {
                Name = x.Name, DefaultValue = "", InputType = x.InputType
            });
            Outputs.SetUpSync(
                MainWindow.Repository,
                Model.Outputs,
                x => new ApiOutput {
                Name = x.Name, Expression = ""
            });
            Headers.SetUpSync(
                MainWindow.Repository,
                Model.Headers,
                _ => new ApiHeader {
                Name = "", Value = ""
            });
        }
Ejemplo n.º 8
0
 public static ApiModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, Api api)
 {
     return(new ApiModel(mainWindow, parent, api));
 }
Ejemplo n.º 9
0
 public static ApiCollectionModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection)
 {
     return new ApiCollectionModel(mainWindow, parent, apiCollection);
 }