Example #1
0
        public static Stream ReadStream(string streamPath)
        {
            var certificate = CertificateGenerator.GetCertificateByThumbprint();

            VC.Setup(null, certificate);
            return(VC.ReadStream(streamPath, true));
        }
Example #2
0
        // Function VcClient.VC.StreamExists(string streamName) just can check the existance of file not directory.
        public static bool CheckStreamExists(string streamPath)
        {
            var certificate = CertificateGenerator.GetCertificateByThumbprint();

            VC.Setup(null, certificate);

            // Function VC.StreamExists will return false if the input is path of a directory.
            return(VC.StreamExists(streamPath));
        }
Example #3
0
        /// <summary>
        /// Upload a file to the VC using the method overload which will preserve line boundaries on large files.
        /// </summary>
        /// <param name="source">Path to the local file.</param>
        /// <param name="dest">Desired stream location.</param>
        /// <param name="expiryDays">Expiry in days (if null, will use default of 30 days).</param>
        public static void UploadFile(string source, string dest, int?expiryDays = null)
        {
            var certificate = CertificateGenerator.GetCertificateByThumbprint();

            VC.Setup(null, certificate);
            var fi = new FileInfo(source);

            VC.Upload(source, dest, 0, fi.Length, false, TimeSpan.FromDays(expiryDays ?? 30), false);
        }
Example #4
0
        // We can use VcClient.VC.DirectoryExists(string directoryName) to check the existance of directory.
        public static bool CheckDirectoryExists(string directoryPath)
        {
            var certificate = CertificateGenerator.GetCertificateByThumbprint();

            VC.Setup(null, certificate);

            // Function VC.DirectoryExists will return true if the input is path of a directory.
            // The input parameter name is directoryName, same as StreamInfo.StreamName . It is just the path.
            return(VC.DirectoryExists(directoryPath));
        }
Example #5
0
        public static List <JToken> GetStreamInfos(string directoryPath)
        {
            var certificate = CertificateGenerator.GetCertificateByThumbprint();

            VC.Setup(null, certificate);

            List <JToken>     streamInfoJTokens = new List <JToken>();
            List <StreamInfo> streamInfos       = VC.GetDirectoryInfo(directoryPath, true);

            foreach (var streamInfo in streamInfos)
            {
                streamInfoJTokens.Add(JToken.Parse(JsonConvert.SerializeObject(streamInfo)));
            }
            return(streamInfoJTokens);
        }
        /// <summary>
        /// Checks view availability
        /// </summary>
        /// <param name="testRun">The testRun used to generate the view calling script</param>
        /// <param name="output">An output parameter, used to capture the exception message</param>
        /// <returns>True, the compilation is a success; false, the compilation failed</returns>
        public static bool CheckViewAvailability(string scriptToCompile, out string output)
        {
            var certificate = CertificateGenerator.GetCertificateFromBase64String();

            VC.Setup(null, certificate);

            var    scriptFilePath   = $"./TheScript_{Guid.NewGuid()}.script";
            var    isSuccessful     = true;
            string exceptionMessage = "Succesful Compilation";

            try
            {
                File.WriteAllText(scriptFilePath, scriptToCompile);
                try
                {
                    ScopeClient.Scope.Compile(scriptFilePath);
                }
                // This exception catches the following conditions:
                // The View is not at the location specified.
                // The data behind the view is not available.
                // The View itself has error handling, and we have run into a view defined issue.
                // The view itself has an error within it during compilation
                catch (ScopeClient.CompilationErrorException e)
                {
                    var trimmedCompilationError = GetCosmosCompileErrorMessage(e.Message);

                    exceptionMessage = trimmedCompilationError;
                }
            }
            finally
            {
                if (File.Exists(scriptFilePath))
                {
                    File.Delete(scriptFilePath);
                }
            }

            output = exceptionMessage;
            return(isSuccessful);
        }
Example #7
0
        public void Fetch()
        {
            VC.Setup(_virtualCluster, VC.NoProxy, null);

            using (DatabaseObjectsDataContext context = new DatabaseObjectsDataContext(Properties.Settings.Default.JobStatisticsConnectionString))
            {
#if DEBUG
                context.Log = Console.Out;
#endif

                int lookbackDays = Properties.Settings.Default.LookbackDays;

                // load all data stored in database that submit time is not earlier than X days ago
                var storedJobStatistics = context.JobStatistics
                                          .Where(js => js.SubmitTime != null && js.SubmitTime >= DateTime.Now.AddDays(-lookbackDays))
                                          .ToDictionary(js => js.Id);

                // get jobs from server (Cosmos)
                List <JobInfo> serverJobs = new List <JobInfo>();

                var jobList = VC.GetJobsList(_virtualCluster);

                serverJobs.AddRange(jobList);

                // find out new jobs and get job statistic information for new jobs.
                var newJobs = serverJobs.Where(job => !storedJobStatistics.ContainsKey(job.ID)).ToList();

                var newJobBatches = SplitJobsToBatches(newJobs);

                int finishedNewBatchCount = 0;
                foreach (var jobBatch in newJobBatches)
                {
                    var stats = new List <JobStatistic>();

                    foreach (var job in jobBatch)
                    {
                        var statistic = GetJobStatistic(job);

                        if (statistic != null)
                        {
                            stats.Add(statistic);
                        }
                    }

                    if (stats.Any())
                    {
                        context.JobStatistics.InsertAllOnSubmit(stats);
                    }

                    context.SubmitChanges();

                    finishedNewBatchCount++;

                    Console.WriteLine("{0}/{1} new job batches has been processed", finishedNewBatchCount, newJobBatches.Count);

                    // sleep for a while to avoid impact cosmos server too much
                    System.Threading.Thread.Sleep(5000);
                }

                // find out updated jobs and get updated job statistic information
                var updatedJobs = serverJobs.Where(job =>
                {
                    if (!storedJobStatistics.ContainsKey(job.ID))
                    {
                        return(false);
                    }

                    var storedJobStatistic    = storedJobStatistics[job.ID];
                    JobInfo.JobState jobState = (JobInfo.JobState)storedJobStatistic.State;
                    if (IsJobStateFinal(jobState))
                    {
                        return(false);
                    }

                    if (jobState == JobInfo.JobState.Queued && job.State == JobInfo.JobState.Queued)
                    {
                        return(false);
                    }

                    return(true);
                }).ToList();

                var updatedJobBatches = SplitJobsToBatches(updatedJobs);

                int finishedUpdatingBatchCount = 0;
                foreach (var jobBatch in updatedJobBatches)
                {
                    foreach (var job in jobBatch)
                    {
                        var storedJobStatistic = storedJobStatistics[job.ID];

                        var newJobStatistic = GetJobStatistic(job);

                        if (newJobStatistic != null)
                        {
                            UpdateJobStatistic(storedJobStatistic, newJobStatistic);
                        }
                    }

                    context.SubmitChanges();

                    finishedUpdatingBatchCount++;

                    Console.WriteLine("{0}/{1} updating job batches has been processed", finishedUpdatingBatchCount, updatedJobBatches.Count);

                    // sleep for a while to avoid impact cosmos server too much
                    System.Threading.Thread.Sleep(5000);
                }
            }
        }
Example #8
0
        public CosmosClient()
        {
            var certificate = CertificateGenerator.GetCertificateByThumbprint();

            VC.Setup(null, certificate);
        }