Exemplo n.º 1
0
        /// <summary>
        /// Used by the generator to create a model for the service being generated
        /// </summary>
        /// <param name="serviceModelPath">Path to the file containing the model of the service</param>
        /// <param name="customizationModelPath">Path to the customizations file for the service</param>
        public ServiceModel(string serviceModelPath, string customizationModelPath)
        {
            using (var reader = new StreamReader(serviceModelPath))
                InitializeServiceModel(reader);

            this._customizationModel = new CustomizationsModel(customizationModelPath);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Used by the generator to create a model for the service being generated
 /// </summary>
 /// <param name="serviceModelPath">Path to the file containing the model of the service</param>
 /// <param name="customizationModelPath">Path to the customizations file for the service</param>
 /// /// <param name="servicePaginatorsPath">Path to the customizations file for the service</param>
 public ServiceModel(string serviceModelPath, string customizationModelPath, string servicePaginatorsPath)
 {
     using (var reader = new StreamReader(serviceModelPath))
     {
         InitializeServiceModel(reader);
     }
     if (File.Exists(servicePaginatorsPath))
     {
         using (var reader = new StreamReader(servicePaginatorsPath))
             InitializePaginators(reader);
     }
     this._customizationModel = new CustomizationsModel(customizationModelPath);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Used for unit testing, creates a service model from a TextReader so that the generation can be checked
 /// </summary>
 /// <param name="serviceModelReader">The reader to get the model information from</param>
 /// <param name="customizationReader">The reader to get any customizations for the service from</param>
 public ServiceModel(TextReader serviceModelReader, TextReader customizationReader)
 {
     InitializeServiceModel(serviceModelReader);
     this._customizationModel = new CustomizationsModel(customizationReader);
 }
Exemplo n.º 4
0
        public ActionResult HomePageCustomize(HomePageCustomizeModel model)
        {
            this.CheckUser();
            Guid homePageGuid = typeof(HomePageCustomizeModel).GUID;

            if (!ViewBag.IsAdmin)
            {
                ViewBag.Message = "You do not have admin permission";
            }
            else
            {
                var context = this.HttpContext.GetOwinContext();
                var db      = context.Get <ApplicationDbContext>();
                if (ModelState.IsValid)
                {
                    try
                    {
                        int iconsUpdated = 0;
                        foreach (string name in Request.Files)
                        {
                            HttpPostedFileBase upload   = Request.Files.Get(name);
                            string             filename = upload.FileName;
                            byte[]             data     = CustomizationBlobs.ReadToEnd(upload.InputStream);
                            if (!string.IsNullOrEmpty(filename) && data.Length > 0)
                            {
                                CustomizationBlobs.UpdateBlob(name, data);

                                if (name == "FileIcon1")
                                {
                                    model.IconUrl1 = filename;
                                }
                                else if (name == "FileIcon2")
                                {
                                    model.IconUrl2 = filename;
                                }
                                iconsUpdated++;
                            }
                        }

                        CustomizationBlobs.UpdateCustomizationJson <HomePageCustomizeModel>("HomePageJson", model);
                        var homePageCustomizations = (from i in db.Customizations where i.Id == homePageGuid select i).FirstOrDefault();
                        if (homePageCustomizations == null)
                        {
                            homePageCustomizations = new CustomizationsModel()
                            {
                                Id = homePageGuid
                            };
                            db.Customizations.Add(homePageCustomizations);
                        }
                        homePageCustomizations.JsonBlobId = "HomePageJson";
                        int    count  = db.SaveChanges();
                        string suffix = "";
                        switch (iconsUpdated)
                        {
                        case 0:
                            suffix = " but not the icons";
                            break;

                        case 1:
                            suffix = " and one of the icons";
                            break;

                        case 2:
                            suffix = " and both icons";
                            break;

                        default:
                            break;
                        }
                        ViewBag.Message = "Updated home page customizations" + suffix;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "Error: " + ex.Message;
                    }
                }
                else
                {
                    // populate existing data into the form
                    var homePageCustomizations = (from i in db.Customizations where i.Id == homePageGuid select i).FirstOrDefault();
                    if (homePageCustomizations != null)
                    {
                        string blobMame = homePageCustomizations.JsonBlobId;
                        HomePageCustomizeModel existing = CustomizationBlobs.GetCustomizationJson <HomePageCustomizeModel>(blobMame);
                        if (existing != null)
                        {
                            model.CopyFrom(existing);
                        }
                    }
                }
            }
            return(View(model));
        }