Example #1
0
        protected override void Execute(CodeActivityContext context)
        {
            console = ActivityConsole.GetDefaultOrNew(context);

            showOutput = ShowOutput.Get(context);
            string folder = FolderPath.Get(context);

            DirectoryInfo di = new DirectoryInfo(folder);

            if (!di.Exists)
            {
                throw new ArgumentException(string.Format("The folder '{0}' does not exist.", folder));
            }

            InheritanceFlags inheritance = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;

            List <FileSystemAccessRule> accessRules = new List <FileSystemAccessRule>();

            accessRules.Add(new FileSystemAccessRule(UserOrGroup.Get(context), FileSystemRights.Read, inheritance, PropagationFlags.None, (Read.Get(context) ? AccessControlType.Allow : AccessControlType.Deny)));
            accessRules.Add(new FileSystemAccessRule(UserOrGroup.Get(context), FileSystemRights.Write, inheritance, PropagationFlags.None, (Write.Get(context) ? AccessControlType.Allow : AccessControlType.Deny)));
            accessRules.Add(new FileSystemAccessRule(UserOrGroup.Get(context), FileSystemRights.ExecuteFile, inheritance, PropagationFlags.None, (ReadAndExecute.Get(context) ? AccessControlType.Allow : AccessControlType.Deny)));

            DirectorySecurity ds = di.GetAccessControl();

            foreach (FileSystemAccessRule rule in accessRules)
            {
                ds.AddAccessRule(rule);
                WriteLineConsole(string.Format("Adding {0} {1} permission for identity {2} to folder {3}", rule.AccessControlType, rule.FileSystemRights, rule.IdentityReference.Value, folder));
            }

            di.SetAccessControl(ds);
        }
Example #2
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string SourcePath      = FolderPath.Get(context);
                string DestinationPath = CopyPath.Get(context);
                string DestFolder      = Path.GetFileName(SourcePath);
                DestinationPath = DestinationPath + "\\" + DestFolder;


                if (Directory.Exists(SourcePath))
                {
                    if (isOverride == true && Directory.Exists(DestinationPath))
                    {
                        Directory.Delete(DestinationPath, true);
                    }
                    else if (isOverride == false && Directory.Exists(DestinationPath))
                    {
                        throw new Exception("File with the same name already exist - " + DestinationPath);
                    }

                    if (!Directory.Exists(DestinationPath))
                    {
                        Directory.CreateDirectory(DestinationPath);
                    }



                    //Now Create all of the directories
                    foreach (string dirPath in Directory.GetDirectories(SourcePath, "*",
                                                                        SearchOption.AllDirectories))
                    {
                        Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));
                    }

                    //Copy all the files & Replaces any files with the same name
                    foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",
                                                                  SearchOption.AllDirectories))
                    {
                        File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true);
                    }
                }
                else if (!Directory.Exists(SourcePath))
                {
                    Log.Logger.LogData("Folder does not exist in path - " + SourcePath + " in activity Folder_Copy", LogLevel.Error);
                    if (!ContinueOnError)
                    {
                        context.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message + " in activity Folder_Copy", LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
Example #3
0
        protected override void Execute(CodeActivityContext context)
        {
            var SourceFilePath     = FolderPath.Get(context);
            var DistinationZipPath = ZippedPath.Get(context);
            var Password_Val       = Password.Get(context);

            using (ZipFile zip = new ZipFile())
            {
                zip.Password = Password_Val.ToString();
                zip.AddDirectory(SourceFilePath);
                zip.Save(DistinationZipPath);
            }
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var folderpath  = FolderPath.Get(context);
            var filepattern = FilePattern.Get(context);

            string[] filepath = Directory.GetFiles(@folderpath, filepattern);

            // Outputs
            return((ctx) => {
                FilePath.Set(ctx, filepath);
            });
        }
Example #5
0
        // TODO: For a better customization/user experience add InArgument<string> DownloadLocation

        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor dropboxSessionProperty = context.DataContext.GetProperties()[WithDropboxSession.DropboxSessionPropertyName];
            IDropboxSession    dropboxSession         = dropboxSessionProperty?.GetValue(context.DataContext) as IDropboxSession;

            if (dropboxSession == null)
            {
                throw new InvalidOperationException(Resources.DropboxSessionNotFoundException);
            }

            await dropboxSession.DownloadFolderAsZipAsync(FolderPath.Get(context), DownloadFolder.Get(context), ZipFileName.Get(context), cancellationToken);

            return((asyncCodeActivityContext) => { });
        }
 protected override void Execute(NativeActivityContext context)
 {
     try
     {
         string[] files      = null;
         string   folderpath = FolderPath.Get(context); //@"C:\Work"
         string   filter     = FilterOnFileExtension.Get(context);
         if ((string.IsNullOrEmpty(folderpath)) || (folderpath.Trim().Length == 0))
         {
             Log.Logger.LogData("Please enter folder path in activity Folder_FileList", LogLevel.Error);
             if (!ContinueOnError)
             {
                 context.Abort();
             }
         }
         else if (!Directory.Exists(folderpath))
         {
             Log.Logger.LogData("Folder does not exist in path - " + folderpath + " in activity Folder_FileList", LogLevel.Error);
             if (!ContinueOnError)
             {
                 context.Abort();
             }
         }
         else if (Directory.Exists(folderpath))
         {
             if ((string.IsNullOrEmpty(filter)) || (filter.Trim().Length == 0))
             {
                 filter = "*";
             }
             if (AllSubDirectories)
             {
                 files = Directory.GetFiles(folderpath, filter, SearchOption.AllDirectories);
             }
             else
             {
                 files = Directory.GetFiles(folderpath, filter, SearchOption.TopDirectoryOnly);
             }
             ResultFileStringArray.Set(context, files);
         }
     }
     catch (Exception ex)
     {
         Log.Logger.LogData(ex.Message + " in activity Folder_FileList", LogLevel.Error);
         if (!ContinueOnError)
         {
             context.Abort();
         }
     }
 }
        protected override void Execute(NativeActivityContext context)
        {
            //throw new NotImplementedException();
            try
            {
                string path    = FolderPath.Get(context);
                string newname = NewFolderName.Get(context);
                //string oldname = FolderName.Get(context);
                //int len = oldname.Length;

                // string filepath = Path.GetDirectoryName(path);

                if (Directory.Exists(path))
                {
                    // string newpath = path.Remove(path.Length - len, len);
                    string dirpath = Path.GetDirectoryName(path);
                    string newpath = dirpath + "\\" + newname;



                    if (isOverride == true)
                    {
                        if (Directory.Exists(newpath) && !(path.Equals(newpath)))
                        {
                            Directory.Delete(newpath, true);
                        }
                    }

                    Directory.Move(path, newpath);
                }
                else
                {
                    Log.Logger.LogData("Folder does not exist in path - " + path + " in activity Folder_Rename", LogLevel.Error);
                    if (!ContinueOnError)
                    {
                        context.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message + " in activity Folder_Rename", LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
 protected override void Execute(NativeActivityContext context)
 {
     try
     {
         string folderPath = FolderPath.Get(context);
         bool   result     = Directory.Exists(folderPath);
         Result.Set(context, result);
     }
     catch (Exception ex)
     {
         Log.Logger.LogData(ex.Message + " in activity Folder_Exists", LogLevel.Error);
         if (!ContinueOnError)
         {
             context.Abort();
         }
     }
 }
Example #9
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                string folderName = FolderName.Get(context);
                string folderPath = FolderPath.Get(context);
                string rawPath    = folderPath;
                if (Directory.Exists(folderPath))
                {
                    folderPath = folderPath + "\\" + folderName;

                    if (Directory.Exists(folderPath))
                    {
                        Log.Logger.LogData("Folder already exists in path - " + folderPath + " in activity Folder_Create", LogLevel.Error);
                        if (!ContinueOnError)
                        {
                            context.Abort();
                        }
                    }
                    else
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                }
                else
                {
                    Log.Logger.LogData("Path does not exist - " + rawPath + " in activity Folder_Create", LogLevel.Error);
                    if (!ContinueOnError)
                    {
                        context.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message + " in activity Folder_Create", LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }
 protected override void Execute(NativeActivityContext context)
 {
     try
     {
         string folderpath = FolderPath.Get(context);
         if (Directory.Exists(folderpath))
         {
             var folderInfo = new FileInfo(folderpath);
             var dirInfo    = new DirectoryInfo(folderpath);
             FolderName.Set(context, folderInfo.Name);
             // FolderCount.Set(context, folderInfo.Extension);
             // FileCount.Set(context, folderInfo.Length);
             FolderCount.Set(context, dirInfo.GetDirectories().Length);
             FileCount.Set(context, dirInfo.GetFiles().Length);
             CreationTime.Set(context, folderInfo.CreationTime);
             LastAccessTime.Set(context, folderInfo.LastAccessTime);
             LastWriteTime.Set(context, folderInfo.LastWriteTime);
         }
         else if (!Directory.Exists(folderpath))
         {
             Log.Logger.LogData("Folder does not exist in path - " + folderpath + " in activity Folder_GetInformation", LogLevel.Error);
             if (!ContinueOnError)
             {
                 context.Abort();
             }
         }
     }
     catch (Exception ex)
     {
         Log.Logger.LogData(ex.Message + " in activity Folder_GetInformation", LogLevel.Error);
         if (!ContinueOnError)
         {
             context.Abort();
         }
     }
 }
Example #11
0
        protected override void Execute(CodeActivityContext context)
        {
            string extract    = FolderPath.Get(context);
            string outputPath = SaveAsPath.Get(context);

            Microsoft.Office.Interop.Excel.Application excel;
            Microsoft.Office.Interop.Excel.Workbook    excelworkBook;
            Microsoft.Office.Interop.Excel.Worksheet   excelSheet1, excelSheet2, excelSheet3, excelSheet4;
            Microsoft.Office.Interop.Excel.Range       excelCellrange;
            Microsoft.Office.Interop.Excel.Borders     border;
            //
            // Start Excel and get Application object.
            excel = new Microsoft.Office.Interop.Excel.Application();

            // for making Excel visible
            excel.Visible       = false;
            excel.DisplayAlerts = false;

            // Creation a new Workbook
            excelworkBook = excel.Workbooks.Add(Type.Missing);

            string root      = "////////";
            string extn      = "";
            string space     = "";
            string temp_path = "";

            int cnt  = 0;
            int cnt1 = 0;

            int k = 2;
            int l = 1;
            int m = 2;

            List <String> addpkg    = new List <string>();
            List <String> addpkg1   = new List <string>();
            List <String> extnlst   = new List <string>();
            List <String> extnlst1  = new List <string>();
            List <String> countval1 = new List <string>();

            string pkg = extract.Split(Path.DirectorySeparatorChar).Last();

            char[] charsTotrim = { '{', '}', ' ', '=' };

            System.Data.DataTable xaml = new System.Data.DataTable();
            DataRow xamlnull           = xaml.NewRow();

            xaml.Columns.Add("XAML");
            xaml.Columns.Add(pkg);
            xaml.Rows.Add(xamlnull);

            System.Data.DataTable fileCnt = new System.Data.DataTable();
            DataRow filenull = fileCnt.NewRow();

            fileCnt.Columns.Add("File_Type");
            fileCnt.Columns.Add("Total_Count");
            fileCnt.Rows.Add(filenull);
            DataRow cntnull = fileCnt.NewRow();

            fileCnt.Rows.Add(cntnull);

            //////////////////////Sheet_For_Tree_View_1
            excelSheet1             = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet;
            excelSheet1.Name        = "Folder_Structure_1";
            excelSheet1.Cells[1, 1] = pkg;
            foreach (string file in Directory.EnumerateFiles(
                         extract, "*.*", SearchOption.AllDirectories))
            {
                if (file.Contains(root))
                {
                    space = new string(' ', root.Length - extract.Length);
                }
                else
                {
                    space = new string(' ', root.Length);
                }
                int position = file.LastIndexOf('\\');
                excelSheet1.Cells[k, l] = file.Replace(root, space).Replace(extract, "");
                root = file.Substring(0, position);
                k++;
                temp_path = file.Substring(position + 1, file.Length - position - 1);
                cnt++;
                int pos = temp_path.LastIndexOf('.');
                extn = temp_path.Substring(pos + 1, temp_path.Length - pos - 1);
                //Console.WriteLine(extn);
                extnlst.Add(extn);
                addpkg.Add(temp_path);
            }
            excelCellrange = excelSheet1.Range[excelSheet1.Cells[1, 1], excelSheet1.Cells[k, l]];
            excelCellrange.EntireColumn.AutoFit();

            var result = extnlst.GroupBy(item => item)
                         .Select(item => new {
                Name  = item.Key,
                Count = item.Count()
            })
                         .OrderByDescending(item => item.Count)
                         .ThenBy(item => item.Name);

            DataRow titlerow = fileCnt.NewRow();

            titlerow["File_Type"] = pkg.ToUpper();
            fileCnt.Rows.Add(titlerow);
            foreach (var addex in result)
            {
                DataRow  dttcount = fileCnt.NewRow();
                string[] splitVal = addex.ToString().Split(',');
                dttcount["File_Type"]   = "." + splitVal[0].Replace("Name", "").Trim(charsTotrim);
                dttcount["Total_Count"] = splitVal[1].Replace("Count", "").Trim(charsTotrim);
                fileCnt.Rows.Add(dttcount);
            }
            DataRow cntnull1 = fileCnt.NewRow();

            fileCnt.Rows.Add(cntnull1);

            var finalpkg = addpkg.Union(addpkg1);

            foreach (var check in finalpkg)
            {
                DataRow dtxaml = xaml.NewRow();
                dtxaml["XAML"] = check;
                if (addpkg.Contains(check))
                {
                    dtxaml[pkg] = "Yes";
                }
                else
                {
                    dtxaml[pkg] = "No";
                }
                xaml.Rows.Add(dtxaml);
            }
            DataRow dtcountnull = xaml.NewRow();

            xaml.Rows.Add(dtcountnull);
            DataRow dtcount = xaml.NewRow();

            dtcount["XAML"] = "Total Number of Files";
            dtcount[pkg]    = cnt;
            xaml.Rows.Add(dtcount);

            /////////////////////////////Sheet For List of File Counts in a Folder
            excelSheet3 = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.Sheets.Add(System.Reflection.Missing.Value,
                                                                                             excelworkBook.Worksheets[excelworkBook.Worksheets.Count],
                                                                                             System.Reflection.Missing.Value,
                                                                                             System.Reflection.Missing.Value);
            excelSheet3.Name = "File_Count";
            int p = 1;
            int q = 1;

            foreach (DataRow dr in fileCnt.Rows)
            {
                foreach (DataColumn dc in fileCnt.Columns)
                {
                    if (p == 1)
                    {
                        excelSheet3.Cells[p, q] = dc.ColumnName.ToString();
                    }
                    else
                    {
                        excelSheet3.Cells[p, q] = dr[dc].ToString();
                    }
                    q++;
                }
                p++;
                q = 1;
            }
            //put everything in a table
            if (fileCnt.Rows.Count == 0)
            {
                excelCellrange = excelSheet3.Range[excelSheet3.Cells[1, 1], excelSheet3.Cells[1, fileCnt.Columns.Count]];
            }
            else
            {
                excelCellrange = excelSheet3.Range[excelSheet3.Cells[1, 1], excelSheet3.Cells[fileCnt.Rows.Count, fileCnt.Columns.Count]];
            }
            excelCellrange.EntireColumn.AutoFit();
            excelCellrange.EntireRow.AutoFit();
            border           = excelCellrange.Borders;
            border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
            border.Weight    = 2d;
            excelCellrange   = excelSheet3.Range["A1", "B1"];
            excelCellrange.Interior.Color = System.Drawing.
                                            ColorTranslator.ToOle(System.Drawing.Color.Lavender);
            excelCellrange.Font.Color = System.Drawing.
                                        ColorTranslator.ToOle(System.Drawing.Color.Black);
            excelCellrange.Font.Bold = true;

            /////////////////////////////Sheet For Compare Sheet
            excelSheet4 = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.Sheets.Add(System.Reflection.Missing.Value,
                                                                                             excelworkBook.Worksheets[excelworkBook.Worksheets.Count],
                                                                                             System.Reflection.Missing.Value,
                                                                                             System.Reflection.Missing.Value);
            excelSheet4.Name = "Package_Explorer";
            //excelCellrange = new Microsoft.Office.Interop.Excel.Range();
            int i = 1;
            int j = 1;

            foreach (DataRow dr in xaml.Rows)
            {
                foreach (DataColumn dc in xaml.Columns)
                {
                    if (i == 1)
                    {
                        excelSheet4.Cells[i, j] = dc.ColumnName.ToString();
                    }
                    else
                    {
                        excelSheet4.Cells[i, j] = dr[dc].ToString();
                    }
                    j++;
                }
                i++;
                j = 1;
            }
            //put everything in a table
            if (xaml.Rows.Count == 0)
            {
                excelCellrange = excelSheet4.Range[excelSheet4.Cells[1, 1], excelSheet4.Cells[1, xaml.Columns.Count]];
            }
            else
            {
                excelCellrange = excelSheet4.Range[excelSheet4.Cells[1, 1], excelSheet4.Cells[xaml.Rows.Count, xaml.Columns.Count]];
            }
            excelCellrange.EntireColumn.AutoFit();
            excelCellrange.EntireRow.AutoFit();
            border           = excelCellrange.Borders;
            border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
            border.Weight    = 2d;
            excelCellrange   = excelSheet4.Range["A1", "B1"];
            excelCellrange.Interior.Color = System.Drawing.
                                            ColorTranslator.ToOle(System.Drawing.Color.Lavender);
            excelCellrange.Font.Color = System.Drawing.
                                        ColorTranslator.ToOle(System.Drawing.Color.Black);
            excelCellrange.Font.Bold = true;

            excelworkBook.SaveAs(outputPath);
            string rslt = "File Created";

            Output.Set(context, rslt);
        }
Example #12
0
        Task <IEnumerable <string> > SaveAttachments(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            string      folderPath = FolderPath.Get(context);
            MailMessage mail       = Message.Get(context);
            string      filter     = Filter.Get(context);

            return(Task.Factory.StartNew((Func <IEnumerable <string> >) delegate
            {
                List <string> list = new List <string>();
                List <Exception> list2 = new List <Exception>();
                if (mail.Attachments == null || mail.Attachments.Count == 0)
                {
                    return list;
                }
                if (string.IsNullOrEmpty(folderPath))
                {
                    folderPath = Directory.GetCurrentDirectory();
                }
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                foreach (Attachment attachment in mail.Attachments)
                {
                    try
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            return list;
                        }
                        string text = Path.GetFileName(attachment.Name);
                        if (!string.IsNullOrEmpty(folderPath))
                        {
                            text = Path.Combine(folderPath, text);
                        }
                        if (string.IsNullOrEmpty(filter) || Regex.IsMatch(text, filter))
                        {
                            try
                            {
                                FileStream fileStream = File.Open(text, FileMode.Create, FileAccess.Write);
                                attachment.ContentStream.Position = 0L;
                                attachment.ContentStream.CopyTo(fileStream);
                                fileStream.Close();
                                list.Add(text);
                            }
                            finally
                            {
                                attachment.ContentStream.Position = 0L;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个异常产生", ex.Message);
                        list2.Add(ex);
                    }
                }
                if (list2.Count > 0)
                {
                    throw new AggregateException(list2);
                }
                return list;
            }));
        }
Example #13
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            PropertyDescriptor dropboxSessionProperty = context.DataContext.GetProperties()[WithDropboxSession.DropboxSessionPropertyName];
            IDropboxSession    dropboxSession         = dropboxSessionProperty?.GetValue(context.DataContext) as IDropboxSession;

            if (dropboxSession == null)
            {
                throw new InvalidOperationException(Resources.DropboxSessionNotFoundException);
            }

            IEnumerable <DropboxFileMetadata> files = await dropboxSession.ListFolderContentAsync(FolderPath.Get(context), Recursive, cancellationToken);

            return((asyncCodeActivityContext) =>
            {
                Files.Set(asyncCodeActivityContext, files);
            });
        }