public IHttpActionResult PutMyPackage(int id, MyPackage myPackage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != myPackage.Id) { return(BadRequest()); } db.Entry(myPackage).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MyPackageExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetMyPackage(int id) { MyPackage myPackage = db.MyPackages.Find(id); if (myPackage == null) { return(NotFound()); } return(Ok(myPackage)); }
public IHttpActionResult PostMyPackage(MyPackage myPackage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.MyPackages.Add(myPackage); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = myPackage.Id }, myPackage)); }
public IHttpActionResult DeleteMyPackage(int id) { MyPackage myPackage = db.MyPackages.Find(id); if (myPackage == null) { return(NotFound()); } db.MyPackages.Remove(myPackage); db.SaveChanges(); return(Ok(myPackage)); }
public void Unsubscribe(string filepath, bool prelowered) { if (fileChangeEx != null && !String.IsNullOrEmpty(filepath)) { if (!prelowered) { filepath = filepath.ToLower(); } uint cookie; lock (eventCookies) { if (eventCookies.TryGetValue(filepath, out cookie)) { ErrorHandler.ThrowOnFailure(fileChangeEx.UnadviseFileChange(cookie)); MyPackage.OutputGeneral("Not Tracking \"" + filepath + "\""); } } } }
public void Ignore(string filepath, bool ignore, bool prelowered) { if (fileChangeEx != null && !String.IsNullOrEmpty(filepath)) { if (!prelowered) { filepath = filepath.ToLower(); } uint cookie; lock (eventCookies) { if (eventCookies.TryGetValue(filepath, out cookie)) { ErrorHandler.ThrowOnFailure(fileChangeEx.IgnoreFile(cookie, filepath, (ignore) ? 0 : 1)); MyPackage.OutputGeneral("Ignoring \"" + filepath + "\""); } } } }
public void Subscribe(string filepath, bool prelowered) { if (fileChangeEx != null && !String.IsNullOrEmpty(filepath)) { if (!prelowered) { filepath = filepath.ToLower(); } lock (eventCookies) { if (!eventCookies.ContainsKey(filepath)) { uint cookie; ErrorHandler.ThrowOnFailure(fileChangeEx.AdviseFileChange(filepath, (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time), this, out cookie)); MyPackage.OutputGeneral("Tracking \"" + filepath + "\""); eventCookies.Add(filepath, cookie); } } } }
private void DownloadData() { try { DateTime SLTime = Convert.ToDateTime(Request["date"]); //选择时间 int year = SLTime.Year; int doy = SLTime.DayOfYear; string[] stationIDS = Request["station"].ToString().Split(','); string[] ObsPath = new string[stationIDS.Length]; int flag = 0; for (int i = 0; i < stationIDS.Length; i++) { string SName = stationIDS[i]; ObsPath[i] = BasePath + SName + "\\" + year.ToString() + "\\" + doy.ToString();; if (!Directory.Exists(ObsPath[i])) { Directory.CreateDirectory(ObsPath[i]); } if (flag == 0) { if (Directory.GetFiles(ObsPath[i]).Length + Directory.GetDirectories(ObsPath[i]).Length > 0) { flag = 1; } } } if (flag == 0)//没有数据 { Response.Write("alert(\"没有数据!\");"); Response.End(); } string SavePath = Server.MapPath("~/Temp/"); if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } string SaveFileName = SavePath + "\\" + DateTime.Now.Ticks.ToString() + ".rar"; string error = ""; string AdminName = Convert.ToString(Session["UserName"]); if (MyPackage.Pack11(ObsPath, SaveFileName, 5, AdminName, out error)) { FileInfo fileInfo = new FileInfo(SaveFileName); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(SaveFileName), System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.Default; Response.WriteFile(fileInfo.FullName); Response.Flush(); File.Delete(fileInfo.FullName); Response.End(); } else { Response.Write("<script>alert(\"下载失败\");</script>"); Response.End(); } } catch (Exception er) { Response.Write("<script>alert(\"下载失败:" + er.Message + "\");</script>"); Response.End(); } }
private void ProcessNode(IVsHierarchy hierarchy, uint itemId, int recursionLevel) { try { MyLog.DebugEnter(this, "ProcessNode(hierarchy, " + itemId + ", " + recursionLevel + ")"); int hr; object oRootName; hr = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Name, out oRootName); if (ErrorHandler.Failed(hr)) { MyPackage.OutputGeneral("ERROR: Could not get root name of item #" + itemId); ErrorHandler.ThrowOnFailure(hr); } string rootName = oRootName as string; if (String.IsNullOrEmpty(rootName)) { rootName = Resources.RootUnknown; } Debug.WriteLine("rootName=" + rootName); string itemName; hr = hierarchy.GetCanonicalName(itemId, out itemName); if (ErrorHandler.Failed(hr)) { switch (hr) { case VSConstants.E_NOTIMPL: // ignore; Nothing to do if we cannot get the file name, but below logic can handle null/empty name... itemName = null; break; default: MyPackage.OutputGeneral("ERROR: Could not get canonical name of item #" + itemId); ErrorHandler.ThrowOnFailure(hr); break; } } Debug.WriteLine("itemName=\"" + itemName + "\""); #if DEBUG && false if (BackgroundWorker != null && !String.IsNullOrEmpty(itemName)) { // Temporary until we call AddFilePathIfChanged after we find out what the item type is BackgroundWorker.ReportProgress(0, itemName); } #endif Guid guidTypeNode; hr = hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out guidTypeNode); if (ErrorHandler.Failed(hr)) { switch (hr) { case VSConstants.E_NOTIMPL: Debug.WriteLine("Guid property E_NOTIMPL for item #" + itemId + " \"" + itemName + "\"; assuming virtual/reference item and ignoring"); // ignore; Below logic can handle Guid.Empty guidTypeNode = Guid.Empty; break; case VSConstants.DISP_E_MEMBERNOTFOUND: Debug.WriteLine("Guid property DISP_E_MEMBERNOTFOUND for item #" + itemId + " \"" + itemName + "\"; assuming reference item and ignoring"); guidTypeNode = Guid.Empty; break; default: MyPackage.OutputGeneral("ERROR: Could not get type guid of item #" + itemId + " \"" + itemName + "\""); ErrorHandler.ThrowOnFailure(hr); break; } } Debug.WriteLine("guidTypeNode=" + guidTypeNode); // // Intentionally ordered from most commonly expected to least commonly expected... // if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_PhysicalFile)) { AddFilePathIfChanged(itemName, rootName, PostReview.ChangeType.Unknown); } else if (itemId == VSConstants.VSITEMID_ROOT) { IVsProject project = hierarchy as IVsProject; if (project != null) { string projectFile; hr = project.GetMkDocument(VSConstants.VSITEMID_ROOT, out projectFile); if (ErrorHandler.Failed(hr)) { switch (hr) { case VSConstants.E_NOTIMPL: // This apparently can happen if the item is a virtual "Solution Items" folder; nothing to do; return; return; default: MyPackage.OutputGeneral("ERROR: Could not get document name of project \"" + rootName + "\""); ErrorHandler.ThrowOnFailure(hr); break; } } AddFilePathIfChanged(projectFile, rootName, PostReview.ChangeType.Unknown); } else { IVsSolution solution = hierarchy as IVsSolution; if (solution != null) { rootName = Resources.RootSolution; string solutionDirectory, solutionFile, solutionUserOptions; ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out solutionDirectory, out solutionFile, out solutionUserOptions)); AddFilePathIfChanged(solutionFile, rootName, PostReview.ChangeType.Unknown); } else { MyPackage.OutputGeneral("ERROR: itemid==VSITEMID_ROOT, but hierarchy is neither Solution or Project"); ErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED); } } } #if DEBUG else if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_PhysicalFolder)) { Debug.WriteLine("ignoring GUID_ItemType_PhysicalFolder"); // future enumeration will handle any individual subitems in this folder... } else if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_VirtualFolder)) { Debug.WriteLine("ignoring GUID_ItemType_VirtualFolder"); // future enumeration will handle any individual subitems in this virtual folder... } else if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_SubProject)) { Debug.WriteLine("ignoring GUID_ItemType_SubProject"); // future enumeration will handle any individual subitems in this sub project... } else if (Guid.Equals(guidTypeNode, Guid.Empty)) { Debug.WriteLine("ignoring itemName=" + itemName + "; guidTypeNode == Guid.Empty"); // future enumeration will handle any individual subitems in this item... } else { MyPackage.OutputGeneral("ERROR: Unhandled node item/type itemName=" + itemName + ", guidTypeNode=" + guidTypeNode); ErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED); } #endif } finally { MyLog.DebugLeave(this, "ProcessNode(hierarchy, " + itemId + ", " + recursionLevel + ")"); } }
/// <summary> /// Code almost 100% taken from VS SDK Example: SolutionHierarchyTraversal /// TODO:(pv) There seems to be an undesirable result when the Solution is set to "Show All Files". /// </summary> /// <param name="hierarchy"></param> /// <param name="itemid"></param> /// <param name="recursionLevel"></param> /// <param name="hierIsSolution"></param> /// <param name="visibleNodesOnly"></param> /// <param name="changes"></param> /// <returns>true if the caller should continue, false if the caller should stop</returns> private bool EnumHierarchyItems(IVsHierarchy hierarchy, uint itemid, int recursionLevel, bool hierIsSolution, bool visibleNodesOnly)//, PostReview.SubmitItemCollection changes) { if (BackgroundInitialSolutionCrawl != null && BackgroundInitialSolutionCrawl.CancellationPending) { return(false); } int hr; IntPtr nestedHierarchyObj; uint nestedItemId; Guid hierGuid = typeof(IVsHierarchy).GUID; // Check first if this node has a nested hierarchy. If so, then there really are two // identities for this node: 1. hierarchy/itemid 2. nestedHierarchy/nestedItemId. // We will recurse and call EnumHierarchyItems which will display this node using // the inner nestedHierarchy/nestedItemId identity. hr = hierarchy.GetNestedHierarchy(itemid, ref hierGuid, out nestedHierarchyObj, out nestedItemId); if (VSConstants.S_OK == hr && IntPtr.Zero != nestedHierarchyObj) { IVsHierarchy nestedHierarchy = Marshal.GetObjectForIUnknown(nestedHierarchyObj) as IVsHierarchy; Marshal.Release(nestedHierarchyObj); // we are responsible to release the refcount on the out IntPtr parameter if (nestedHierarchy != null) { // Display name and type of the node in the Output Window EnumHierarchyItems(nestedHierarchy, nestedItemId, recursionLevel, false, visibleNodesOnly); } } else { object pVar; // Display name and type of the node in the Output Window ProcessNode(hierarchy, itemid, recursionLevel); recursionLevel++; // Get the first child node of the current hierarchy being walked // NOTE: to work around a bug with the Solution implementation of VSHPROPID_FirstChild, // we keep track of the recursion level. If we are asking for the first child under // the Solution, we use VSHPROPID_FirstVisibleChild instead of _FirstChild. // In VS 2005 and earlier, the Solution improperly enumerates all nested projects // in the Solution (at any depth) as if they are immediate children of the Solution. // Its implementation _FirstVisibleChild is correct however, and given that there is // not a feature to hide a SolutionFolder or a Project, thus _FirstVisibleChild is // expected to return the identical results as _FirstChild. hr = hierarchy.GetProperty(itemid, ((visibleNodesOnly || (hierIsSolution && recursionLevel == 1) ? (int)__VSHPROPID.VSHPROPID_FirstVisibleChild : (int)__VSHPROPID.VSHPROPID_FirstChild)), out pVar); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); if (VSConstants.S_OK == hr) { // We are using Depth first search so at each level we recurse to check if the node has any children // and then look for siblings. uint childId = MyPackage.GetItemId(pVar); while (childId != VSConstants.VSITEMID_NIL) { if (!EnumHierarchyItems(hierarchy, childId, recursionLevel, false, visibleNodesOnly)) { break; } // NOTE: to work around a bug with the Solution implementation of VSHPROPID_NextSibling, // we keep track of the recursion level. If we are asking for the next sibling under // the Solution, we use VSHPROPID_NextVisibleSibling instead of _NextSibling. // In VS 2005 and earlier, the Solution improperly enumerates all nested projects // in the Solution (at any depth) as if they are immediate children of the Solution. // Its implementation _NextVisibleSibling is correct however, and given that there is // not a feature to hide a SolutionFolder or a Project, thus _NextVisibleSibling is // expected to return the identical results as _NextSibling. hr = hierarchy.GetProperty(childId, ((visibleNodesOnly || (hierIsSolution && recursionLevel == 1)) ? (int)__VSHPROPID.VSHPROPID_NextVisibleSibling : (int)__VSHPROPID.VSHPROPID_NextSibling), out pVar); if (VSConstants.S_OK == hr) { childId = MyPackage.GetItemId(pVar); } else { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); break; } } } } return(BackgroundInitialSolutionCrawl == null || !BackgroundInitialSolutionCrawl.CancellationPending); }