Exemplo n.º 1
0
        /// <summary>
        /// Chart의 Xml 정보를 HttpResponse 객체에 쓴다.
        /// </summary>
        /// <param name="dataXml">Chart의 Xml 정보</param>
        protected virtual void WriteDataXml(string dataXml)
        {
            if (IsDebugEnabled)
            {
                log.Debug(@"Chart 정보를 응답스트림에 쓰기 시작합니다. 응답할 Chart Xml=[{0}]", dataXml.EllipsisChar(1024));
            }

            Response.Clear();
            Response.ContentType = @"text/xml";
            Response.Expires     = -1;

            byte[] output = ArrayTool.Combine(StringTool.MultiBytesPrefixBytes, Response.ContentEncoding.GetBytes(dataXml));

            // 압축을 지원하고, 압축할 만큼 크기가 크다면...
            var needCompress = CanCompression && dataXml.Length > CompressionThreshold;

            if (needCompress)
            {
                // 압축했을 때에, 압축 방법을 응답헤더에 꼭 붙여줘야 Client에서 알아먹겠죠?
                Response.AppendHeader(@"Content-Encoding", CompressionKind.ToString().ToLower());
                output = Compressor.Compress(output);
            }

            Response.AppendHeader(@"Content-Length", output.Length.ToString());
            Response.OutputStream.Write(output, 0, output.Length);
            Response.Flush();

            if (IsDebugEnabled)
            {
                log.Debug(@"Chart 정보를 응답스트림에 쓰기를 완료했습니다!!!");
            }
        }
Exemplo n.º 2
0
        public void Can_Add_And_Load_Task()
        {
            Cache.Clear();

            var task = new TaskCacheItem
            {
                IsDone  = false,
                Summary = @"Task to cached.",
                Data    = ArrayTool.GetRandomBytes(0x2000)
            };

            var taskId = task.Id.ToString();

            Cache.Add(taskId, task);
            taskIdStrs.Add(taskId);

            var tasks = Cache.GetAllKeys().Select(key => Cache.Get <TaskCacheItem>(key)).ToList();

            Assert.IsTrue(tasks.Any(t => t.IsDone == false));

            var retrieved = Cache.Get <TaskCacheItem>(taskId);

            Assert.IsNotNull(retrieved);
            Assert.AreEqual(taskId, retrieved.Id.ToString());

            Cache.Clear();

            if (Cache.GetAllKeys().Contains(taskId))
            {
                retrieved = Cache.Get(taskId) as TaskCacheItem;
                Assert.IsNull(retrieved);
            }
        }
Exemplo n.º 3
0
 public void InsertMonsterSkillData(ref SysMonsterMainVo monsterMain)
 {
     if (monsterMain == null)
     {
         Debug.LogError("InsertMonsterSkillData Error!!");
         return;
     }
     string[] stringValue = StringUtils.GetStringValue(monsterMain.attack_id, ',');
     if (!ArrayTool.isNullOrEmpty(stringValue))
     {
         string[] array = stringValue;
         for (int i = 0; i < array.Length; i++)
         {
             string skillID = array[i];
             this.InsertData(skillID, 0);
         }
     }
     string[] stringValue2 = StringUtils.GetStringValue(monsterMain.skill_id, ',');
     if (!ArrayTool.isNullOrEmpty(stringValue2))
     {
         string[] array2 = stringValue2;
         for (int j = 0; j < array2.Length; j++)
         {
             string skillID2 = array2[j];
             this.InsertData(skillID2, 0);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 비동기적으로 <paramref name="bytes"/> 내용을 파일에 씁니다.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static Task WriteAllBytes(string path, byte[] bytes)
        {
            path.ShouldNotBeWhiteSpace("path");
            bytes.ShouldNotBeNull("bytes");

            if (IsDebugEnabled)
            {
                log.Debug("파일에 데이타를 비동기적으로 저장합니다... path=[{0}], bytes=[{1}]", path, ArrayTool.Copy(bytes, 0, 80).BytesToHex());
            }

            var fileStream = OpenWrite(path);

            return
                (fileStream
                 .WriteAsync(bytes, 0, bytes.Length)
                 .ContinueWith(antecedent => {
                var ex = antecedent.Exception;

                With.TryAction(() => {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                });
                if (ex != null)
                {
                    throw ex;
                }
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }
Exemplo n.º 5
0
        public void TestOfReferenceTypeClone90882378()
        {
            var objs = new List <object>();

            objs.Add(new Uri("http://localhost"));
            objs.Add(new Rectangle(0, 0, 100, 100));

            //BinaryTree<int> btree = new RwBinaryTree<int>();
            //btree.AddRange(1, 2, 3, 4, 5, 6);
            //objs.Add(btree);

            Console.WriteLine("Original Object List = " + ArrayTool.AsString(objs.ToArray()));

            var objs2 = SerializerTool.DeepCopy(objs);

            if (objs2 == null)
            {
                throw new NullReferenceException("DeepCopy failed");
            }

            Console.WriteLine("Cloned Object List   = " + ArrayTool.AsString(objs2.ToArray()));

            for (int i = 0; i < objs.Count; i++)
            {
                Assert.AreEqual(objs[i], objs2[i]);
            }

            // RwBinaryTree<int> btree2 = (RwBinaryTree<int>)objs[2];
            // Console.WriteLine("Cloned Object List[2]= " + btree2.ToString());

            // Assert.AreEqual(btree, btree2);
        }
Exemplo n.º 6
0
        public void ReferenceTypeSerializeBinaryTest477378791()
        {
            using (var ms = new ValueStream()) {
                var objs = new List <object>();

                objs.Add(new Uri("http://localhost"));
                objs.Add(new Rectangle(0, 0, 100, 100));

                // BinaryTree<int> btree = new BinaryTree<int>();
                // btree.AddRange(1, 2, 3, 4, 5, 6);
                // objs.Add(btree);

                // SerializerTool.BinarySerialize(objs, ms);
                SerializerTool.Serialize(objs, ms, BinaryFormatter);

                ms.Position = 0;
                Console.WriteLine("Original Objects  = " + ArrayTool.AsString(objs.ToArray()));
                Console.WriteLine("Binary Serialized =\r\n" + ms.GetHexDumpString());

                ms.Position = 0;
                // List<object> objs2 = (List<object>)SerializerTool.BinaryDeserialize(ms);
                var objs2 = SerializerTool.Deserialize <List <object> >(ms, BinaryFormatter);

                Console.WriteLine("Deserialized      = " + ArrayTool.AsString(objs2.ToArray()));

                for (int i = 0; i < objs.Count; i++)
                {
                    Assert.AreEqual(objs[i], objs2[i]);
                }
            }
        }
        public void Serialized_Caching(Type serializerType)
        {
            var serializer = (ISerializer)ActivatorTool.CreateInstance(serializerType);
            var repository = new SharedCacheRepository(serializer);

            var tasks       = new List <TaskCacheItem>();
            var cachedTasks = new List <TaskCacheItem>();

            for (var i = 0; i < 10; i++)
            {
                var task = new TaskCacheItem()
                {
                    IsDone  = false,
                    Summary = "Task " + i + " to cached.",
                    Data    = ArrayTool.GetRandomBytes(0x2000)
                };

                tasks.Add(task);
                repository.Set(task.Id.ToString(), task);
            }

            foreach (var task in tasks)
            {
                var cachedTask = repository.Get(task.Id.ToString()) as TaskCacheItem;

                cachedTask.Should().Not.Be.Null();
                cachedTasks.Add(cachedTask);
            }
        }
Exemplo n.º 8
0
        public void Can_Add_Multiple_And_Clear()
        {
            Cache.Clear();
            taskIdStrs.Clear();

            const int TaskCount = 1000;

            for (int i = 0; i < TaskCount; i++)
            {
                var task = new TaskCacheItem()
                {
                    IsDone  = false,
                    Summary = "Task " + i + " to cached.",
                    Data    = ArrayTool.GetRandomBytes(0x2000)
                };

                Cache.Add(task.Id.ToString(), task);
                taskIdStrs.Add(task.Id.ToString());
            }

            Assert.AreEqual(TaskCount, Cache.GetAllKeys().Count);

            foreach (var taskId in taskIdStrs)
            {
                Assert.IsNotNull(Cache.Get(taskId), "캐시에 해당 키의 정보가 없습니다. taskId=" + taskId);
            }
        }
Exemplo n.º 9
0
 protected void TestError()
 {
     if (ArrayTool.EqualsArrays(m_werr, m_buf4))
     {
         ReadVersion();
         throw new DatabaseError(ReadString());
     }
 }
Exemplo n.º 10
0
	public static int getTotalSize(params object[] arrs)
	{
		int num = 0;
		for (int i = 0; i < arrs.Length; i++)
		{
			object[] arr = (object[])arrs[i];
			num += ArrayTool.getSize(arr);
		}
		return num;
	}
Exemplo n.º 11
0
    private AudioClip getRandomClip(AudioClip[] clips)
    {
        if (ArrayTool.isNullOrEmpty(clips))
        {
            return(null);
        }
        int num = UnityEngine.Random.Range(0, clips.Length);

        return(clips[num]);
    }
Exemplo n.º 12
0
 protected void ReadHeader(string data)
 {
     byte[] b = Encoding.ASCII.GetBytes(data);
     ReadBuffer4();
     TestError();
     if (!ArrayTool.EqualsArrays(m_buf4, b))
     {
         Logging.Error("Bad content of PHP Tunnel:" + Encoding.ASCII.GetString(IOTool.ReadToEnd(m_fr)));
         throw new StreamFormatError(String.Format("Invalid PHP - Tunnel format, expected {0}, found {1}", data, Encoding.ASCII.GetString(m_buf4)));
     }
 }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                ViewState["CurrentTime"] = DateTime.Now;

                // 엄청 큰 데이타를 Client로 내려보내지 않고 서버에서 관리합니다.
                //
                ViewState["LargeData"] = ArrayTool.GetRandomBytes(1024 * 128);
                ViewState["LargeStr"]  = StringTool.Replicate("동해물과 백두산이 마르고 닳도록", 100);
            }
        }
Exemplo n.º 14
0
        private void ReadFONT(FNT FNT)
        {
            Height  = FNT.Header.Glyphs.Size1;
            Width   = FNT.Header.Glyphs.Size2;
            Palette = FNT.Palette.Pallete;
            if (FNT.Header.Glyphs.BitsPerPixel == 4)
            {
                PixelFormat = PixelFormats.Indexed4;
            }
            else if (FNT.Header.Glyphs.BitsPerPixel == 8)
            {
                PixelFormat = PixelFormats.Indexed8;
            }
            else
            {
                throw new Exception("ReadFONT Error: unknown PixelFormat");
            }

            var DecList = FNT.Compressed.GetDecompressedData();

            if (FNT.Header.Glyphs.BitsPerPixel == 4)
            {
                ArrayTool.ReverseByteInList(DecList);
            }

            for (int i = 0; i < DecList.Count; i++)
            {
                var Cut = FNT.WidthTable[i] == null ? new VerticalCut(0, (byte)Width) : FNT.WidthTable[i].Value;

                int index = i + 32;
                if (DataList.ContainsKey(index))
                {
                    DataList[index] = DecList[i];
                }
                else
                {
                    DataList.Add(index, DecList[i]);
                }

                if (CutList.ContainsKey(index))
                {
                    CutList[index] = Cut;
                }
                else
                {
                    CutList.Add(index, Cut);
                }
            }
        }
Exemplo n.º 15
0
    private void CheckRecommend()
    {
        Array modeArray = Enum.GetValues(typeof(GameSystem.Mode));
        List <GameSystem.Mode> lockedModesHP = new List <GameSystem.Mode>(modeArray.Length);
        List <GameSystem.Mode> lockedModesLP = new List <GameSystem.Mode>(modeArray.Length);

        foreach (GameSystem.Mode mode in modeArray)
        {
            if (PlayerProfile.LoadModeUnlock(mode) == false)
            {
                if (ArrayTool.Constains(Constant.RECOMMEND_ORDER_HIGH_PRIORITY, mode))
                {
                    lockedModesHP.Add(mode);
                }
                else if (ArrayTool.Constains(Constant.RECOMMEND_ORDER_LOW_PRIORITY, mode))
                {
                    lockedModesLP.Add(mode);
                }
            }
        }

        if (ENTER_TIMES > 0 && ENTER_TIMES % Constant.RECOMMEND_TRIGGER_TIMES == 0)
        {
            if (lockedModesHP.Count > 0)
            {
                GameSystem.GetInstance().RecommendMode = RandomTool.Element(lockedModesHP);
            }
            else if (lockedModesLP.Count > 0)
            {
                GameSystem.GetInstance().RecommendMode = RandomTool.Element(lockedModesLP);
            }
            else
            {
                return;
            }

            string title = string.Format(TextManager.GetText("recommend_mode_title"), TextManager.GetText(string.Format("mode_name_{0}", (int)GameSystem.GetInstance().RecommendMode)));
            string yesButtonText = string.Format(TextManager.GetText("unlock_condition"), Constant.MODE_UNLOCK_COIN[(int)GameSystem.GetInstance().RecommendMode]);
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.SetRecommendMode(GameSystem.GetInstance().RecommendMode);
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.SetConfirmCallback(RecommendConfirmCallback);
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.SetContent(title, null, ConfirmStyle.YesNoClose);
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.SetYesButtonText(yesButtonText);
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.SetNoButtonText(TextManager.GetText("trial"));
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.DisableNextYesSound();
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.DisableNextNoSound();
            GameSystem.GetInstance().gameUI.recommendConfirmMenu.Show(true);
        }
    }
Exemplo n.º 16
0
        public void MassiveInsert(int taskCount)
        {
            for (var i = 0; i < taskCount; i++)
            {
                var item = new TaskCacheItem
                {
                    IsDone  = false,
                    Summary = "Task " + i + " to cached.",
                    Data    = ArrayTool.GetRandomBytes(DataSize)
                };

                Cache.Add(item.Id.ToString(), item, DateTime.Now.AddSeconds(5));
            }

            var stats = IndexusDistributionCache.SharedCache.GetStats();
        }
Exemplo n.º 17
0
        protected static Parent CreateParentObject(string name, int age, params Child[] children)
        {
            var parent = new Parent
            {
                Name        = name,
                Age         = age,
                Description = ArrayTool.GetRandomBytes(1024).BytesToHex()
            };

            foreach (var child in children)
            {
                parent.Children.Add(child);
                child.Parent = parent;
            }
            return(parent);
        }
Exemplo n.º 18
0
 public void InsertSkillUnitSkillData(ref SysSkillUnitVo skillUnitVo)
 {
     if (skillUnitVo == null)
     {
         Debug.LogError("InsertSkillUnitSkillData Error!!!");
         return;
     }
     string[] stringValue = StringUtils.GetStringValue(skillUnitVo.skill_id, ',');
     if (!ArrayTool.isNullOrEmpty(stringValue))
     {
         string[] array = stringValue;
         for (int i = 0; i < array.Length; i++)
         {
             string skillID = array[i];
             this.InsertData(skillID, 0);
         }
     }
 }
Exemplo n.º 19
0
 public void broadCastMsg(string msg, bool refreshMonoChildren = false)
 {
     if (this._monoChildren == null || refreshMonoChildren)
     {
         this._monoChildren = base.GetComponentsInChildren <MsgMono>();
     }
     if (!ArrayTool.isNullOrEmpty(this._monoChildren))
     {
         MsgMono[] monoChildren = this._monoChildren;
         for (int i = 0; i < monoChildren.Length; i++)
         {
             MsgMono msgMono = monoChildren[i];
             if (!(msgMono == null))
             {
                 msgMono.SendMessage(msg, SendMessageOptions.DontRequireReceiver);
             }
         }
     }
 }
Exemplo n.º 20
0
        public void ValueTypeSerializeBinaryTest1776368509()
        {
            using (var ms = new ValueStream()) {
                var strs = new[] { "가", "나", "다", "라" };

                SerializerTool.Serialize(strs, ms, BinaryFormatter);
                // SerializerTool.BinarySerialize(strs, ms);

                ms.Position = 0;
                Console.WriteLine("Original Strings  = " + ArrayTool.AsString(strs));
                Console.WriteLine("Binary Serialized =\r\n" + ms.GetHexDumpString());

                ms.Position = 0;
                // string[] strs2 = (string[])SerializerTool.BinaryDeserialize(ms);
                var strs2 = SerializerTool.Deserialize <string[]>(ms, BinaryFormatter);
                log.Debug("Deserialized      = " + ArrayTool.AsString(strs2));

                Assert.AreEqual(strs, strs2);
            }
        }
Exemplo n.º 21
0
        private void OpenFont()
        {
            var GlyphList = fnt.Compressed.GetDecompressedData();
            var CutList   = fnt.WidthTable.WidthTable;

            PixelFormat pixelFormat;

            if (fnt.Header.Glyphs.BitsPerPixel == 4)
            {
                pixelFormat = PixelFormats.Indexed4;
            }
            else if (fnt.Header.Glyphs.BitsPerPixel == 8)
            {
                pixelFormat = PixelFormats.Indexed8;
            }
            else
            {
                pixelFormat = PixelFormats.Default;
            }

            if (pixelFormat == PixelFormats.Indexed4)
            {
                ArrayTool.ReverseByteInList(GlyphList);
            }

            var pallete = new BitmapPalette(fnt.Palette.GetImagePalette().Select(x => Color.FromArgb(x.A, x.R, x.G, x.B)).ToArray());

            if (GlyphList.Count <= CutList.Count)
            {
                for (int i = 0; i < GlyphList.Count; i++)
                {
                    var image = BitmapSource.Create(fnt.Header.Glyphs.Size1,
                                                    fnt.Header.Glyphs.Size2,
                                                    96, 96, pixelFormat, pallete,
                                                    GlyphList[i],
                                                    (pixelFormat.BitsPerPixel * fnt.Header.Glyphs.Size2 + 7) / 8);
                    image.Freeze();
                    GlyphCuts.Add(new GlyphCut(image, CutList[i], i));
                }
            }
        }
Exemplo n.º 22
0
        public void MassiveInsertAsync(int taskCount)
        {
            var tasks = new List <Task>();

            for (var i = 0; i < taskCount; i++)
            {
                var item = new TaskCacheItem
                {
                    IsDone  = false,
                    Summary = "Task " + i + " to cached.",
                    Data    = ArrayTool.GetRandomBytes(DataSize)
                };

                var task = Task.Factory.StartNew(() => Cache.Add(item.Id.ToString(), item, DateTime.Now.AddSeconds(5)));
                tasks.Add(task);
            }

            Task.WaitAll(tasks.ToArray());

            var stats = IndexusDistributionCache.SharedCache.GetStats();
        }
Exemplo n.º 23
0
        /// <summary>
        /// 테스트용 임시 파일을 생성한다.
        /// </summary>
        public FileInfo CreateTestFile(string filepath, long size)
        {
            var fi = new FileInfo(filepath);

            var buffer = new byte[BufferSize];

            ArrayTool.GetRandomBytes(buffer);

            using (var bs = new BufferedStream(fi.OpenWrite())) {
                long writeCount = 0;
                do
                {
                    bs.Write(buffer, 0, BufferSize);
                    writeCount += BufferSize;
                } while(size > writeCount);

                bs.Flush();
            }

            return(fi);
        }
Exemplo n.º 24
0
        public void ExpirationTest(int taskCount)
        {
            TaskCacheItem item;

            for (var i = 0; i < taskCount; i++)
            {
                item = new TaskCacheItem()
                {
                    IsDone  = false,
                    Summary = "Task " + i + " to cached.",
                    Data    = ArrayTool.GetRandomBytes(DataSize)
                };

                Cache.Add(item.Id.ToString(), item, DateTime.Now.AddSeconds(1));
            }

            Thread.Sleep(TimeSpan.FromSeconds(2));

            item = new TaskCacheItem()
            {
                IsDone  = false,
                Summary = "Task xxxx to cached.",
                Data    = ArrayTool.GetRandomBytes(DataSize)
            };

            Cache.Add(item.Id.ToString(), item, DateTime.Now.AddSeconds(1));

            Thread.Sleep(TimeSpan.FromSeconds(2));

            item = new TaskCacheItem()
            {
                IsDone  = false,
                Summary = "Task xxxx to cached.",
                Data    = ArrayTool.GetRandomBytes(DataSize)
            };

            Cache.Add(item.Id.ToString(), item, DateTime.Now.AddSeconds(1));

            var stats = IndexusDistributionCache.SharedCache.GetStats();
        }
Exemplo n.º 25
0
        public UserInfo(string firstName, string lastName, string address,
                        string city, string state, string zipCode, string email,
                        string userName, string passWord)
        {
            FirstName = firstName;
            LastName  = lastName;
            Address   = address;
            City      = city;
            State     = state;
            ZipCode   = zipCode;
            Email     = email;
            UserName  = userName;
            Password  = passWord;

            Age        = 0;
            UpdateTime = DateTime.Now;

            ByteArray   = ArrayTool.GetRandomBytes(1024 * 4);
            Description = "동해물과 백두산이 마르고 닳도록 하느님이 보우하사 우리나라 만세. Hello World. ".Replicate(10);

            HomeAddr   = new AddressInfo();
            OfficeAddr = new AddressInfo();
        }
Exemplo n.º 26
0
        protected virtual void CreateObjectsInDB()
        {
            parentsInDB = new List <Parent>();

            parentsInDB.Add(CreateParentObject("Parent1", 100, new Child {
                Description = ArrayTool.GetRandomBytes(1024).BytesToHex()
            },
                                               new Child {
                Description = ArrayTool.GetRandomBytes(1024).BytesToHex()
            }));
            parentsInDB.Add(CreateParentObject("Parent2", 200, new Child {
                Description = ArrayTool.GetRandomBytes(1024).BytesToHex()
            },
                                               new Child {
                Description = ArrayTool.GetRandomBytes(1024).BytesToHex()
            }));
            parentsInDB.Add(CreateParentObject("Parent4", 400, new Child {
                Description = ArrayTool.GetRandomBytes(1024).BytesToHex()
            }));

            AssumeParentObjectNamesAreUnique(parentsInDB);
            SaveAndFlushToDatabase(parentsInDB);
        }
Exemplo n.º 27
0
    public void InsertEntitySkillData(EntityVo entityVo)
    {
        EntityType entity_type = entityVo.entity_type;

        if (entity_type == EntityType.Hero)
        {
            int           skin         = (entityVo.skin <= 0) ? 0 : entityVo.skin;
            SysHeroMainVo heroMainData = BaseDataMgr.instance.GetHeroMainData(entityVo.npc_id);
            if (heroMainData != null)
            {
                string[] stringValue = StringUtils.GetStringValue(heroMainData.attack_id, ',');
                if (!ArrayTool.isNullOrEmpty(stringValue))
                {
                    string[] array = stringValue;
                    for (int i = 0; i < array.Length; i++)
                    {
                        string skillID = array[i];
                        this.InsertData(skillID, skin);
                    }
                }
                string[] stringValue2 = StringUtils.GetStringValue(heroMainData.skill_id, ',');
                if (!ArrayTool.isNullOrEmpty(stringValue2))
                {
                    string[] array2 = stringValue2;
                    for (int j = 0; j < array2.Length; j++)
                    {
                        string skillID2 = array2[j];
                        this.InsertData(skillID2, skin);
                    }
                }
            }
            else
            {
                Debug.LogError("Hero [" + entityVo.npc_id + "] is wrong!!");
            }
        }
    }
Exemplo n.º 28
0
	public static int getSize(object[] arr)
	{
		return ArrayTool.isNullOrEmpty(arr) ? 0 : arr.Length;
	}
Exemplo n.º 29
0
        /// <summary>
        /// (x,y) 값으로 (t, ?) 값을 찾는다
        /// </summary>
        /// <param name="x">x 값</param>
        /// <param name="y">f(x)의 값</param>
        /// <param name="t">보간을 수행할 위치</param>
        /// <returns>f(t)의 값</returns>
        public override double[] Interpolate(double[] x, double[] y, double[] t)
        {
            CheckSameLength(x, y);
            t.ShouldNotBeEmpty("t");

            int N = x.Length;
            int M = t.Length;

            var    r = new double[M];
            double dr;

            int    ns;
            double den, dif, dift, ho, hp, w;

            unsafe
            {
                fixed(double *rp = &r[0])
                fixed(double *xp = &x[0])
                fixed(double *yp = &y[0])
                fixed(double *tp = &t[0])
                {
                    for (var k = 0; k < M; k++)
                    {
                        dif = Math.Abs(tp[k] - xp[0]);
                        ns  = 0;

                        var c = ArrayTool.Copy(y, 0, y.Length);
                        var d = ArrayTool.Copy(y, 0, y.Length);

                        fixed(double *cp = &c[0])
                        fixed(double *dp = &d[0])
                        {
                            for (var m = 0; m < N; m++)
                            {
                                if ((dift = Math.Abs(tp[k] - xp[m])) < dif)
                                {
                                    ns  = m;
                                    dif = dift;
                                }
                            }

                            rp[k] = yp[ns--];

                            for (var m = 0; m < N - 1; m++)
                            {
                                for (var i = 0; i < N - m - 1; i++)
                                {
                                    ho = xp[i] - tp[k];
                                    hp = xp[i + m + 1] - tp[k];
                                    w  = cp[i + 1] - dp[i];

                                    if (Math.Abs((den = ho - hp) - 0.0) < double.Epsilon)
                                    {
                                        throw new InvalidOperationException("Error in routine point");
                                    }

                                    den   = w / den;
                                    dp[i] = hp * den;
                                    cp[i] = ho * den;
                                }

                                rp[k] += (dr = (2 * (ns + 1) < (N - m - 1) ? cp[ns + 1] : dp[ns--]));
                            }
                        }
                    }
                }
            }
            return(r);
        }
Exemplo n.º 30
0
        public static ImageData DrawText(IEnumerable <TextBaseElement> text, PersonaFont personaFont, Dictionary <int, byte> Shift, int LineSpacing)
        {
            if (text != null && personaFont != null)
            {
                ImageData returned = new ImageData();
                ImageData line     = new ImageData();
                foreach (var a in text)
                {
                    if (a.IsText)
                    {
                        for (int i = 0; i < a.Data.Length; i++)
                        {
                            int index = 0;

                            if (0x20 <= a.Data[i] & a.Data[i] < 0x80)
                            {
                                index = a.Data[i];
                            }
                            else if (0x80 <= a.Data[i] & a.Data[i] < 0xF0)
                            {
                                index = (a.Data[i] - 0x81) * 0x80 + a.Data[i + 1] + 0x20;
                                i++;
                            }

                            var Glyph = personaFont.GetGlyph(index);

                            if (Glyph.Item1 != null)
                            {
                                byte      shift;
                                bool      shiftb = Shift.TryGetValue(index, out shift);
                                ImageData glyph  = new ImageData(Glyph.Item1, personaFont.PixelFormat, personaFont.Width, personaFont.Height);
                                byte      Left   = Glyph.Item2.Left;
                                byte      Right  = Glyph.Item2.Right;
                                glyph = shiftb == false?Crop(glyph, new Rectangle(Left, 0, Right - Left, glyph.PixelHeight))
                                            : ImageData.Shift(Crop(glyph, new Rectangle(Left, 0, Right - Left, glyph.PixelHeight)), shift);

                                line = MergeLeftRight(line, glyph, 1);
                            }
                        }
                    }
                    else
                    {
                        if (ArrayTool.ByteArrayCompareWithSimplest(a.Data, new byte[] { 0x0A }))
                        {
                            if (returned.IsEmpty)
                            {
                                if (line.IsEmpty)
                                {
                                    returned = new ImageData(PixelFormats.Indexed4, 1, 32);
                                }
                                else
                                {
                                    returned = line;
                                    line     = new ImageData();
                                }
                            }
                            else
                            {
                                if (line.IsEmpty)
                                {
                                    returned = MergeUpDown(returned, new ImageData(PixelFormats.Indexed4, 1, 32), LineSpacing);
                                }
                                else
                                {
                                    returned = MergeUpDown(returned, line, LineSpacing);
                                    line     = new ImageData();
                                }
                            }
                        }
                    }
                }
                returned = ImageData.MergeUpDown(returned, line, LineSpacing);
                return(returned);
            }
            return(new ImageData());
        }