public void Save(Package package)
 {
     PackageDao dao = new PackageDao();
     using (Transaction tx = new Transaction())
     {
         dao.Save<Package>(package);
         tx.Commit();
     }
 }
        public Data.Guid CreatePackage(Package package, IPackageStatusNotifier notifier)
        {
            PackageDao dao = new PackageDao();

            this.guid = package.Guid;
            String siteGuid = package.OwnerSubscriptionId;

            SitePackage sitepackage = new SitePackage();
            IList<SitePackageTheme> packageThemes = new List<SitePackageTheme>();
            IList<SitePackagePage> packagePages = new List<SitePackagePage>();
            IList<SiteContentType> packageContentTypes = new List<SiteContentType>();
            IList<SiteContent> packageContent = new List<SiteContent>();
            IList<CmsSitePath> sitePaths = new List<CmsSitePath>();

            DoNotify(notifier, "Packaging Themes");
            PackageThemes(siteGuid, packageThemes, notifier);

            DoNotify(notifier, "Packaging Pages");
            PackagePages(siteGuid, packagePages);

            DoNotify(notifier, "Packaging Content Types");
            PackageContentTypes(siteGuid, packageContentTypes);

            DoNotify(notifier, "Packaging Content");
            PackageContent(siteGuid, packageContent);

            IStorageClient client = StorageHelper.GetStorageClient();
            String imageDirectory = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, siteGuid);

            DoNotify(notifier, "Creating Page Image Snapshots (please wait)");
            sitepackage.PageImages = client.CreateSnapshot(imageDirectory, StorageClientConst.RootFolder);
            sitepackage.Themes = packageThemes;
            sitepackage.SiteMapPaths = CmsSiteMap.Instance.GetAllPaths(siteGuid);
            sitepackage.Pages = packagePages;
            sitepackage.ContentTypes = packageContentTypes;
            sitepackage.SiteContent = packageContent;
            sitepackage.OriginalSiteGuid = siteGuid;

            DoNotify(notifier, "Creating Package Archive");
            byte[] data = null;
            using (MemoryStream outputstream = new MemoryStream())
            {
                //Serialize the object and then compress the serialized object
                data = Serializer.ToByteArray<SitePackage>(sitepackage);
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddEntry("sitepackage.bin", data);
                    zip.Save(outputstream);
                }
                data = null;

                //Write the serialized data to the container
                data = outputstream.ToArray();
            }

            DoNotify(notifier, "Saving Package Archive");
            client = StorageHelper.GetStorageClient();
            client.Save(PackageContainer,PackageDirectory, package.Guid + PackageExtension, data, Permissions.Private);

            return package.Guid;
        }
        public IList<PackageScreenshot> GetScreenshotUrls(Package package)
        {
            IStorageClient client = StorageHelper.GetStorageClient();
            IList<PackageScreenshot> results = new List<PackageScreenshot>();

            foreach (String screenshot in package.ScreenshotList)
            {
                StorageFile file = client.GetFile("package-screenshots", package.PackageTypeString, screenshot);

                PackageScreenshot item = new PackageScreenshot();
                item.Name = file.Filename;
                item.PackageGuid = package.Guid;
                item.Url = file.Url;

                results.Add(item);
            }

            return results;
        }
        public void AddToUser(Data.Guid userGuid, Package package)
        {
            //Make sure this package isn't already assocaited
            UserPackageDao dao = new UserPackageDao();

            UserPackage userPackage = dao.FindByUserAndPackage(userGuid, package.Guid);
            if (userPackage == null)
            {
                userPackage = new UserPackage();
                userPackage.UserGuid = userGuid.Value;
                userPackage.PackageGuid = package.Guid;
                userPackage.PackageTitle = package.Title;
                userPackage.PackageType = package.PackageTypeString;

                using (Transaction tx = new Transaction())
                {
                    dao.Save<UserPackage>(userPackage);
                    tx.Commit();
                }
            }
        }