public void RefreshItem(MOG_Command command) { // No reason to bother if they have no library working directory if (MOG_ControllerLibrary.GetWorkingDirectory().Length == 0) { return; } // Make sure this contains an encapsulated command? MOG_Command encapsulatedCommand = command.GetCommand(); if (encapsulatedCommand != null) { // No reason to bother if they are in a different project if (string.Compare(MOG_ControllerProject.GetProjectName(), encapsulatedCommand.GetProject(), true) != 0) { return; } // Check if this encapsulatedCommand contains a valid assetFilename? if (encapsulatedCommand.GetAssetFilename().GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { // No reason to bother if this asset's classification doesn't match their mCurrentClassification if (string.Compare(CurrentClassification, encapsulatedCommand.GetAssetFilename().GetAssetClassification(), true) != 0) { return; } } // Can we find the asset node of this file? int itemid = FindListItem(encapsulatedCommand.GetAssetFilename().GetAssetFullName()); if (itemid == -1) { // Check if this was a post command? if (encapsulatedCommand.GetCommandType() == MOG_COMMAND_TYPE.MOG_COMMAND_Post) { // Create a new item ListViewItem item = CreateListViewItemForAsset(encapsulatedCommand.GetAssetFilename()); if (item != null) { LibraryListView.Items.Add(item); itemid = FindListItem(encapsulatedCommand.GetAssetFilename().GetAssetFullName()); } } } // Now check if we finally found our itemid? if (itemid != -1) { ListViewItem item = LibraryListView.Items[itemid]; if (item != null) { int classificationIdx = FindColumn("Classification"); int nameIdx = FindColumn("Name"); int statusIdx = FindColumn("Status"); int userIdx = FindColumn("User"); int commentIdx = FindColumn("Comment"); int localFileIdx = FindColumn("LocalFile"); int repositoryFileIdx = FindColumn("RepositoryFile"); int localTimestampIdx = FindColumn("Local Timestamp"); int serverTimestampIdx = FindColumn("Server Timestamp"); int fullname = FindColumn("Fullname"); int extensionIdx = FindColumn("Extension"); // Determin the type of encapsulated command switch (encapsulatedCommand.GetCommandType()) { case MOG_COMMAND_TYPE.MOG_COMMAND_LockWriteRelease: case MOG_COMMAND_TYPE.MOG_COMMAND_LockReadRelease: UpdateItem(item); break; case MOG_COMMAND_TYPE.MOG_COMMAND_LockWriteRequest: case MOG_COMMAND_TYPE.MOG_COMMAND_LockReadRequest: string status = ""; string comment = encapsulatedCommand.GetDescription(); string username = encapsulatedCommand.GetUserName(); if (String.Compare(MOG_ControllerProject.GetUserName(), encapsulatedCommand.GetUserName(), true) == 0) { status = "CheckedOut"; } else { status = "Locked"; } item.ImageIndex = MogUtil_AssetIcons.GetLockedBinaryIcon(item.SubItems[repositoryFileIdx].Text); item.SubItems[commentIdx].Text = comment; item.SubItems[userIdx].Text = username; item.SubItems[statusIdx].Text = status; UpdateListViewItemColors(item, status); break; case MOG_COMMAND_TYPE.MOG_COMMAND_Post: item.SubItems[repositoryFileIdx].Text = MOG_ControllerLibrary.ConstructBlessedFilenameFromAssetName(encapsulatedCommand.GetAssetFilename()); UpdateItem(item); break; case MOG_COMMAND_TYPE.MOG_COMMAND_RemoveAssetFromProject: // Make sure to remove this file just incase it had been previously synced MOG_ControllerLibrary.Unsync(encapsulatedCommand.GetAssetFilename()); // Proceed to delete this item RemoveItem(itemid); break; } // Update the item's colors UpdateListViewItemColors(item, item.SubItems[statusIdx].Text); } } } }
private void UpdateItem(ListViewItem item) { string status = ""; string username = ""; string comment = ""; string localTimestamp = ""; // Find our desired columns int statusIdx = FindColumn("Status"); int userIdx = FindColumn("User"); int commentIdx = FindColumn("Comment"); int localTimestampIdx = FindColumn("Local Timestamp"); int serverTimestampIdx = FindColumn("Server Timestamp"); int localFileIdx = FindColumn("LocalFile"); int repositoryFileIdx = FindColumn("RepositoryFile"); string repositoryFile = item.SubItems[repositoryFileIdx].Text; MOG_Filename repositoryAssetFilename = new MOG_Filename(repositoryFile); // Check if this file exist locally? string localFile = item.SubItems[localFileIdx].Text; if (localFile.Length != 0) { // Obtain the localFile info FileInfo fileInfo = new FileInfo(localFile); // Does this local file exist? if (fileInfo != null && fileInfo.Exists) { // Compare our local file's timestamp to the server's revision localTimestamp = MOG_Time.GetVersionTimestamp(fileInfo.LastWriteTime); if (localTimestamp == repositoryAssetFilename.GetVersionTimeStamp()) { // Indicate this item is synced and up-to-date status = "Up-to-date"; } else { // Indicate this item is synced status = "Out-of-date"; } } else { // Indicate this item is not synced status = "unSynced"; } } else { // Indicate this item is not synced status = "unSynced"; } // Check if this file exists in the repository? if (repositoryFile.Length != 0) { // Check the lock statusIdx of the asset MOG_Command sourceLock = MOG_ControllerProject.PersistentLock_Query(repositoryAssetFilename.GetAssetFullName()); if (sourceLock.IsCompleted() && sourceLock.GetCommand() != null) { MOG_Command lockHolder = sourceLock.GetCommand(); // Obtain the lock info item.ImageIndex = MogUtil_AssetIcons.GetLockedBinaryIcon(repositoryFile); username = lockHolder.GetUserName(); comment = lockHolder.GetDescription(); // Check if this is locked by me? if (username == MOG_ControllerProject.GetUserName()) { status = "CheckedOut"; } else { status = "Locked"; } } else { // Update this file's icon item.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(repositoryFile); } } // Update the item with the new information item.SubItems[statusIdx].Text = status; item.SubItems[userIdx].Text = username; item.SubItems[commentIdx].Text = comment; item.SubItems[localTimestampIdx].Text = MogUtils_StringVersion.VersionToString(localTimestamp); item.SubItems[serverTimestampIdx].Text = MogUtils_StringVersion.VersionToString(repositoryAssetFilename.GetVersionTimeStamp()); // Update the color for this locked item UpdateListViewItemColors(item, status); }