public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace) { StringBuilder itemXml; string isLocal = string.Empty; StringBuilder tmp; values.TryGetValue("ItemXml", out itemXml); values.TryGetValue("IsLocalSave", out tmp); if (tmp != null) { isLocal = tmp.ToString(); } bool isLocalSave; bool.TryParse(isLocal, out isLocalSave); var res = new ExecuteMessage { HasError = false}; if(itemXml == null || itemXml.Length == 0) { res.SetMessage("Invalid workspace item definition " + DateTime.Now); res.HasError = true; } else { try { XElement xe = itemXml.ToXElement(); var workspaceItem = new WorkspaceItem(xe); if (workspaceItem.WorkspaceID != theWorkspace.ID) { res.SetMessage("Cannot update a workspace item from another workspace " + DateTime.Now); res.HasError = true; } else { theWorkspace.Update(workspaceItem, isLocalSave); res.SetMessage("Workspace item updated " + DateTime.Now); } } catch(Exception ex) { res.SetMessage("Error updating workspace item " + DateTime.Now); res.SetMessage(ex.Message); res.SetMessage(ex.StackTrace); res.HasError = true; } } Dev2JsonSerializer serializer = new Dev2JsonSerializer(); return serializer.SerializeToBuilder(res); }
public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace) { ExecuteMessage result = new ExecuteMessage { HasError = false }; string resourceID = null; string resourceType = null; StringBuilder tmp; values.TryGetValue("ResourceID", out tmp); if(tmp != null) { resourceID = tmp.ToString(); } values.TryGetValue("ResourceType", out tmp); if(tmp != null) { resourceType = tmp.ToString(); } Dev2Logger.Log.Info(String.Format("Reload Resource. Id:{0} Type:{1}",resourceID,resourceType)); try { // 2012.10.01: TWR - 5392 - Server does not dynamically reload resources if(resourceID == "*") { ResourceCatalog.Instance.LoadWorkspace(theWorkspace.ID); } else { // // Ugly conversion between studio resource type and server resource type // enDynamicServiceObjectType serviceType; switch(resourceType) { case "HumanInterfaceProcess": case "Website": case "WorkflowService": serviceType = enDynamicServiceObjectType.WorkflowActivity; break; case "Service": serviceType = enDynamicServiceObjectType.DynamicService; break; case "Source": serviceType = enDynamicServiceObjectType.Source; break; case "Server": serviceType = enDynamicServiceObjectType.Source; break; default: throw new Exception("Unexpected resource type '" + resourceType + "'."); } Guid getID; if(resourceID != null && Guid.TryParse(resourceID, out getID)) { // // Copy the file from the server workspace into the current workspace // theWorkspace.Update( new WorkspaceItem(theWorkspace.ID, HostSecurityProvider.Instance.ServerID, Guid.Empty, getID) { Action = WorkspaceItemAction.Edit, IsWorkflowSaved = true, ServiceType = serviceType.ToString() }, false); } else { theWorkspace.Update( new WorkspaceItem(theWorkspace.ID, HostSecurityProvider.Instance.ServerID, Guid.Empty, Guid.Empty) { Action = WorkspaceItemAction.Edit, ServiceName = resourceID, IsWorkflowSaved = true, ServiceType = serviceType.ToString() }, false); } // // Reload resources // ResourceCatalog.Instance.LoadWorkspace(theWorkspace.ID); result.SetMessage(string.Concat("'", resourceID, "' Reloaded...")); } } catch(Exception ex) { result.SetMessage(string.Concat("Error reloading '", resourceID, "'...")); Dev2Logger.Log.Error(ex); } Dev2JsonSerializer serializer = new Dev2JsonSerializer(); return serializer.SerializeToBuilder(result); }