public static string EnsureResourceFileName(string file, string directory)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                return(string.Empty);
            }

            var filepath = file.Split('\\');

            if (filepath.Length > 3)
            {
                StringBuilder filePathBuilder = new StringBuilder();
                for (int i = 1; i < filepath.Length; i++)
                {
                    filePathBuilder.AppendFormat(String.Format("\\{0}", filepath[i]));
                }

                string objectDirectory = Path.Combine(String.Format("{0}\\{1}", directory, filePathBuilder.ToString()));
                SalesforceFileProcessing.EnsureFolder(objectDirectory);

                return(objectDirectory);
            }


            return(string.Empty);
        }
        public static string EnsureFileName(string file, string directory)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                return(string.Empty);
            }

            var filepath = file.Split('/');

            if (filepath.Length >= 3)
            {
                StringBuilder filePathBuilder = new StringBuilder();
                for (int i = 1; i < filepath.Length; i++)
                {
                    filePathBuilder.AppendFormat(String.Format("\\{0}", filepath[i]));
                }

                string objectDirectory = Path.Combine(String.Format("{0}\\{1}", directory, filePathBuilder.ToString()));
                SalesforceFileProcessing.EnsureFolder(objectDirectory);

                return(objectDirectory);
            }

            // lame special handling
            switch (filepath.Length)
            {
            case 1:
            {
                string objectDirectory = Path.Combine(directory, file);
                SalesforceFileProcessing.EnsureFolder(objectDirectory);

                return(objectDirectory);
            }

            case 2:
            {
                // this most likely is a share filename with multiple instances of the same file, we should check for duplicate
                string objectDirectory = Path.Combine(directory, filepath[1]);
                SalesforceFileProcessing.EnsureFolder(objectDirectory);

                if (File.Exists(objectDirectory))
                {
                    objectDirectory = Path.Combine(directory, String.Format("{0}-{1}", Guid.NewGuid().ToString(), filepath[1]));
                }

                return(objectDirectory);
            }
            }

            return(String.Empty);
        }
        private void ProcessFiles(IEnumerable <SalesforceFileProxy> filesToSave, string directory)
        {
            SalesforceFileProcessing.EnsureFolder(directory);

            foreach (SalesforceFileProxy salesforceFileProxy in filesToSave)
            {
                var filename = SalesforceFileProcessing.EnsureFileName(salesforceFileProxy.FileName, directory);

                if (salesforceFileProxy.BinaryBody != null && !SalesforceFileProcessing.SaveByteArray(filename, salesforceFileProxy.BinaryBody))
                {
                    Log.Error("Couldn't write binary file to disk");
                }
            }
        }
コード例 #4
0
        public bool SaveProject(string filename)
        {
            SalesforceFileProcessing.EnsureFolder(filename);
            try
            {
                using (FileStream fs = File.Open(filename, FileMode.Create))
                    using (StreamWriter sw = new StreamWriter(fs))
                        using (JsonWriter jw = new JsonTextWriter(sw))
                        {
                            jw.Formatting = Formatting.Indented;

                            JsonSerializer serializer = new JsonSerializer();
                            serializer.Serialize(jw, _salesforceMigrationsProject);
                        }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                return(false);
            }
        }