Esempio n. 1
0
        private static Action <object> MakeCallback(EditGistController ctrl, string key)
        {
            var weakCtrl = new WeakReference <EditGistController>(ctrl);

            return(new Action <object>(_ =>
            {
                var model = weakCtrl.Get()?._model;
                if (model == null || !model.Files.ContainsKey(key))
                {
                    return;
                }

                var originalGist = weakCtrl.Get()?._originalGist;

                var createController = new ModifyGistFileController(key, model.Files[key].Content);
                createController.Save = (name, content) =>
                {
                    if (string.IsNullOrEmpty(name))
                    {
                        throw new InvalidOperationException("Please enter a name for the file");
                    }

                    //If different name & exists somewhere else
                    if (!name.Equals(key))
                    {
                        if (weakCtrl.Get()?.IsDuplicateName(name) == true)
                        {
                            throw new InvalidOperationException("A filename by that type already exists");
                        }
                    }

                    if (originalGist?.Files.ContainsKey(key) == true)
                    {
                        model.Files[key] = new GistEditModel.File {
                            Content = content, Filename = name
                        }
                    }
                    ;
                    else
                    {
                        model.Files.Remove(key);
                        model.Files[name] = new GistEditModel.File {
                            Content = content
                        };
                    }
                };

                weakCtrl.Get()?.NavigationController.PushViewController(createController, true);
            }));
        }
Esempio n. 2
0
        private void AddFile()
        {
            var createController = new ModifyGistFileController();

            createController.Save = (name, content) => {
                if (string.IsNullOrEmpty(name))
                {
                    name = GenerateName();
                }

                if (IsDuplicateName(name))
                {
                    throw new InvalidOperationException("A filename by that type already exists");
                }
                _model.Files[name] = new GistEditModel.File {
                    Content = content
                };
            };
            NavigationController.PushViewController(createController, true);
        }