private void writeContentType(String filePath, Alfresco.RepositoryWebService.Reference rwsRef, String property, String mimetype) { Alfresco.ContentWebService.Reference newContentNode = new Alfresco.ContentWebService.Reference(); newContentNode.path = rwsRef.path; newContentNode.uuid = rwsRef.uuid; Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store(); cwsStore.address = "SpacesStore"; spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; newContentNode.store = cwsStore; // Open the file and convert to byte array FileStream inputStream = new FileStream(filePath, FileMode.Open); int bufferSize = (int)inputStream.Length; byte[] bytes = new byte[bufferSize]; inputStream.Read(bytes, 0, bufferSize); inputStream.Close(); ContentFormat contentFormat = new ContentFormat(); contentFormat.mimetype = mimetype; WebServiceFactory.getContentService().write(newContentNode, property, bytes, contentFormat); }
// load the treeView private void buildTree(TreeNode parentNode, Reference childReference) { // Query for the children of the reference QueryResult result = this.repoService.queryChildren(childReference); if (result.resultSet.rows != null) { foreach (ResultSetRow row in result.resultSet.rows) { // only interested in folders if (row.node.type.Contains("folder") == true) { foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("name") == true) { // add a node to the tree view TreeNode node = this.addChildNode(parentNode, namedValue.value, row.node); // Create the reference for the node selected Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = row.node.id; // add the child nodes buildTree(node, reference); } } } } } }
public RepositoryWebService.Reference GetReferenceFromResultSetRow(ResultSetRow row) { RepositoryWebService.Reference reference = null; reference = new Alfresco.RepositoryWebService.Reference(); reference.uuid = row.node.id; reference.store = spacesStore; NamedValue[] namedValues = row.columns; Dictionary <string, string> namedValuesMap = new Dictionary <string, string>(); // iterate through the columns of the result set to extract specific named values foreach (NamedValue namedValue in namedValues) { namedValuesMap.Add(namedValue.name, namedValue.value); } String path = namedValuesMap["{http://www.alfresco.org/model/content/1.0}path"]; name = namedValuesMap["{http://www.alfresco.org/model/content/1.0}name"]; reference.path = PathUtils.CovertFromModelPathToRepositoryPath(path); return(reference); }
/// <summary> /// Populate the list box with the children of the company home /// </summary> private void populateListBox() { Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.path = "/app:company_home"; populateListBox(reference); }
/// <summary> /// Click handler for the 'Go Up' button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButton1_Click(object sender, EventArgs e) { if (this.parentReferences.Count != 0) { Alfresco.RepositoryWebService.Reference reference = this.parentReferences[this.parentReferences.Count - 1] as Alfresco.RepositoryWebService.Reference; this.parentReferences.RemoveAt(this.parentReferences.Count - 1); populateListBox(reference); } }
/// <summary> /// Populate the list with the children of the passed reference /// </summary> /// <param name="reference"></param> private void populateListBox(Alfresco.RepositoryWebService.Reference reference) { // Clear the list listViewBrowse.Clear(); // Set the current reference this.currentReference = reference; // Query for the children of the reference QueryResult result = this.repoService.queryChildren(reference); if (result.resultSet.rows != null) { int index = 0; foreach (ResultSetRow row in result.resultSet.rows) { // Get the name of the node string name = null; foreach (Alfresco.RepositoryWebService.NamedValue namedValue in row.columns) { if (namedValue.name.Contains("name") == true) { name = namedValue.value; } } // Create the list view item that will correspond to the child node ListViewItem item = new ListViewItem(); item.Text = name; if (row.node.type.Contains("folder") == true) { item.ImageIndex = 0; } else { item.ImageIndex = 1; } item.Tag = row.node; // Add the item to the list if (row.node.type.Contains("folder") == true) { listViewBrowse.Items.Insert(index, item); index++; } else { listViewBrowse.Items.Add(item); } } } }
private void deleteReference(Alfresco.RepositoryWebService.Reference reference) { Alfresco.RepositoryWebService.Predicate where = new Alfresco.RepositoryWebService.Predicate(); where.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; CMLDelete cmlDelete = new CMLDelete(); cmlDelete.where = where; CML cml = new CML(); cml.delete = new CMLDelete[] { cmlDelete }; this.repoService.update(cml); }
/// <summary> /// Double click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listViewBrowse_DoubleClick(object sender, EventArgs e) { ListViewItem item = listViewBrowse.SelectedItems[0]; if (item != null) { ResultSetRowNode node = item.Tag as ResultSetRowNode; if (node != null) { if (node.type.Contains("folder") == true) { // Create the reference for the node selected Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = node.id; // Parent references this.parentReferences.Add(this.currentReference); // Populate the list with the children of the selected node populateListBox(reference); } else { // Create the reference for the node selected Alfresco.ContentWebService.Store spacesStore2 = new Alfresco.ContentWebService.Store(); spacesStore2.scheme = Alfresco.ContentWebService.StoreEnum.workspace; spacesStore2.address = "SpacesStore"; Alfresco.ContentWebService.Reference reference = new Alfresco.ContentWebService.Reference(); reference.store = spacesStore2; reference.uuid = node.id; // Lets try and get the content Alfresco.ContentWebService.Predicate predicate = new Alfresco.ContentWebService.Predicate(); predicate.Items = new Object[] { reference }; Content[] contents = this.contentService.read(predicate, "{http://www.alfresco.org/model/content/1.0}content"); Content content = contents[0]; if (content.url != null && content.url.Length != 0) { string url = content.url + "?ticket=" + AuthenticationUtils.Ticket; webBrowser.Url = new Uri(url); } } } } }
private void initializeRootFolder() { // Suppress repainting the TreeView until all the objects have been created. treeView1.BeginUpdate(); // get the root position, Company Home TreeNode rootNode = new TreeNode(); Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.path = "/app:company_home"; // Create a query object Query query = new Query(); query.language = Constants.QUERY_LANG_LUCENE; query.statement = "Path:\"/\" AND @cm\\:title:\"Company Home\""; QueryResult result = this.repoService.query(this.spacesStore, query, true); string name = null; if (result.resultSet.rows != null) { // construct root node ResultSetRow row = result.resultSet.rows[0]; foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("title") == true) { name = namedValue.value; rootNode.Text = name; rootNode.Name = name; } } rootNode.Tag = row.node; } // add the root node to the tree view this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { rootNode }); buildTree(rootNode, reference); // Begin repainting the TreeView. treeView1.EndUpdate(); }
private Content UpdateDocument(Alfresco.RepositoryWebService.Reference reference, byte[] document) { MimetypeMap mimeType = new MimetypeMap(); var newContentNode = new Alfresco.ContentWebService.Reference(); newContentNode.path = reference.path; newContentNode.uuid = reference.uuid; Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store(); cwsStore.address = Constants.SPACES_STORE; newContentNode.store = cwsStore; var contentFormat = new Alfresco.ContentWebService.ContentFormat(); contentFormat.mimetype = mimeType.GuessMimetype(Name); return(WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, document, contentFormat)); }
private void buildTree(TreeNode parentNode, Reference childReference) { try { // Query for the children of the reference QueryResult result = this.repoService.queryChildren(childReference); if (result.resultSet.rows != null) { foreach (ResultSetRow row in result.resultSet.rows) { // only interested in folders if (row.node.type.Contains("folder") == true) { foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("name") == true) { // add a node to the tree view TreeNode node = this.addChildNode(parentNode, namedValue.value, row.node); // Create the reference for the node selected Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = row.node.id; if (this.selectedUuid.Equals(reference.uuid)) { this.setInitNode(node); } // add the child node buildTree(node, reference); } } } } } } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "frmTreeViewBrowse method buildTree(" + childReference.uuid + ") " + e.Message, e.StackTrace); } }
private CML getCMLUpdate(String uuid, NamedValue[] properties) { // ************ test ***********8 /* * for (int i = 0; i < properties.Length; i++) * { * * NamedValue name = properties[i]; * if (name.name.Equals(Alfresco.Constants.PROP_DESCRIPTION)) * { * MessageBox.Show("Gotcha"); * name.value = "UPDATE"; * properties[i] = name; * } * } */ Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = uuid; CMLUpdate cmlUpdate = new CMLUpdate(); Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate(); pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; cmlUpdate.where = pred; cmlUpdate.property = properties; // Create and execute the cml statement CML cml = new CML(); cml.update = new CMLUpdate[] { cmlUpdate }; return(cml); }
private void initializeRootFolder() { try { // Suppress repainting the TreeView until all the objects have been created. this.treeView1.BeginUpdate(); // get the root position, Company Home TreeNode rootNode = new TreeNode(); Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.path = "/app:company_home"; // Create a query object Query query = new Query(); query.language = QueryLanguageEnum.lucene; query.statement = "Path:\"/\" AND @cm\\:title:\"Company Home\""; QueryResult result = this.repoService.query(this.spacesStore, query, true); string name = null; if (result.resultSet.rows != null) { // construct root node ResultSetRow row = result.resultSet.rows[0]; foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("title") == true) { name = namedValue.value; rootNode.Text = name; rootNode.Name = name; } } rootNode.Tag = row.node; if (this.selectedUuid.Equals(row.node.id)) { this.setInitNode(rootNode); } } // add the root node to the tree view this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { rootNode }); try { this.buildTree(rootNode, reference); } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "frmTreeViewBrowse method initializeRootFolder calling buildtree recursion method " + e.Message, e.StackTrace); } // Begin repainting the TreeView. this.treeView1.EndUpdate(); } catch (Exception ex) { Log log = new Log(); log.ErrorLog(".\\log\\", "frmTreeViewBrowse method initializeRootFolder " + ex.Message, ex.StackTrace); } }
private CML getCMLUpdate(String uuid, NamedValue[] properties) { // ************ test ***********8 /* for (int i = 0; i < properties.Length; i++) { NamedValue name = properties[i]; if (name.name.Equals(Alfresco.Constants.PROP_DESCRIPTION)) { MessageBox.Show("Gotcha"); name.value = "UPDATE"; properties[i] = name; } } */ Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = uuid; CMLUpdate cmlUpdate = new CMLUpdate(); Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate(); pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; cmlUpdate.where = pred; cmlUpdate.property = properties; // Create and execute the cml statement CML cml = new CML(); cml.update = new CMLUpdate[] { cmlUpdate }; return cml; }
//********************************************************** // Function: ReleaseDoc() // Scope: internal // Overview: Document release point. Use the ReleaseData // object to release the current document's data // to the external data source. // Params: none // Returns: One of the following: KFX_REL_SUCCESS, // KFX_REL_ERROR, KFX_REL_DOCCLASSERROR, // KFX_REL_QUEUED // Called By: The Batch Release Manager. Called once for each // document to be released. //********************************************************** public AscentRelease.KfxReturnValue ReleaseDoc() { try { String name = ReleaseUtils.getLinkValue(this.releaseData.Values, ReleaseConstants.CONTENT_TYPE + Alfresco.Constants.PROP_NAME); if (name == null || name.Equals("")) { // node name is null or "" Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc - Content name is empty, check index fields in Release setup or the Content Type properties in Alfresco", ""); return AscentRelease.KfxReturnValue.KFX_REL_ERROR; } String location = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION); // get properties and aspects list int i = 0; ArrayList aspectFields = new ArrayList(); ArrayList properties = new ArrayList(); NamedValue nameValue = new NamedValue(); // if its a content type field then create a NamedValue otherwise // store in the aspect array to be used later on foreach (AscentRelease.Value oValue in releaseData.Values) { String value = oValue.Value; String destination = oValue.Destination; if (destination.StartsWith(ReleaseConstants.CONTENT_TYPE)) { // content type field nameValue = new NamedValue(); // need to remove the prefix int start = ReleaseConstants.CONTENT_TYPE.Length; nameValue.name = destination.Substring(start, (destination.Length - start)); nameValue.value = value; nameValue.isMultiValue = false; properties.Add(nameValue); } else { // aspect field aspectFields.Add(oValue); } } // create the CML bool isNew = true; String existingUuid = this.getNodeUuidFromLocation(this.locationUuid, name); CML cml; // flag to delete refnode if there is an error uploading the content bool deleteOnErrFlag = true; if (existingUuid.Equals("")) { // new content to upload cml = this.getCMLCreate((NamedValue[])properties.ToArray(typeof(NamedValue))); } else { // update, set deleteFlag to false for updating node Content deleteOnErrFlag = false; cml = this.getCMLUpdate(existingUuid, (NamedValue[])properties.ToArray(typeof(NamedValue))); isNew = false; } // create any aspects CMLAddAspect[] cmlAspects = null; String aspects = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_ASPECTS); AscentRelease.Value aspectValue; if (aspects != null) { // seperate the aspects string String[] aspectNames = ReleaseUtils.SplitByString(aspects, ReleaseConstants.SEPERATOR); String aspectName; cmlAspects = new CMLAddAspect[aspectNames.Length]; // for each aspect create a aspect CML for (i = 0; i < aspectNames.Length; i++) { aspectName = aspectNames[i]; // create the aspect CML CMLAddAspect addAspect = new CMLAddAspect(); addAspect.aspect = aspectName; if (isNew) { addAspect.where_id = "1"; } else { // use predicate Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = existingUuid; Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate(); pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; addAspect.where = pred; } ArrayList aspectProperties = new ArrayList(); // add the aspect fields for this aspect for (int j = 0; j < aspectFields.Count; j++) { // loop thru the aspects fields and add the relevent fields aspectValue = (AscentRelease.Value)aspectFields[j]; String destination = aspectValue.Destination; String prefix = ReleaseConstants.ASPECT + ReleaseConstants.SEPERATOR + aspectName; if (destination.StartsWith(prefix)) { // content type field nameValue = new NamedValue(); // need to remove the prefix int start = prefix.Length; nameValue.name = destination.Substring(start, (destination.Length - start)); nameValue.value = aspectValue.Value; nameValue.isMultiValue = false; aspectProperties.Add(nameValue); } } addAspect.property = (NamedValue[])aspectProperties.ToArray(typeof(NamedValue)); cmlAspects[i] = addAspect; } } // add any aspects if (cmlAspects != null && cmlAspects.Length > 0) { cml.addAspect = cmlAspects; } UpdateResult[] updateResult = this.repoService.update(cml); if (!this.writeNewContent(updateResult[0].destination, deleteOnErrFlag)) { // failed to update content, deleted return AscentRelease.KfxReturnValue.KFX_REL_ERROR; } return AscentRelease.KfxReturnValue.KFX_REL_SUCCESS; } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc " + e.Message, e.StackTrace); return AscentRelease.KfxReturnValue.KFX_REL_ERROR; } }
private void buildTree(TreeNode parentNode, Reference childReference) { try { // Query for the children of the reference QueryResult result = this.repoService.queryChildren(childReference); if (result.resultSet.rows != null) { foreach (ResultSetRow row in result.resultSet.rows) { // only interested in folders if (row.node.type.Contains("folder") == true) { foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("name") == true) { // add a node to the tree view TreeNode node = this.addChildNode(parentNode, namedValue.value, row.node); // Create the reference for the node selected Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = row.node.id; if (this.selectedUuid.Equals(reference.uuid)) { this.setInitNode(node); } // add the child node buildTree(node, reference); } } } } } } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "frmTreeViewBrowse method buildTree(" + childReference.uuid + ") " + e.Message, e.StackTrace); } }
private void btnUpload_Click(object sender, EventArgs e) { try { String file = this.textBox1.Text; if (file.Equals("")) { MessageBox.Show("Please select a file"); this.btnSelect.Focus(); return; } if (this.tbLocation.Text.Equals("")) { MessageBox.Show("Please select the location"); this.btnLocation.Focus(); return; } int start = file.LastIndexOf("\\") + 1; int length = file.Length - start; // get the filename only String fileName = file.Substring(start, length); if (file == null || file.Equals("")) { MessageBox.Show("please select a file"); return; } // Display a wait cursor while the file is uploaded Cursor.Current = Cursors.WaitCursor; // Initialise the reference to the spaces store Alfresco.RepositoryWebService.Store spacesStore = new Alfresco.RepositoryWebService.Store(); spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; spacesStore.address = "SpacesStore"; // Create the parent reference, the company home folder Alfresco.RepositoryWebService.ParentReference parentReference = new Alfresco.RepositoryWebService.ParentReference(); parentReference.store = spacesStore; // parentReference.path = "/app:company_home"; parentReference.uuid = this.locationUuid; parentReference.associationType = Constants.ASSOC_CONTAINS; parentReference.childName = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, fileName); // Create the properties list NamedValue nameProperty = new NamedValue(); nameProperty.name = Constants.PROP_NAME; nameProperty.value = fileName; nameProperty.isMultiValue = false; NamedValue[] properties = new NamedValue[2]; properties[0] = nameProperty; nameProperty = new NamedValue(); nameProperty.name = Constants.PROP_TITLE; nameProperty.value = fileName; nameProperty.isMultiValue = false; properties[1] = nameProperty; // Create the CML create object CMLCreate create = new CMLCreate(); create.parent = parentReference; create.id = "1"; create.type = Constants.TYPE_CONTENT; create.property = properties; // Create and execute the cml statement CML cml = new CML(); cml.create = new CMLCreate[] { create }; UpdateResult[] updateResult = repoService.update(cml); // work around to cast Alfresco.RepositoryWebService.Reference to // Alfresco.ContentWebService.Reference Alfresco.RepositoryWebService.Reference rwsRef = updateResult[0].destination; Alfresco.ContentWebService.Reference newContentNode = new Alfresco.ContentWebService.Reference(); newContentNode.path = rwsRef.path; newContentNode.uuid = rwsRef.uuid; Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store(); cwsStore.address = "SpacesStore"; spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; newContentNode.store = cwsStore; // Open the file and convert to byte array FileStream inputStream = new FileStream(file, FileMode.Open); int bufferSize = (int)inputStream.Length; byte[] bytes = new byte[bufferSize]; inputStream.Read(bytes, 0, bufferSize); inputStream.Close(); Alfresco.ContentWebService.ContentFormat contentFormat = new Alfresco.ContentWebService.ContentFormat(); contentFormat.mimetype = mimeType.GuessMimetype(file); WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat); // Reset the cursor to the default for all controls. Cursor.Current = Cursors.Default; MessageBox.Show(file + " uploaded"); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); MessageBox.Show(ex.StackTrace); } }
private void initializeRootFolder() { try { // Suppress repainting the TreeView until all the objects have been created. this.treeView1.BeginUpdate(); // get the root position, Company Home TreeNode rootNode = new TreeNode(); Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.path = "/app:company_home"; // Create a query object Query query = new Query(); query.language = QueryLanguageEnum.lucene; query.statement = "Path:\"/\" AND @cm\\:title:\"Company Home\""; QueryResult result = this.repoService.query(this.spacesStore, query, true); string name = null; if (result.resultSet.rows != null) { // construct root node ResultSetRow row = result.resultSet.rows[0]; foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("title") == true) { name = namedValue.value; rootNode.Text = name; rootNode.Name = name; } } rootNode.Tag = row.node; if (this.selectedUuid.Equals(row.node.id)) { this.setInitNode(rootNode); } } // add the root node to the tree view this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { rootNode }); try { this.buildTree(rootNode, reference); } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "frmTreeViewBrowse method initializeRootFolder calling buildtree recursion method " + e.Message, e.StackTrace); } // Begin repainting the TreeView. this.treeView1.EndUpdate(); } catch (Exception ex) { Log log = new Log(); log.ErrorLog(".\\log\\", "frmTreeViewBrowse method initializeRootFolder " + ex.Message, ex.StackTrace); } }
private void initializeRootFolder() { // Suppress repainting the TreeView until all the objects have been created. treeView1.BeginUpdate(); // get the root position, Company Home TreeNode rootNode = new TreeNode(); Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.path = "/app:company_home"; // Create a query object Query query = new Query(); query.language = Constants.QUERY_LANG_LUCENE; query.statement = "Path:\"/\" AND @cm\\:title:\"Company Home\""; QueryResult result = this.repoService.query(this.spacesStore, query, true); string name = null; if (result.resultSet.rows != null) { // construct root node ResultSetRow row = result.resultSet.rows[0]; foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("title") == true) { name = namedValue.value; rootNode.Text = name; rootNode.Name = name; } } rootNode.Tag = row.node; } // add the root node to the tree view this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { rootNode }); buildTree(rootNode, reference); // Begin repainting the TreeView. treeView1.EndUpdate(); }
// load the treeView private void buildTree(TreeNode parentNode, Reference childReference) { // Query for the children of the reference QueryResult result = this.repoService.queryChildren(childReference); if (result.resultSet.rows != null) { foreach (ResultSetRow row in result.resultSet.rows) { // only interested in folders if (row.node.type.Contains("folder") == true) { foreach (NamedValue namedValue in row.columns) { if (namedValue.name.Contains("name") == true) { // add a node to the tree view TreeNode node = this.addChildNode(parentNode, namedValue.value, row.node); // Create the reference for the node selected Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = row.node.id; // add the child nodes buildTree(node, reference); } } } } } }
private bool writeNewContent(Alfresco.RepositoryWebService.Reference rwsRef, bool deleteOnErrFlag) { bool success = true; try { // write the content if (this.imageContentProp != null) { try { foreach (AscentRelease.ImageFile image in releaseData.ImageFiles) { String filePath = image.FileName; // get the file and check its size FileInfo imageFile = new FileInfo(filePath); if (imageFile.Length > ReleaseConstants.MAX_FILE_SIZE) { // get the smaller file filePath = filePath.Insert(filePath.LastIndexOf("."), "t"); } this.writeContentType(filePath, rwsRef, this.imageContentProp, ReleaseConstants.MIME_TYPE_TIFF); break; } } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method writeNewContent " + e.Message, e.StackTrace); return(false); } } if (this.ocrContentProp != null) { this.writeContentType(releaseData.TextFilePath, rwsRef, this.ocrContentProp, ReleaseConstants.MIME_TYPE_TEXT); } if (this.pdfContentProp != null) { this.writeContentType(releaseData.KofaxPDFFileName, rwsRef, this.pdfContentProp, ReleaseConstants.MIME_TYPE_PDF); } releaseData.RepositoryDocumentID = rwsRef.uuid; } catch (Exception ex) { String errorMessage = ReleaseConstants.ERR_NOT_NODE_DELETED; if (deleteOnErrFlag) { this.deleteReference(rwsRef); errorMessage = ReleaseConstants.ERR_NODE_DELETED; } Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method writeNewContent " + ex.Message, ex.StackTrace); success = false; } return(success); }
private void UploadNow(string fileName, string file) { // Initialise the reference to the spaces store Alfresco.RepositoryWebService.Store spacesStore = new Alfresco.RepositoryWebService.Store(); spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; spacesStore.address = "SpacesStore"; // Create the parent reference, the company home folder Alfresco.RepositoryWebService.ParentReference parentReference = new Alfresco.RepositoryWebService.ParentReference(); parentReference.store = spacesStore; //parentReference.path = "/app:company_home" parentReference.uuid = LocationUuid; parentReference.associationType = Constants.ASSOC_CONTAINS; parentReference.childName = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, fileName); // Create the properties list NamedValue nameProperty = new NamedValue(); nameProperty.name = Constants.PROP_NAME; nameProperty.value = fileName; nameProperty.isMultiValue = false; NamedValue[] properties = new NamedValue[2]; properties[0] = nameProperty; nameProperty = new NamedValue(); nameProperty.name = Constants.PROP_TITLE; nameProperty.value = fileName; nameProperty.isMultiValue = false; properties[1] = nameProperty; // Create the CML create object CMLCreate create = new CMLCreate(); create.parent = parentReference; create.id = "1"; create.type = Constants.TYPE_CONTENT; create.property = properties; // Create and execute the cml statement CML cml = new CML(); cml.create = new CMLCreate[] { create }; UpdateResult[] updateResult = repoService.update(cml); // work around to cast Alfresco.RepositoryWebService.Reference to // Alfresco.ContentWebService.Reference Alfresco.RepositoryWebService.Reference rwsRef = updateResult[0].destination; Alfresco.ContentWebService.Reference newContentNode = new Alfresco.ContentWebService.Reference(); newContentNode.path = rwsRef.path; newContentNode.uuid = rwsRef.uuid; Alfresco.ContentWebService.Store cwsStore = new Alfresco.ContentWebService.Store(); cwsStore.address = "SpacesStore"; spacesStore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace; newContentNode.store = cwsStore; // Open the file and convert to byte array FileStream inputStream = new FileStream(file, FileMode.Open); int bufferSize = (int)inputStream.Length; byte[] bytes = new byte[bufferSize]; inputStream.Read(bytes, 0, bufferSize); inputStream.Close(); ContentFormat contentFormat = new ContentFormat(); if (rdjpeg.Checked == true) { contentFormat.mimetype = "image/jpeg"; } else if (rdgif.Checked == true) { contentFormat.mimetype = "image/gif"; } else if (rdtiff.Checked == true) { contentFormat.mimetype = "image/tiff"; } WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat); }
/// <summary> /// Populate the list with the children of the passed reference /// </summary> /// <param name="reference"></param> private void populateListBox(Alfresco.RepositoryWebService.Reference reference) { // Clear the list listViewBrowse.Clear(); // Set the current reference this.currentReference = reference; // Query for the children of the reference QueryResult result = this.repoService.queryChildren(reference); if (result.resultSet.rows != null) { int index = 0; foreach (ResultSetRow row in result.resultSet.rows) { // Get the name of the node string name = null; foreach (Alfresco.RepositoryWebService.NamedValue namedValue in row.columns) { if (namedValue.name.Contains("name") == true) { name = namedValue.value; } } // Create the list view item that will correspond to the child node ListViewItem item = new ListViewItem(); item.Text = name; if (row.node.type.Contains("folder") == true) { item.ImageIndex = 0; } else { item.ImageIndex = 1; } item.Tag = row.node; // Add the item to the list if (row.node.type.Contains("folder") == true) { listViewBrowse.Items.Insert(index, item); index++; } else { listViewBrowse.Items.Add(item); } } } }
/// <summary> /// Populate the list box with the children of the company home /// </summary> private void populateListBox() { Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.path = "/app:company_home"; populateListBox(reference); }
/// <summary> /// Double click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listViewBrowse_DoubleClick(object sender, EventArgs e) { ListViewItem item = listViewBrowse.SelectedItems[0]; if (item != null) { ResultSetRowNode node = item.Tag as ResultSetRowNode; if (node != null) { if (node.type.Contains("folder") == true) { // Create the reference for the node selected Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = node.id; // Parent references this.parentReferences.Add(this.currentReference); // Populate the list with the children of the selected node populateListBox(reference); } else { // Create the reference for the node selected Alfresco.ContentWebService.Store spacesStore2 = new Alfresco.ContentWebService.Store(); spacesStore2.scheme = Alfresco.ContentWebService.StoreEnum.workspace; spacesStore2.address = "SpacesStore"; Alfresco.ContentWebService.Reference reference = new Alfresco.ContentWebService.Reference(); reference.store = spacesStore2; reference.uuid = node.id; // Lets try and get the content Alfresco.ContentWebService.Predicate predicate = new Alfresco.ContentWebService.Predicate(); predicate.Items = new Object[] { reference }; Content[] contents = this.contentService.read(predicate, "{http://www.alfresco.org/model/content/1.0}content"); Content content = contents[0]; if (content.url != null && content.url.Length != 0) { string url = content.url + "?ticket=" + AuthenticationUtils.Ticket; webBrowser.Url = new Uri(url); } } } } }
public RepositoryWebService.Reference GetReferenceFromResultSetRow(ResultSetRow row) { RepositoryWebService.Reference reference = null; reference = new Alfresco.RepositoryWebService.Reference(); reference.uuid = row.node.id; reference.store = spacesStore; NamedValue[] namedValues = row.columns; Dictionary<string, string> namedValuesMap = new Dictionary<string, string>(); // iterate through the columns of the result set to extract specific named values foreach (NamedValue namedValue in namedValues) { namedValuesMap.Add(namedValue.name, namedValue.value); } String path = namedValuesMap["{http://www.alfresco.org/model/content/1.0}path"]; name = namedValuesMap["{http://www.alfresco.org/model/content/1.0}name"]; reference.path = PathUtils.CovertFromModelPathToRepositoryPath(path); return reference; }
//********************************************************** // Function: ReleaseDoc() // Scope: internal // Overview: Document release point. Use the ReleaseData // object to release the current document's data // to the external data source. // Params: none // Returns: One of the following: KFX_REL_SUCCESS, // KFX_REL_ERROR, KFX_REL_DOCCLASSERROR, // KFX_REL_QUEUED // Called By: The Batch Release Manager. Called once for each // document to be released. //********************************************************** public AscentRelease.KfxReturnValue ReleaseDoc() { try { String name = ReleaseUtils.getLinkValue(this.releaseData.Values, ReleaseConstants.CONTENT_TYPE + Alfresco.Constants.PROP_NAME); if (name == null || name.Equals("")) { // node name is null or "" Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc - Content name is empty, check index fields in Release setup or the Content Type properties in Alfresco", ""); return(AscentRelease.KfxReturnValue.KFX_REL_ERROR); } String location = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION); // get properties and aspects list int i = 0; ArrayList aspectFields = new ArrayList(); ArrayList properties = new ArrayList(); NamedValue nameValue = new NamedValue(); // if its a content type field then create a NamedValue otherwise // store in the aspect array to be used later on foreach (AscentRelease.Value oValue in releaseData.Values) { String value = oValue.Value; String destination = oValue.Destination; if (destination.StartsWith(ReleaseConstants.CONTENT_TYPE)) { // content type field nameValue = new NamedValue(); // need to remove the prefix int start = ReleaseConstants.CONTENT_TYPE.Length; nameValue.name = destination.Substring(start, (destination.Length - start)); nameValue.value = value; nameValue.isMultiValue = false; properties.Add(nameValue); } else { // aspect field aspectFields.Add(oValue); } } // create the CML bool isNew = true; String existingUuid = this.getNodeUuidFromLocation(this.locationUuid, name); CML cml; // flag to delete refnode if there is an error uploading the content bool deleteOnErrFlag = true; if (existingUuid.Equals("")) { // new content to upload cml = this.getCMLCreate((NamedValue[])properties.ToArray(typeof(NamedValue))); } else { // update, set deleteFlag to false for updating node Content deleteOnErrFlag = false; cml = this.getCMLUpdate(existingUuid, (NamedValue[])properties.ToArray(typeof(NamedValue))); isNew = false; } // create any aspects CMLAddAspect[] cmlAspects = null; String aspects = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_ASPECTS); AscentRelease.Value aspectValue; if (aspects != null) { // seperate the aspects string String[] aspectNames = ReleaseUtils.SplitByString(aspects, ReleaseConstants.SEPERATOR); String aspectName; cmlAspects = new CMLAddAspect[aspectNames.Length]; // for each aspect create a aspect CML for (i = 0; i < aspectNames.Length; i++) { aspectName = aspectNames[i]; // create the aspect CML CMLAddAspect addAspect = new CMLAddAspect(); addAspect.aspect = aspectName; if (isNew) { addAspect.where_id = "1"; } else { // use predicate Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference(); reference.store = this.spacesStore; reference.uuid = existingUuid; Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate(); pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference }; addAspect.where = pred; } ArrayList aspectProperties = new ArrayList(); // add the aspect fields for this aspect for (int j = 0; j < aspectFields.Count; j++) { // loop thru the aspects fields and add the relevent fields aspectValue = (AscentRelease.Value)aspectFields[j]; String destination = aspectValue.Destination; String prefix = ReleaseConstants.ASPECT + ReleaseConstants.SEPERATOR + aspectName; if (destination.StartsWith(prefix)) { // content type field nameValue = new NamedValue(); // need to remove the prefix int start = prefix.Length; nameValue.name = destination.Substring(start, (destination.Length - start)); nameValue.value = aspectValue.Value; nameValue.isMultiValue = false; aspectProperties.Add(nameValue); } } addAspect.property = (NamedValue[])aspectProperties.ToArray(typeof(NamedValue)); cmlAspects[i] = addAspect; } } // add any aspects if (cmlAspects != null && cmlAspects.Length > 0) { cml.addAspect = cmlAspects; } UpdateResult[] updateResult = this.repoService.update(cml); if (!this.writeNewContent(updateResult[0].destination, deleteOnErrFlag)) { // failed to update content, deleted return(AscentRelease.KfxReturnValue.KFX_REL_ERROR); } return(AscentRelease.KfxReturnValue.KFX_REL_SUCCESS); } catch (Exception e) { Log log = new Log(); log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc " + e.Message, e.StackTrace); return(AscentRelease.KfxReturnValue.KFX_REL_ERROR); } }