コード例 #1
0
        public ActionResult Upload(HttpPostedFileBase fileToUpload, PluginModel plugin)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Entities db = new Entities();

                    //Get the selected group from the database using the groupId
                    Group uploadGroup = db.Groups.Single(g => g.GroupId == plugin.selectedGroupId);

                    string generated = Guid.NewGuid().ToString();
                    Plugin toUpload = new Plugin()
                    {
                        PluginName = plugin.nameOfUpload,
                        PluginGenerated = generated
                    };
                    uploadGroup.Plugins.Add(toUpload);
                    db.SaveChanges();

                    //xsd.exe requires a '.xml' on the end of the file
                    string filePath = Path.Combine(Server.MapPath("~/Groups/" + plugin.selectedGroupId + "/Plugins"), toUpload.PluginGenerated + ".xml");

                    if (fileToUpload != null)
                    {
                        if (System.IO.File.Exists(filePath))
                        {
                            return RedirectToAction("Upload", "Plugin", new { Message = UploadMessageId.PluginExistsError });
                        }
                        else
                        {
                            try
                            {
                                fileToUpload.SaveAs(filePath);
                            }
                            catch
                            {
                                return RedirectToAction("Upload", "Plugin", new { Message = UploadMessageId.PluginPathError });
                            }
                        }
                        //update the database with successful upload
                        //Load XML into cs file
                        CreateCSFile(filePath);
                        TempData["csLoc"] = filePath.Replace(".xml", ".cs");
                        //present class to user without attributes
                        DynamicPlugin output = CreateDynamicPluginObject(filePath.Replace(".xml", ".cs"));
                        output.PluginId = toUpload.PluginID;
                        return View("VerifyPlugin", output);
                    }
                }
                catch (Exception)
                {
                    return RedirectToAction("Upload", "Plugin", new { Message = UploadMessageId.UploadPluginFailure });
                }
            }

            //Something is wrong if code execution goes past the try/catch statement.

            return View(plugin);
        }
コード例 #2
0
        public ActionResult Upload(UploadMessageId? message)
        {
            //Cookie cutter from Controllers/AccountControlller.cs, just changed to work with plugins.
            //Question mark is to allow for null values.
            //Good description here http://stackoverflow.com/questions/446835/what-do-two-question-marks-together-mean-in-c
            ViewBag.StatusMessage =
            message == UploadMessageId.UploadPluginSuccess ? "Your Plugin has successfully been uploaded."
            : message == UploadMessageId.UploadPluginFailure ? "Your Plugin was not successfully uploaded."
            : message == UploadMessageId.PluginPathError ? "Your Plugin was not moved to the server."
            : message == UploadMessageId.PluginExistsError ? "The plugin you selected already exists."
            : message == UploadMessageId.UserNotFound ? "Could not verify ID. Plugin not uploaded."
            : "";

            ViewBag.StatusFailure =
                message == UploadMessageId.PluginErrorMessage ? "There was an error uploading your plugin, please try again."
                : "";

            Entities db = new Entities();
            List<Group> groupsUserInArray;

            groupsUserInArray = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId).GroupsIn.ToList();

            var model = new PluginModel
            {
                uploadList = groupsUserInArray
            };

            return View(model);
        }