private static async Task<DeploymentDirectoryConfig> FetchDeploymentConfig(IRemoteDirectory deploymentRootDir)
 {
     IRemoteFile configFile = await deploymentRootDir.GetFile(Constants.DeploymentConfigFileName);
     if (!await configFile.Exists())
     {
         Trace.TraceInformation("The deployments config file {0} was not found in the {1} directory; i.e. NO applications to deploy.", Constants.DeploymentConfigFileName, deploymentRootDir.Name);
         return new DeploymentDirectoryConfig(new List<DeploymentConfig>());
     }
     return await new DeploymentConfigParser().ParseData(configFile.DownloadText().Result);
 }
Example #2
0
 public RemoteSyncDirectory(
     IRemoteDirectory remoteDirectory,
     bool compressBlobs = false)
 {
     RemoteDirectory                   = remoteDirectory;
     _remoteIndexOutputFactory         = GetAzureIndexOutputFactory();
     _remoteDirectoryIndexInputFactory = GetAzureIndexInputFactory();
     LoggingService = new TraceLoggingService();
     CompressBlobs  = compressBlobs;
 }
        private static async Task <DeploymentDirectoryConfig> FetchDeploymentConfig(IRemoteDirectory deploymentRootDir)
        {
            IRemoteFile configFile = await deploymentRootDir.GetFile(Constants.DeploymentConfigFileName);

            if (!await configFile.Exists())
            {
                Trace.TraceInformation("The deployments config file {0} was not found in the {1} directory; i.e. NO applications to deploy.", Constants.DeploymentConfigFileName, deploymentRootDir.Name);
                return(new DeploymentDirectoryConfig(new List <DeploymentConfig>()));
            }
            return(await new DeploymentConfigParser().ParseData(configFile.DownloadText().Result));
        }
Example #4
0
 public RemoteSyncDirectory(IRemoteDirectory remoteDirectory,
                            Directory cacheDirectory,
                            bool compressBlobs = false)
 {
     CacheDirectory                    = cacheDirectory;
     LoggingService                    = new TraceLoggingService();
     RemoteDirectory                   = remoteDirectory;
     _lockFactory                      = GetLockFactory();
     _remoteIndexOutputFactory         = GetAzureIndexOutputFactory();
     _remoteDirectoryIndexInputFactory = GetAzureIndexInputFactory();
     GuardCacheDirectory(CacheDirectory);
     CompressBlobs = compressBlobs;
 }
 public RemoteSimpleLock(string lockFile, RemoteSyncDirectory syncDirectory, IRemoteDirectory remoteDirectory)
 {
     if (syncDirectory == null)
     {
         throw new ArgumentNullException(nameof(syncDirectory));
     }
     if (string.IsNullOrWhiteSpace(lockFile))
     {
         throw new ArgumentException("Value cannot be null or whitespace.", nameof(lockFile));
     }
     _lockFile           = lockFile;
     _azureSyncDirectory = syncDirectory;
     _remoteDirectory    = remoteDirectory;
 }
Example #6
0
        public async Task DownloadApplication(AppIdentity appIdentity)
        {
            IRemoteDirectory appDeploymentDir =
                await _deploymentsRootDirectory.GetDirectory(appIdentity.Id);

            if (await appDeploymentDir.Exists())
            {
                IRemoteDirectory versionDir = await appDeploymentDir.GetDirectory(appIdentity.Version.ToString());

                if (await versionDir.Exists())
                {
                    await
                    versionDir.Download(Path.Combine(_applicationRootPath,
                                                     ApplicationUtils.GetApplicationRelativePath(appIdentity)));
                }
                return;
            }
            Trace.TraceError("{0} could not be downloaded because it was not found in the blob storage", appIdentity);
        }
 public RemoteDirectoryIndexOutput(RemoteSyncDirectory azureSyncDirectory, string name,
                                   ILoggingService loggingService)
 {
     //NOTE: _name was null here, is this intended? https://github.com/azure-contrib/AzureDirectory/issues/19 I have changed this to be correct now
     _name = name;
     _azureSyncDirectory   = azureSyncDirectory ?? throw new ArgumentNullException(nameof(azureSyncDirectory));
     _azureRemoteDirectory = _azureSyncDirectory.RemoteDirectory;
     _fileMutex            = SyncMutexManager.GrabMutex(_azureSyncDirectory, _name);
     _fileMutex.WaitOne();
     try
     {
         // create the local cache one we will operate against...
         _indexOutput = CacheDirectory.CreateOutput(_name);
     }
     finally
     {
         _fileMutex.ReleaseMutex();
     }
 }
Example #8
0
        public RemoteReadOnlyLuceneSyncDirectory(IRemoteDirectory remoteDirectory,
                                                 string cacheDirectoryPath,
                                                 string cacheDirectoryName,
                                                 bool compressBlobs = false) : base(remoteDirectory, compressBlobs)
        {
            _cacheDirectoryPath = cacheDirectoryPath;
            _cacheDirectoryName = cacheDirectoryName;
            IsReadOnly          = true;
            if (CacheDirectory == null)
            {
                LoggingService.Log(new LogEntry(LogLevel.Error, null, $"CacheDirectory null. Creating or rebuilding cache"));

                CreateOrReadCache();
            }
            else
            {
                CheckDirty();
            }
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command2"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private Command2(AsyncPackage package, OleMenuCommandService commandService)
        {
            this.package   = package ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem      = new MenuCommand(new EventHandler(this.ExecuteAsync), menuCommandID);

            commandService.AddCommand(menuItem);

            try
            {
                ConnectionInfoStore connectionInfoStore = new ConnectionInfoStore();
                connectionInfoStore.Load();
                if (connectionInfoStore.Connections.Count > 0)
                {
                    remoteSystem = new RemoteSystem((ConnectionInfo)connectionInfoStore.Connections[0]);
                    directory    = remoteSystem.FileSystem.GetDirectory(SpecialDirectory.Home);
                }
            }
            catch { }
        }
        public async Task <IEnumerable <AppIdentity> > FetchDeployments(string deploymentId)
        {
            var apps = new HashSet <AppIdentity>();

            DeploymentDirectoryConfig deploymentDirectoryConfig = await FetchDeploymentConfig(_deploymentRootDir);

            foreach (DeploymentConfig deploymentConfig in deploymentDirectoryConfig.DeploymentsConfigs.Where(deploymentConfig => deploymentConfig.DeploymentIds.Contains(deploymentId)))
            {
                try
                {
                    IRemoteDirectory deploymentDir = await _deploymentRootDir.GetDirectory(deploymentConfig.AppIdentity.Id);

                    if (await deploymentDir.Exists())
                    {
                        deploymentDir = await deploymentDir.GetDirectory(deploymentConfig.AppIdentity.Version.ToString());
                    }
                    if (!await deploymentDir.Exists())
                    {
                        Trace.TraceError("Could not find deployment {0}", deploymentConfig.AppIdentity);
                        continue;
                    }
                    if (apps.Contains(deploymentConfig.AppIdentity))
                    {
                        Trace.TraceError(
                            "Application {0} has already been deployed, the request will be ignored.", deploymentConfig.AppIdentity);
                        continue;
                    }

                    apps.Add(deploymentConfig.AppIdentity);
                }
                catch (Exception e)
                {
                    Trace.TraceError("Exception occured while loading application {0}, Exception: {1}", deploymentConfig.AppIdentity, e);
                }
            }
            return(apps);
        }
Example #11
0
        public RemoteDirectoryIndexInput(RemoteSyncDirectory azuredirectory, IRemoteDirectory helper, string name,
                                         ILoggingService loggingService)
        {
            _name = name;
            _name = _name.Split(new string[] { "%2F" }, StringSplitOptions.RemoveEmptyEntries).Last();
            _remoteSyncDirectory = azuredirectory ?? throw new ArgumentNullException(nameof(azuredirectory));
#if FULLDEBUG
            Trace.WriteLine($"opening {_name} ");
#endif
            _fileMutex = SyncMutexManager.GrabMutex(_remoteSyncDirectory, _name);
            _fileMutex.WaitOne();
            try
            {
                var fileName = _name;

                var fFileNeeded = false;
                if (!CacheDirectory.FileExists(fileName))
                {
                    fFileNeeded = true;
                }
                else
                {
                    var cachedLength   = CacheDirectory.FileLength(fileName);
                    var blobProperties = helper.GetFileProperties(fileName);


                    if (cachedLength != blobProperties.Item1)
                    {
                        fFileNeeded = true;
                    }
                    else
                    {
                        // cachedLastModifiedUTC was not ouputting with a date (just time) and the time was always off
                        var unixDate = CacheDirectory.FileModified(fileName);
                        var start    = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        var cachedLastModifiedUtc = start.AddMilliseconds(unixDate).ToUniversalTime();

                        if (cachedLastModifiedUtc != blobProperties.Item2)
                        {
                            var timeSpan = blobProperties.Item2.Subtract(cachedLastModifiedUtc);
                            if (timeSpan.TotalSeconds > 1)
                            {
                                fFileNeeded = true;
                            }
                            else
                            {
#if FULLDEBUG
                                Trace.WriteLine(timeSpan.TotalSeconds);
#endif
                                // file not needed
                            }
                        }
                    }
                }

                // if the file does not exist
                // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
                if (fFileNeeded)
                {
                    helper.SyncFile(CacheDirectory, fileName, azuredirectory.CompressBlobs);

                    // and open it as an input
                    _indexInput = CacheDirectory.OpenInput(fileName);
                }
                else
                {
#if FULLDEBUG
                    Trace.WriteLine($"Using cached file for {_name}");
#endif

                    // open the file in read only mode
                    _indexInput = CacheDirectory.OpenInput(fileName);
                }
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Example #12
0
 /// <summary>
 /// Downloads application from the remote directory to the local file system.
 /// </summary>
 /// <param name="applicationRootPath">The target path where the applications will be downloaded</param>
 /// <param name="deploymentsRootDirectory">The remote directory from where the applications will be downloaded</param>
 public ApplicationDownloader(string applicationRootPath, IRemoteDirectory deploymentsRootDirectory)
 {
     _applicationRootPath      = applicationRootPath;
     _deploymentsRootDirectory = deploymentsRootDirectory;
 }
Example #13
0
 public RemoteDirectorySimpleLockFactory(RemoteSyncDirectory azureSyncDirectory, IRemoteDirectory remoteDirectory)
 {
     _azureSyncDirectory = azureSyncDirectory;
     _remoteDirectory    = remoteDirectory;
 }
 public IndexInput GetIndexInput(RemoteSyncDirectory azuredirectory, IRemoteDirectory helper, string name, ILoggingService loggingService)
 {
     return(new RemoteDirectoryIndexInput(azuredirectory, helper, name, loggingService));
 }
 public RemoteApplicationDeploymentDirectory(IRemoteDirectory deploymentRootDir)
 {
     _deploymentRootDir = deploymentRootDir;
 }
Example #16
0
 public void ScpToRemote(List <string> files, string dir_path, string dir, IVsOutputWindowPane outputWindowPane)
 {
     try
     {
         lock (lock_obj)
         {
             // ThreadHelper.ThrowIfNotOnUIThread();
             var dte = Package.GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
             dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Activate();
             if (files.Count == 0)
             {
                 outputWindowPane.OutputStringThreadSafe("No file can be copied");
                 return;
             }
             ConnectionInfoStore connectionInfoStore = new ConnectionInfoStore();
             connectionInfoStore.Load();
             if (connectionInfoStore.Connections.Count < 1)
             {
                 outputWindowPane.OutputStringThreadSafe("No connection found. Add connection in [Tools] / [Options] / [Cross Platform]");
                 return;
             }
             outputWindowPane.OutputStringThreadSafe("Connecting...\n");
             if (remoteSystem == null)
             {
                 remoteSystem = new RemoteSystem((ConnectionInfo)connectionInfoStore.Connections[0]);
                 directory    = remoteSystem.FileSystem.GetDirectory(SpecialDirectory.Home);
             }
             using (var concurrencySemaphore = new System.Threading.SemaphoreSlim(8))
             {
                 int         num    = 0;
                 int         length = files.Count;
                 List <Task> tasks  = new List <Task>();
                 foreach (string file in files)
                 {
                     concurrencySemaphore.Wait();
                     var t = Task.Run(() =>
                     {
                         string str2           = file.Substring(dir_path.Length);
                         string remoteFileName = directory.FullPath + "/projects/" + dir + str2.Replace('\\', '/');
                         string remotePath     = remoteFileName.Substring(0, remoteFileName.LastIndexOf('/'));
                         try
                         {
                             if (File.Exists(file))
                             {
                                 remoteSystem.FileSystem.UploadFile(file, remoteFileName);
                                 outputWindowPane.OutputStringThreadSafe("[" + Interlocked.Increment(ref num) + "/" + length + "] " + remoteFileName + "\n");
                             }
                             else
                             {
                                 Interlocked.Increment(ref num);
                                 outputWindowPane.OutputStringThreadSafe("Skip " + file + " (file not exists)\n");
                             }
                         }
                         catch (liblinux.IO.IOException ex1)
                         {
                             if (ex1.Message.Contains("No such file"))
                             {
                                 remoteSystem.FileSystem.CreateDirectories(remotePath);
                                 remoteSystem.FileSystem.UploadFile(file, remoteFileName);
                                 outputWindowPane.OutputStringThreadSafe("[" + Interlocked.Increment(ref num) + "/" + length + "] " + remoteFileName + "\n");
                             }
                             else
                             {
                                 Interlocked.Increment(ref num);
                                 outputWindowPane.OutputStringThreadSafe("Upload failed: " + file + "\n");
                             }
                         }
                         catch (Exception ex)
                         {
                             Interlocked.Increment(ref num);
                             outputWindowPane.OutputStringThreadSafe("Upload failed: " + file + ", ex: " + ex.ToString() + "\n");
                         }
                         finally
                         {
                             concurrencySemaphore.Release();
                         }
                     });
                     tasks.Add(t);
                 }
                 Task.WaitAll(tasks.ToArray());
             }
             remoteSystem.Disconnect();
             remoteSystem.Dispose();
             outputWindowPane.OutputStringThreadSafe("Copy to " + remoteSystem.ConnectionInfo.HostNameOrAddress + " done.\n");
             // prepare for next time
             remoteSystem = new RemoteSystem((ConnectionInfo)connectionInfoStore.Connections[0]);
             directory    = remoteSystem.FileSystem.GetDirectory(SpecialDirectory.Home);
         }
     }
     catch (Exception ex)
     {
         remoteSystem = null;
         throw ex;
     }
 }
Example #17
0
 /// <summary>
 /// Downloads application from the remote directory to the local file system.
 /// </summary>
 /// <param name="applicationRootPath">The target path where the applications will be downloaded</param>
 /// <param name="deploymentsRootDirectory">The remote directory from where the applications will be downloaded</param>
 public ApplicationDownloader(string applicationRootPath, IRemoteDirectory deploymentsRootDirectory)
 {
     _applicationRootPath = applicationRootPath;
     _deploymentsRootDirectory = deploymentsRootDirectory;
 }
 public RemoteApplicationDeploymentDirectory(IRemoteDirectory deploymentRootDir)
 {
     _deploymentRootDir = deploymentRootDir;
 }