示例#1
0
        public static void ChangeWorkState(int work, State state, double delta)
        {
            var currentTime = WorkUtility.GetWorkTime(work);
            var value       = currentTime + delta;

            ChangeWorkField(work, "/fields/Microsoft.VSTS.Scheduling.CompletedWork", value);
        }
示例#2
0
 public static void ChangeWorkCurrentState(int work, State state)
 {
     if (connection.area != "")
     {
         var currentTime = WorkUtility.GetWorkTime(work);
         var localState  = GetLocalState(state);
         ChangeWorkField(work, connection.area, localState);
     }
 }
示例#3
0
        // TODO: сделать заполнение из списка свойств
        private static void ChangeWorkField(int work, string path, object value)
        {
            var currentTime = WorkUtility.GetWorkTime(work);

            var Uri_getId      = string.Format(@"https://dev.azure.com/{0}/{1}/_apis/wit/workitems/{2}?api-version=5.1", connection.organization, connection.project, work);
            var postParameters = JArray.FromObject(new[] { new {
                                                               op = "add",
                                                               path,
                                                               value
                                                           } }).ToString();

            using (WebClient wc = new WebClient()) {
                wc.Headers[HttpRequestHeader.ContentType]   = "application/json-patch+json";
                wc.Headers[HttpRequestHeader.Authorization] = $"Basic {Utils.Base64Encode(":" + connection.token)}";
                wc.UploadString(Uri_getId, "PATCH", postParameters);
            }
        }
示例#4
0
        public JsonResult ExecuteCommand(Command command)
        {
            string     fileNameFullPath, fileContents, newfileContents, searchTerm = "", newTerm = "", message, errorMessage;
            int        startIndexSearchTerm, index;
            PageEntity pageEntity;

            try
            {
                if ((command.Cmd == "menu") || (command.Cmd == "sub1") || (command.Cmd == "sub2"))
                {
                    fileNameFullPath = string.Format("C:\\git_cjonasl\\Leander\\Solutions\\Nr1\\WebApplication1\\Views\\Main\\_Layout{0}.cshtml", command.Page.ToString());
                    fileContents     = Utility.ReturnFileContents(fileNameFullPath, out errorMessage);

                    if (errorMessage != null)
                    {
                        return(Json(string.Format("ERROR!!\r\n{0}", errorMessage), JsonRequestBehavior.AllowGet));
                    }

                    switch (command.Cmd)
                    {
                    case "menu":
                        searchTerm = string.Format("<span class='title' data-location='Menu{0}'>", command.Menu.ToString());
                        break;

                    case "sub1":
                        searchTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}'>", command.Menu.ToString(), command.Sub1.ToString());
                        break;

                    case "sub2":
                        searchTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}Sub{2}'>", command.Menu.ToString(), command.Sub1.ToString(), command.Sub2.ToString());
                        break;
                    }

                    if (!Utility.IsSearchTermUniqueInString(fileContents, searchTerm, out startIndexSearchTerm, out errorMessage))
                    {
                        return(Json(string.Format("ERROR!!\r\n{0}", errorMessage), JsonRequestBehavior.AllowGet));
                    }

                    index = fileContents.IndexOf("</span>", startIndexSearchTerm + searchTerm.Length - 1);

                    if (index == -1)
                    {
                        return(Json("ERROR!! Can't find </span> after search term!", JsonRequestBehavior.AllowGet));
                    }

                    searchTerm = fileContents.Substring(startIndexSearchTerm, index + 7 - startIndexSearchTerm);

                    switch (command.Cmd)
                    {
                    case "menu":
                        newTerm = string.Format("<span class='title' data-location='Menu{0}'>{1}</span>", command.Menu.ToString(), command.Val);
                        break;

                    case "sub1":
                        newTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}'>{2}</span>", command.Menu.ToString(), command.Sub1.ToString(), command.Val);
                        break;

                    case "sub2":
                        newTerm = string.Format("<span class='title' data-location='Menu{0}Sub{1}Sub{2}'>{3}</span>", command.Menu.ToString(), command.Sub1.ToString(), command.Sub2.ToString(), command.Val);
                        break;
                    }

                    newfileContents = fileContents.Replace(searchTerm, newTerm);
                    Utility.CreateNewFile(fileNameFullPath, newfileContents);
                }
                else if ((command.Cmd == "icon") || (command.Cmd == "title") || ((command.Cmd.Length >= 3) && (command.Cmd.Substring(0, 3) == "tab")))
                {
                    if ((command.Cmd == "icon") && !Utility.IconExists(command.Val))
                    {
                        return(Json("ERROR!! The icon does not exist!!", JsonRequestBehavior.AllowGet));
                    }

                    switch (command.Cmd)
                    {
                    case "icon":
                        pageEntity = PageEntity.Icon;
                        break;

                    case "title":
                        pageEntity = PageEntity.Title;
                        break;

                    default:
                        pageEntity = PageEntity.Tab;
                        break;
                    }

                    HandleSaveOfPageEntity(pageEntity, command.Page, command.Menu, command.Sub1, command.Sub2, command.Tab, command.Val);
                }
                else if ((command.Cmd == "nr") || (command.Cmd == "er")) //New resource or edit resource
                {
                    LoadResourceData loadResourceData = new LoadResourceData();

                    loadResourceData.ArrayWithKeyWords = KeyWordUtility.ReturnArrayWithKeyWords(out errorMessage);

                    if (errorMessage != null)
                    {
                        return(Json(errorMessage, JsonRequestBehavior.AllowGet));
                    }

                    if (command.Cmd == "nr")
                    {
                        ResourcesType resourcesType;

                        switch (command.Val)
                        {
                        case "ThumbUpLocation":
                            resourcesType = ResourcesType.ThumbUpLocation;
                            break;

                        case "Html":
                            resourcesType = ResourcesType.Html;
                            break;

                        case "Self":
                            resourcesType = ResourcesType.Self;
                            break;

                        default:
                            return(Json("ERROR!! Incorrect ResourcesType!", JsonRequestBehavior.AllowGet));
                        }

                        loadResourceData.Resource = new Resource(0, resourcesType, "", "", "", "", 0, 0, "", "", "", "");
                    }
                    else
                    {
                        loadResourceData.Resource = ResourceUtility.GetResource(int.Parse(command.Val), out errorMessage);

                        if (errorMessage != null)
                        {
                            return(Json(string.Format("ERROR!!\r\n", errorMessage), JsonRequestBehavior.AllowGet));
                        }
                    }

                    return(Json(loadResourceData, JsonRequestBehavior.AllowGet));
                }
                else if ((command.Cmd == "r") && (command.Val == "rg"))
                {
                    ResourcePresentationInSearchUtility.RegenerateResourceFile(out message);
                    return(Json(message, JsonRequestBehavior.AllowGet));
                }
                else if ((command.Cmd == "r") && (command.Val == "check"))
                {
                    ResourcePresentationInSearchUtility.CheckResourceFile(out message);
                    return(Json(message, JsonRequestBehavior.AllowGet));
                }
                else if (command.Cmd == "task")
                {
                    WorkUtility.CreateTask(command.Val, out message);
                    return(Json(message, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(string.Format("ERROR!! The command \"{0}\" is not supported", command.Cmd), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(string.Format("ERROR!! An Exception happened! e.Message:\r\n{0}", e.Message), JsonRequestBehavior.AllowGet));
            }

            return(Json("Success", JsonRequestBehavior.AllowGet));
        }