private void Source_OnCommandOutput(IOutputCommand sender, object output) { ContentReference cr = (output.GetType() == typeof(ContentReference)) ? (ContentReference)output : ContentReference.Parse(output.ToString()); var c = _repo.Get <IContent>(cr); OnCommandOutput?.Invoke(this, c); }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (output is string) { if (contents == null) { contents = new List <string>(); } contents.Add(output as string); } else if (output is IDictionary <string, object> ) { //Check for contents and create attachment var dic = output as IDictionary <string, object>; if (dic.ContainsKey("Contents")) { var content = (dic["Contents"] is List <string>) ? string.Join("\n", (dic["Contents"] as List <string>).ToArray()) : dic["Contents"] as string; var file = new TransferFile(); file.FileName = FileName ?? GenerateFileName(); file.Mimetype = Mimetype ?? "text/plain"; file.Data = UTF8Encoding.UTF8.GetBytes(content); dic["Attachment"] = file; OnCommandOutput?.Invoke(this, dic); } } }
protected string DownloadAsset(string url) { try { WebClient wc = new WebClient(); byte[] asset = wc.DownloadData(url); string ext = Path.GetExtension(url); var ctype = _mresolver.GetFirstMatching(ext); ContentType contentType = _trepo.Load(ctype); //TODO: Support destination that should be resolved. var assetFile = _repo.GetDefault <MediaData>(SiteDefinition.Current.GlobalAssetsRoot, contentType.ID); assetFile.Name = Path.GetFileName(url); var blob = _blobFactory.CreateBlob(assetFile.BinaryDataContainer, ext); using (var s = blob.OpenWrite()) { var w = new StreamWriter(s); w.BaseStream.Write(asset, 0, asset.Length); w.Flush(); } assetFile.BinaryData = blob; var assetContentRef = _repo.Save(assetFile, SaveAction.Publish); OnCommandOutput?.Invoke(this, assetContentRef); //If piped, output the reference that was just created } catch (Exception exc) { return(exc.Message); } return(null); }
public string Execute(params string[] parameters) { string path = HttpContext.Current.Server.MapPath("~/packages.config"); if (File.Exists(path)) { int cnt = 0; var xdoc = XDocument.Parse(File.ReadAllText(path)); foreach (var xe in xdoc.Descendants("package")) { string name = xe.Attribute("id").Value; string version = xe.Attribute("version").Value; if (OnlyName) { OnCommandOutput?.Invoke(this, name); } else { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("Name", name); dic.Add("Version", version); OnCommandOutput?.Invoke(this, dic); } cnt++; } return($"Listed {cnt} packages"); } return(null); }
public string Execute(params string[] parameters) { if (File == null) { if (contents == null) { //Prepare file for download File = new TransferFile(); File.FileName = FileName ?? "test.txt"; File.Mimetype = Mimetype ?? "text/plain"; File.Data = UTF8Encoding.UTF8.GetBytes("This is a test text file"); return("No file provided as input. Test file generated."); } else { File = new TransferFile(); File.FileName = FileName ?? GenerateFileName(); File.Mimetype = Mimetype ?? "text/plain"; File.Data = UTF8Encoding.UTF8.GetBytes(string.Join("\n", contents.ToArray())); } OnCommandOutput?.Invoke(this, File); } return(null); }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (output is ContentData) { var content = output as ContentData; if (content.Property[Name].PropertyValueType == typeof(int)) { content.SetValue(Name, int.Parse(Value)); } else if (content.Property[Name].PropertyValueType == typeof(bool)) { content.SetValue(Name, bool.Parse(Value)); } else if (content.Property[Name].PropertyValueType == typeof(ContentReference)) { content.SetValue(Name, ContentReference.Parse(Value)); } else if (content.Property[Name].PropertyValueType == typeof(XhtmlString)) { content.SetValue(Name, new XhtmlString(Value)); } else { content.SetValue(Name, Value); } } OnCommandOutput?.Invoke(this, output); }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { var content = output as IContent; var r = _repo.Save(content, Action); OnCommandOutput?.Invoke(this, r); }
public string Execute(params string[] parameters) { MembershipUserCollection results = null; if (!string.IsNullOrEmpty(ByEmail)) { results = Membership.FindUsersByEmail(ByEmail); } else if (!string.IsNullOrEmpty(ByName)) { results = Membership.FindUsersByName(ByName); } else { results = Membership.GetAllUsers(); } int usercnt = 0; foreach (MembershipUser user in results) { usercnt++; if (OnlyOnline && !user.IsOnline) { continue; } OnCommandOutput?.Invoke(this, user); } int onlinecnt = Membership.GetNumberOfUsersOnline(); return($"Went through {usercnt} users. {onlinecnt} users online."); }
public string Execute(params string[] parameters) { if (string.IsNullOrEmpty(Key) && parameters.Length > 0) { Key = parameters.First(); } if (!string.IsNullOrEmpty(Key)) { if (Value != null) { ConfigurationManager.AppSettings.Set(Key, Value); } OnCommandOutput?.Invoke(this, ConfigurationManager.AppSettings[Key]); return($"Done. Appsetting \"{Key}\"=\"{ConfigurationManager.AppSettings[Key]}\"."); } int cnt = 0; foreach (var r in ConfigurationManager.AppSettings.AllKeys) { OnCommandOutput?.Invoke(this, r + ": " + ConfigurationManager.AppSettings[r]); cnt++; } return($"Done, listing {cnt} appsettings"); }
private void HandleContentType(ContentType ct) { if (!ListContent) { if (!UseDictionary) { OnCommandOutput.Invoke(this, _modelUsage.IsContentTypeUsed(ct)); } else { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("ContentType", ct); dic.Add("IsContentTypeUsed", _modelUsage.IsContentTypeUsed(ct)); OnCommandOutput.Invoke(this, dic); } } else { if (!UseDictionary) { foreach (var c in _modelUsage.ListContentOfContentType(ct)) { OnCommandOutput.Invoke(this, c); } } else { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("ContentType", ct); dic.Add("ContentUsage", _modelUsage.ListContentOfContentType(ct)); OnCommandOutput.Invoke(this, dic); } } }
public string Execute(params string[] parameters) { foreach (var s in parameters) { OnCommandOutput?.Invoke(this, s); } return(null); }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (_taken < Count) { OnCommandOutput?.Invoke(this, output); _taken++; } }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { _seen++; if (_seen > Count) { OnCommandOutput?.Invoke(this, output); } }
private void Copy(ContentReference cref) { var dest = (!string.IsNullOrEmpty(Destination) ? ContentReference.Parse(Destination) :_repo.Get <IContent>(cref).ParentLink); var cf = _repo.Copy(cref, dest); OnCommandOutput?.Invoke(this, cf); _count++; }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (output is IEnumerable) { foreach (var o in (output as IEnumerable)) { OnCommandOutput?.Invoke(this, o); } } }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { string json = JsonConvert.SerializeObject(output, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented }); OnCommandOutput?.Invoke(this, json); }
public string Execute(params string[] parameters) { int cnt = 0; foreach (var r in _trepo.List()) { OnCommandOutput?.Invoke(this, r); cnt++; } return($"Done, listing {cnt} content types"); }
public string Execute(params string[] parameters) { if (parameters.Length > 0) { foreach (var p in parameters) { ContentReference cr = ContentReference.Parse(p); var c = _repo.Get <IContent>(cr); OnCommandOutput?.Invoke(this, c); } } return(null); }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { object val = output; if (!string.IsNullOrEmpty(Property)) { val = FetchSingleProperty(output, Property); } //Evalutate if (((val is IList <object>) && (val as IList <object>).Any(o => Evaluate(o))) || Evaluate(val)) { OnCommandOutput?.Invoke(this, output); } }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (_type == null) { return; } bool isit = _type.IsAssignableFrom(output.GetType()); bool rt = (_not) ? !isit : isit; if (rt) { OnCommandOutput?.Invoke(this, output); } }
public string Execute(params string[] parameters) { object val = HttpContext.Current.Session[Key]; if (OnCommandOutput == null) { return(Key + ": " + val); } else { OnCommandOutput.Invoke(this, val); } return(null); }
public string Execute(params string[] parameters) { if (HttpContext.Current.Request["filename"] != null && HttpContext.Current.Request["data"] != null) { //We have an uploaded file TransferFile tf = new TransferFile(); tf.FileName = HttpContext.Current.Request["filename"]; tf.Data = Convert.FromBase64String(HttpContext.Current.Request["data"]); OnCommandOutput?.Invoke(this, tf); return("File uploaded successfully"); } else { return("No file uploaded"); } }
private void GetPropertiesAndPassOn(object output) { if (properties.Count == 1) { OnCommandOutput?.Invoke(this, FetchSingleProperty(output, properties.First())); } else { Dictionary <string, object> rt = new Dictionary <string, object>(); foreach (var p in properties) { rt.Add(p, FetchSingleProperty(output, p)); } OnCommandOutput?.Invoke(this, rt); } }
public string Execute(params string[] parameters) { //Produce CSV file contents StringBuilder sb = new StringBuilder(); var keys = content.SelectMany(kvp => kvp.Keys).Distinct().ToList(); if (ShowHeader) { sb.AppendLine(string.Join(Separator, keys.Select(s => "\"" + s + "\"").ToArray())); } foreach (var l in content) { bool isFirst = true; foreach (var k in keys) { if (!isFirst) { sb.Append(Separator); } else { isFirst = false; } if (l.ContainsKey(k)) { object o = l[k]; if (o is int || o is bool || o is double) { sb.Append(o.ToString()); } else { sb.Append("\"" + o.ToString() + "\""); } } } sb.AppendLine(); } OnCommandOutput?.Invoke(this, sb.ToString()); return(null); }
public string Execute(params string[] parameters) { if (string.IsNullOrEmpty(Key) && parameters.Length > 0) { Key = parameters[0]; } if (_value == null && !string.IsNullOrEmpty(Value)) { _value = Value; } if (_value == null && parameters.Length == 2) { _value = parameters.Last(); } _dictionary[Key] = _value; OnCommandOutput?.Invoke(this, _dictionary); return(null); }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (output is IContent) { OnCommandOutput?.Invoke(this, FindUrl(((IContent)output).ContentLink)); } if (output is ContentReference) { OnCommandOutput?.Invoke(this, FindUrl((ContentReference)output)); } if (output is string) { OnCommandOutput?.Invoke(this, FindUrl(ContentReference.Parse((string)output))); } if (output is int) { OnCommandOutput?.Invoke(this, FindUrl(new ContentReference((int)output))); } }
private void Source_OnCommandOutput(IOutputCommand sender, object output) { if (Format == null) { OnCommandOutput?.Invoke(this, output.ToString()); } else { string rt = Format; foreach (Match m in Regex.Matches(Format, @"{([a-zA-Z0-9]+\:?[^\}]*)}").Cast <Match>()) { string key = m.Groups[1].Value; string val = GetElementFromSource(output, key); //Replace in rt rt = rt.Replace(m.Value, val); } OnCommandOutput?.Invoke(this, rt); } }
public string Execute(params string[] parameters) { if (transferFile == null) { return("No file provided"); } else { string txt = UTF8Encoding.UTF8.GetString(transferFile.Data); if (SingleString) { OnCommandOutput?.Invoke(this, txt); } else { txt.Split('\n').ToList().ForEach(l => OnCommandOutput?.Invoke(this, l)); } } return($"Successfully read {transferFile.FileName}"); }
public string Execute(params string[] parameters) { ContentType ct = null; if (!string.IsNullOrEmpty(ContentTypeName)) { ct = _trepo.Load(ContentTypeName); } else if (ContentTypeID != 0) { ct = _trepo.Load(ContentTypeID); } else if (parameters.Length > 0) { ct = _trepo.Load(parameters.First()); } else { return("No Content Type specified"); } ContentReference pref = ContentReference.EmptyReference; if (!string.IsNullOrEmpty(Parent)) { pref = ContentReference.Parse(Parent); } else if (parameters.Length == 2) { pref = ContentReference.Parse(parameters.Last()); } else { return("No Parent specified"); } var content = _repo.GetDefault <IContent>(pref, ct.ID); OnCommandOutput?.Invoke(this, content); return($"Content of type {ct.Name} created below {pref} and passed to the pipe."); }
public string Execute(params string[] parameters) { int cnt = 0; if (string.IsNullOrEmpty(Parent) && parameters.Any()) { Parent = parameters.First(); } ContentReference start = ContentReference.StartPage; if (!string.IsNullOrEmpty(Parent)) { if (Parent.ToLower() == "root") { start = ContentReference.RootPage; } else if (Parent.ToLower() == "globalblocks") { start = ContentReference.GlobalBlockFolder; } else if (Parent.ToLower() == "siteblocks") { start = ContentReference.SiteBlockFolder; } else { start = ContentReference.Parse(Parent); } } foreach (var r in _repo.GetDescendents(start)) { OnCommandOutput?.Invoke(this, _repo.Get <IContent>(r)); cnt++; } return($"Done, listing {cnt} content items"); }