Beispiel #1
0
        /// <summary>
        /// Gets the site.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        /// <param name="returnInactive"></param>
        /// <returns></returns>
        public static SiteDto GetSite(Guid siteId, bool returnInactive)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CmsCache.CreateCacheKey("site", siteId.ToString());

            SiteDto dto = null;

            // check cache first
            object cachedObject = CmsCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (SiteDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                lock (CmsCache.GetLock(cacheKey))
                {
                    cachedObject = CmsCache.Get(cacheKey);
                    if (cachedObject != null)
                    {
                        dto = (SiteDto)cachedObject;
                    }
                    else
                    {
                        SiteAdmin admin = new SiteAdmin();
                        admin.Load(siteId, returnInactive);
                        dto = admin.CurrentDto;

                        // Insert to the cache collection
                        CmsCache.Insert(cacheKey, dto, CmsConfiguration.Instance.Cache.SitesCollectionTimeout);
                    }
                }
            }

            // Continue with security checks and other operations

            /*
             * foreach (SiteDto.SiteRow row in dto.Site.Rows)
             * {
             *  // Check Security
             *  IDataReader reader = DataHelper.CreateDataReader(dto.SiteSecurity, String.Format("SiteId = '{0}' or SiteId = '{1}'", Guid.Empty, row.SiteId));
             *  PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader));
             *  if (!PermissionManager.CheckPermission(SecurityScope.Site.ToString(), Permission.Read, recordSet))
             *  {
             *      row.Delete();
             *      continue;
             *  }
             * }
             * */

            if (dto.HasChanges())
            {
                dto.AcceptChanges();
            }

            return(dto);
        }
        public override void Execute()
        {
            WriteLiteral("\r\n\r\n");



            #line 4 "..\..\packages\_pagestart.cshtml"

            if (!PackageManagerModule.InitPackageSourceFile())
            {
                var instructionsPath = VirtualPathUtility.ToAbsolute(PageUtils.GetPageVirtualPath("SourceFileInstructions"));
                if (!Request.FilePath.Equals(instructionsPath, StringComparison.OrdinalIgnoreCase))
                {
                    Response.Redirect(instructionsPath);
                }
            }
            Layout            = "_Layout.cshtml";
            PageData["Title"] = PackageManagerResources.ModuleTitle;
            string packagesVirutalPath = SiteAdmin.GetVirtualPath("~/packages");
            PageData["BreadCrumbs"].Add(Tuple.Create(PackageManagerResources.ModuleTitle, Href(packagesVirutalPath)));


            #line default
            #line hidden
        }
        public void GetAdminVirtualPathDoesNotAppendAdminVirtualPathIfPathStartsWithAdminVirtualPath()
        {
            // Act
            string vpath = SiteAdmin.GetVirtualPath("~/_Admin/Foo");

            // Assert
            Assert.Equal("~/_Admin/Foo", vpath);
        }
        public void GetAdminVirtualPathAppendsAdminVirtualPath()
        {
            // Act
            string vpath = SiteAdmin.GetVirtualPath("~/Foo");

            // Assert
            Assert.Equal("~/_Admin/Foo", vpath);
        }
Beispiel #5
0
        public virtual string AddSite(StatsSite site)
        {
            // generate unique SiteID
            //int iSiteId = site.Name.GetHashCode();
            //if (iSiteId < 0)
            //     iSiteId *= -1;

            //string siteId = iSiteId.ToString();

            // create logs folder if not exists
            //if (!FileUtils.DirectoryExists(site.LogDirectory))
            //    FileUtils.CreateDirectory(site.LogDirectory);

            // add site
            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            if (site.Users == null || site.Users.Length == 0)
            {
                throw new Exception("At least one user (site owner) should be specified when creating new statistics site");
            }

            string         ownerUsername = site.Users[0].Username.ToLower();
            GenericResult1 result        = stAdmin.AddSite(Username, Password,
                                                           site.Users[0].Username, site.Users[0].Password, site.Users[0].FirstName, site.Users[0].LastName,
                                                           ServerId, 0, site.Name, site.LogDirectory, LogFormat, LogWildcard, LogDeleteDays,
                                                           SmarterLogsPath, SmarterLogDeleteMonths, "", "", TimeZoneId);

            if (!result.Result)
            {
                throw new Exception("Error creating statistics site: " + result.Message);
            }

            string siteId = GetSiteId(site.Name);

            int iSiteId = Int32.Parse(siteId);

            // add other users
            UserAdmin usrAdmin = new UserAdmin();

            PrepareProxy(usrAdmin);
            foreach (StatsUser user in site.Users)
            {
                if (user.Username.ToLower() != ownerUsername)
                {
                    // add user
                    GenericResult2 r = usrAdmin.AddUser(Username, Password, iSiteId,
                                                        user.Username, user.Password, user.FirstName, user.LastName, user.IsAdmin);
                    if (!r.Result)
                    {
                        throw new Exception("Error adding site user: " + r.Message);
                    }
                }
            }

            return(siteId);
        }
        public static void Start()
        {
            SiteAdmin.Register("~/Rabbit/", "Rabbit Framework Admin",
                               "Administrative Tools to manage modules, to generate code and to run unit tests.");

            var appPart = new ApplicationPart(typeof(PreApplicationStartCode).Assembly,
                                              SiteAdmin.GetVirtualPath("~/Rabbit/"));

            ApplicationPart.Register(appPart);

            SiteEngine.Start();
        }
        public void GetReturnUrlThrowsIfReturnUrlIsNotAppRelative()
        {
            // Arrange
            var mockRequest = new Mock <HttpRequestBase>();
            var queryString = new NameValueCollection();

            queryString["ReturnUrl"] = "http://www.bing.com";
            mockRequest.Setup(m => m.QueryString).Returns(queryString);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => SiteAdmin.GetReturnUrl(mockRequest.Object), "The return URL specified for request redirection is invalid.");
        }
        public void GetReturnUrlReturnsNullIfNotSet()
        {
            // Arrange
            var mockRequest = new Mock <HttpRequestBase>();

            mockRequest.Setup(m => m.QueryString).Returns(new NameValueCollection());

            // Act
            string returlUrl = SiteAdmin.GetReturnUrl(mockRequest.Object);

            // Assert
            Assert.Null(returlUrl);
        }
        public void GetRedirectUrlAppendsAppRelativePathAsReturnUrl()
        {
            // Arrange
            var mockRequest = new Mock <HttpRequestBase>();

            mockRequest.Setup(m => m.RawUrl).Returns("~/_Admin/foo/bar/baz");
            mockRequest.Setup(m => m.QueryString).Returns(new NameValueCollection());

            // Act
            string redirectUrl = SiteAdmin.GetRedirectUrl(mockRequest.Object, "register", MakeAppRelative);

            // Assert
            Assert.Equal("~/_Admin/register?ReturnUrl=%7e%2f_Admin%2ffoo%2fbar%2fbaz", redirectUrl);
        }
        public void GetReturnUrlReturnsReturlUrlQueryStringParameterIfItIsAppRelative()
        {
            // Arrange
            var mockRequest = new Mock <HttpRequestBase>();
            var queryString = new NameValueCollection();

            queryString["ReturnUrl"] = "~/_Admin/bar?foo=1";
            mockRequest.Setup(m => m.QueryString).Returns(queryString);

            // Act
            string returnUrl = SiteAdmin.GetReturnUrl(mockRequest.Object);

            // Assert
            Assert.Equal("~/_Admin/bar?foo=1", returnUrl);
        }
Beispiel #11
0
        public virtual void DeleteSite(string siteId)
        {
            // delete site
            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            int sid = Int32.Parse(siteId);

            GenericResult1 result = stAdmin.DeleteSite(Username, Password, sid, true);

            if (!result.Result)
            {
                throw new Exception("Error deleting statistics site: " + result.Message);
            }
        }
        public override void Execute()
        {
            WriteLiteral("\r\n\r\n");


            WriteLiteral("\r\n");



            #line 5 "..\..\EnableInstructions.cshtml"

            Page.Title = AdminResources.SecurityTitle;

            if (AdminSecurity.HasAdminPassword())
            {
                SiteAdmin.RedirectToHome(Response);
                return;
            }

            string url = SiteAdmin.GetRedirectUrl(SiteAdmin.AdminVirtualPath);



            #line default
            #line hidden
            WriteLiteral("\r\n");



            #line 16 "..\..\EnableInstructions.cshtml"
            Write(Html.Raw(AdminResources.EnableInstructions));


            #line default
            #line hidden
            WriteLiteral("\r\n<br />\r\n<p>\r\n    ");



            #line 19 "..\..\EnableInstructions.cshtml"
            Write(Html.Raw(String.Format(CultureInfo.CurrentCulture, AdminResources.ContinueAfterEnableText, Html.Encode(Href(url)))));


            #line default
            #line hidden
            WriteLiteral("\r\n</p>\r\n\r\n");
        }
        public void GetRedirectUrlDoesNotAppendsAppRelativePathAsReturnUrlIfAlreadyExists()
        {
            // Arrange
            var mockRequest = new Mock <HttpRequestBase>();

            mockRequest.Setup(m => m.RawUrl).Returns("~/_Admin/foo/bar/baz?ReturnUrl=~/foo");
            var queryString = new NameValueCollection();

            queryString["ReturnUrl"] = "~/foo";
            mockRequest.Setup(m => m.QueryString).Returns(queryString);

            // Act
            string redirectUrl = SiteAdmin.GetRedirectUrl(mockRequest.Object, "register", MakeAppRelative);

            // Assert
            Assert.Equal("~/_Admin/register?ReturnUrl=%7e%2ffoo", redirectUrl);
        }
Beispiel #14
0
        /// <summary>
        /// 创建默认的商户管理员账号
        /// </summary>
        private void CreateDefaultAdmin(DbExecutor db, int siteId)
        {
            if (db.Exists <SiteAdmin>(t => t.SiteID == siteId))
            {
                return;
            }
            SiteAdmin admin = new SiteAdmin()
            {
                SiteID    = siteId,
                AdminName = "admin",
                Password  = Encryption.SHA1WithMD5("admin"),
                CreateAt  = DateTime.Now,
                IsDefault = true,
                Status    = SiteAdmin.AdminStatus.Normal
            };

            admin.Add(db);
        }
Beispiel #15
0
        /// <summary>
        /// Saves the site.
        /// </summary>
        /// <param name="dto">The dto.</param>
        public static void SaveSite(SiteDto dto)
        {
            /*
             * if (!ProfileConfiguration.Instance.EnablePermissions)
             * {
             *  if (!SecurityManager.CheckPermission(new string[] { CmsRoles.AdminRole }))
             *      return;
             * }
             * */

            if (dto == null)
            {
                throw new NullReferenceException(String.Format("SiteDto can not be null"));
            }

            SiteAdmin admin = new SiteAdmin(dto);

            admin.Save();
        }
Beispiel #16
0
        public virtual string[] GetSites()
        {
            List <string> sites = new List <string>();

            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            SiteInfoArrayResult result = stAdmin.GetAllSites(Username, Password, false);

            if (result.Sites == null)
            {
                return(sites.ToArray());
            }

            foreach (SiteInfo site in result.Sites)
            {
                sites.Add(site.DomainName);
            }

            return(sites.ToArray());
        }
Beispiel #17
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Login != null ? Login.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Id.GetHashCode();
         hashCode = (hashCode * 397) ^ (NodeId != null ? NodeId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AvatarUrl != null ? AvatarUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (GravatarId != null ? GravatarId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Url != null ? Url.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (FollowersUrl != null ? FollowersUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (FollowingUrl != null ? FollowingUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (GistsUrl != null ? GistsUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StarredUrl != null ? StarredUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SubscriptionsUrl != null ? SubscriptionsUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (OrganizationsUrl != null ? OrganizationsUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReposUrl != null ? ReposUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (EventsUrl != null ? EventsUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReceivedEventsUrl != null ? ReceivedEventsUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ SiteAdmin.GetHashCode();
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Company != null ? Company.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Blog != null ? Blog.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Location != null ? Location.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Email != null ? Email.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Hireable != null ? Hireable.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Bio != null ? Bio.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ PublicRepos.GetHashCode();
         hashCode = (hashCode * 397) ^ PublicGists.GetHashCode();
         hashCode = (hashCode * 397) ^ Followers.GetHashCode();
         hashCode = (hashCode * 397) ^ Following.GetHashCode();
         hashCode = (hashCode * 397) ^ CreatedAt.GetHashCode();
         hashCode = (hashCode * 397) ^ UpdatedAt.GetHashCode();
         return(hashCode);
     }
 }
Beispiel #18
0
        public virtual string GetSiteId(string siteName)
        {
            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            SiteInfoArrayResult result = stAdmin.GetAllSites(Username, Password, false);

            if (result.Sites == null)
            {
                return(null);
            }

            foreach (SiteInfo site in result.Sites)
            {
                if (String.Compare(siteName, site.DomainName, 0) == 0)
                {
                    return(site.SiteID.ToString());
                }
            }

            return(null);
        }
 public void GetAdminVirtualPathThrowsIfPathIsNull()
 {
     // Act & Assert
     Assert.ThrowsArgumentNull(() => SiteAdmin.GetVirtualPath(null), "virtualPath");
 }
 internal static string GetPackagesHome()
 {
     return(SiteAdmin.GetVirtualPath("~/packages"));
 }
 internal static string GetPageVirtualPath(string page)
 {
     return(SiteAdmin.GetVirtualPath("~/packages/" + page));
 }
Beispiel #22
0
 public async Task UpdateUserAsync(SiteAdmin siteAdmin)
 {
     _db.Update(siteAdmin);
     await _db.SaveChangesAsync();
 }
Beispiel #23
0
        public virtual void UpdateSite(StatsSite site)
        {
            // update site
            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            int siteId = Int32.Parse(site.SiteId);

            // get original site
            SiteInfoResult siteResult = stAdmin.GetSite(Username, Password, siteId);

            if (siteResult.Site == null)
            {
                return;
            }

            SiteInfo origSite = siteResult.Site;

            // update site with only required properties
            GenericResult1 result = stAdmin.UpdateSite(Username, Password, siteId, site.Name, origSite.LogDirectory,
                                                       origSite.LogFormat, origSite.LogWildcard, origSite.LogDaysBeforeDelete,
                                                       origSite.SmarterLogDirectory, origSite.SmarterLogMonthsBeforeDelete, origSite.ExportPath, origSite.ExportPathURL,
                                                       origSite.TimeZoneID);

            if (!result.Result)
            {
                throw new Exception("Error updating statistics site: " + result.Message);
            }

            // update site users
            UserAdmin usrAdmin = new UserAdmin();

            PrepareProxy(usrAdmin);

            // get original users
            if (site.Users != null)
            {
                List <string>       origUsers     = new List <string>();
                List <string>       newUsers      = new List <string>();
                string              ownerUsername = null;
                UserInfoResultArray usrResult     = usrAdmin.GetUsers(Username, Password, siteId);
                foreach (UserInfo user in usrResult.user)
                {
                    // add to original users
                    origUsers.Add(user.UserName.ToLower());

                    // remember owner (he can't be deleted)
                    if (user.IsSiteOwner)
                    {
                        ownerUsername = user.UserName.ToLower();
                    }
                }

                // add, update users
                foreach (StatsUser user in site.Users)
                {
                    if (!origUsers.Contains(user.Username.ToLower()))
                    {
                        // add user
                        GenericResult2 r = usrAdmin.AddUser(Username, Password, siteId,
                                                            user.Username, user.Password, user.FirstName, user.LastName, user.IsAdmin);
                        if (!r.Result)
                        {
                            throw new Exception("Error adding site user: "******"Error updating site user: " + r.Message);
                        }
                    }

                    // add to new users list
                    newUsers.Add(user.Username.ToLower());
                }

                // delete users
                foreach (string username in origUsers)
                {
                    if (!newUsers.Contains(username) && username != ownerUsername)
                    {
                        // delete user
                        GenericResult2 r = usrAdmin.DeleteUser(Username, Password, siteId, username);
                    }
                }
            }
        }
Beispiel #24
0
        public virtual StatsSite GetSite(string siteId)
        {
            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            int            sid    = Int32.Parse(siteId);
            SiteInfoResult result = stAdmin.GetSite(Username, Password, sid);

            if (result.Site == null)
            {
                return(null);
            }

            StatsSite site = new StatsSite();

            site.Name          = result.Site.DomainName;
            site.ExportPath    = result.Site.ExportPath;
            site.ExportPathUrl = result.Site.ExportPathURL;
            site.LogDirectory  = result.Site.LogDirectory;
            site.TimeZoneId    = TimeZoneId;
            site.Status        = result.Site.SiteStatus;

            // process stats URL
            string url = null;

            if (!String.IsNullOrEmpty(StatisticsUrl))
            {
                url = StringUtils.ReplaceStringVariable(StatisticsUrl, "domain_name", site.Name);
                url = StringUtils.ReplaceStringVariable(url, "site_id", siteId);
            }

            // get site users
            UserAdmin usrAdmin = new UserAdmin();

            PrepareProxy(usrAdmin);

            UserInfoResultArray usrResult = usrAdmin.GetUsers(Username, Password, sid);

            if (usrResult.user != null)
            {
                site.Users = new StatsUser[usrResult.user.Length];
                for (int i = 0; i < site.Users.Length; i++)
                {
                    site.Users[i]           = new StatsUser();
                    site.Users[i].Username  = usrResult.user[i].UserName;
                    site.Users[i].Password  = usrResult.user[i].Password;
                    site.Users[i].FirstName = usrResult.user[i].FirstName;
                    site.Users[i].LastName  = usrResult.user[i].LastName;
                    site.Users[i].IsAdmin   = usrResult.user[i].IsAdmin;
                    site.Users[i].IsOwner   = usrResult.user[i].IsSiteOwner;
                }

                if (site.Users.Length > 0 && !String.IsNullOrEmpty(url))
                {
                    url = StringUtils.ReplaceStringVariable(url, "username", site.Users[0].Username);
                    url = StringUtils.ReplaceStringVariable(url, "password", site.Users[0].Password);
                }
            }

            site.StatisticsUrl = url;

            return(site);
        }
        public override void Execute()
        {
            WriteLiteral("\r\n\r\n");



            WriteLiteral("\r\n");


            DefineSection("PackageHead", () => {
                WriteLiteral("\r\n    <script type=\"text/javascript\" src=\"");



            #line 7 "..\..\packages\Default.cshtml"
                Write(Href("scripts/Default.js"));


            #line default
            #line hidden
                WriteLiteral("\"></script>\r\n    <noscript>");



            #line 8 "..\..\packages\Default.cshtml"
                Write(PackageManagerResources.JavascriptRequired);


            #line default
            #line hidden
                WriteLiteral("</noscript>\r\n");
            });

            WriteLiteral("\r\n");



            #line 10 "..\..\packages\Default.cshtml"

            Page.SectionTitle = PackageManagerResources.SectionTitle;
            // Page Constants
            const int    PackagesPerPage  = 10;
            const string FilterCookieName = "packagesFilter";

            // Request parameters
            var view              = GetView(PageUtils.GetFilterValue(Request, FilterCookieName, "view"));
            var searchTerm        = Request.QueryString["search"];
            var packageSourceName = PageUtils.GetFilterValue(Request, FilterCookieName, "source");

            var packageSource = PageUtils.GetPackageSource(packageSourceName);

            PageUtils.PersistFilter(Response, FilterCookieName, new Dictionary <string, string> {
                { "view", view.ToString() },
                { "source", packageSourceName },
            });

            // Add values to ModelState
            ModelState.SetModelValue("view", view.ToString());

            WebProjectManager projectManager;
            WebGrid           grid;
            int totalPackages = 0;

            try {
                // This entire block needs ot be inside a try catch block. This is necessary because exceptions could be fired at two places
                // 1. When trying to connect to the remote repository. 2. When executing the Linq expression

                IEnumerable <IPackage> packages;

                projectManager = new WebProjectManager(packageSource.Source, PackageManagerModule.SiteRoot);
                // Read packages
                switch (view)
                {
                case View.Updates:
                    packages = projectManager.GetPackagesWithUpdates(searchTerm, packageSource.FilterPreferredPackages);
                    break;

                case View.Online:
                    IQueryable <IPackage> remotePackages = projectManager.GetRemotePackages(searchTerm, packageSource.FilterPreferredPackages);
                    totalPackages = remotePackages.Count();
                    packages      = WebProjectManager.CollapseVersions(remotePackages);
                    break;

                default:
                    packages = projectManager.GetInstalledPackages(searchTerm);
                    break;
                }
                if (view != View.Online)
                {
                    totalPackages = packages.Count();
                }

                grid = new WebGrid(rowsPerPage: PackagesPerPage, pageFieldName: "page");

                packages = packages.Skip(grid.PageIndex * PackagesPerPage)
                           .Take(PackagesPerPage);

                grid.Bind(packages.ToList(), columnNames: Enumerable.Empty <string>(), autoSortAndPage: false, rowCount: totalPackages);
            }
            catch (Exception exception) {
            #line default
            #line hidden
                WriteLiteral("        <div class=\"error message\">");



            #line 69 "..\..\packages\Default.cshtml"
                Write(exception.Message);


            #line default
            #line hidden
                WriteLiteral("</div>\r\n");



            #line 70 "..\..\packages\Default.cshtml"
                return;
            }



            #line default
            #line hidden
            WriteLiteral("\r\n");



            #line 74 "..\..\packages\Default.cshtml"

            var completedAction = Request.QueryString["action-completed"];
            if (!completedAction.IsEmpty())
            {
                var    packageName = Html.Encode(Request.QueryString["packageName"]);
                string message     = null;
                if (completedAction.Equals("Install", StringComparison.OrdinalIgnoreCase))
                {
                    message = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.InstallSuccess, packageName);
                }
                else if (completedAction.Equals("Uninstall", StringComparison.OrdinalIgnoreCase))
                {
                    message = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.UninstallSuccess, packageName);
                }
                else if (completedAction.Equals("Update", StringComparison.OrdinalIgnoreCase))
                {
                    message = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.UpdateSuccess, packageName);
                }

                if (message != null)
                {
            #line default
            #line hidden
                    WriteLiteral("            <div class=\"success message\">\r\n                <img class=\"inline\" sr" +
                                 "c=\"");



            #line 91 "..\..\packages\Default.cshtml"
                    Write(Href(SiteAdmin.GetVirtualPath("~/images/ok.png")));


            #line default
            #line hidden
                    WriteLiteral("\" alt=\"");



            #line 91 "..\..\packages\Default.cshtml"
                    Write(Html.Raw(message));


            #line default
            #line hidden
                    WriteLiteral("\" />&nbsp;");



            #line 91 "..\..\packages\Default.cshtml"
                    Write(Html.Raw(message));


            #line default
            #line hidden
                    WriteLiteral("\r\n            </div>\r\n");



                    WriteLiteral("            <br />\r\n");



            #line 94 "..\..\packages\Default.cshtml"
                }
            }



            #line default
            #line hidden
            WriteLiteral("<form method=\"get\" action=\"\" class=\"group\">\r\n    <div class=\"left form-actions\">\r" +
                         "\n        <label>");



            #line 99 "..\..\packages\Default.cshtml"
            Write(PackageManagerResources.ShowLabel);


            #line default
            #line hidden
            WriteLiteral(":\r\n        ");



            #line 100 "..\..\packages\Default.cshtml"
            Write(Html.DropDownList("view", from v in new[] { View.Installed, View.Online, View.Updates }
                                    select new SelectListItem {
                Text = GetViewName(v), Value = v.ToString()
            }));


            #line default
            #line hidden
            WriteLiteral("\r\n        </label>                           \r\n   \r\n");



            #line 104 "..\..\packages\Default.cshtml"
            if (PackageManagerModule.PackageSources.Count() > 1)
            {
            #line default
            #line hidden


            #line 105 "..\..\packages\Default.cshtml"
                WriteLiteral("            <span ");


            #line default
            #line hidden

            #line 105 "..\..\packages\Default.cshtml"
                if (view == View.Installed)
                {
            #line default
            #line hidden

            #line 105 "..\..\packages\Default.cshtml"
                    Write(Html.Raw("style=\"display: none\""));


            #line default
            #line hidden

            #line 105 "..\..\packages\Default.cshtml"
                    ;
                }

            #line default
            #line hidden
                WriteLiteral(">\r\n                &nbsp;\r\n                <label>");



            #line 108 "..\..\packages\Default.cshtml"
                Write(PackageManagerResources.PackageSourceLabel);


            #line default
            #line hidden
                WriteLiteral(":</label>\r\n                ");



            #line 109 "..\..\packages\Default.cshtml"
                Write(Html.DropDownList("source", from f in PackageManagerModule.PackageSources.OrderBy(p => p.Name)
                                        select new SelectListItem {
                    Value    = f.Name,
                    Text     = f.Name,
                    Selected = f.Name.Equals(packageSourceName, StringComparison.OrdinalIgnoreCase)
                }
                                        ));


            #line default
            #line hidden
                WriteLiteral("\r\n            </span>\r\n");



            #line 117 "..\..\packages\Default.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("    </div>\r\n\r\n    <div class=\"right\">\r\n        <fieldset class=\"no-border\">\r\n    " +
                         "        <input type=\"text\" id=\"search\" name=\"search\" size=\"30\" value=\"");



            #line 122 "..\..\packages\Default.cshtml"
            Write(searchTerm);


            #line default
            #line hidden
            WriteLiteral("\" />\r\n            <input type=\"submit\" value=\"");



            #line 123 "..\..\packages\Default.cshtml"
            Write(PackageManagerResources.SearchLabel);


            #line default
            #line hidden
            WriteLiteral("\" />\r\n            <input type=\"reset\" id=\"searchReset\" value=\"");



            #line 124 "..\..\packages\Default.cshtml"
            Write(PackageManagerResources.ClearLabel);


            #line default
            #line hidden
            WriteLiteral("\" />\r\n        </fieldset>\r\n    </div>\r\n</form>\r\n\r\n");



            #line 129 "..\..\packages\Default.cshtml"
            if (view != View.Online && !projectManager.LocalRepository.GetPackages().Any())
            {
                var onlineLink = Href(PageUtils.GetPackagesHome()) + "?view=" + View.Online;


            #line default
            #line hidden

            #line 131 "..\..\packages\Default.cshtml"
                Write(Html.Raw(String.Format(CultureInfo.CurrentCulture, PackageManagerResources.NoPackagesInstalled, Html.Encode(onlineLink))));


            #line default
            #line hidden

            #line 131 "..\..\packages\Default.cshtml"

                return;
            }


            #line default
            #line hidden
            WriteLiteral("\r\n");



            #line 135 "..\..\packages\Default.cshtml"
            if (!grid.Rows.Any())
            {
            #line default
            #line hidden
                WriteLiteral("    <h3>");



            #line 136 "..\..\packages\Default.cshtml"
                Write(PackageManagerResources.NoPackagesFound);


            #line default
            #line hidden
                WriteLiteral("</h3>\r\n");



            #line 137 "..\..\packages\Default.cshtml"
            }
            else
            {
            #line default
            #line hidden
                WriteLiteral("    <ul id=\"package-list\">\r\n");



            #line 140 "..\..\packages\Default.cshtml"
                var dataDictionary = new Dictionary <string, object>(1);


            #line default
            #line hidden


            #line 141 "..\..\packages\Default.cshtml"
                foreach (var item in grid.Rows)
                {
                    IPackage package = item.Value;
                    dataDictionary["package"] = package;


            #line default
            #line hidden
                    WriteLiteral("        <li>\r\n            <div class=\"column-left\">\r\n                ");



            #line 146 "..\..\packages\Default.cshtml"
                    Write(RenderPage("_Package.cshtml", dataDictionary));


            #line default
            #line hidden
                    WriteLiteral("\r\n            </div>\r\n            <div class=\"right\">\r\n                <form meth" +
                                 "od=\"get\" action=\"");



            #line 149 "..\..\packages\Default.cshtml"
                    Write(Href(GetPostUrl(view, package, projectManager)));


            #line default
            #line hidden
                    WriteLiteral("\">\r\n                    <input type=\"hidden\" name=\"page\" value=\"");



            #line 150 "..\..\packages\Default.cshtml"
                    Write(grid.PageIndex + 1);


            #line default
            #line hidden
                    WriteLiteral("\" />\r\n                    <input type=\"hidden\" name=\"package\" value=\"");



            #line 151 "..\..\packages\Default.cshtml"
                    Write(package.Id);


            #line default
            #line hidden
                    WriteLiteral("\" />\r\n                    <input type=\"hidden\" name=\"version\" value=\"");



            #line 152 "..\..\packages\Default.cshtml"
                    Write(package.Version);


            #line default
            #line hidden
                    WriteLiteral("\" />\r\n                    <input type=\"hidden\" name=\"packageName\" value=\"");



            #line 153 "..\..\packages\Default.cshtml"
                    Write(package.GetDisplayName());


            #line default
            #line hidden
                    WriteLiteral("\" />\r\n                    <input class=\"formatted\" type=\"submit\" value=\"");



            #line 154 "..\..\packages\Default.cshtml"
                    Write(GetSubmitText(view, package, projectManager));


            #line default
            #line hidden
                    WriteLiteral("\" />\r\n                </form>\r\n            </div>\r\n            <div class=\"clear\"" +
                                 "></div>\r\n        </li>\r\n");



            #line 159 "..\..\packages\Default.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("    </ul>\r\n");



            #line 161 "..\..\packages\Default.cshtml"
            }


            #line default
            #line hidden


            #line 162 "..\..\packages\Default.cshtml"
            if (totalPackages > PackagesPerPage)
            {
            #line default
            #line hidden
                WriteLiteral("    <div class=\"pager\">\r\n        <strong>");



            #line 164 "..\..\packages\Default.cshtml"
                Write(PackageManagerResources.PageLabel);


            #line default
            #line hidden
                WriteLiteral(": </strong>\r\n        ");



            #line 165 "..\..\packages\Default.cshtml"
                Write(grid.Pager(WebGridPagerModes.FirstLast | WebGridPagerModes.NextPrevious,
                                 nextText: PackageManagerResources.NextText,
                                 previousText: PackageManagerResources.PreviousText));


            #line default
            #line hidden
                WriteLiteral("\r\n    </div>\r\n");



            #line 169 "..\..\packages\Default.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("\r\n\r\n");
        }
        //==================================================================================//
        //      Store Admin information                                                     //
        //                                                                                  //
        //      Register the admin information if it is empty. Otherwise edit it.           //
        //                                                                                  //
        //      Note: If the edit is true then the account is being edited.                 //
        //      Otherwise it is being registered.                                           //
        //==================================================================================//
        public static bool StoreAdminData(RegisterModel regAdmin, ref bool edit)
        {
            int UserId = WebSecurity.GetUserId(regAdmin.EmailAddress);

            edit = false;

            try
            {
                SiteAdmin CurrentAdmin;

                using (ITintheDTestTableEntities context = new ITintheDTestTableEntities())
                {
                    // Put everything we find in the database in the var variable. All the
                    // information will be gotten using the User ID.

                    var AdminData = from r in context.SiteAdmin
                                    where r.UserId == UserId
                                    select r;

                    // If the user has some information then edit it.
                    // Otherwise register the account.

                    if (AdminData.Count() > 0 && UserId > 0)
                    {
                        CurrentAdmin = AdminData.FirstOrDefault();
                        CurrentAdmin.Status = regAdmin.AccountStatus;
                        CurrentAdmin.Company = regAdmin.CompanyName;
                        CurrentAdmin.EmailAddress = regAdmin.EmailAddress;
                        CurrentAdmin.Name = regAdmin.Name;
                        CurrentAdmin.Telephone = regAdmin.Telephone;
                        CurrentAdmin.UserId = UserId;

                        // Store the avatar if it is supplied.

                        if (regAdmin.ImageFile != null)
                        {
                            UserImage image = new UserImage();

                            using (MemoryStream ms = new MemoryStream())
                            {
                                regAdmin.ImageFile.InputStream.CopyTo(ms);

                                image.FileContent = ms.ToArray();
                                image.FileName = Path.GetFileName(regAdmin.ImageFile.FileName);
                                image.ContentType = regAdmin.ImageFile.ContentType;
                                image.ContentLength = regAdmin.ImageFile.ContentLength;

                                DatabaseHelper.UploadImage(image, CurrentAdmin.UserId);

                                CurrentAdmin.ImageUploaded = "Yes";
                                regAdmin.ImageUploaded = "Yes";
                            }
                        }

                        edit = true;
                    }

                    else
                    {
                        CurrentAdmin = new SiteAdmin();

                        CurrentAdmin.Status = regAdmin.AccountStatus;
                        CurrentAdmin.Company = regAdmin.CompanyName;
                        CurrentAdmin.Name = regAdmin.Name;
                        CurrentAdmin.EmailAddress = regAdmin.EmailAddress;
                        CurrentAdmin.Telephone = regAdmin.Telephone;

                        context.AddToSiteAdmin(CurrentAdmin);
                    }

                    try
                    {
                        // If the account is edited then save changes. Otherwise register the account.

                        if (edit == false)
                        {
                            WebSecurity.CreateUserAndAccount(regAdmin.EmailAddress, regAdmin.Password);

                            DatabaseHelper.AddUserToRole(regAdmin.EmailAddress, "Admin");

                            CurrentAdmin.UserId = WebSecurity.GetUserId(regAdmin.EmailAddress);

                            // Store the avatar if it is supplied.

                            if (regAdmin.ImageFile != null)
                            {
                                UserImage image = new UserImage();

                                using (MemoryStream ms = new MemoryStream())
                                {
                                    regAdmin.ImageFile.InputStream.CopyTo(ms);

                                    image.FileContent = ms.ToArray();
                                    image.FileName = Path.GetFileName(regAdmin.ImageFile.FileName);
                                    image.ContentType = regAdmin.ImageFile.ContentType;
                                    image.ContentLength = regAdmin.ImageFile.ContentLength;

                                    DatabaseHelper.UploadImage(image, CurrentAdmin.UserId);

                                    CurrentAdmin.ImageUploaded = "Yes";
                                    regAdmin.ImageUploaded = "Yes";
                                }
                            }

                            else
                            {
                                CurrentAdmin.ImageUploaded = "No";
                                regAdmin.ImageUploaded = "No";
                            }
                        }

                        context.SaveChanges();

                        return true;
                    }

                    catch (Exception ex)
                    {
                        string errorMessage = ex.Message;

                        return false;
                    }
                }
            }

            catch (Exception ex)
            {
                string exMessage = ex.Message;

                return false;
            }
        }