예제 #1
0
        public static BrainstormingEventLogger GetInstance(CloudStorage storage)
        {
            if (loggerInstance == null)
            {
                lock (syncRoot)
                {
                    if (loggerInstance == null)
                    {
                        loggerInstance = new BrainstormingEventLogger(storage);

                        ICloudDirectoryEntry targetFolder;
                        try
                        {
                            targetFolder = storage.GetFolder("/UserStudy_Log");
                        }
                        catch (Exception ex)
                        {
                            targetFolder = storage.CreateFolder("/UserStudy_Log");
                        }

                    }
                }
            }
            return loggerInstance;
        }
		protected void ExecuteUpload(IExecuteBoxNetUploaderWorkflowMessage message, GenericNetworkCredentials authenticationToken, FileInfo inputFilePath)
		{
			var cancellationTokenSource = new CancellationTokenSource();
			var cancellationToken = cancellationTokenSource.Token;

			var task = Task.Factory.StartNew(() => { });
			task.ContinueWith((t) =>
			{
				BoxNetUploaderService.Uploaders.Add(message, new CancellableTask
				{
					Task = task,
					CancellationTokenSource = cancellationTokenSource
				});

				var configuration = GetBoxNetConfiguration();
				var storage = new CloudStorage();
				var accessToken = storage.Open(configuration, authenticationToken);

				var folder = string.IsNullOrEmpty(message.Settings.Folder) ? storage.GetRoot() : storage.GetFolder(message.Settings.Folder);
				if (folder == null)
				{
					throw new Exception(string.Format("Folder does not exist - {0}", message.Settings.Folder));
				}
				else
				{
					var file = storage.CreateFile(folder, inputFilePath.Name);
					var uploader = file.GetDataTransferAccessor();
					using (var inputFileStream = inputFilePath.OpenRead())
					{
						uploader.Transfer(inputFileStream, nTransferDirection.nUpload, FileOperationProgressChanged, task);
					}
				}

				if (storage.IsOpened)
				{
					storage.Close();
				}
			}
			, cancellationToken)
			.ContinueWith((t) =>
			{
				var executedBoxNetUploaderWorkflowMessage = new ExecutedBoxNetUploaderWorkflowMessage()
				{
					CorrelationId = message.CorrelationId,
					Cancelled = t.IsCanceled,
					Error = t.Exception
				};

				var bus = BusDriver.Instance.GetBus(BoxNetUploaderService.BusName);
				bus.Publish(executedBoxNetUploaderWorkflowMessage);

				BoxNetUploaderService.Uploaders.Remove(message);
			});
		}
예제 #3
0
        private IStorageFolder getDirectoryInfo(IStorageFolder parentFolder, CloudStorage cloudStorage)
        {
            if (parentFolder == null)
                parentFolder = new YandexStorageFolder
                {
                    Files = new List<IStorageFile>(),
                    Name = string.Empty,
                    ParentFolder = null,
                    Path = "/",
                    SubFolders = new List<IStorageFolder>()
                };

            var cloudDirectoryEntry = cloudStorage.GetFolder(parentFolder.Path);

            if (cloudDirectoryEntry == null || cloudDirectoryEntry.Count == 0)
                return parentFolder;
            else
            {
                foreach (var dirItem in cloudDirectoryEntry)
                {
                    if (dirItem.Length == 0)
                    {
                        var subfolder = new YandexStorageFolder
                        {
                            Files = new List<IStorageFile>(),
                            Name = dirItem.Name,
                            ParentFolder = parentFolder,
                            Path = string.Concat(parentFolder.Path, dirItem.Name, "/"),
                            SubFolders = new List<IStorageFolder>(),
                            DateTime = dirItem.Modified
                        };

                        parentFolder.SubFolders.Add(GetDirectoryInfo(subfolder));
                    }
                    else
                        parentFolder.Files.Add(new YandexStorageFile
                        {
                            DateTime = dirItem.Modified,
                            Extension = Path.GetExtension(dirItem.Name).ToLower(),
                            Name = dirItem.Name,
                            Size = dirItem.Length,
                            ParentFolder = parentFolder
                        });
                }
            }

            return parentFolder;
        }
예제 #4
0
        private void Save(string filename, MemoryStream memoryStream)
        {
            var storage = new CloudStorage();
            storage.Open(_cloudStorageConfiguration, _cloudeStorageCredentials);

            var backupFolder = storage.GetFolder(ArchiveFolderPath);
            if (backupFolder == null) { throw new Exception("Cloud folder not found: " + ArchiveFolderPath); }

            var cloudFile = storage.CreateFile(backupFolder, filename);
            using (var cloudStream = cloudFile.GetContentStream(FileAccess.Write))
            {
                cloudStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Position);
            }

            if (storage.IsOpened) { storage.Close(); }
        }
예제 #5
0
        public void Test()
        {
            Uri u = new Uri("https://webdav.yandex.ru");
            ICloudStorageConfiguration config = new WebDavConfiguration(u);

            GenericNetworkCredentials cred = new GenericNetworkCredentials();
            cred.UserName = "******";
            cred.Password = "******";

            CloudStorage storage = new CloudStorage();
            ICloudStorageAccessToken storageToken = storage.Open(config, cred);

              //  storage.GetCloudConfiguration(nSupportedCloudConfigurations.WebDav);
            // After successful login you may do the necessary Directory/File manipulations by the SharpBox API
            // Here is the most often and simplest one
            ICloudDirectoryEntry root = storage.GetRoot();

            var f =storage.GetFolder("/");
            //f.First().

            //var c =storage.GetCloudConfiguration(nSupportedCloudConfigurations.WebDav);
            //storage.
            storage.Close();
        }
예제 #6
0
        public ActionResult GridViewPartialUpdate(inventarioImportaciones.Models.productos item)
        {
            var model = db.productos_List;
            if (ModelState.IsValid)
            {
                try
                {
                    var modelItem = model.FirstOrDefault(it => it.Codigo == item.Codigo);
                    if (item.Imagen.Length!=item.ImagenSelect.Length)
                    {
                        item.DirImagen = "";
                        string path = @"C:\Visual .net\DanielAsp";
                        string filename = path+"\\"+item.Nombre;
                        var fsC = new BinaryWriter(new FileStream( filename + ".jpg", FileMode.Append, FileAccess.Write));
                        fsC.Write(item.ImagenSelect);
                        fsC.Close();

                        CloudStorage dropBoxStorage = new CloudStorage();
                        var dropBoxConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox);
                        ICloudStorageAccessToken accessToken = null;
                        // load a valid security token from file
                        using (FileStream fs = System.IO.File.Open(@"C:\Visual .net\InventariosImportaciones\InventariosImportaciones\SharpDropBox.Token",
                        FileMode.Open, FileAccess.Read,
                        FileShare.None))
                        {
                            accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
                        }

                        var storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);

                        var publicFolder = dropBoxStorage.GetFolder("/");
                        // GetFolder("/Public");
                        foreach (var fof in publicFolder)
                        {
                            // check if we have a directory
                            Boolean bIsDirectory = fof is ICloudDirectoryEntry;
                            // output the info
                            Console.WriteLine("{0}: {1}", bIsDirectory ? "DIR" : "FIL", fof.Name);
                        }

                        String srcFile = Environment.ExpandEnvironmentVariables(filename + ".jpg");
                      ICloudFileSystemEntry fileUploaded=  dropBoxStorage.UploadFile(srcFile, publicFolder);

                      ICloudDirectoryEntry fEntry = dropBoxStorage.GetFolder("/");
                      ICloudFileSystemEntry fszz = dropBoxStorage.GetFileSystemObject("Gamma Quick Kids 21in.jpg", fEntry);

                      string d = DropBoxStorageProviderTools.GetPublicObjectUrl(storageToken, fszz).AbsoluteUri;
                      Console.WriteLine(d);
                        dropBoxStorage.DownloadFile(publicFolder, item.Nombre + ".jpg", Environment.ExpandEnvironmentVariables(path));

                        dropBoxStorage.Close();
                    }
                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_GridViewPartial", model.ToList());
        }
 private static ICloudDirectoryEntry GetDirectoryPath(CloudStorage storage)
 {
     return storage.GetFolder(_remoteDirectory, storage.GetRoot())
         ?? storage.CreateFolder(_remoteDirectory, storage.GetRoot());
 }
예제 #8
0
        public byte[] GetFile(IStorageFile file)
        {
            byte[] fileData = null;
            CloudStorage cloudStorage = null;

            try
            {
                cloudStorage = new CloudStorage();
                cloudStorage.Open(config, credentials);

                ICloudDirectoryEntry cloudDirectoryEntry;
                
                if (file.ParentFolder == null)
                    cloudDirectoryEntry = cloudStorage.GetRoot();
                else
                    cloudDirectoryEntry = cloudStorage.GetFolder(file.ParentFolder.Path);

                if (cloudDirectoryEntry != null && cloudDirectoryEntry.Count != 0)
                {
                    var cloudFile = cloudDirectoryEntry.FirstOrDefault(f => f.Name == file.Name);
                    if (cloudFile != null)
                    {
                        using (var ms = new MemoryStream())
                        {
                            cloudStorage.DownloadFile(cloudFile.Name, cloudDirectoryEntry, ms);
                            fileData = ms.GetBuffer();
                        }
                    }
                }
            }
            finally
            {
                if (cloudStorage != null && cloudStorage.IsOpened)
                    cloudStorage.Close();
            }

            return fileData;
        }
예제 #9
0
        public StorageFolderResult Execute(WebDavConfigurationModel model, string path, int accountId)
        {
            model = model.With(m => !string.IsNullOrEmpty(m.ServerUrl))
                   .With(m => !string.IsNullOrEmpty(m.AccountLogin))
                   .With(m => !string.IsNullOrEmpty(m.AccountPassword));

            if (model == null)
                throw new PluginException(PluginErrorCodes.InvalidCredentialsOrConfiguration);

            StorageFolderResult result = new StorageFolderResult();

            Uri uri = new Uri(model.ServerUrl);
            ICloudStorageConfiguration config = new WebDavConfiguration(uri);
            GenericNetworkCredentials cred = new GenericNetworkCredentials();
            cred.UserName = model.AccountLogin;
            cred.Password = model.AccountPassword;

            if (string.IsNullOrEmpty(path))
                path = "/";
            else
                path = path.RemoveCharDuplicates('/');
            if (!path.Equals("/", StringComparison.OrdinalIgnoreCase))
                path = path.TrimEnd('/');

            CloudStorage storage = null;
            try
            {
                storage = new CloudStorage();
                ICloudStorageAccessToken storageToken = storage.Open(config, cred);
                ICloudDirectoryEntry directory = storage.GetFolder(path, true);

                result.CurrentFolderName = directory.Name;
                result.CurrentFolderUrl = path;
                path = path.TrimEnd('/');
                foreach (var entry in directory)
                {
                    var dirEntry = entry as ICloudDirectoryEntry;
                    string entryPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", path, "/", entry.Name);
                    if (dirEntry != null)
                    {
                        result.AddItem(new StorageFolder
                        {
                            Name = dirEntry.Name,
                            Path = entryPath,
                            StorageAccountId = accountId
                        });
                    }
                    else
                    {
                        result.AddItem(new StorageFile
                        {
                            Name = entry.Name,
                            Path = entryPath,
                            StorageAccountId = accountId
                        });
                    }
                }

                StoragePathItem rootPath = new StoragePathItem
                {
                    Name = "/",
                    Url = "/"
                };
                string relativePath = path.Trim('/').RemoveCharDuplicates('/');
                if (relativePath.Length > 0)
                {
                    string[] pathItems = relativePath.Split('/');
                    StringBuilder pathUrlsBuilder = new StringBuilder("/");
                    foreach (var pathItem in pathItems)
                    {
                        pathUrlsBuilder.Append(pathItem);
                        rootPath.AppendItem(new StoragePathItem
                            {
                                Name = pathItem,
                                Url = pathUrlsBuilder.ToString()
                            });
                        pathUrlsBuilder.Append("/");
                    }
                }

                result.CurrentPath = rootPath;
            }
            finally
            {
                if (storage != null)
                    storage.Close();
            }

            return result;
        }