Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("选择工厂模式");
            var type = Console.ReadLine();

            switch (type)
            {
            case "1":    //工厂模式
                var   sharpFactory = new SharpeFactory();
                Sharp sharp        = sharpFactory.GetSharpe("R");
                sharp.Draw();
                Console.ReadLine();
                break;

            case "2":    //抽象工厂模式
                AbstractFactory abstractFactory = FactoryProducer.GetFactory("1212");
                IColor          color           = abstractFactory.GetColor("B");
                color.Fill();
                Console.ReadLine();
                break;

            case "3":    //建造者模式
                MealBuilder mealBuilder = new MealBuilder();
                Meal        vgMeal      = mealBuilder.PrepareVegMeal();
                Console.WriteLine("Veg meal");
                vgMeal.ShowItems();
                Console.WriteLine($"Total Cost:{vgMeal.GetCost()}");
                Meal nonVegMeal = mealBuilder.PrepareNonVegMeal();
                Console.WriteLine("NonVeg Meal");
                nonVegMeal.ShowItems();
                Console.WriteLine($"Total Cost:{nonVegMeal.GetCost()}");
                break;
            }
        }
Exemplo n.º 2
0
 public Note(Letter Name, Length Duration, int Octave, Sharp Accidental = Sharp.Natural, bool Dotted = false)
 {
     this.Name       = Name;
     this.Duration   = Duration;
     this.Octave     = Octave;
     this.Dotted     = Dotted;
     this.Accidental = Accidental;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 保存员工设置实体,包括添加、修改、删除
        /// </summary>
        /// <param name="list">待保存的员工设置集合</param>
        /// <returns></returns> 
        public int Save(Sharp.Common.BaseEntity item)
        {
            int result = 0;
            try
            {
                result = Dal.Submit(item);

            }
            catch (Exception)
            {
                throw;

            }
            return result;
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var H_W = Console.ReadLine().Split();
            var H   = int.Parse(H_W[0]);
            var W   = int.Parse(H_W[1]);

            var Si    = Enumerable.Range(1, H).Select(_ => Console.ReadLine()).SelectMany(x => x).ToArray();
            var sharp = new Sharp[Si.Count(x => x == '#')];
            var grid  = Enumerable.Repeat('0', H * W).ToArray();

            for (int i = 0, cnt = 0; i < H * W; i++)
            {
                if (Si[i] == '#')
                {
                    sharp[cnt].i = i / W;
                    sharp[cnt].j = i % W;
                    cnt++;
                }
            }

            for (int i = 0; i < H * W; i++)
            {
                foreach (var s in sharp)
                {
                    if (s.i == i / W & s.j == i % W)
                    {
                        grid[i] = '#';
                        break;
                    }
                    else if (Math.Abs(i / W - s.i) <= 1 & Math.Abs(i % W - s.j) <= 1)
                    {
                        grid[i]++;
                    }
                }
            }

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    Console.Write(grid[W * i + j]);
                }
                Console.WriteLine();
            }
        }
Exemplo n.º 5
0
        private bool GetDenoising(Operation opera, Sharp sharp, int size)
        {
            ImageParam imgParam = new ImageParam();

            imgParam = (ImageParam)Marshal.PtrToStructure(ImgDenoising(opera, sharp, size), typeof(ImageParam));
            if (imgParam.result)
            {
                Bitmap imgDenoising = new Bitmap(imgParam.width, imgParam.height, imgParam.step, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, imgParam.data);
                imgDenoising.Palette = CvToolBox.ScalePalette;
                pboxDenoising.Image  = imgDenoising;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ICovariant <Sharp>    isharp = new Sharp();
            ICovariant <Rectange> irect  = new Rectange();

            isharp = irect;
            //irect = isharp;

            Sharp testShape = isharp.Method1();

            int?testNull = null;

            testNull = 6;

            string strTest = "aaaaaa aaaaa";

            strTest.Split(' ');
        }
Exemplo n.º 7
0
        private static void downloadFiles(object Sharp)
        {
            var fileLocation = System.IO.Directory.GetParent
                                   (System.IO.Directory.GetParent(Environment.CurrentDirectory)
                                   .ToString()).ToString();
            Sharp sharp = Sharp as Sharp;
            var   story = sharp.story;
            int   order = sharp.order;
            var   a     = 0;
            var   b     = (story.Items.Length / 2) - 1;

            if (order > 0)
            {
                a = story.Items.Length / 2;
                b = story.Items.Length;
            }
            for (var i = a; i < b; i++)
            {
                //Goes through the item's resources
                if (story.Items[i].Resources.Length > 0)
                {
                    foreach (var res in story.Items[i].Resources)
                    {
                        //downloads resource file if there is a file extension to file
                        if (res.FileExtension != null)
                        {
                            res.DownloadFile(fileLocation + "\\Files\\" + res.Name + res.FileExtension);
                        }
                    }
                }
                // check to see if item has a image based off the sharpcloud image url
                Regex zeroImage = new Regex(@"00000000");
                Match zeroMatch = zeroImage.Match(story.Items[i].ImageUri.ToString());
                // Downloads image to folder if url is not all 0s
                if (!zeroMatch.Success)
                {
                    using (WebClient client = new WebClient())
                    {
                        client.DownloadFile(story.Items[i].ImageUri, (fileLocation + "\\" + "Files" + "\\" + story.Items[i].Name + ".jpg"));
                    }
                }
            }
            Console.WriteLine("Files Downloaded");
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            /*
            ICovariant<Sharp> isharp = new Sharp();
            ICovariant<Rectange> irect = new Rectange();

            //要使下面的语句成立,需要将接口声明为Out
            //如果一个泛型接口IFoo<T>,IFoo<TSub>可以转换为IFoo<TParent>的话,我们称这个过程为协变,而且说“这个泛型接口支持对T的协变”。
            isharp = irect;
            */

            //那我如果反过来呢,考虑如下代码:
            ICovariant<Sharp> isharp = new Sharp();
            ICovariant<Rectange> irect = new Rectange();
            //要使下面的语句成立,需要将接口声明为In
            //如果一个泛型接口IFoo<T>,IFoo<TParent>可以转换为IFoo<TSub>的话,我们称这个过程为抗变(contravariant),而且说“这个泛型接口支持对T的抗变”!
            irect = isharp;
            Console.ReadLine();
        }
Exemplo n.º 9
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        GameObject source = other.gameObject;
        //print("The dart projectile has connected with "+ source + "!");

        // Check if colliding with a Brazier
        BrazierAI bzai = source.GetComponent <BrazierAI>();

        if (bzai && bzai.burning)
        {
            Sharp sh = GetComponent <Sharp>();
            sh.sharpness = Sharpness.Burning;
            anim.SetBool("burning", true);
            return;
        }

        // Check if colliding with the original spawning Dart Trap.
        if (source == mySpawner)
        {
            return;
        }

        // Check if colliding with another dart.
        DartTrapAI dtai = source.GetComponent <DartTrapAI>();

        if (dtai)
        {
            return;
        }


        // Check if colliding with pitfalls.
        PitfallAI pfai = source.GetComponent <PitfallAI>();

        if (pfai)
        {
            return;
        }

        // Collision with anything else. Let's hit.
        OnDartHit(source);
    }
Exemplo n.º 10
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Sharp mySharp = other.gameObject.GetComponent <Sharp>();

        if (!isBurned && mySharp && (mySharp.sharpness == Sharpness.Burning || mySharp.sharpness == Sharpness.Normal))
        {
            for (int i = 0; i < buttonListener.Length; i++)
            {
                ButtonListener myListener = buttonListener[i];
                myListener.OnButtonTrigger(gameObject);
                myListener.OnButtonTriggerEnter(gameObject);
            }

            GetComponent <AudioSource>().Play();

            isBurned = true;
            if (activateTime > 0)
            {
                _activateTimer = activateTime;
            }
        }
    }
Exemplo n.º 11
0
        //静态工厂方法
        public static Sharp GetSharp(String type, double a, double b)
        {
            Sharp sharp = null;

            if (type.Equals("三角形"))
            {
                sharp = new Triangle(a);
            }
            else if (type.Equals("圆形"))
            {
                sharp = new Circular(a);
            }
            else if (type.Equals("正方形"))
            {
                sharp = new Square(a);
            }
            else if (type.Equals("长方形"))
            {
                sharp = new Rectangle(a, b);
            }
            return(sharp);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 工厂类
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Sharp GetSharp(string type)
        {
            Sharp sharp = null;

            if (type.Equals("1"))
            {
                sharp = new Circle();
            }
            else if (type.Equals("2"))
            {
                sharp = new Triangle();
            }
            else if (type.Equals("3"))
            {
                sharp = new Rectangle();
            }
            else
            {
                throw new UnSupportedShapeException();
            }

            return(sharp);
        }
Exemplo n.º 13
0
        public static void addItems(object Sharp)
        {
            Sharp sharp       = Sharp as Sharp;
            var   story       = sharp.story;
            var   sc          = sharp.sc;
            var   itemSheet   = sharp.sheet;
            var   itemRows    = itemSheet.Dimension.End.Row;
            var   itemColumns = itemSheet.Dimension.End.Column;
            int   start       = 2;

            if (Thread.CurrentThread.Name == "secondHalf")
            {
                start = 3;
            }
            for (int rowNum = start; rowNum <= itemRows; rowNum += 2) //selet starting row here
            {
                // check to see if category is in the story
                if (story.Category_FindByName(itemSheet.Cells[rowNum, 3].Value.ToString()) == null)
                {
                    // adds new category to story if category is new
                    story.Category_AddNew(itemSheet.Cells[rowNum, 3].Value.ToString());
                    // Sets color of category based on argb value
                    string[] colors   = itemSheet.Cells[rowNum, 11].Value.ToString().Split('|');
                    var      catColor = Color.FromArgb(Int32.Parse(colors[0]), Int32.Parse(colors[1]), Int32.Parse(colors[2]), Int32.Parse(colors[3]));
                    story.Category_FindByName(itemSheet.Cells[rowNum, 3].Value.ToString()).Color = catColor;
                }
                // Check to see if item is already in the story
                if (story.Item_FindByName(itemSheet.Cells[rowNum, 1].Value.ToString()) == null)
                {
                    var  catID  = story.Category_FindByName(itemSheet.Cells[rowNum, 3].Value.ToString());
                    Item scItem = story.Item_AddNew(itemSheet.Cells[rowNum, 1].Value.ToString());
                    scItem.Category       = catID;
                    scItem.Description    = itemSheet.Cells[rowNum, 2].GetValue <string>();
                    scItem.StartDate      = Convert.ToDateTime(itemSheet.Cells[rowNum, 4].Value.ToString());
                    scItem.DurationInDays = itemSheet.Cells[rowNum, 2].GetValue <int>();
                    // checks subcategory of item
                    if (itemSheet.Cells[rowNum, 9].GetValue <string>() != "null")
                    {
                        // checks to see if subcategory is in the story
                        if (catID.SubCategory_FindByName(itemSheet.Cells[rowNum, 9].GetValue <string>()) == null)
                        {
                            // adds subcategory to category of item if not found
                            catID.SubCategory_AddNew(itemSheet.Cells[rowNum, 9].GetValue <string>());
                        }
                        // sets subcategory to the item
                        scItem.SubCategory = catID.SubCategory_FindByName(itemSheet.Cells[rowNum, 9].GetValue <string>());
                    }
                    // check to see if image path is there for item
                    if (itemSheet.Cells[rowNum, 12].GetValue <string>() != "null")
                    {
                        // uploads image to sharpcloud if image path found
                        if (File.Exists(itemSheet.Cells[rowNum, 12].GetValue <string>() + scItem.Name + ".jpg"))
                        {
                            FileInfo fileInfo = new FileInfo(itemSheet.Cells[rowNum, 12].GetValue <string>() + scItem.Name + ".jpg");
                            byte[]   data     = new byte[fileInfo.Length];
                            using (FileStream fs = fileInfo.OpenRead())
                            {
                                fs.Read(data, 0, data.Length);
                            }
                            scItem.ImageId = sc.UploadImageData(data, "", false);
                        }
                    }
                    // Check to see if item has resources
                    if (itemSheet.Cells[rowNum, 6].GetValue <string>() != "null")
                    {
                        string[] resources = itemSheet.Cells[rowNum, 6].GetValue <string>().Split('|');
                        for (var z = 0; z < resources.Length - 1; z++)
                        {
                            string[] resLine  = resources[z].Split('~');
                            string[] downLine = resLine[1].Split('*');
                            // uploads file if there is a file extension
                            if (downLine.Length > 1)
                            {
                                if (File.Exists(itemSheet.Cells[rowNum, 12].GetValue <string>() + downLine[0] + downLine[1]))
                                {
                                    scItem.Resource_AddFile(itemSheet.Cells[rowNum, 12].GetValue <string>() + downLine[0] + downLine[1], resLine[0], null);
                                }
                            }
                            // adds url to another site
                            else
                            {
                                scItem.Resource_AddName(resLine[0], null, resLine[1]);
                            }
                        }
                    }
                    // Add Tags to the item
                    if (itemSheet.Cells[rowNum, 7].GetValue <string>() != "null")
                    {
                        string[] tags = itemSheet.Cells[rowNum, 7].GetValue <string>().Split('|');
                        for (var x = 0; x < tags.Length - 1; x++)
                        {
                            scItem.Tag_AddNew(tags[x]);
                        }
                    }
                    // Adds Panels to the item
                    if (itemSheet.Cells[rowNum, 8].GetValue <string>() != "null")
                    {
                        string[] panLine = itemSheet.Cells[rowNum, 8].GetValue <string>().Split('|');
                        for (var t = 0; t < panLine.Length - 1; t++)
                        {
                            string[] panData = panLine[t].Split('@');
                            if (scItem.Panel_FindByTitle(panData[0]) == null)
                            {
                                // sets panel type based off string
                                switch (panData[1])
                                {
                                case "RichText":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.RichText, panData[2]);
                                    break;

                                case "Attribute":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.Attribute, panData[2]);
                                    break;

                                case "CustomResource":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.CustomResource, panData[2]);
                                    break;

                                case "HTML":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.HTML, panData[2]);
                                    break;

                                case "Image":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.Image, panData[2]);
                                    break;

                                case "Video":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.Video, panData[2]);
                                    break;

                                case "Undefined":
                                    scItem.Panel_Add(panData[0], Panel.PanelType.Undefined, panData[2]);
                                    break;
                                }
                            }
                        }
                    }
                    // add attribute to the item
                    for (var j = 13; j < itemColumns; j++)
                    {
                        if (itemSheet.Cells[rowNum, j].Value != null && itemSheet.Cells[rowNum, j].Value.ToString() != "")
                        {
                            string[] attribute = itemSheet.Cells[1, j].Value.ToString().Split('|');
                            if (attribute[1] == "Date")
                            {
                                scItem.SetAttributeValue(story.Attribute_FindByName(attribute[0]), DateTime.FromOADate(Double.Parse(itemSheet.Cells[rowNum, j].Value.ToString())));
                            }
                            else if (attribute[1] == "Numeric")
                            {
                                scItem.SetAttributeValue(story.Attribute_FindByName(attribute[0]), Double.Parse(itemSheet.Cells[rowNum, j].Value.ToString()));
                            }
                            else
                            {
                                scItem.SetAttributeValue(story.Attribute_FindByName(attribute[0]), itemSheet.Cells[rowNum, j].Value.ToString());
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
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);
             * }
             */
        }
Exemplo n.º 15
0
        //Grabs all item data with their attributes
        private static void ItemSheet(object Sharp)
        {
            var fileLocation = System.IO.Directory.GetParent
                                   (System.IO.Directory.GetParent(Environment.CurrentDirectory)
                                   .ToString()).ToString();
            Sharp sharp     = Sharp as Sharp;
            var   story     = sharp.story;
            var   sc        = sharp.sc;
            var   catData   = story.Categories;
            var   attList   = sharp.attList;
            var   attCount  = sharp.attCount;
            var   itemSheet = sharp.sheet;
            var   order     = sharp.order;
            var   sheetLine = sharp.sheetLine;

            // Goes through items in category order
            foreach (var cat in catData)
            {
                foreach (var item in story.Items)
                {
                    // check to see if category matches item category
                    if (item.Category.Name == cat.Name)
                    {
                        // Creates the initial list for the item
                        var itemList = new List <string> {
                            item.Name, item.Description, item.Category.Name, item.StartDate.ToString(), item.DurationInDays.ToString()
                        };

                        //Goes through the item's resources
                        var resLine = "";
                        if (item.Resources.Length > 0)
                        {
                            foreach (var res in item.Resources)
                            {
                                //downloads resource file if there is a file extension to file
                                if (res.FileExtension != null)
                                {
                                    resLine += res.Name + "~" + res.Name + "*" + res.FileExtension + "|";
                                }
                                // Gets the url for a website
                                else
                                {
                                    resLine += res.Name + "~" + res.Url + "|";
                                }
                            }
                        }
                        // Item has no resources
                        else
                        {
                            resLine = "null";
                        }
                        // Add the resource data to list
                        itemList.Add(resLine);
                        // Adds the tags to the list
                        var tagLine = "";
                        if (item.Tags.Length > 0)
                        {
                            foreach (var tag in item.Tags)
                            {
                                tagLine += tag.Text + "|";
                            }
                        }
                        else
                        {
                            tagLine = "null";
                        }

                        itemList.Add(tagLine);
                        // Adds the panels to the list
                        var panLine = "";
                        // Check to see if item has any panels containing data
                        var dataCount = 0;
                        foreach (var pan in item.Panels)
                        {
                            // Check to see if panel data is empty
                            if (pan.Data.ToString() != "_EMPTY_")
                            {
                                dataCount++;
                                panLine += pan.Title + "@" + pan.Type + "@" + pan.Data + "|";
                            }
                        }
                        if (dataCount == 0)
                        {
                            panLine = "null";
                        }
                        itemList.Add(panLine);
                        // adds the sub category to the item
                        var subLine = "";
                        // checks to see if item has a subcategory
                        try
                        {
                            subLine = item.SubCategory.Name;
                        }
                        catch
                        {
                            subLine = "null";
                        }
                        itemList.Add(subLine);
                        itemList.Add(attCount.ToString());
                        //Adds the color of the category to the list
                        var colors = (cat.Color.A + "|" + cat.Color.R + "|" + cat.Color.G + "|" + cat.Color.B).ToString();
                        itemList.Add(colors);
                        // check to see if item has a image based off the sharpcloud image url
                        Regex zeroImage = new Regex(@"00000000");
                        Match zeroMatch = zeroImage.Match(item.ImageUri.ToString());
                        // Downloads image to folder if url is not all 0s
                        itemList.Add(fileLocation + "\\" + "Files" + "\\");
                        string[] itemLine = itemList.ToArray();
                        var      go       = 1;
                        foreach (var itemCell in itemLine)
                        {
                            itemSheet.Cells[sheetLine, go].Value = itemCell;
                            if (go == 5)
                            {
                                itemSheet.Cells[sheetLine, go].Value = Double.Parse(itemCell);
                                itemSheet.Cells[sheetLine, go].Style.Numberformat.Format = "#";
                            }
                            if (go == 10)
                            {
                                itemSheet.Cells[sheetLine, go].Value = Double.Parse(itemCell);
                            }

                            go++;
                        }
                        // Adds the attributes to the item
                        foreach (var att in attList)
                        {
                            switch (att.Type.ToString())
                            {
                            case "Text":
                                itemSheet.Cells[sheetLine, go].Value = item.GetAttributeValueAsText(att);
                                break;

                            case "Numeric":
                                itemSheet.Cells[sheetLine, go].Value = item.GetAttributeValueAsDouble(att);
                                itemSheet.Cells[sheetLine, go].Style.Numberformat.Format = "0.00";
                                break;

                            case "Date":
                                itemSheet.Cells[sheetLine, go].Value = item.GetAttributeValueAsDate(att);
                                itemSheet.Cells[sheetLine, go].Style.Numberformat.Format = "mm/dd/yyyy hh:mm:ss AM/PM";
                                break;

                            case "List":
                                itemSheet.Cells[sheetLine, go].Value = item.GetAttributeValueAsText(att);
                                break;

                            case "Location":
                                itemSheet.Cells[sheetLine, go].Value = item.GetAttributeValueAsText(att);
                                break;
                            }
                            go++;
                        }
                        // Adds entire list to the row for the item.

                        sheetLine++;
                    }
                }
            }

            // Writes file to disk
            Console.WriteLine("ItemSheet Written");
        }
Exemplo n.º 16
0
 private static extern IntPtr ImgDenoising(Operation opera, Sharp sharp, int size);
Exemplo n.º 17
0
        public ActionResult Result(string SelectedTest)//Выводит результат тестирвоания
        {
            List <Sharp> sharp = null;

            try
            {
                if (Request.Cookies["user"] != null)//если пользователь авторизован на странице
                {
                    switch (SelectedTest)
                    {
                    case "Sharp":
                    {
                        sharp = Sharp.Load();                                                                             //загружаем данные из бд с правильными ответами
                        int maxAnsTruth = sharp.Count();                                                                  //запоминаем кол-во вопросов
                        int noRightAns  = 0;                                                                              //кол-во неправильных ответов

                        for (int i = 1; i <= maxAnsTruth; i++)                                                            //пробегаемся по всем вопросам
                        {
                            if (Request.Form["quest" + i.ToString()] != sharp.First(x => x.ID == i).NUMANSWER.ToString()) //если пользователь выбрал неправильный ответ
                            {
                                noRightAns++;
                            }
                        }

                        List <Users> users = Users.Load();                                                                   // загружаем данные из бд с пользователями

                        double percentRes = ((double)(maxAnsTruth - noRightAns) / (double)(maxAnsTruth + noRightAns)) * 100; //процентное соотношение  неправильных ответов
                        string email      = Request.Cookies["user"].Value;                                                   //запоминаем email авторизованного пользователя

                        users.First(x => x.EMAIL == email).SHARP = Convert.ToInt32(percentRes);                              //запоминаем результат прохождения теста в учетной записи пользователя
                        Users.SaveChanges(users.First(x => x.EMAIL == email));                                               //сохраняем изменения в БД

                        if (percentRes >= 90)
                        {
                            ViewBag.Result  = "Тест на знание языка C# пройден на оценку - 5";
                            ViewBag.Message = "Поздравляю ! Вы отлично владеете данным языком и можете похвастаться даже своими проектами. С вашими знаниями " +
                                              "можно устроиться практически в любую компанию со стартовым заработком 50к или даже можете хорошо зарекомендовать себя на фрилансе";
                        }
                        else if (percentRes >= 75 && percentRes < 90)
                        {
                            ViewBag.Result  = "Тест на знание языка C# пройден на оценку - 4";
                            ViewBag.Message = "Поздравляю ! Вы довольно не плохо владеете данным языком, хотя все же есть пробелы над которыми стоит поработать. С вашими знаниями " +
                                              "можно устроиться максимум на позицию Junior разработчика со стартовым заработком ~30к";
                        }
                        else if (percentRes > 50 && percentRes <= 75)
                        {
                            ViewBag.Result  = "Тест на знание языка C# пройден на оценку - 3";
                            ViewBag.Message = "Поздравляю ! Вы прошли тест, но увы результаты оставляют желать лучшего. С вашими знаниями " +
                                              "будет довольно сложно устроиться даже на позицию Junior разработчика. Для улучшения результата стоит подтянуть свои знания языка прочитав по ней литературу";
                        }
                        else
                        {
                            ViewBag.Result  = "Тест на знание языка C# пройден на оценку - 2";
                            ViewBag.Message = "Увы...вы не прошли тест. Это говорит о том, что вы либо не знаете язык совсем, либо вы изучали его не правильно. Рекомендуем вам после " +
                                              "изучения каждой темы по языку закреплять материал на практике.";
                        }
                        break;
                    }

                    default:
                        break;
                    }
                }
                else
                {
                    throw new Exception("Доступ к этой странцие имеют только авторизованные пользвоатели");
                }
            }catch (Exception exc)
            {
                ViewBag.Msg = exc.Message;
                return(View("Error"));
            }
            return(View());
        }
Exemplo n.º 18
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();
        }