コード例 #1
0
ファイル: ApiCollectionModel.cs プロジェクト: kswoll/restless
        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);
        }
コード例 #2
0
ファイル: ApiCollectionModel.cs プロジェクト: kswoll/restless
        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);
        }
コード例 #3
0
ファイル: ApiItemModel.cs プロジェクト: kswoll/restless
 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;
 }
コード例 #4
0
ファイル: ApiItemModel.cs プロジェクト: kswoll/restless
        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);
        }
コード例 #5
0
ファイル: ApiItemModel.cs プロジェクト: kswoll/restless
        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;
                }
            });
        }
コード例 #6
0
ファイル: ApiItemModel.cs プロジェクト: kswoll/restless
        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;
                }
            });
        }
コード例 #7
0
        private async Task <ApiCollectionModel> OnAddApiCollection(ApiCollectionModel parent)
        {
            var apiCollection = ApiCollection.Create();

            if (parent == null)
            {
                await Repository.AddItem(apiCollection);
            }

            var model = new ApiCollectionModel(this, parent, apiCollection);

            if (parent == null)
            {
                Items.Add(model);
            }
            else
            {
                parent.Items.Add(model);
            }

            SelectedItem = model;

            return(model);
        }
コード例 #8
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 = ""
            });
        }
コード例 #9
0
 public static ApiModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, Api api)
 {
     return(new ApiModel(mainWindow, parent, api));
 }
コード例 #10
0
ファイル: MainWindowModel.cs プロジェクト: kswoll/restless
        private async Task<ApiModel> OnAddApi(ApiCollectionModel parent)
        {
            var api = Api.Create();
            if (parent == null)
                await Repository.AddItem(api);

            var model = new ApiModel(this, parent, api);
            if (parent == null)
                Items.Add(model);
            else
                parent.Items.Add(model);

            SelectedItem = model;

            return model;
        }
コード例 #11
0
ファイル: ApiCollectionModel.cs プロジェクト: kswoll/restless
 public static ApiCollectionModel Import(MainWindowModel mainWindow, ApiCollectionModel parent, ApiCollection apiCollection)
 {
     return new ApiCollectionModel(mainWindow, parent, apiCollection);
 }