protected virtual void LogLastAction(object o, ContentAction action) { Thread thread = new Thread(() => { try { if (o is TextContent) { var textContent = (TextContent)o; var repository = textContent.GetRepository(); var folderName = textContent.FolderName; var contentSummary = textContent.GetSummary(); LastAction lastAction = new LastAction() { Repository = repository, FolderName = folderName, ContentSummary = contentSummary, Action = action, UtcActionDate = DateTime.UtcNow }; EngineContext.Current.Resolve <Kooboo.CMS.Search.Persistence.ILastActionProvider>().Add(lastAction); } } catch (Exception e) { Kooboo.HealthMonitoring.Log.LogException(e); } }); thread.Start(); }
public virtual unsafe void Send(OpAction <T> item) { ContentAction action = new ContentAction(); action.Type = item.Type; if (item.Data != null) { action.KeyValue = _propertyInfo.GetValue(item.Data).ToString(); if (item.Type == ActionType.Add || item.Type == ActionType.Update) { action.Data = item.Data.ToJsonString(); } } var bs = Encoding.UTF8.GetBytes(action.ToJsonString()); var sendData = new byte[bs.Length + 4]; fixed(byte *ptrBs = bs) { Marshal.Copy(new IntPtr(ptrBs), sendData, 4, bs.Length); int len = bs.Length; byte *ptr = (byte *)&len; Marshal.Copy(new IntPtr(ptr), sendData, 0, 4); } _stream.Write(sendData); _stream.ReadBoolean(); }
public ContentOwnerEventArgs(ContentAction action, string lastName, string newName, T previousContent, T newContent) { this.Action = action; this.LastName = lastName; this.NewName = newName; this.Previous = previousContent; this.New = newContent; }
public ActionResult ModifyContent(string formId, string fieldId,ContentAction contentAction) { if(formsCollection != null && !string.IsNullOrEmpty(formId) && !string.IsNullOrEmpty(fieldId)) { Form form = GetForm(formId); if(form != null) { if(DBHelper.GetInstance().GetField(fieldId) != null) { MongoDBRef dbref = new MongoDBRef(DBHelper.GetInstance().FieldsCollection().Name,fieldId); if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction)) { if(form.Contents.Contains(dbref)) { if(contentAction == ContentAction.Remove) { form.Contents.Remove(dbref); } else if(contentAction == ContentAction.Up) { LinkedListNode<MongoDBRef> prev = form.Contents.Find(dbref).Previous; if(prev != null) { form.Contents.Remove(dbref); form.Contents.AddBefore(prev,dbref); } } else if(contentAction == ContentAction.Down) { LinkedListNode<MongoDBRef> next = form.Contents.Find(dbref).Next; if(next != null) { form.Contents.Remove(dbref); form.Contents.AddAfter(next,dbref); } } } } else { if(!form.Contents.Contains(dbref)) { form.Contents.AddLast(dbref); } } formsCollection.Save(form); } } } return RedirectToAction("Index",new{Id = formId}); }
/// <summary> /// 检查是否已经全部保存 /// </summary> public virtual void CheckAllSaved() { ContentAction action = new ContentAction(); action.Type = ActionType.CheckSaved; var bs = Encoding.UTF8.GetBytes(action.ToJsonString()); _stream.Write(bs.Length); _stream.Write(bs); try { _stream.ReadBoolean(); } catch { } }
void runForSend() { var buffer = new List <byte>(20480); while (!_disposed || _queue.Count > 0) { _event.WaitOne(); _event.Reset(); while (_queue.TryDequeue(out OpAction <T> item)) { while (!_disposed) { try { ContentAction action = new ContentAction(); action.Type = item.Type; if (item.Data != null) { action.KeyValue = _propertyInfo.GetValue(item.Data).ToString(); action.Data = item.Data.ToJsonString(); } var bs = Encoding.UTF8.GetBytes(action.ToJsonString()); var lenbs = BitConverter.GetBytes(bs.Length); buffer.AddRange(lenbs); buffer.AddRange(bs); if (buffer.Count > 10240) { bs = buffer.ToArray(); buffer.Clear(); _stream.Write(bs); } if (item.CallBack != null) { item.CallBack(); } if (item.Type == ActionType.CheckSaved) { if (buffer.Count > 0) { bs = buffer.ToArray(); buffer.Clear(); _stream.Write(bs); } try { _stream.ReadBoolean(); } catch { } _stream.Dispose(); return; } break; } catch { _stream.Dispose(); try { init(); } catch { _stream = null; } } } } } _stream.Dispose(); }
public ContentEventContext(ContentAction contentAction, TextContent content) { this.ContentAction = contentAction; this.Content = content; }
private void BuildFileContent(IAbsoluteDirectoryPath modPackagePath, IRelativeDirectoryPath relativeTargetPath, IRelativeFilePath relativePath, ICollection<RootRpf> list, ContentAction action, FileType type = FileType.Default) { if (_config.AudioPathsOnly && !IsAudioPath(relativeTargetPath)) return; var rpfFile = RpfFile.FromPath(relativeTargetPath.GetAbsolutePathFrom(_gameDir)); if (!rpfFile.ExternalRpfFile.Exists) { throw new Exception("Unable to find an RPF file: " + rpfFile.ExternalRpfFile); } IDirectory root = list.FirstOrDefault(x => x.FilePath.Equals(rpfFile.ExternalRpfFile)); if (root == null) { var rootRpf = new RootRpf(rpfFile.ExternalRpfFile); root = rootRpf; list.Add(rootRpf); } foreach (var p in rpfFile.PathParts) { if (p.EndsWith(".rpf")) { root = root.Contents.ContainsKey(p) ? (InnerRpf)root.Contents[p] : (InnerRpf)(root.Contents[p] = new InnerRpf()); } else { root = root.Contents.ContainsKey(p) ? (InnerDirectory)root.Contents[p] : (InnerDirectory)(root.Contents[p] = new InnerDirectory()); } } var file = relativePath.FileName; IFileContent f; if (file.EndsWith(".rpf")) f = root.Contents.ContainsKey(file) ? (InnerRpf)root.Contents[file] : (InnerRpf)(root.Contents[file] = new InnerRpf()); else f = root.Contents.ContainsKey(file) ? (InnerFile)root.Contents[file] : (InnerFile)(root.Contents[file] = new InnerFile()); f.FilePath = relativePath.GetAbsolutePathFrom(modPackagePath); f.Action = action; f.Type = type; }
public static void Fire(ContentAction contentAction, TextContent textContent) { EventBus.Send(new ContentEventContext(contentAction, textContent)); }
public ActionResult ModifyContent(string flowId, string groupId, string taskId, ContentAction contentAction) { if(flowsCollection != null && !string.IsNullOrEmpty(flowId) && !string.IsNullOrEmpty(groupId) && !string.IsNullOrEmpty(taskId)) { Flow flow = GetFlow(flowId); if(flow != null) { Group group = DBHelper.GetInstance().GetGroup(groupId); Task task = DBHelper.GetInstance().GetTask(taskId); if(group != null && task != null) { MongoDBRef groupdbref = new MongoDBRef(DBHelper.GetInstance().GroupsCollection().Name,group.Name); MongoDBRef taskdbref = new MongoDBRef(DBHelper.GetInstance().TasksCollection().Name,task.Name); FlowContentRef dbref = new FlowContentRef{Group = groupdbref, Task = taskdbref}; if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction)) { bool found = false; foreach(FlowContentRef fcref in flow.Contents) { if(fcref.Equals(dbref)) { dbref = fcref; found = true; break; } } if(found) { if(contentAction == ContentAction.Remove) { flow.Contents.Remove(dbref); } else if(contentAction == ContentAction.Up) { LinkedListNode<FlowContentRef> prev = flow.Contents.Find(dbref).Previous; if(prev != null) { flow.Contents.Remove(dbref); flow.Contents.AddBefore(prev,dbref); } } else if(contentAction == ContentAction.Down) { LinkedListNode<FlowContentRef> next = flow.Contents.Find(dbref).Next; if(next != null) { flow.Contents.Remove(dbref); flow.Contents.AddAfter(next,dbref); } } } } else { if(!flow.Contents.Contains(dbref)) { flow.Contents.AddLast(dbref); } } flowsCollection.Save(flow); } } } return RedirectToAction("Index",new{Id = flowId}); }
public virtual void ProcessMessage(Repository repository, TextContent originalContent, string receivingFolder, bool keepStatus, ContentAction action) { var targetFolder = new TextFolder(repository, receivingFolder).AsActual(); if ((ContentAction.Add & action) == action && (originalContent.Published.HasValue && originalContent.Published.Value == true)) { var content = targetFolder.CreateQuery().WhereEquals("UUID", originalContent.UUID).FirstOrDefault(); if (content == null) { Services.ServiceFactory.TextContentManager.Copy(originalContent, targetFolder, keepStatus, true, null); } else { UpdateAction(repository, originalContent, targetFolder, keepStatus); } } else if ((ContentAction.Update & action) == action) { UpdateAction(repository, originalContent, targetFolder, keepStatus); } else if ((ContentAction.Delete & action) == action) { DeleteAction(repository, originalContent, targetFolder); } }
public virtual void ReceiveContent(Repository repository, TextContent originalContent, ContentAction action) { //bool processed = false; var allReceivers = All(repository, "").Select(o => Get(repository, o.Name)); foreach (var receivingSetting in allReceivers) { if (CheckSetting(originalContent, receivingSetting, action)) { ProcessMessage(repository, originalContent, receivingSetting.ReceivingFolder, receivingSetting.KeepStatus, action); //processed = true; } } }
private bool CheckSetting(ContentBase content, ReceivingSetting receivingSetting, ContentAction action) { if (receivingSetting.ReceivingFolder == null && receivingSetting.ReceivingFolder.Length == 0) { return(false); } if (!string.IsNullOrEmpty(receivingSetting.SendingRepository) && string.Compare(receivingSetting.SendingRepository, content.Repository, true) != 0) { return(false); } if (!string.IsNullOrEmpty(receivingSetting.SendingFolder) && string.Compare(receivingSetting.SendingFolder, content.FolderName, true) != 0) { return(false); } return(true); }
private bool CheckSetting(ContentBase content, ReceivingSetting receivingSetting, ContentAction action) { if (receivingSetting.ReceivingFolder == null && receivingSetting.ReceivingFolder.Length == 0) { return(false); } if (!string.IsNullOrEmpty(receivingSetting.SendingRepository) && string.Compare(receivingSetting.SendingRepository, content.Repository, true) != 0) { return(false); } if (!string.IsNullOrEmpty(receivingSetting.SendingFolder) && string.Compare(receivingSetting.SendingFolder, content.FolderName, true) != 0) { return(false); } //if (receivingSetting.Published.HasValue && content.Published != receivingSetting.Published.Value) //{ // return false; //} //if ((receivingSetting.AcceptAction & action) != action) //{ // return false; //} return(true); }