private async void LoadStoryAndCheckPerms(string id, string name)
        {
            try
            {
                var story = _sc.LoadStory(id);

                var perms = story.StoryAsRoadmap.GetPermission(username.Text);

                if (perms != ShareAction.owner && perms != ShareAction.admin)
                {
                    await SetText($"WARNING: You don't have admin permission on story '{name}'");
                    await SetText($"SKIPPING... '{name}'");

                    _stories.Add(id, null);
                }
                else
                {
                    _stories.Add(id, story);
                    await SetText($"Loaded '{story.Name}'");
                }
            }
            catch (Exception ex)
            {
                await SetText($"WARNING: there was a problem loading '{name}'");

                _stories.Add(id, null);
            }
        }
예제 #2
0
        private void share_Click(object sender, RoutedEventArgs e)
        {
            string[] attr = { "Project Lead|Text",           "Project Team|Text",            "External ID|Numeric",                         "Priority|Numberic",
                              "Value Stream/LOB|List",       "RAG Status|List",              "Percent Complete|Numeric",                    "Due Date|Date",    "New Requested Budget|Numeric",
                              "Appropriated Budget|Numeric", "Project Business Value|Text",  "Project Dependencies/Assumptions/Risks|Text",
                              "Status Comments|Text",        "Total Spent to Date|Numberic", "Financial Comments|Text" };
            // Load from App.Config
            string sharpCloudUsername = shareSharpUsername.Text;
            string sharpCloudPassword = shareSharpPassword.Password.ToString();
            string sharePointUsername = shareUsername.Text;
            string sharePointPassword = sharePassword.Password.ToString();
            string sharePointSite     = "https://hawaiioimt.sharepoint.com/sites/ets";

            // Login into sharpcloud
            var sc = new SharpCloudApi();

            try
            {
                sc = new SharpCloudApi(sharpCloudUsername, sharpCloudPassword);
            }
            catch
            {
                MessageBox.Show("Incorrect Sharpcloud info");
                return;
            }

            Story story = sc.LoadStory(shareStory.Text);
            // Login into Sharepoint
            var securePassword = new SecureString();

            foreach (var character in sharePointPassword)
            {
                securePassword.AppendChar(character);
            }
            securePassword.MakeReadOnly();
            var           sharePointCredentials = new SharePointOnlineCredentials(sharePointUsername, securePassword);
            ClientContext context = new ClientContext(sharePointSite);

            context.Credentials = sharePointCredentials;
            Microsoft.SharePoint.Client.List list = context.Web.Lists.GetByTitle("Projects");
            // Setup query
            CamlQuery query = new CamlQuery();

            query.ViewXml = "<View/>";
            Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);
            // Loads list
            context.Load(list);
            context.Load(items);
            context.ExecuteQuery();
            // Goes through List
            // Adds Attribute to story if none exist
            addAttribute(story, attr);
            // Goes through List Items
            foreach (var item in items)
            {
                addItem(story, item, attr);
            }
            story.Save();
        }
 public void CreateClient()
 {
     // first create an instanceof SharpCloudApi
     try
     {
         scClient = new SharpCloudApi(username, password);
         scStory  = scClient.LoadStory(story_id);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            // Load story and get data

            var config = new Configuration();

            var api = new SharpCloudApi(
                config.Username,
                config.Password,
                config.Url);

            var story             = api.LoadStory(config.StoryId);
            var itemsData         = story.GetItemsData();
            var relationshipsData = story.GetRelationshipsData();

            // Write data to Excel

            var writer = new ExcelWriter();

            writer.AddSheet("Items", itemsData);
            writer.AddSheet("Relationships", relationshipsData);
        }
예제 #5
0
        static void Main(string[] args)
        {
            // Get info from config file
            var team   = ConfigurationManager.AppSettings["team"];
            var userid = ConfigurationManager.AppSettings["user"];
            var passwd = ConfigurationManager.AppSettings["pass"];
            var sheet  = ConfigurationManager.AppSettings["sheet"];
            // Login and get story data from Sharpcloud
            var    sc       = new SharpCloudApi(userid, passwd);
            var    teamBook = sc.StoriesTeam(team);
            string fileName = System.IO.Directory.GetParent
                                  (System.IO.Directory.GetParent(Environment.CurrentDirectory).ToString()).ToString() + "\\" + sheet + ".xlsx";

            // Load data from excel
            using (ExcelPackage xlPackage = new ExcelPackage(new FileInfo(fileName)))
            {
                // Generate data from worksheets
                var itemSheet   = xlPackage.Workbook.Worksheets.First();
                var itemRows    = itemSheet.Dimension.End.Row;
                var itemColumns = itemSheet.Dimension.End.Column;
                // Creating the objects to be used in the threads
                // add attribute to story

                foreach (var book in teamBook)
                {
                    var story = sc.LoadStory(book.Id);
                    Console.WriteLine("Adding tags to " + story.Name);
                    for (var k = 2; k < itemRows; k++)
                    {
                        if (story.ItemTag_FindByName(itemSheet.Cells[k, 1].Value.ToString()) == null)
                        {
                            story.ItemTag_AddNew(itemSheet.Cells[k, 1].Value.ToString(), " ", itemSheet.Cells[k, 3].Value.ToString());
                        }
                    }
                    story.Save();
                }
            }
        }
예제 #6
0
        public static async void ProcessBowTies(SharpCloudApi sc, string teamId, string portfolioId, string controlId, string temaplateId, Logger log)
        {
            // combine all bowtie stories 
            log.Log($"Reading Portfolio Story");
            await Task.Delay(100);
            var portfolioStory = sc.LoadStory(portfolioId);
            var attSubCat = portfolioStory.Attribute_FindByName("Risk Sub Category") ??
                               portfolioStory.Attribute_Add("Risk Sub Category", Attribute.AttributeType.List);


            log.Log($"Reading Control Story");
            await Task.Delay(100);
            var controlsStory = sc.LoadStory(controlId);

            // make sure risk count exists
            var _riskCount = "RiskCount";
            var attRiskCountControlStory = controlsStory.Attribute_FindByName(_riskCount) ??
                               controlsStory.Attribute_Add(_riskCount, Attribute.AttributeType.Numeric);
            var attOverallControlRatingControlStory = controlsStory.Attribute_FindByName(_attrControlRating) ??
                   controlsStory.Attribute_Add(_attrControlRating, Attribute.AttributeType.List);
            var attManagedControlStory = controlsStory.Attribute_FindByName(_attrControlOpinion) ??
                   controlsStory.Attribute_Add(_attrControlOpinion, Attribute.AttributeType.List);
            var attRiskLevelControlStory = controlsStory.Attribute_FindByName(_attrRiskLevel) ??
                   controlsStory.Attribute_Add(_attrRiskLevel, Attribute.AttributeType.List);
            var attBasisOfOpinionControlStory = controlsStory.Attribute_FindByName(_attrBasisOfOpinion) ??
                   controlsStory.Attribute_Add(_attrBasisOfOpinion, Attribute.AttributeType.List);
            var attKeyScorecardAreaControlStory = controlsStory.Attribute_FindByName(_attrImpactedArea) ??
                               controlsStory.Attribute_Add(_attrImpactedArea, Attribute.AttributeType.List);
            var attDirectorateControlStory = controlsStory.Attribute_FindByName(_attrDirectorate) ??
                               controlsStory.Attribute_Add(_attrDirectorate, Attribute.AttributeType.List);
            var attControlOwnerControlStory = controlsStory.Attribute_FindByName(_attrControlOwner) ??
                               controlsStory.Attribute_Add(_attrControlOwner, Attribute.AttributeType.List);


            /* Don't remove
            attOverallControlRating.Labels_Delete(_multipleValues); // always removed
            attManaged.Labels_Delete(_multipleValues); // always removed
            */

            // remove control ratings for existing controls

            foreach (var itm in controlsStory.Items)
            {
                itm.RemoveAttributeValue(attManagedControlStory);
                itm.RemoveAttributeValue(attOverallControlRatingControlStory);
                itm.RemoveAttributeValue(attRiskLevelControlStory);
                itm.RemoveAttributeValue(attBasisOfOpinionControlStory);
                itm.RemoveAttributeValue(attKeyScorecardAreaControlStory);
                itm.RemoveAttributeValue(attDirectorateControlStory);
                itm.RemoveAttributeValue(attControlOwnerControlStory);

                itm.SetAttributeValue(attRiskCountControlStory, 0);

                // delete all resources - we will add new ones back in later
                var list = new List<string>();
                foreach (var res in itm.Resources)
                {
                    if (res.Description == _strRiskControlInstance || res.Description == _strRiskRelatedStory)
                        list.Add(res.Id);
                }
                foreach(var id in list)
                    itm.Resource_DeleteById(id);
            }



            foreach (var teamStory in sc.StoriesTeam(teamId))
            {
                if (teamStory.Id != portfolioId && teamStory.Id != temaplateId && teamStory.Id != controlId)// && teamStory.Id == "aad81010-af26-4ba2-954a-420383fb6d1f")
                {
                    log.Log($"Reading from '{teamStory.Name}'");
                    await Task.Delay(100);

                    
                    try
                    {
                        var story = sc.LoadStory(teamStory.Id);
                        var riskItemSource = story.Item_FindByExternalId("RISK");

                        if (riskItemSource != null)
                        {
                            var riskItem = portfolioStory.Item_FindByExternalId(story.Id) ??
                               portfolioStory.Item_AddNew(riskItemSource.Name, false);

                            riskItem.Name = riskItemSource.Name;
                            riskItem.Description = riskItemSource.Description;
                            riskItem.ExternalId = story.Id;

                            var attDirectorate = story.Attribute_FindByName(_attrDirectorate);
                            var riskCategoryName = riskItemSource.GetAttributeValueAsText(attDirectorate);

                            string catName, subCatName;
                            var split = riskCategoryName.Split('.');
                            if (split.Count() == 1)
                            {
                                catName = split[0];
                                subCatName = "";
                            }
                            else // maybe multiple sub cats
                            {
                                catName = split[0];
                                subCatName = riskCategoryName.Substring(catName.Length+1);
                            }

                            var riskCategory = portfolioStory.Category_FindByName(catName) ??
                                               portfolioStory.Category_AddNew(catName);
                            riskItem.Category = riskCategory;

                            riskItem.SetAttributeValue(attSubCat, subCatName); // set the sub category attribute
                            // TODO Set the real sub category when the SDK supports this.

                            // copy and assigned risk tags
                            foreach (var t in riskItemSource.Tags)
                                riskItem.Tag_AddNew(t.Text);


                            var res = riskItem.Resource_FindByName(teamStory.Name) ?? riskItem.Resource_AddName(teamStory.Name);
                            res.Description = story.Description;
                            res.Url = new Uri(story.Url);

                            LoadPanelData(riskItem, story, _cause, _listCauses, _widthCauses);
                            LoadPanelData(riskItem, story, _causeControls, _listCausesControls, _widthCausesControls);
                            LoadPanelData(riskItem, story, _causeControlActions, _listCausesActions, _widthCausesActions);
                            LoadPanelData(riskItem, story, _consequence, _listConsequenses, _widthConsequenses);
                            LoadPanelData(riskItem, story, _consequenceControls, _listConsequensesControls, _widthConsequensesControls);
                            LoadPanelData(riskItem, story, _consequenceActions, _listConsequensesActions, _widthConsequensesActions);
                            LoadPanelData(riskItem, story, _ewi, _listEWI, _widthEWI);

                            if (riskItemSource != null)
                                CopyAllAttributeValues(riskItemSource, riskItem);
                            else
                                log.LogError($"Could not find a risk item in {teamStory.Name}");


                            // do the controls
                            var attManagedControlsRiskStory = story.Attribute_FindByName(_attrControlOpinion) ??
                                                       story.Attribute_Add(_attrControlOpinion, Attribute.AttributeType.List);

                            var attRiskLevelControlsRiskStory = story.Attribute_FindByName(_attrRiskLevel) ??
                                                       story.Attribute_Add(_attrRiskLevel, Attribute.AttributeType.List);

                            var attOverallControlRatingControlsRiskStory = story.Attribute_FindByName(_attrControlRating) ??
                                                       story.Attribute_Add(_attrControlRating, Attribute.AttributeType.List);

                            var attBasisOfOpinionRiskStory = story.Attribute_FindByName(_attrBasisOfOpinion) ??
                                                       story.Attribute_Add(_attrBasisOfOpinion, Attribute.AttributeType.List);

                            var attScorecardAreaRiskStory = story.Attribute_FindByName(_attrImpactedArea) ??
                                                       story.Attribute_Add(_attrImpactedArea, Attribute.AttributeType.List);

                            var attControlOwnerRiskStory = story.Attribute_FindByName(_attrControlOwner) ??
                                                       story.Attribute_Add(_attrControlOwner, Attribute.AttributeType.List);


                            foreach (var itemControlSource in story.Items.Where( i =>
                                            (i.Category.Name == _causeControls ||
                                             i.Category.Name == _consequenceControls)))
                            {
                                var itemControlDestination = controlsStory.Item_FindByName(itemControlSource.Name) ??
                                            controlsStory.Item_AddNew(itemControlSource.Name);

                                itemControlDestination.Description = itemControlSource.Description;

                                itemControlDestination.Tag_AddNew(itemControlSource.Category.Name);
                                // add any tags
                                foreach (var t in itemControlSource.Tags)
                                {
                                    itemControlDestination.Tag_AddNew(t.Text);
                                }

                                var resC = itemControlDestination.Resource_FindByUrl(itemControlSource.Url);
                                if (resC == null)
                                    resC = itemControlDestination.Resource_AddName(itemControlSource.Id); // need to be unique
                                resC.Name = "Usage of this control";
                                resC.Description = $"Control used in '{story.Name}'";//"Instance of This Control";
                                resC.Url = new Uri(itemControlSource.Url);

                                var resCC = itemControlSource.Resource_FindByUrl(itemControlDestination.Url);
                                if (resCC == null)
                                    resCC = itemControlSource.Resource_AddName(itemControlDestination.Id); // need to be unique
                                resCC.Name = "Control Library";
                                resCC.Description = "View this control in Control library";
                                resCC.Url = new Uri(itemControlDestination.Url);


                                // risk control
                                AddAttributeButCheckForDiffernce(itemControlSource, attManagedControlsRiskStory, itemControlDestination, attManagedControlStory);
                                // overall risk rating
                                AddAttributeButCheckForDiffernce(riskItemSource, attOverallControlRatingControlsRiskStory, itemControlDestination, attOverallControlRatingControlStory);
                                // overall risk Level
                                AddAttributeButCheckForDiffernce(riskItemSource, attRiskLevelControlsRiskStory, itemControlDestination, attRiskLevelControlStory);
                                // add risk basis of opinion
                                AddAttributeButCheckForDiffernce(itemControlSource, attBasisOfOpinionRiskStory, itemControlDestination, attBasisOfOpinionControlStory);
                                // add risk group (category)
                                AddAttributeButCheckForDiffernce(riskItemSource, attScorecardAreaRiskStory, itemControlDestination, attKeyScorecardAreaControlStory);
                                // add risk directorate
                                AddAttributeButCheckForDiffernce(riskItemSource, attDirectorate, itemControlDestination, attDirectorateControlStory);
                                // add risk directorate
                                AddAttributeButCheckForDiffernce(itemControlSource, attControlOwnerRiskStory, itemControlDestination, attControlOwnerControlStory);

                            }
                            story.Save();// save resourc links
                        }
                        else
                        {
                            log.LogError($"Could not find a risk item in {teamStory.Name}");
                        }

                    }
                    catch (Exception e)
                    {
                        log.LogError(e.Message);
                    }
                }
            }

            // process control item resource panels
            foreach (var itm in controlsStory.Items)
            {
                // delete all resources - we will add new ones back in later
                var listR = new List<string>();
                var listC = new List<string>();
                foreach (var res in itm.Resources)
                {
                    if (res.Description == _strRiskControlInstance)
                        listC.Add(res.Id);
                    if (res.Description == _strRiskRelatedStory)
                        listR.Add(res.Id);
                }
            }
 
            log.Log($"Saving {portfolioStory.Name}");
            portfolioStory.Save();
            log.Log($"Saving {controlsStory.Name}");
            controlsStory.Save();
            await Task.Delay(1000);

            log.HideProgress();
        }
예제 #7
0
        static void Main(string[] args)
        {
            var fileLocation = System.IO.Directory.GetParent
                                   (System.IO.Directory.GetParent(Environment.CurrentDirectory)
                                   .ToString()).ToString();
            // Loads user setting from config file
            var             teamstoryid = ConfigurationManager.AppSettings["teamstoryid"];
            var             portfolioid = ConfigurationManager.AppSettings["portfolioid"];
            var             templateid  = ConfigurationManager.AppSettings["templateid"];
            var             userid      = ConfigurationManager.AppSettings["user"];
            var             passwd      = ConfigurationManager.AppSettings["pass"];
            var             URL         = ConfigurationManager.AppSettings["URL"];
            var             storyID     = ConfigurationManager.AppSettings["story"];
            MatchCollection matchUrl    = Regex.Matches(storyID, @"story\/(.+)\/view");

            string[] matchGroup = null;
            string   storyUrl   = "";

            if (matchUrl.Count > 0)
            {
                matchGroup = matchUrl[0].ToString().Split('/');
                storyUrl   = matchGroup[1];
            }
            else
            {
                storyUrl = storyID;
            }
            // Login and get story data from Sharpcloud
            var sc    = new SharpCloudApi(userid, passwd, URL);
            var story = sc.LoadStory(storyUrl);
            //Create EPPlus and create a workbook with 2 spreadsheets
            FileInfo     newFile = new FileInfo(fileLocation + "\\combine.xlsx");
            ExcelPackage pck     = new ExcelPackage(newFile);
            //Add the Content sheets
            var itemSheet = pck.Workbook.Worksheets.FirstOrDefault(x => x.Name == "Items");

            if (itemSheet == null)
            {
                itemSheet = pck.Workbook.Worksheets.Add("Items");
            }
            var relationshipSheet = pck.Workbook.Worksheets.First();

            if (pck.Workbook.Worksheets.Count > 1)
            {
                relationshipSheet = pck.Workbook.Worksheets.ElementAt(1);
            }
            if (relationshipSheet == itemSheet)
            {
                relationshipSheet = pck.Workbook.Worksheets.Add("RelationshipSheet");
            }
            //Setting up the threads
            object a, b;
            Sharp  first  = new Sharp();
            Sharp  second = new Sharp();

            first.sc     = sc; first.story = story; first.sheet = itemSheet;
            first.order  = 0;
            second.story = story;
            second.order = 1;
            a            = first;
            b            = second;
            // Initial Item Header list
            var headList = new List <string> {
                "Name", "Description", "Category", "Start", "Duration",
                "Resources", "Tags", "Panels", "Subcategory", "AttCount", "cat_color", "file_path"
            };
            // Filters the default attributes from the story
            var   attData  = story.Attributes;
            var   attList  = new List <SC.API.ComInterop.Models.Attribute>();
            Regex regex    = new Regex(@"none|None|Sample");
            var   attCount = 0;

            foreach (var att in attData)
            {
                // Checks to see if attribute header is a default attritube.
                Match match = regex.Match(att.Name);
                if (!match.Success)
                {
                    // Adds non-default attribute to the List and to the header line
                    attList.Add(att);
                    attCount++;
                    headList.Add(att.Name + "|" + att.Type + "|" + att.Description);
                }
            }
            var go = 1;

            foreach (var head in headList)
            {
                itemSheet.Cells[1, go].Value = head;
                go++;
            }
            first.attList   = attList;
            first.sheetLine = 2;
            first.attCount  = attCount;

            // Insert data into 2 spreadsheets
            firstHalf  = new Thread(new ParameterizedThreadStart(downloadFiles));
            downloader = new Thread(new ParameterizedThreadStart(downloadFiles));

            firstHalf.Start(a);
            downloader.Start(b);
            ItemSheet(a);
            RelationshipSheet(story, relationshipSheet);
            pck.SaveAs(newFile);

            /*
             * Console.WriteLine("Resource Tags");
             * foreach (var resTag in story.ResourceTags)
             * {
             *  Console.WriteLine(resTag.Name);
             * }
             */
        }
예제 #8
0
        static void Main(string[] args)
        {
            string fileName = System.IO.Directory.GetParent(System.IO.Directory.GetParent(Environment.CurrentDirectory).ToString()).ToString() + "\\combine.xlsx";
            // Get info from config file
            var teamstoryid = ConfigurationManager.AppSettings["teamstoryid"];
            var portfolioid = ConfigurationManager.AppSettings["portfolioid"];
            var templateid  = ConfigurationManager.AppSettings["templatIeid"];
            var userid      = ConfigurationManager.AppSettings["user"];
            var passwd      = ConfigurationManager.AppSettings["pass"];
            var URL         = ConfigurationManager.AppSettings["URL"];
            var storyID     = ConfigurationManager.AppSettings["story"];
            var storyTwo    = ConfigurationManager.AppSettings["storyTwo"];

            // Login and get story data from Sharpcloud
            var sc    = new SharpCloudApi(userid, passwd, URL);
            var story = sc.LoadStory(storyID);

            // Load data from excel
            using (ExcelPackage xlPackage = new ExcelPackage(new FileInfo(fileName)))
            {
                // Generate data from worksheets
                var itemSheet   = xlPackage.Workbook.Worksheets.First();
                var relSheet    = xlPackage.Workbook.Worksheets.ElementAt(1);
                var relRows     = relSheet.Dimension.End.Row;
                var relCols     = relSheet.Dimension.End.Column;
                var itemRows    = itemSheet.Dimension.End.Row;
                var itemColumns = itemSheet.Dimension.End.Column;
                // Creating the objects to be used in the threads
                object a, b;
                Sharp  first  = new Sharp();
                Sharp  second = new Sharp();
                first.sheet  = itemSheet; first.sc = sc; first.story = story; first.order = 0;
                second.sheet = itemSheet; second.sc = sc; second.story = story; second.order = 1;
                // Creating the threads
                firstHalf       = new Thread(new ParameterizedThreadStart(addItems));
                secondHalf      = new Thread(new ParameterizedThreadStart(addItems));
                firstHalf.Name  = "firstHalf";
                secondHalf.Name = "secondHalf";
                // add attribute to story
                for (var k = 13; k < itemColumns; k++)
                {
                    string[] attribute = itemSheet.Cells[1, k].Value.ToString().Split('|');
                    if (story.Attribute_FindByName(attribute[0]) == null)
                    {
                        switch (attribute[1])
                        {
                        case "Text":
                            story.Attribute_Add(attribute[0], SC.API.ComInterop.Models.Attribute.AttributeType.Text);
                            break;

                        case "Numeric":
                            story.Attribute_Add(attribute[0], SC.API.ComInterop.Models.Attribute.AttributeType.Numeric);
                            break;

                        case "Date":
                            story.Attribute_Add(attribute[0], SC.API.ComInterop.Models.Attribute.AttributeType.Date);
                            break;

                        case "List":
                            story.Attribute_Add(attribute[0], SC.API.ComInterop.Models.Attribute.AttributeType.List);
                            break;

                        case "Location":
                            story.Attribute_Add(attribute[0], SC.API.ComInterop.Models.Attribute.AttributeType.Location);
                            break;
                        }
                        story.Attribute_FindByName(attribute[0]).Description = attribute[2];
                    }
                }
                // go through item sheet
                a = first;
                b = second;
                firstHalf.Start(a);
                secondHalf.Start(b);
                // Waits for all the items to be in the story before adding relationships
                firstHalf.Join();
                secondHalf.Join();
                Console.WriteLine("Adding Relationships");
                string[] attSplit = null;
                // Add attribute relationship to story
                for (var i = 6; i < relCols; i++)
                {
                    attSplit = relSheet.Cells[1, i].Value.ToString().Split('|');
                    if (story.RelationshipAttribute_FindByName(attSplit[0]) == null)
                    {
                        switch (attSplit[1])
                        {
                        case "Numeric":
                            story.RelationshipAttribute_Add(attSplit[0], RelationshipAttribute.RelationshipAttributeType.Numeric);
                            break;

                        case "Date":
                            story.RelationshipAttribute_Add(attSplit[0], RelationshipAttribute.RelationshipAttributeType.Date);
                            break;

                        case "List":
                            story.RelationshipAttribute_Add(attSplit[0], RelationshipAttribute.RelationshipAttributeType.List);
                            break;

                        case "Text":
                            story.RelationshipAttribute_Add(attSplit[0], RelationshipAttribute.RelationshipAttributeType.Text);
                            break;
                        }
                    }
                }
                // Add relationships to items
                for (int rowNum = 2; rowNum <= relRows; rowNum++)
                {
                    // Establish relationships between 2 items
                    var currentItem = story.Item_FindByName(relSheet.Cells[rowNum, 1].Value.ToString());
                    var nextItem    = story.Item_FindByName(relSheet.Cells[rowNum, 2].Value.ToString());
                    var rel         = story.Relationship_AddNew(currentItem, nextItem);
                    // Assign direction to relationship
                    switch (relSheet.Cells[rowNum, 3].Value.ToString())
                    {
                    case "None":
                        rel.Direction = Relationship.RelationshipDirection.None;
                        break;

                    case "AtoB":
                        rel.Direction = Relationship.RelationshipDirection.AtoB;
                        break;

                    case "BtoA":
                        rel.Direction = Relationship.RelationshipDirection.BtoA;
                        break;

                    case "Both":
                        rel.Direction = Relationship.RelationshipDirection.Both;
                        break;
                    }
                    string[] tagArray = null;
                    if (relSheet.Cells[rowNum, 4].Value != null && relSheet.Cells[rowNum, 4].Value != "")
                    {
                        tagArray = relSheet.Cells[rowNum, 4].ToString().Split('|');
                        for (var i = 0; i < tagArray.Length - 1; i++)
                        {
                            rel.Tag_AddNew(tagArray[i]);
                        }
                    }
                    var relCom = story.Item_FindByName(relSheet.Cells[rowNum, 5].Value.ToString());
                    for (var k = 6; k < relCols; k++)
                    {
                        attSplit = relSheet.Cells[1, k].Value.ToString().Split('|');
                        rel.SetAttributeValue(story.RelationshipAttribute_FindByName(attSplit[0]), relSheet.Cells[rowNum, k].Value.ToString());
                    }
                }
            }
            story.Save();
        }
예제 #9
0
        private async void ClickButtonPostIts(object sender, RoutedEventArgs e)
        {
            if (!ValidateSettings())
            {
                return;
            }

            try
            {
                // We need to use async here becasuse we need to use the clipboard to access the images in Excel
                // and this must be done from the UI thread
                var vm = DataContext as ViewModels.MainViewModel;

                vm.SetFormOn(true);
                vm.Status = "Starting...";
                await Task.Delay(100);

                var sc = new SharpCloudApi(_user, _password, _url);

                vm.Status = "Reading Post-It images from Excel...";
                await Task.Delay(100);

                ReadPostItsFromExcel(sc, _filename, vm);
                while (_wait)
                {
                    await Task.Delay(100);
                }

                if (!_bCancel)
                {
                    vm.Status = "Loading story...";
                    await Task.Delay(100);

                    var rm = sc.LoadStory(_rid);

                    vm.Status = "Adding items...";
                    await Task.Delay(100);

                    //                   var atts = rm.Attribute_FindByName("Labels");
                    //                   if (atts == null)
                    //                       atts = rm.Attribute_Add("Labels", Attribute.AttributeType.List);
                    var attsRow = rm.Attribute_FindByName("ExcelRow");
                    if (attsRow == null)
                    {
                        attsRow = rm.Attribute_Add("ExcelRow", Attribute.AttributeType.Numeric);
                    }
                    var attsCol = rm.Attribute_FindByName("ExcelCol");
                    if (attsCol == null)
                    {
                        attsCol = rm.Attribute_Add("ExcelCol", Attribute.AttributeType.Numeric);
                    }

                    foreach (var imageProp in _list)
                    {
                        var item = rm.Item_AddNew(imageProp.itemName);

                        item.ImageId     = imageProp.imageId;
                        item.Description = imageProp.itemName;
                        item.HideName    = true;
                        item             = CreateAndAssignCategoryIfPoss(item, imageProp.categoryName);
                        item.ExternalId  = imageProp.Id;

                        item.SetAttributeValue(attsRow, imageProp.row);
                        item.SetAttributeValue(attsCol, imageProp.col);

                        item.Tag_AddNew(imageProp.categoryName);

                        //                        var lbl = atts.Labels_Find(name.categoryName);
                        //                       if (lbl == null)
                        //                           atts.Labels_Add(name.categoryName);
                        //                       item.SetAttributeValue(atts, name.categoryName);
                    }

                    vm.Status = "Saving...";
                    rm.Save();
                }
                vm.SetFormOn(false);
            }
            catch (Exception ex)
            {
                var vm = DataContext as ViewModels.MainViewModel;
                vm.SetFormOn(false);
                MessageBox.Show(ex.Message);

                var trace = new System.Diagnostics.StackTrace(ex);
                MessageBox.Show(trace.ToString());
            }
        }
예제 #10
0
        public static void UpdateNewsFeed()
        {
            string newsFeedURL        = ConfigurationManager.AppSettings["BBCFeedURL"];
            string sharpCloudUsername = ConfigurationManager.AppSettings["SharpCloudUsername"];
            string sharpCloudPassword = ConfigurationManager.AppSettings["SharpCloudPassword"];
            string sharpCloudStoryID  = ConfigurationManager.AppSettings["SharpCloudStoryID"];

            //First, download the RSS feed data from the BBC News website
            XmlReader       reader = XmlReader.Create(newsFeedURL);
            SyndicationFeed feed   = SyndicationFeed.Load(reader);

            reader.Close();

            //Connect to SharpCloud, and load the story
            var   _client = new SharpCloudApi(sharpCloudUsername, sharpCloudPassword);
            Story rm      = _client.LoadStory(sharpCloudStoryID);

            //Ensure that the categories exist, if not then create them
            Category worldCat  = rm.Category_FindByName("World") ?? rm.Category_AddNew("World");
            Category busCat    = rm.Category_FindByName("Business") ?? rm.Category_AddNew("Business");
            Category sportCat  = rm.Category_FindByName("Sport") ?? rm.Category_AddNew("Sport");
            Category techCat   = rm.Category_FindByName("Technology") ?? rm.Category_AddNew("Technology");
            Category enterCat  = rm.Category_FindByName("Entertainment") ?? rm.Category_AddNew("Entertainment");
            Category healthCat = rm.Category_FindByName("Health") ?? rm.Category_AddNew("Health");
            Category otherCat  = rm.Category_FindByName("Other") ?? rm.Category_AddNew("Other");

            foreach (SyndicationItem newsItem in feed.Items)
            {
                //Try to find the item in the story using the news item id as the external id
                Item scItem = rm.Item_FindByExternalId(newsItem.Id);
                if (scItem == null)
                {
                    var    wc         = new WebClient();
                    byte[] imageBytes = null;
                    if (newsItem.ElementExtensions.Count > 0)
                    {
                        //download the news story image from the web
                        try
                        {
                            string imageURL = newsItem.ElementExtensions[1].GetObject <XElement>().LastAttribute.PreviousAttribute.Value;
                            imageBytes = wc.DownloadData(imageURL);
                        }
                        catch (Exception)
                        {
                        }
                    }

                    String newsTitle = newsItem.Title.Text;
                    String summary   = newsItem.Summary.Text;

                    //create a new item in SharpCloud, with a name which is the title of the news story
                    scItem = rm.Item_AddNew(newsTitle);

                    //look at the URL of the news story to figure out which category it should be in
                    if (newsItem.Links[0].Uri.ToString().Contains("world"))
                    {
                        scItem.Category = worldCat;
                    }
                    else if (newsItem.Links[0].Uri.ToString().Contains("business"))
                    {
                        scItem.Category = busCat;
                    }
                    else if (newsItem.Links[0].Uri.ToString().Contains("sport"))
                    {
                        scItem.Category = sportCat;
                    }
                    else if (newsItem.Links[0].Uri.ToString().Contains("technology"))
                    {
                        scItem.Category = techCat;
                    }
                    else if (newsItem.Links[0].Uri.ToString().Contains("entertainment"))
                    {
                        scItem.Category = enterCat;
                    }
                    else if (newsItem.Links[0].Uri.ToString().Contains("health"))
                    {
                        scItem.Category = healthCat;
                    }
                    else
                    {
                        scItem.Category = otherCat;
                    }

                    scItem.Description = summary;
                    scItem.ExternalId  = newsItem.Id;
                    scItem.StartDate   = newsItem.PublishDate.DateTime;
                    scItem.Resource_AddName("BBC News URL", "Click here to view the news story on the web", newsItem.Links[0].Uri.ToString());

                    if (imageBytes != null)
                    {
                        scItem.ImageId = _client.UploadImageData(imageBytes, "", false);
                    }

                    try
                    {
                        //now look at the web page for the story and extract the main text
                        var getHtmlWeb = new HtmlWeb();
                        var document   = getHtmlWeb.Load(newsItem.Links[0].Uri.ToString());
                        if (document != null)
                        {
                            var node = document.DocumentNode.SelectSingleNode("//div[@class='story-body__inner']");
                            if (newsItem.Links[0].Uri.ToString().Contains("sport"))
                            {
                                node = document.DocumentNode.SelectSingleNode("//div[@class='article']");
                            }
                            if (node != null)
                            {
                                string newsText = "";
                                foreach (var child in node.ChildNodes)
                                {
                                    if (child.Name == "p")
                                    {
                                        if (newsText != "")
                                        {
                                            newsText += "<BR><BR>";
                                        }
                                        newsText += child.InnerHtml;
                                    }
                                    else if (child.Name == "span")
                                    {
                                        if (newsText != "")
                                        {
                                            newsText += "<BR><BR>";
                                        }
                                        newsText += "<b>" + child.InnerHtml + "</b>";
                                    }
                                }
                                //create a text panel on the item with the text of the story that we have from the web page
                                scItem.Panel_Add("News Detail", Panel.PanelType.RichText, newsText);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            //update the story description with the date/time
            rm.Description = string.Format("Last Updated (UTC): {0:ddd dd MMM yyyy HH:mm}", DateTime.UtcNow);

            //save the story to SharpCloud
            rm.Save();

            //now see if we need to delete any items
            bool deletedAnyItems = false;

            foreach (Item scnewsItem in rm.Items)
            {
                bool FoundItem = false;
                foreach (SyndicationItem newsItem in feed.Items)
                {
                    if (scnewsItem.ExternalId == newsItem.Id)
                    {
                        FoundItem = true;
                        break;
                    }
                }
                if (FoundItem == false)
                {
                    //delete it
                    rm.Item_DeleteById(scnewsItem.Id);
                    deletedAnyItems = true;
                }
            }
            if (deletedAnyItems)
            {
                rm.Save();
            }


            Environment.Exit(0);
        }
        private async void DoIt()
        {
            try
            {
                button.IsEnabled = false;

                var teamId     = team.Text;     // "amrcrustydemo";
                var templateID = template.Text; // "f17c88ef-409a-4a2e-ab01-65b0ac93b371";

                _sc = new SharpCloudApi(username.Text, password.Password, url.Text);

                Status.Text = "";

                await SetText("Reading template...");

                var templateStory = _sc.LoadStory(templateID);

                await SetText($"Template '{templateStory.Name}' Loaded.");

                _tags = new Dictionary <string, ItemTag>();
                // check the story tags exist in the template
                StoryLite[] teamstories;
                if (cbDirectory.IsChecked == false)
                {
                    teamstories = _sc.StoriesTeam(teamId);
                }
                else
                {
                    teamstories = _sc.StoriesDirectory(teamId);
                }

                if (teamstories == null)
                {
                    if (cbDirectory.IsChecked == false)
                    {
                        await SetText($"Oops... Looks like your team does not exist");
                    }
                    else
                    {
                        await SetText($"Oops... Looks like your directory does not exist");
                    }

                    await SetText($"Aborting process");

                    goto End;
                }

                foreach (var ts in teamstories)
                {
                    if (ts.Id.ToLower() != templateID.ToLower())
                    {
                        var tag = templateStory.ItemTag_FindByName(ts.Name);
                        if (tag == null)
                        {
                            await SetText($"Tag '{ts.Name}' created.");

                            tag = templateStory.ItemTag_AddNew(ts.Name, "Created automatically", _tagGroup);
                        }
                        _tags.Add(ts.Id, tag);
                    }
                }
                templateStory.Save();
                await SetText($"'{templateStory.Name}' saved.");


                Story story;

                // remove any existing tags
                if (chkRemoveOldtags.IsChecked == true)
                {
                    await SetText($"Deleting tags");

                    _stories = new Dictionary <string, Story>();
                    _stories.Add(templateStory.Id, templateStory);

                    foreach (var ts in teamstories)
                    {
                        if (ts.Id.ToLower() != templateID.ToLower())
                        {
                            if (!_stories.ContainsKey(ts.Id))
                            {
                                LoadStoryAndCheckPerms(ts.Id, ts.Name);
                            }
                            story = _stories[ts.Id];

                            if (story != null)
                            {
                                foreach (var i in story.Items)
                                {
                                    await RemoveTags(i, _tags);
                                }
                            }
                        }
                    }

                    // save
                    foreach (var s in _stories)
                    {
                        await SetText($"Saving '{s.Value.Name}'");

                        s.Value.Save();
                    }
                    await SetText($"Tags Deletion Complete.");
                }


                _stories = new Dictionary <string, Story>();
                _stories.Add(templateStory.Id, templateStory);

                // asign new tags
                foreach (var ts in teamstories)
                {
                    if (ts.Id.ToLower() != templateID.ToLower())
                    {
                        if (!_stories.ContainsKey(ts.Id))
                        {
                            LoadStoryAndCheckPerms(ts.Id, ts.Name);
                        }
                        story = _stories[ts.Id];

                        foreach (var i in story.Items)
                        {
                            await UpdateItem(i, _tags[story.Id]);
                        }
                    }
                }

                foreach (var s in _stories)
                {
                    if (s.Value != null)
                    {
                        await SetText($"Saving '{s.Value.Name}'");

                        s.Value.Save();
                    }
                }
                await SetText($"Complete.");
            }
            catch (Exception ex)
            {
                await SetText($"There was an error.");
                await SetText($"'{ex.Message}'.");
                await SetText($"'{ex.StackTrace}'.");
            }

End:
            button.IsEnabled = true;
        }
예제 #12
0
        public bool ConnectAndProcessCube()
        {
            try
            {

            using (AdomdConnection cubeConnection = new AdomdConnection(_configDetails.ConnectionString))
            {
                cubeConnection.Open();

                using (AdomdCommand cmd = new AdomdCommand(_configDetails.MDXQuery, cubeConnection))
                {
                    Console.WriteLine("Connected to the cube");

                    DataSet ds = new DataSet();
                    ds.EnforceConstraints = false;
                    ds.Tables.Add();
                    DataTable dt = ds.Tables[0];
                    dt.Load(cmd.ExecuteReader());

                    Console.WriteLine(string.Format("Data loaded from cube: {0} rows", dt.Rows.Count));

                    //we have the data table, now find the index of the fields we want
                    _configDetails.FindDataTableIndexesForAllColumns(dt.Columns);

                    int rowCount = dt.Rows.Count;
                    int colCount = _configDetails.SharpCloudAttributes.Count;

                    //arrayValues is the array that we pass to the SharpCloud Lib dll in order to update the story
                    string[,] arrayValues = new string[rowCount + 1, colCount];

                    //the first row must be the column headings, eg:
                    //arrayValues[0, 0] = "ExternalID";
                    //arrayValues[0, 1] = "Name";

                    for (int i = 0; i < _configDetails.SharpCloudAttributes.Count; i++)
                    {
                        if (_configDetails.SharpCloudAttributes[i].SharpCloudAttributeName.ToUpper() == "NAME" ||
                            _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName.ToUpper() == "CATEGORY" ||
                            _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName.ToUpper() == "EXTERNALID" ||
                            _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName.ToUpper() == "EXTERNAL ID")
                        {
                            //built in column, don't change
                            arrayValues[0, i] = _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName;
                        }
                        else if (_configDetails.SharpCloudAttributes[i].AttributeDataType.ToUpper() == "LIST")
                        {
                            arrayValues[0, i] = string.Format("L__{0}", _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName);
                        }
                        else if (_configDetails.SharpCloudAttributes[i].AttributeDataType.ToUpper() == "NUMERIC")
                        {
                            arrayValues[0, i] = string.Format("N__{0}", _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName);
                        }
                        else if (_configDetails.SharpCloudAttributes[i].AttributeDataType.ToUpper() == "DATE")
                        {
                            arrayValues[0, i] = string.Format("D__{0}", _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName);
                        }
                        else if (_configDetails.SharpCloudAttributes[i].AttributeDataType.ToUpper() == "TEXT")
                        {
                            arrayValues[0, i] = string.Format("T__{0}",_configDetails.SharpCloudAttributes[i].SharpCloudAttributeName);
                        }
                        else
                        {
                            arrayValues[0, i] = _configDetails.SharpCloudAttributes[i].SharpCloudAttributeName;
                        }
                        _configDetails.SharpCloudAttributes[i].ArrayColumnIndex = i;
                    }

                    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
                    {
                        DataRow dataRow = dt.Rows[rowIndex];

                        for (int attIndex = 0; attIndex < _configDetails.SharpCloudAttributes.Count; attIndex++)
                        {
                            SharpCloudAttribute sharpCloudAttribute = _configDetails.SharpCloudAttributes[attIndex];
                            string cubeValueString = dataRow.ItemArray[sharpCloudAttribute.CubeTableMappingIndex].ToString();
                            if (sharpCloudAttribute.AttributeDataType == "NUMERIC")
                            {
                                double numericValue;
                                if (double.TryParse(cubeValueString, out numericValue))
                                {
                                    arrayValues[rowIndex + 1, sharpCloudAttribute.ArrayColumnIndex] = numericValue.ToString();
                                }
                                else
                                {
                                    arrayValues[rowIndex + 1, sharpCloudAttribute.ArrayColumnIndex] = "(null)";
                                }
                            }
                            else
                            {
                                //must be a string
                                arrayValues[rowIndex + 1, sharpCloudAttribute.ArrayColumnIndex] = cubeValueString;
                            }
                        }

                    }

                    string errorMessage;

                    Console.WriteLine(string.Format("Connecting to SharpCloud"));

                    var client = new SharpCloudApi(_configDetails.SharpCloudUserName, _configDetails.SharpCloudPassword, _configDetails.SharpCloudURL);
                    Story rm = client.LoadStory(_configDetails.SharpCloudStoryID);
                    Console.WriteLine(string.Format("Loaded story from SharpCloud, now updating"));
                    if (rm.UpdateStoryWithArray(arrayValues, _configDetails.DeleteMissingItems, out errorMessage))
                    {
                        rm.Save();
                        Console.WriteLine("***Update Complete***");
                        Console.WriteLine("");
                        Console.WriteLine("Press any key to close this window");
                        Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("Error updating story: " + errorMessage);
                        Console.WriteLine("");
                        Console.WriteLine("Press any key to close this window");
                        Console.ReadLine();
                    }

                }

            };
            return true;

            }
            catch (Exception ex)
            {

                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine("");
                Console.WriteLine("Press any key to close this window");
                Console.ReadLine();
                return false;
            }
        }
예제 #13
0
        private void update_Click(object sender, RoutedEventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
            var progBar = sharpProgress;

            update.IsEnabled = false;
            var teamText  = Team.Text;
            var storyText = Story.Text;
            var userText  = Username.Text;

            sc = new SharpCloudApi(userText, Password.Password.ToString());
            try
            {
                Console.WriteLine(sc.Stories());
            }
            catch
            {
                MessageBox.Show("Invalid Username or Password");
                update.IsEnabled = true;
                return;
            }
            StoryLite[] teamBook = new StoryLite[30];
            try
            {
                teamBook = sc.StoriesTeam(teamText);
            }
            catch
            {
                MessageBox.Show("Invalid Team");
                update.IsEnabled = true;
                return;
            }
            Story dashStory = null;

            try
            {
                dashStory = sc.LoadStory(storyText);
            }
            catch
            {
                MessageBox.Show("Invalid Story");
                update.IsEnabled = true;
                return;
            }
            sharpProgress.Maximum = teamBook.Length - 1;
            sharpProgress.Value   = 0;
            sharpProgress.Minimum = 1;

            // Adds new attributes if story does not have it
            if (dashStory.Attribute_FindByName("Appropriated Budget") == null)
            {
                dashStory.Attribute_Add("Appropriated Budget", SC.API.ComInterop.Models.Attribute.AttributeType.Numeric);
            }
            if (dashStory.Attribute_FindByName("RAG Status") == null)
            {
                dashStory.Attribute_Add("RAG Status", SC.API.ComInterop.Models.Attribute.AttributeType.List);
            }
            if (dashStory.Attribute_FindByName("New Requested Budget") == null)
            {
                dashStory.Attribute_Add("New Requested Budget", SC.API.ComInterop.Models.Attribute.AttributeType.Numeric);
            }
            if (dashStory.Attribute_FindByName("Project Business Value") == null)
            {
                dashStory.Attribute_Add("Project Business Value", SC.API.ComInterop.Models.Attribute.AttributeType.Text);
            }
            if (dashStory.Attribute_FindByName("Project Dependencies/Assumptions/Risks") == null)
            {
                dashStory.Attribute_Add("Project Dependencies/Assumptions/Risks", SC.API.ComInterop.Models.Attribute.AttributeType.Text);
            }
            if (dashStory.Attribute_FindByName("Total Spent to Date") == null)
            {
                dashStory.Attribute_Add("Total Spent to Date", SC.API.ComInterop.Models.Attribute.AttributeType.Numeric);
            }
            Story tagStory = sc.LoadStory(teamBook[0].Id);

            // Add tags to new story
            foreach (var tag in tagStory.ItemTags)
            {
                if (dashStory.ItemTag_FindByName(tag.Name) == null)
                {
                    dashStory.ItemTag_AddNew(tag.Name, tag.Description, tag.Group);
                }
            }
            MessageBox.Show("Updating");
            sharpProgress.Value++;
            foreach (StoryLite storyTeam in teamBook)
            {
                Story story = sc.LoadStory(storyTeam.Id);
                highCost(dashStory, story);
                sharpProgress.Value++;
            }
            dashStory.Save();
            MessageBox.Show("Done");
            update.IsEnabled = true;
        }