Ejemplo n.º 1
0
        private static string RemovePath(string list, string item)
        {
            var paths = new List<string>(list.Split(';'));

            for (int i = 0; i < paths.Count; i++)
            {
                if (string.Compare(paths[i], item, true) == 0)
                {
                    paths.RemoveAt(i);
                    return string.Join(";", paths.ToArray());
                }
            }

            // not present
            return list;
        }
Ejemplo n.º 2
0
        //Shunting yard algorithm
        public static double ProcessEquation(string equation, AttributeProperty property, int level, int previousLevel, float previousAnswer)
        {
            if (equation.Equals("")) {
                throw new ArgumentException("Equation is empty.");
            }
            List<string> result = new List<string>(Regex.Split(equation.ToLower().Trim()));
            for (int i = result.Count - 1; i >= 0; i--) {
                if (result[i].Equals("") || result[i].Equals(" ")) {
                    result.RemoveAt(i);
                }
            }
            Queue<string> queue = new Queue<string>();
            Stack<string> stack = new Stack<string>();

            for (int i = 0; i < result.Count; i++) {
                if (result[i].Equals("x") || result[i].Equals("X")) {
                    result[i] = level.ToString();
                }
                else if (result[i].Equals("k") || result[i].Equals("K")) {
                    if (previousLevel > 0) {
                        result[i] = previousLevel.ToString();
                    }
                    else {
                        result[i] = "0";
                    }
                }
                else if (result[i].Equals("p") || result[i].Equals("P")) {
                    result[i] = previousAnswer.ToString();
                }
                else if (result[i].Equals("r") || result[i].Equals("R")) {
                    float value = UnityEngine.Random.Range(1f, 1000f);
                    value /= 1000f;
                    result[i] = value.ToString();
                }
            }

            TokenClass previousTokenClass = TokenClass.Value;
            for (int i = 0; i < result.Count; i++) {
                string element = result[i];

                if (element.Equals("y") || element.Equals("=")) {
                    continue;
                }

                TokenClass tokenClass = GetTokenClass(element);
                switch (tokenClass) {
                    case TokenClass.Value:
                        queue.Enqueue(element);
                        break;
                    case TokenClass.LeftParentheses:
                        stack.Push(element);
                        break;
                    case TokenClass.RightParentheses:
                        while (!stack.Peek().Equals("(")) {
                            queue.Enqueue(stack.Pop());
                        }
                        stack.Pop();
                        break;
                    case TokenClass.Operator:
                        if (element.Equals("-") && (previousTokenClass == TokenClass.Operator || previousTokenClass == TokenClass.LeftParentheses) && (stack.Count == 0 || result[i - 1].Equals("("))) {
                            //Push unary operator "Negative" to stack.
                            stack.Push("NEG");
                            break;
                        }
                        if (element.Equals("-") && (i + 1 < result.Count) && GetTokenClass(result[i + 1]) == TokenClass.Value) {
                            if (previousTokenClass == TokenClass.Value) {
                                stack.Push(element);
                            }
                            else {
                                stack.Push("NEG");
                            }
                            break;
                        }
                        if (stack.Count > 0) {
                            string stackTopToken = stack.Peek();
                            if (GetTokenClass(stackTopToken) == TokenClass.Operator) {
                                Associativity tokenAssociativity = GetAssociativity(stackTopToken);
                                int tokenPrecedence = GetPrecedence(element);
                                int stackTopPrecedence = GetPrecedence(stackTopToken);
                                if ((tokenAssociativity == Associativity.Left && tokenPrecedence <= stackTopPrecedence) || (tokenAssociativity == Associativity.Right && tokenPrecedence < stackTopPrecedence)) {
                                    queue.Enqueue(stack.Pop());
                                }
                            }
                        }
                        stack.Push(element);
                        break;
                }

                if (tokenClass == TokenClass.Value || tokenClass == TokenClass.RightParentheses) {
                    if (i < result.Count - 1) {
                        string nextToken = result[i + 1];
                        TokenClass nextTokenClass = GetTokenClass(nextToken);
                        if (nextTokenClass != TokenClass.Operator && nextTokenClass != TokenClass.RightParentheses) {
                            result.Insert(i + 1, "*");
                        }
                    }
                }

                previousTokenClass = tokenClass;
            }

            while (stack.Count > 0) {
                string operand = stack.Pop();
                if (operand.Equals("(") || operand.Equals(")")) {
                    throw new ArgumentException("Mismatched parentheses.");
                }
                queue.Enqueue(operand);
            }

            Stack<string> expressionStack = new Stack<string>();
            while (queue.Count > 0) {
                string token = queue.Dequeue();
                TokenClass tokenClass = GetTokenClass(token);
                if (tokenClass == TokenClass.Value) {
                    expressionStack.Push(token);
                }
                else {
                    double answer = 0f;
                    if (tokenClass == TokenClass.Operator) {
                        string rightOperand = expressionStack.Pop();
                        string leftOperand = expressionStack.Pop();
                        if (token.Equals("+")) {
                            answer = double.Parse(leftOperand);
                            answer += double.Parse(rightOperand);
                        }
                        else if (token.Equals("-")) {
                            answer = double.Parse(leftOperand);
                            answer -= double.Parse(rightOperand);
                        }
                        else if (token.Equals("*")) {
                            answer = double.Parse(leftOperand);
                            answer *= double.Parse(rightOperand);
                        }
                        else if (token.Equals("/")) {
                            answer = double.Parse(leftOperand);
                            answer /= double.Parse(rightOperand);
                        }
                        else if (token.Equals("^")) {
                            double baseValue = double.Parse(leftOperand);
                            double exponent = double.Parse(rightOperand);
                            answer = Math.Pow(baseValue, exponent);
                        }
                    }
                    else if (tokenClass == TokenClass.Negative) {
                        string operand = expressionStack.Pop();
                        answer = double.Parse(operand) * -1f;
                    }
                    expressionStack.Push(answer.ToString());
                }
            }

            if (expressionStack.Count != 1) {
                throw new ArgumentException("Invalid equation.");
            }

            double finalAnswer = double.Parse(expressionStack.Pop());

            return finalAnswer;
        }
Ejemplo n.º 3
0
 /// <summary>  
 /// 二进制替换,如果没有替换则返回原数组对像的复本. 内部使用List,比直接用数组替换效率低25%  
 /// </summary>  
 /// <param name="sourceByteArray">源数据</param>  
 ///   
 /// </summary>  
 /// <param name="oldValue">需要替换的数据</param>  
 /// <param name="newValue">将要替换成为的数据</param>  
 public static byte[] ReplaceA( byte[] sourceByteArray, byte[] oldValue, byte[] newValue)
 {
     //创建新数据多出1字节
     int newArrayLen = (int)((newValue.Length / (double)oldValue.Length) * sourceByteArray.Length) + 1;
     //得到数组长度
     newArrayLen = Math.Max(newArrayLen, sourceByteArray.Length);
     int oldCurindex = 0;
     List<byte> result = new List<byte>(newArrayLen);
     //替换数据替换
     for (int x = 0; x < sourceByteArray.Length; x++)
     {
         var b = sourceByteArray[x];
         result.Add(b);
         if (b == oldValue[oldCurindex])
         {
             if (oldCurindex == oldValue.Length - 1)
             {
                 oldCurindex = 0;
                 //称除现有数据
                 for (int k = 0; k < oldValue.Length; k++)
                 {
                     result.RemoveAt(result.Count - 1);
                 }
                 //添加新数据
                 result.AddRange(newValue);
             }
             else
             {
                 oldCurindex++;
             }
         }
     }
     byte[] resultarr = result.ToArray();
     result.Clear();
     result = null;
     return resultarr;
 }
		private void SyncWebSiteBindingsChanges(string siteId, ServerBinding[] bindings)
		{
			// ensure site bindings
			if (bindings == null || bindings.Length == 0)
				throw new Exception("SiteServerBindingsEmpty");
			
			using (var srvman = GetServerManager())
			{
				var iisObject = srvman.Sites[siteId];
				//
				lock (((ICollection)iisObject.ChildElements).SyncRoot)
				{
					var itemsToRemove = new List<Binding>();
					// Determine HTTP bindings to remove
					foreach (Binding element in iisObject.Bindings)
					{
						if (String.Equals(element.Protocol, Uri.UriSchemeHttp))
						{
							itemsToRemove.Add(element);
						}
					}
					// Remove bindings
					while (itemsToRemove.Count > 0)
					{
						iisObject.Bindings.Remove(itemsToRemove[0]);
						itemsToRemove.RemoveAt(0);
					}
					// Create HTTP bindings received
					foreach (var serverBinding in bindings)
					{
						var bindingInformation = String.Format("{0}:{1}:{2}", serverBinding.IP, serverBinding.Port, serverBinding.Host);
						iisObject.Bindings.Add(bindingInformation, Uri.UriSchemeHttp);
					}
				}
				//
				srvman.CommitChanges();
			}
		}
Ejemplo n.º 5
0
        public static string GetString(ref List<string> Values)
        {
            if(Values.Count <= 0)
                return "0";

            string str = Values[0];
            Values.RemoveAt(0);

            return str;
        }
        /// <summary>
        /// Cmdlet end processing
        /// </summary>
        protected override void EndProcessing()
        {
            if (jobList.Count >= 0)
            {
                List<ProgressRecord> records = new List<ProgressRecord>();
                int defaultTaskRecordCount = 4;
                string summary = String.Format(Resources.CopyBlobSummaryCount, total, finished, jobList.Count, failed);
                ProgressRecord summaryRecord = new ProgressRecord(0, Resources.CopyBlobSummaryActivity, summary);
                records.Add(summaryRecord);

                int workerPtr = 0;
                int taskRecordStartIndex = 1;

                for (int i = 1; i <= jobList.Count; i++)
                {
                    ProgressRecord record = new ProgressRecord(i % defaultTaskRecordCount + taskRecordStartIndex, Resources.CopyBlobActivity, Resources.CopyBlobActivity);
                    records.Add(record);
                }

                while (jobList.Count > 0)
                {
                    summary = String.Format(Resources.CopyBlobSummaryCount, total, finished, jobList.Count, failed);
                    summaryRecord.StatusDescription = summary;
                    WriteProgress(summaryRecord);

                    for (int i = taskRecordStartIndex; i <= defaultTaskRecordCount && !ShouldForceQuit; i++)
                    {
                        ICloudBlob blob = jobList[workerPtr];
                        int recordIndex = workerPtr + taskRecordStartIndex;
                        GetBlobWithCopyStatus(blob);
                        WriteCopyProgress(blob, records[recordIndex]);
                        UpdateTaskCount(blob.CopyState.Status);

                        if (blob.CopyState.Status != CopyStatus.Pending)
                        {
                            WriteCopyState(blob);
                            jobList.RemoveAt(workerPtr);
                            records.RemoveAt(recordIndex);
                        }
                        else
                        {
                            workerPtr++;
                        }

                        if (jobList.Count == 0)
                        {
                            break;
                        }

                        if (workerPtr >= jobList.Count)
                        {
                            workerPtr = 0;
                            break;
                        }
                    }

                    if (ShouldForceQuit)
                    {
                        break;
                    }
                    else
                    {
                        //status update interval
                        int interval = 1 * 1000; //in millisecond
                        Thread.Sleep(interval);
                    }
                }
            }

            base.EndProcessing();
        }
Ejemplo n.º 7
0
        //递归更新
        protected void GetMenus2(string menuId, List<int> flags)
        {
            IQueryable<SysMenu> listTree;
            if (menuId == null)
            {
                listTree = from f in db.SysMenu
                           where (f.ParentId) == null
                           orderby f.Sort
                           select f;
            }
            else
            {
                listTree = from f in db.SysMenu
                           where menuId == (f.ParentId)
                           orderby f.Sort
                           select f;
            }


            if (listTree != null && listTree.Any())
            {
                flags.Add(1000);
                foreach (SysMenu item in listTree)
                {
                    //修改编码
                    item.Remark = string.Join("", flags);
                 
                    if (item.SysMenu1.Any())
                    {
                        item.IsLeaf = "叶子";
                        //非子节点,递归
                        GetMenus2(item.Id, flags);
                        flags.RemoveAt(flags.Count - 1);
                    }
                    else
                    {
                        item.IsLeaf = null;
                    }
                    //值+1
                    flags[flags.Count - 1]++;
                }
            }
        }
Ejemplo n.º 8
0
        public List<ConsumeCardMaster_ccm_Info> SearchDisplayRecords(UserCardPair_ucp_Info searchInfo)
        {
            List<ConsumeCardMaster_ccm_Info> infoList = new List<ConsumeCardMaster_ccm_Info>();

            UserCardPair_ucp_Info ucpInfo;
            CardUserMaster_cus_Info cusInfo;
            ConsumeCardMaster_ccm_Info ccmInfo;

            if (searchInfo.ucp_iCardNo > 0 || !String.IsNullOrEmpty(searchInfo.ucp_cCardID))
            {
                //searchInfo.ucp_cUseStatus = "Normal";

                ccmInfo = new ConsumeCardMaster_ccm_Info();

                ucpInfo = _iucpDA.SearchRecords(searchInfo).OrderBy(p => p.ucp_dAddDate).FirstOrDefault();//查卡用戶關系表

                if (ucpInfo != null && ucpInfo.ucp_cUseStatus != DefineConstantValue.ConsumeCardStatus.Returned.ToString())
                {
                    cusInfo = new CardUserMaster_cus_Info();
                    cusInfo.cus_cRecordID = ucpInfo.ucp_cCUSID;
                    cusInfo = _icumDA.DisplayRecord(cusInfo);//查用戶信息

                    ccmInfo.ccm_cCardID = ucpInfo.ucp_cCardID;
                    ccmInfo.ccm_lIsActive = true;
                    ccmInfo = _iccmDA.SearchRecords(ccmInfo).FirstOrDefault();//查卡信息

                    if(ccmInfo != null)
                    {
                        ccmInfo.CardOwner = cusInfo;
                        ccmInfo.UCPInfo = ucpInfo;
                        infoList.Add(ccmInfo);
                    }
                }
                else if(!String.IsNullOrEmpty(searchInfo.ucp_cCardID))
                {
                    ccmInfo = new ConsumeCardMaster_ccm_Info();
                    ccmInfo.ccm_cCardID = searchInfo.ucp_cCardID;
                    ccmInfo.ccm_lIsActive = true;
                    ccmInfo = _iccmDA.SearchRecords(ccmInfo).FirstOrDefault();

                    if(ccmInfo != null)
                    {
                        infoList.Add(ccmInfo);
                    }
                }

            }
            else if (!String.IsNullOrEmpty(searchInfo.CardOwner.cus_cChaName) || searchInfo.CardOwner.cus_cClassID != Guid.Empty)
            {
                List<CardUserMaster_cus_Info> cusList = _icumDA.SearchRecords(searchInfo.CardOwner);

                if (cusList != null)
                {
                    for (int index = 0; index < cusList.Count; index++)
                    {
                        searchInfo.ucp_cCUSID = cusList[index].cus_cRecordID;

                        ucpInfo = _iucpDA.SearchRecords(searchInfo).OrderBy(p => p.ucp_dAddDate).FirstOrDefault();

                        if (ucpInfo != null && ucpInfo.ucp_cUseStatus == DefineConstantValue.ConsumeCardStatus.Normal.ToString())
                        {
                            ccmInfo = new ConsumeCardMaster_ccm_Info();
                            ccmInfo.ccm_cCardID = ucpInfo.ucp_cCardID;
                            ccmInfo.ccm_cCardState = searchInfo.CardInfo.ccm_cCardState;
                            ccmInfo.ccm_lIsActive = true;

                            ccmInfo = _iccmDA.SearchRecords(ccmInfo).FirstOrDefault();//查卡信息

                            if (ccmInfo != null)
                            {
                                ccmInfo.CardOwner = cusList[index];
                                ccmInfo.UCPInfo = ucpInfo;

                                infoList.Add(ccmInfo);
                            }

                        }
                    }
                }
            }
            else
            {
                List<ConsumeCardMaster_ccm_Info> ccmList = _iccmDA.SearchRecords(new ConsumeCardMaster_ccm_Info() { ccm_lIsActive = true});
                if (ccmList != null)
                {
                    for (int index = 0; index < ccmList.Count; index++)
                    {
                        ucpInfo = new UserCardPair_ucp_Info();
                        ucpInfo.ucp_cCardID = ccmList[index].ccm_cCardID;
                        ucpInfo.ucp_cUseStatus = DefineConstantValue.ConsumeCardStatus.Normal.ToString();

                        ucpInfo = _iucpBL.SearchRecords(ucpInfo).FirstOrDefault();

                        if(ucpInfo != null)
                        {
                            ccmList[index].UCPInfo = ucpInfo;
                            ccmList[index].CardOwner = ucpInfo.CardOwner;
                        }

                        infoList.Add(ccmList[index]);
                    }
                }

            }

            if (infoList != null && infoList.Count > 0 && searchInfo.PairTime_From != null && searchInfo.PairTime_To != null)
            {
                for (int index = 0; index < infoList.Count; index++)
                {
                    if (infoList[index].UCPInfo.ucp_dPairTime < searchInfo.PairTime_From || infoList[index].UCPInfo.ucp_dPairTime > searchInfo.PairTime_To)
                    {
                        infoList.RemoveAt(index);
                        index--;
                    }
                }
            }

            return infoList;
        }
Ejemplo n.º 9
0
        string ResumeUploadInChunks(string path, Ticket t, int chunk_size, int max_chunks, bool firstTime)
        {
            const int maxFailedAttempts = 5;

            if (!firstTime)
            {
                // Check the ticket
                Debug.WriteLine("ResumeUploadInChunks(" + path + ") Checking ticket...", "VimeoClient");
                var ticket = vimeo_videos_upload_checkTicket(t.id);
                if (ticket == null || ticket.id != t.id)
                {
                    Debug.WriteLine("Error in checking ticket. aborting.", "VimeoClient");
                    return null;
                }
                t = ticket;
            }

            //Load the file, calculate the number of chunks
            var file = new FileInfo(path);
            int chunksCount = GetChunksCount(file.Length, chunk_size);
            Debug.WriteLine("Will upload in " + chunksCount + " chunks", "VimeoClient");

            //Queue chunks for upload
            List<int> missingChunks = new List<int>(chunksCount);
            for (int i = 0; i < chunksCount; i++) missingChunks.Add(i);
            
            int failedAttempts = 0;
            int counter = 0;
            while (failedAttempts <= maxFailedAttempts)
            {
                if (firstTime)
                {
                    firstTime = false;
                }
                else
                {
                    //Verify and remove the successfully uploaded chunks
                    Debug.WriteLine("Verifying chunks...", "VimeoClient");
                    var verify = vimeo_videos_upload_verifyChunks(t.id);
                    Debug.WriteLine(verify.Items.Count.ToString() + "/" + chunksCount + " chunks uploaded successfully.", "VimeoClient");

                    missingChunks.Clear();
                    for (int i = 0; i < chunksCount; i++) missingChunks.Add(i);
                    foreach (var item in verify.Items)
                    {
                        if (missingChunks.Contains(item.id) && item.size == GetChunkSize(file.Length, item.id, chunk_size))
                            missingChunks.Remove(item.id);
                    }
                }

                //If there are no chunks left or the limit is reached stop.
                if (missingChunks.Count == 0 || (max_chunks > 0 && counter >= max_chunks)) 
                    break;

                //Post chunks
                while (missingChunks.Count > 0)
                {
                    //If there are no chunks left or the limit is reached stop.
                    if (missingChunks.Count == 0 || (max_chunks > 0 && counter >= max_chunks)) 
                        break;

                    if (failedAttempts > maxFailedAttempts) break;

                    int chunkId = missingChunks[0];
                    missingChunks.RemoveAt(0);

                    Debug.WriteLine("Posting chunk " + chunkId + ". " + missingChunks.Count + " chunks left.", "VimeoClient");
                    try
                    {
                        counter++;
                        PostVideo(t, chunkId, path, chunk_size);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e, "VimeoClient");
                        failedAttempts++;
                    }
                }
            }

            if (missingChunks.Count == 0)
            {
                //All chunks are uploaded
                return vimeo_videos_upload_complete(file.Name, t.id);
            }

            if ((max_chunks > 0 && counter >= max_chunks))
            {
                //Max limit is reached
                return string.Empty;
            }

            //Error
            return null;
        }