コード例 #1
0
 public DataShare(
     string lookGUID,
     string lookVersion,
     string redirectorSrvUri)
 {
     InternalState = DataShareInternalState.Worked;
     LookGUID      = lookGUID;
     LookVersion   = lookVersion;
     DataList      = new List <string>();
     TaskState     = new DataShareTaskState(redirectorSrvUri);
     cts           = new CancellationTokenSource(10 * 60 * 1000);
     SendingTask   = new Task <bool>(() => DataShareTaskCode.TaskProccessData(cts.Token, TaskState), cts.Token);
     //Task cwt = SendingTask.ContinueWith(task => new Timer(DelayTimerCallback, null, 1 * 1 * 1000, Timeout.Infinite));
 }
コード例 #2
0
 private void DelayTimerCallback(Object aState)
 {
     InternalState = DataShareInternalState.Reconnect;
     SendingTask   = new Task <bool>(() => DataShareTaskCode.TaskProccessData(cts.Token, TaskState), cts.Token);
     SendingTask.Start();
 }
コード例 #3
0
        public DataShareState ProccessData(string nowDataStr, List <DataShareImage> images)
        {
            if (InternalState == DataShareInternalState.Error)
            {
                return(ExternalState);
            }

            if (DelayTimer != null)
            {
                DelayTimer.Dispose();
                DelayTimer = null;
            }

            if (SendingTask.Status == TaskStatus.Faulted || SendingTask.Status == TaskStatus.Canceled || (SendingTask.Status == TaskStatus.RanToCompletion && !SendingTask.Result))
            {
                InternalState = DataShareInternalState.Error;
                DelayTimer    = new Timer(DelayTimerCallback, null, 1 * 1 * 1000, Timeout.Infinite);
                return(ExternalState);
            }

            if (InternalState == DataShareInternalState.Reconnect)
            {
                if (SendingTask.Status != TaskStatus.RanToCompletion)
                {
                    return(ExternalState);
                }
                else
                {
                    InternalState = DataShareInternalState.Worked;
                }
            }

            if (String.IsNullOrEmpty(nowDataStr))
            {
                if (DataList.Count == 0)
                {
                    return(ExternalState);
                }
            }
            else
            {
                if (DataList.Count < 10000)
                {
                    string dataShareDataStr = CreateDataShareDataStr(nowDataStr, images);
                    //Console.WriteLine("\ndataShareDataStr: " + dataShareDataStr);
                    DataList.Add(dataShareDataStr);
                }
            }

            if (SendingTask.Status == TaskStatus.Running)
            {
                return(ExternalState);
            }

            if (SendingTask.Status == TaskStatus.RanToCompletion)
            {
                SendingTask = new Task <bool>(() => DataShareTaskCode.TaskProccessData(cts.Token, TaskState), cts.Token);
            }

            if (SendingTask.Status == TaskStatus.Created)
            {
                TaskState.Message = CreateMessage();
                DataList.Clear();
                SendingTask.Start();
            }

            return(ExternalState);
        }