/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> /// <param name="context">The execution context under which the activity executes.</param> protected override IEnumerable <ISequence> Execute(CodeActivityContext context) { string filename = Filename.Get(context); ISequenceParser parser = SequenceParsers.FindParserByFileName(filename); if (parser == null) { throw new ArgumentException("Could not determine parser for " + filename); } string alphaName = DesiredAlphabet; if (!string.IsNullOrEmpty(alphaName)) { alphaName = alphaName.ToLowerInvariant(); IAlphabet alphabet = Alphabets.All.FirstOrDefault(a => a.Name.ToLowerInvariant() == alphaName); if (alphabet == null) { throw new ArgumentException("Unknown alphabet name"); } parser.Alphabet = alphabet; } if (LogOutput) { var tw = context.GetExtension <TextWriter>() ?? Console.Out; tw.WriteLine("Reading sequences from " + filename); } return(parser.Parse()); }
protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context) { var filename = Filename.Get(context); var id = _id.Get(context); var ignoreerrors = IgnoreErrors.Get(context); var q = "{\"_id\": \"" + id + "\"}"; if (!string.IsNullOrEmpty(filename)) { q = "{\"filename\":\"" + filename + "\"}"; } // await global.webSocketClient.DeleteOne("files", q); var rows = await global.webSocketClient.Query <JObject>("fs.files", q); if (rows.Length == 0) { if (!ignoreerrors) { throw new Exception("File not found"); } return(42); } foreach (var row in rows) { var _id = row["_id"].ToString(); await global.webSocketClient.DeleteOne("fs.files", _id); } return(42); }
protected override void Execute(CodeActivityContext context) { var useHeaderRow = false; if (UseHeaderRow != null) { useHeaderRow = UseHeaderRow.Get(context); } string[] delimeters = null; if (Delimeter != null) { var d = Delimeter.Get(context); if (!string.IsNullOrEmpty(d)) { delimeters = new string[] { d }; } } if (delimeters == null || delimeters.Length == 0) { delimeters = new string[] { ",", ";" } } ; System.Data.DataTable result = null; var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); result = GetDataTabletFromCSVFile(filename, useHeaderRow, delimeters); if (DataTable != null) { context.SetValue(DataTable, result); } } }
protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); var arguments = Arguments.Get(context); var workingdirectory = WorkingDirectory.Get(context); var waitforexit = WaitForExit.Get(context); var waitforexittimeout = WaitForExitTimeout.Get(context); ProcessStartInfo startInfo = new ProcessStartInfo(); filename = Environment.ExpandEnvironmentVariables(filename); startInfo.FileName = filename; startInfo.Arguments = arguments; startInfo.WorkingDirectory = workingdirectory; var p = Process.Start(startInfo); if (waitforexit) { if (waitforexittimeout.TotalMilliseconds > 50) { p.WaitForExit((int)waitforexittimeout.TotalMilliseconds); } else { p.WaitForExit(); } } }
protected override void Execute(CodeActivityContext context) { var workbook = Workbook.Get(context); var filename = Filename.Get(context); var saveChanges = SaveChanges.Get(context); if (!string.IsNullOrEmpty(filename)) { filename = Environment.ExpandEnvironmentVariables(filename); } if (string.IsNullOrEmpty(filename)) { workbook.Close(saveChanges); } else { foreach (Microsoft.Office.Interop.Excel.Workbook w in officewrap.application.Workbooks) { if (w.FullName == filename) { try { workbook = w; w.Close(saveChanges); //worksheet = workbook.ActiveSheet; break; } catch (Exception) { workbook = null; } } } } }
protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); var script = Script.Get(context); var function = Function.Get(context); var newinstance = NewInstance.Get(context); var param1 = Param1.Get(context); var param2 = Param2.Get(context); var param3 = Param3.Get(context); var param4 = Param4.Get(context); if (sharpAHK.ahkGlobal.ahkdll == null || newinstance) { New_AHKSession(newinstance); } if (!sharpAHK.ahkGlobal.ahkdll.FunctionExists(function)) { if (!string.IsNullOrEmpty(filename)) { sharpAHK.ahkGlobal.ahkdll.LoadFile(filename); } else { sharpAHK.ahkGlobal.ahkdll.LoadScript(script); } } if (!sharpAHK.ahkGlobal.ahkdll.FunctionExists(function)) { throw new ArgumentNullException("Function '" + function + "' does not exists"); } var result = sharpAHK.ahkGlobal.ahkdll.ExecFunction(function, param1, param2, param3, param4); Result.Set(context, result); }
protected override void Execute(CodeActivityContext context) { var includeBaseDirectory = IncludeBaseDirectory.Get(context); var compressionLevel = CompressionLevel.Get(context); var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); var path = Path.Get(context); path = Environment.ExpandEnvironmentVariables(path); if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(filename)) { if (System.IO.File.Exists(filename)) { if (Overwrite.Get(context)) { System.IO.File.Delete(filename); } else { throw new System.IO.IOException("The file '" + filename + "' already exists."); } } System.IO.Compression.ZipFile.CreateFromDirectory(path, filename, (System.IO.Compression.CompressionLevel)compressionLevel, includeBaseDirectory); } }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> /// <param name="context">The execution context under which the activity executes.</param> protected override void Execute(CodeActivityContext context) { string filename = Filename.Get(context); ISequenceFormatter formatter = SequenceFormatters.FindFormatterByFileName(filename); if (formatter == null) { throw new ArgumentException("Could not determine formatter for " + filename); } if (LogOutput) { var tw = context.GetExtension <TextWriter>() ?? Console.Out; tw.WriteLine("Writing sequences to " + filename); } try { foreach (var s in Sequences.Get(context)) { formatter.Format(s); } } finally { formatter.Close(); } }
// Add wait for element protected override void Execute(CodeActivityContext context) { AndroidDriver <AndroidElement> driver; // Inherit driver from scope activity OR from input (if out of context) try { driver = context.DataContext.GetProperties()["Driver"].GetValue(context.DataContext) as AndroidDriver <AndroidElement>; } catch { driver = Driver.Get(context); } // Receive fields string filename = Filename.Get(context) ?? "capture"; int delay = Delay.Get(context); // Set up path string defaultPath = driver.Capabilities.GetCapability(AndroidMobileCapabilityType.AndroidScreenshotPath) as string; string fullPath = Path.Combine(defaultPath, filename + ".png"); Thread.Sleep(delay); // Take screenshot Screenshot s = driver.GetScreenshot(); s.SaveAsFile(fullPath, ScreenshotImageFormat.Png); }
protected override void Execute(CodeActivityContext context) { var workbook = Workbook.Get(context); var filename = Filename.Get(context); var saveChanges = SaveChanges.Get(context); if (!string.IsNullOrEmpty(filename)) { filename = Environment.ExpandEnvironmentVariables(filename); } if (string.IsNullOrEmpty(filename)) { workbook.Close(saveChanges); } else { int workbookcount = 0; bool foundit = false; foreach (Microsoft.Office.Interop.Excel.Workbook w in officewrap.application.Workbooks) { if (w.FullName == filename || string.IsNullOrEmpty(filename)) { try { officewrap.application.DisplayAlerts = false; workbook = w; w.Close(saveChanges); officewrap.application.DisplayAlerts = true; foundit = true; //worksheet = workbook.ActiveSheet; break; } catch (Exception) { workbook = null; } } } Microsoft.Office.Interop.Excel.Workbook tempworkbook = officewrap.application.ActiveWorkbook; if (!foundit && tempworkbook != null) { officewrap.application.DisplayAlerts = false; if (saveChanges && !string.IsNullOrEmpty(filename)) { tempworkbook.SaveAs(Filename: filename); } else { tempworkbook.Close(saveChanges); } officewrap.application.DisplayAlerts = true; } if (workbookcount == 0 || string.IsNullOrEmpty(filename)) { officewrap.application.Quit(); } } }
protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); Application activeObject = null; object missing = Type.Missing; Document document = null; try { activeObject = (Application)Marshal.GetActiveObject("Word.Application"); foreach (Document current in activeObject.Documents) { if (current.FullName == filename) { document = current; break; } } } catch { activeObject = null; } finally { if (activeObject == null) { activeObject = (Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046"))); } activeObject.Visible = true; } object ofilename = filename; if (document == null) { document = activeObject.Documents.Open(ref ofilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); } var p = document.Content.Paragraphs; int index = Index.Get(context); if (Index.Expression == null) { var r = document.Range(0, document.Paragraphs.Last.Range.End); r.Text = Text.Get(context); // + "\r"; } else { if (p.Count < index) { throw new Exception("filename only contains " + p.Count + " Paragraphs"); } p[index].Range.Text = Text.Get(context); } }
protected async override Task <int> ExecuteAsync(AsyncCodeActivityContext context) { var filename = Filename.Get(context); var id = _id.Get(context); var filepath = LocalPath.Get(context); var ignorepath = IgnorePath.Get(context); await global.webSocketClient.DownloadFileAndSave(filename, id, filepath, ignorepath); return(13); }
protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); string json = System.IO.File.ReadAllText(filename); System.Data.DataTable dt = (System.Data.DataTable)JsonConvert.DeserializeObject(json, (typeof(System.Data.DataTable))); DataTable.Set(context, dt); }
protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(filename); context.SetValue(Result, reader); var result = GetTextFromAllPages(reader); context.SetValue(AllText, result); }
protected override void Execute(CodeActivityContext context) { var saveChanges = SaveChanges.Get(context); var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); Application activeObject = null; object missing = Type.Missing; Document document = null; try { activeObject = (Application)Marshal.GetActiveObject("Word.Application"); if (!string.IsNullOrEmpty(filename)) { foreach (Document current in activeObject.Documents) { if (current.FullName == filename) { document = current; document.Close(saveChanges); break; } } } } catch { activeObject = null; } finally { if (activeObject == null) { activeObject = (Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046"))); } activeObject.Visible = true; } int doccount = 0; foreach (Document current in activeObject.Documents) { if (current.FullName == filename) { doccount++; break; } } if (doccount == 0 || string.IsNullOrEmpty(filename)) { activeObject.Quit(saveChanges); } }
protected override void Execute(NativeActivityContext context) { var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); var b = new Bitmap(filename); var v = new ImageElement(Rectangle.Empty, b); context.SetValue(Result, v); context.ScheduleAction(Body, v, OnBodyComplete); }
protected override void Execute(CodeActivityContext context) { Envelope env = Envelope.Get(context); string name = Name.Get(context); string filename = Filename.Get(context); Document doc = new Document(name, filename); env.AddDocument(doc); Document.Set(context, doc); }
protected override void Execute(CodeActivityContext context) { var filename = Filename.Get(context); var script = Script.Get(context); var newinstance = NewInstance.Get(context); if (sharpAHK.ahkGlobal.ahkdll == null || newinstance) { New_AHKSession(newinstance); } if (!string.IsNullOrEmpty(filename)) { if (!System.IO.File.Exists(filename)) { throw new System.IO.FileNotFoundException("File not found", filename); } script = System.IO.File.ReadAllText(filename); } var vars = context.DataContext.GetProperties(); foreach (dynamic v in vars) { var value = v.GetValue(context.DataContext); if (value != null) { try { sharpAHK.ahkGlobal.ahkdll.SetVar(v.DisplayName, value.ToString()); } catch (Exception) { } } else { sharpAHK.ahkGlobal.ahkdll.SetVar(v.DisplayName, ""); } } sharpAHK.ahkGlobal.ahkdll.ExecRaw(script); foreach (dynamic v in vars) { try { var value = sharpAHK.ahkGlobal.ahkdll.GetVar(v.DisplayName); v.SetValue(context.DataContext, value); } catch (Exception) { } } //var result = sharpAHK.ahkGlobal.ahkdll.ExecFunction(function, param1, param2, param3, param4); //Result.Set(context, result); }
protected override void Execute(CodeActivityContext context) { var email = EMail.Get(context); var filename = Filename.Get(context); var folder = Folder.Get(context); var astype = Type.Get(context); if (!string.IsNullOrEmpty(folder)) { filename = System.IO.Path.Combine(folder, RemoveInvalidChars(email.Subject)); switch (astype) { case "4": filename += ".doc"; break; case "5": filename += ".html"; break; case "8": filename += ".ics"; break; case "10": filename += ".mht"; break; case "3": filename += ".msg"; break; case "9": filename += ".msg"; break; case "1": filename += ".rtf"; break; case "2": filename += ".oft"; break; case "0": filename += ".txt"; break; case "7": filename += ".vcs"; break; case "6": filename += ".vcf"; break; } } email.mailItem.SaveAs(filename, astype); // olMSGUnicode / msg : 9 olMSG / msg : 3 if (!string.IsNullOrEmpty(folder)) { Filename.Set(context, filename); } }
protected override void Execute(CodeActivityContext context) { var key = Key.Get(context); var queue = Queue.Get(context); var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); var res = SimpleRequests.HttpUploadFile(queue + "/upload", filename, key, "content", "image/jpeg"); var o = JObject.Parse(res); var fileurl = o["results"][0]["annotation"].ToString(); context.SetValue(Result, fileurl); }
protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context) { var filename = Filename.Get(context); var id = _id.Get(context); var filepath = LocalPath.Get(context); var ignorepath = IgnorePath.Get(context); // await global.webSocketClient.DownloadFileAndSave(filename, id, filepath, ignorepath); Uri baseUri = new Uri(global.openflowconfig.baseurl); filepath = Environment.ExpandEnvironmentVariables(filepath); var q = "{\"_id\": \"" + id + "\"}"; if (!string.IsNullOrEmpty(filename)) { q = "{\"filename\":\"" + filename + "\"}"; } var rows = await global.webSocketClient.Query <JObject>("files", q, null, 100, 0, "{\"_id\": -1}"); if (rows.Length == 0) { throw new Exception("File not found"); } if (rows.Length == 0) { throw new Exception("File not found"); } filename = rows[0]["filename"].ToString(); id = rows[0]["_id"].ToString(); Uri downloadUri = new Uri(baseUri, "/download/" + id); var url = downloadUri.ToString(); // if(string.IsNullOrEmpty(filename)) filename = "temp." // if (System.IO.File.Exists(filepath) && !overwrite) return 42; using (var client = new System.Net.WebClient()) { // client.Headers.Add("Authorization", "jwt " + global.webSocketClient); client.Headers.Add(System.Net.HttpRequestHeader.Authorization, global.webSocketClient.jwt); if (ignorepath) { filename = System.IO.Path.GetFileName(filename); } await client.DownloadFileTaskAsync(new Uri(url), System.IO.Path.Combine(filepath, filename)); } return(42); }
protected override void Execute(CodeActivityContext context) { var overwrite = Overwrite.Get(context); var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); var path = Path.Get(context); path = Environment.ExpandEnvironmentVariables(path); if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(filename)) { var archive = ZipFile.OpenRead(filename); archive.ExtractToDirectory(path, overwrite); } }
protected async override Task <string> ExecuteAsync(AsyncCodeActivityContext context) { var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); var path = Path.Get(context); if (!System.IO.File.Exists(filename)) { throw new System.IO.FileNotFoundException("File not found " + filename); } string id = await global.webSocketClient.UploadFile(filename, path, null); return(id); }
protected override void Execute(CodeActivityContext context) { var useHeaderRow = false; if (UseHeaderRow != null) { useHeaderRow = UseHeaderRow.Get(context); } System.Data.DataSet result = null; var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); using (var stream = System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { // Auto-detect format, supports: // - Binary Excel files (2.0-2003 format; *.xls) // - OpenXml Excel files (2007 format; *.xlsx) var conf = new ExcelDataReader.ExcelDataSetConfiguration { ConfigureDataTable = _ => new ExcelDataReader.ExcelDataTableConfiguration { UseHeaderRow = useHeaderRow } }; using (var reader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream)) { // Choose one of either 1 or 2: // 1. Use the reader methods //do //{ // while (reader.Read()) // { // // reader.GetDouble(0); // } //} while (reader.NextResult()); // 2. Use the AsDataSet extension method result = reader.AsDataSet(conf); } } if (DataSet != null) { context.SetValue(DataSet, result); } }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { string fn = Filename.Get(context); if (string.IsNullOrWhiteSpace(fn)) { throw new ArgumentNullException("Filename", "Missing filename to execute."); } string args = Arguments.Get(context); TextWriter tw = context.GetExtension <TextWriter>() ?? Console.Out; Func <int> exec = () => { ProcessStartInfo psi = new ProcessStartInfo(fn) { CreateNoWindow = true, ErrorDialog = false, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = this.UseShellExec, }; if (!string.IsNullOrEmpty(args)) { psi.Arguments = args; } _process = Process.Start(psi); _process.OutputDataReceived += (sender, eventArgs) => tw.WriteLine(eventArgs.Data); _process.ErrorDataReceived += (sender, eventArgs) => tw.WriteLine(eventArgs.Data); _process.WaitForExit(); int rc = _process.ExitCode; _process = null; return(rc); }; context.UserState = exec; return(exec.BeginInvoke(callback, state)); }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } var filename = Filename.Get(context); var recordUrl = RecordUrl.Get <string>(context); var dup = new DynamicUrlParser(recordUrl); var foundNote = GetNote(localContext.OrganizationService, filename, dup.Id); FoundNote.Set(context, foundNote); }
protected override void Execute(CodeActivityContext context) { var includeHeader = false; if (IncludeHeader != null) { includeHeader = IncludeHeader.Get(context); } var filename = Filename.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); var delimeter = Delimeter.Get(context); if (string.IsNullOrEmpty(delimeter)) { delimeter = ";"; } var dt = DataTable.Get(context); dt.ToCSV(filename, delimeter, includeHeader); }
protected override void StartLoop(NativeActivityContext context) { var filename = Filename.Get(context); var maxresults = MaxResults.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); Application activeObject = null; object missing = Type.Missing; Document document = null; try { activeObject = (Application)Marshal.GetActiveObject("Word.Application"); foreach (Document current in activeObject.Documents) { if (current.FullName == filename) { document = current; break; } } } catch { activeObject = null; } finally { if (activeObject == null) { activeObject = (Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046"))); } activeObject.Visible = true; } object ofilename = filename; if (document == null) { document = activeObject.Documents.Open(ref ofilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); } var p = document.Content.Paragraphs; string text = ""; int index = Index.Get(context); Count.Set(context, p.Count); var result = new List <string>(); if (Index.Expression == null) { for (var i = 0; i < p.Count; i++) { result.Add(p[i + 1].Range.Text); text += p[i + 1].Range.Text; if (maxresults > 0 && maxresults == result.Count) { break; } } } else { if (p.Count < index) { throw new Exception("filename only contains " + p.Count + " Paragraphs"); } for (var i = (index - 1); i < p.Count; i++) { result.Add(p[i + 1].Range.Text); text += p[i + 1].Range.Text; if (maxresults > 0 && maxresults == result.Count) { break; } } //text = p[index].Range.Text; } Text.Set(context, text); IEnumerator <string> _enum = result.ToList().GetEnumerator(); _elements.Set(context, _enum); bool more = _enum.MoveNext(); if (more) { if (Body != null) { context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } } }
protected override void Execute(NativeActivityContext context) { filename = Filename.Get(context); officewrap.application.Visible = Visible.Get(context); if (!string.IsNullOrEmpty(filename)) { filename = Environment.ExpandEnvironmentVariables(filename); } workbook = (Workbook != null ? Workbook.Get(context) : null); if (!string.IsNullOrEmpty(filename) && workbook != null) { if (workbook.FullName.ToLower() != filename.ToLower()) { try { workbook.Close(true); workbook = null; Task.Run(() => { GC.Collect(); }); } catch (Exception) { throw; } } } if (workbook == null) { if (!string.IsNullOrEmpty(filename)) { filename = Environment.ExpandEnvironmentVariables(filename); foreach (Microsoft.Office.Interop.Excel.Workbook w in officewrap.application.Workbooks) { if (w.FullName == filename) { workbook = w; break; } } if (workbook == null) { workbook = officewrap.application.Workbooks.Open(filename); } } else { workbook = officewrap.application.Workbooks.Add(); } } var _worksheet = (Worksheet != null ? Worksheet.Get(context) : null); worksheet = workbook.ActiveSheet; if (!string.IsNullOrEmpty(_worksheet)) { foreach (Microsoft.Office.Interop.Excel.Worksheet s in workbook.Sheets) { if (s.Name == _worksheet) { s.Activate(); worksheet = s; } } } //Application.Set(context, application); Workbook.Set(context, workbook); }
protected override void Execute(NativeActivityContext context) { var readPassword = ReadPassword.Get(context); if (string.IsNullOrEmpty(readPassword)) { readPassword = null; } var writePassword = WritePassword.Get(context); if (string.IsNullOrEmpty(writePassword)) { writePassword = null; } filename = Filename.Get(context); officewrap.application.Visible = true; // officewrap.application.Visible = Visible.Get(context); if (!string.IsNullOrEmpty(filename)) { filename = Environment.ExpandEnvironmentVariables(filename); } workbook = (Workbook != null ? Workbook.Get(context) : null); if (!string.IsNullOrEmpty(filename) && workbook != null) { if (workbook.FullName.ToLower() != filename.ToLower()) { try { workbook.Close(true); workbook = null; Task.Run(() => { GC.Collect(); }); } catch (Exception) { throw; } } } if (!string.IsNullOrEmpty(filename) && workbook == null) { foreach (Microsoft.Office.Interop.Excel.Workbook w in officewrap.application.Workbooks) { if (w.FullName == filename) { workbook = w; break; } } if (workbook == null) { officewrap.application.DisplayAlerts = false; //application.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow; if (System.IO.File.Exists(filename)) { //workbook = officewrap.application.Workbooks.Open(filename, ReadOnly: false); workbook = officewrap.application.Workbooks.Open(filename, ReadOnly: false, Password: readPassword, WriteResPassword: writePassword); } else { workbook = officewrap.application.Workbooks.Add(); workbook.Activate(); //workbook.SaveCopyAs(filename); workbook.SaveAs(Filename: filename); } officewrap.application.DisplayAlerts = true; } } if (workbook == null) { workbook = officewrap.application.ActiveWorkbook; } if (workbook == null) { } var _worksheet = (Worksheet != null ? Worksheet.Get(context) : null); worksheet = workbook.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet; if (!string.IsNullOrEmpty(_worksheet)) { foreach (object obj in workbook.Sheets) { Worksheet s = obj as Worksheet; if (s != null && s.Name == _worksheet) { s.Activate(); worksheet = s; } } } var sheetPassword = SheetPassword.Get(context); if (string.IsNullOrEmpty(sheetPassword)) { sheetPassword = null; } if (!string.IsNullOrEmpty(sheetPassword) && worksheet != null) { worksheet.Unprotect(sheetPassword); } //Application.Set(context, application); Workbook.Set(context, workbook); }