Ejemplo n.º 1
0
        public ActionResult Create(ImportBatchesViewModelItem model)
        {
            model.ValidateEntry(db, ModelState);
            if (ModelState.IsValid)
            {
                if (model.Current)
                {
                    if (model.Current)
                    {
                        ImportBatch currentBatch = db.ImportBatches.FirstOrDefault(x => x.Current);
                        if (currentBatch != null)
                        {
                            currentBatch.Current         = false;
                            db.Entry(currentBatch).State = EntityState.Modified;
                        }
                    }
                }

                var item = model.ToEntity();
                db.ImportBatches.Add(item);
                db.SaveChanges();
                ShowGenericSavedMessage();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <bool> BatchImport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            OpenFolderDialog ofd = new OpenFolderDialog();

            ofd.Title = "Select import directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                ImportBatch            dialog     = new ImportBatch(workspace, selection, dir, ".png");
                List <ImportBatchInfo> batchInfos = await dialog.ShowDialog <List <ImportBatchInfo> >(win);

                foreach (ImportBatchInfo batchInfo in batchInfos)
                {
                    AssetContainer cont = batchInfo.cont;

                    AssetTypeValueField baseField = workspace.GetBaseField(cont);

                    string file = batchInfo.importFile;

                    byte[] byteData = File.ReadAllBytes(file);
                    baseField.Get("m_Script").GetValue().Set(byteData);

                    byte[] savedAsset = baseField.WriteToByteArray();

                    var replacer = new AssetsReplacerFromMemory(
                        0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                    workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                }
                return(true);
            }
            return(false);
        }
        public static ImportBatch ToEntity(this ImportBatchesViewModelItem model)
        {
            var item = new ImportBatch
            {
                ImportBatchId   = model.ImportBatchId,
                ImportBatchName = model.ImportBatchName,
                Current         = model.Current
            };

            return(item);
        }
Ejemplo n.º 4
0
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            for (int i = 0; i < selection.Count; i++)
            {
                selection[i] = new AssetContainer(selection[i], TextureHelper.GetByteArrayTexture(workspace, selection[i]));
            }

            OpenFolderDialog ofd = new OpenFolderDialog();

            ofd.Title = "Select import directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                ImportBatch            dialog     = new ImportBatch(workspace, selection, dir, ".png");
                List <ImportBatchInfo> batchInfos = await dialog.ShowDialog <List <ImportBatchInfo> >(win);

                bool success = await ImportTextures(win, batchInfos);

                if (success)
                {
                    //some of the assets may not get modified, but
                    //uabe still makes replacers for those anyway
                    foreach (AssetContainer cont in selection)
                    {
                        byte[] savedAsset = cont.TypeInstance.WriteToByteArray();

                        var replacer = new AssetsReplacerFromMemory(
                            0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                        workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        public PDFBatchImporterViewModel()
        {
            Manager.Context.Piece.Load();
            AllPieces = Manager.Context.Piece.Local.ToObservableCollection();

            Manager.Context.Part.Load();
            AllParts = Manager.Context.Part.Local.ToObservableCollection();

            Batch = new ImportBatch(new ImportCandidateImporter(Manager));

            OpenFileCommand = new DelegateCommand(executeOpenFileCommand, canExecuteOpenFileCommand);
            ImportCommand   = new DelegateCommand(executeImportCommand, canExecuteImportCommand);
            AssignCommand   = new DelegateCommand(executeAssignCommand, canExecuteAssignCommand);

            DeleteSelectedImportCandidateCommand = new DelegateCommand(executeDelteSelectedImportCandidateCommand, canExecuteDeleteSelectedImportCandidateCommand);
            DeleteSelectedImportPageCommand      = new DelegateCommand(executeDeleteSelectedImportPageCommand, canExecuteDeleteSelectedImportPageCommand);
            OpenDocumentInExplorerCommand        = new DelegateCommand(executeOpenDocumentInExplorerCommand, canExecuteOpenDocumentInExplorerCommand);
            SplitImportCandidateOnPage           = new DelegateCommand(executeSplitImportCandidateOnPage, canExecuteSplitImportCandidateOnPage);

            TakeoverAssignedPiece = true;
        }