예제 #1
0
        public static bool CreateShare(string shareName, int totalSpace, string networkSharePath, int userId, string userName)
        {
            bool result = false;

            using (UploadContext ctx = new UploadContext())
            {
                ctx.Configuration.LazyLoadingEnabled = false;

                var location = new Share
                {
                    ShareName        = shareName,
                    TotalSpace       = totalSpace,
                    FreeSpace        = totalSpace, // When we start, all space is free.
                    NetworkSharePath = networkSharePath,
                    UserName         = userName,
                    UserId           = userId
                };

                ctx.Shares.Add(location);
                ctx.SaveChanges();
                result = true;
            }

            return(result);
        }
예제 #2
0
        public static bool CreateUploadRecords(string storageFileName, long size, int shareId)
        {
            bool result = false;

            using (UploadContext ctx = new UploadContext())
            {
                Share        share     = ctx.Shares.Where(s => s.ShareId == shareId).FirstOrDefault();
                UploadRecord file      = new UploadRecord();
                string[]     arrayName = storageFileName.Split('.');
                file.ShareId       = shareId;
                file.CloudId       = 1;
                file.Container     = string.Empty;
                file.Description   = "Description";
                file.Extension     = arrayName.Length > 1 ? arrayName[1] : string.Empty;
                file.FileCloudName = "Azure Pack";
                file.IsHidden      = false;
                file.IsShared      = false;
                file.Name          = arrayName.Length > 0 ? arrayName[0] : storageFileName;
                file.MimeType      = arrayName.Length > 1 ? arrayName[1]: string.Empty;
                file.Size          = size;
                file.CreatedDate   = DateTime.Now;
                file.ExpiredDate   = file.CreatedDate.AddDays(7);

                ctx.UploadRecords.Add(file);
                ctx.SaveChanges();

                //Update Share with new freeSpace
                int newFreeSpace = share.FreeSpace - (int)size;
                UpdateShare(share.ShareId, newFreeSpace);

                result = true;
            }

            return(result);
        }