Ejemplo n.º 1
0
 public static void RunActionInTask(Action action)
 {
     Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).ContinueWith(task =>
     {
         if (task.Exception != null)
         {
             task.Exception.Handle(ex =>
             {
                 LogSupport.Error(ex);
                 return(true);
             });
         }
     }, uiScheduler);
 }
Ejemplo n.º 2
0
        public static async void SaveStringToFile(string s, Dictionary <string, List <string> > filter = null)
        {
            try
            {
                var picker = new Windows.Storage.Pickers.FileSavePicker();
                picker.SuggestedStartLocation =
                    Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

                if (filter == null)
                {
                    filter = new Dictionary <string, List <string> >();
                    filter.Add("Text File", new List <string>()
                    {
                        ".txt"
                    });
                }
                foreach (var kv in filter)
                {
                    picker.FileTypeChoices.Add(kv.Key, kv.Value);
                }
                Windows.Storage.StorageFile file = await picker.PickSaveFileAsync();

                if (file != null)
                {
                    SaveStringToFile(file, s);
                    //using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync())
                    //{
                    //    using (DataWriter dataWriter = new DataWriter(transaction.Stream))
                    //    {
                    //        dataWriter.WriteString(s);
                    //        transaction.Stream.Size = await dataWriter.StoreAsync();
                    //        await transaction.CommitAsync();
                    //    }
                    //}
                }
            }
            catch (Exception ex)
            {
                LogSupport.Error(ex);
            }
        }
Ejemplo n.º 3
0
 static string GetDefaultMemo(Parameter p)
 {
     try
     {
         string s = "";
         if (p == null || p.Value == null)
         {
             return(s);
         }
         if (p.Value.GetType() == typeof(int))
         {
             s = int.MinValue.ToString() + "-" + int.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(short))
         {
             s = short.MinValue.ToString() + "-" + short.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(long))
         {
             s = long.MinValue.ToString() + "-" + long.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(byte))
         {
             s = byte.MinValue.ToString() + "-" + byte.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(uint))
         {
             s = uint.MinValue.ToString() + "-" + uint.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(ushort))
         {
             s = ushort.MinValue.ToString() + "-" + ushort.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(ulong))
         {
             s = ulong.MinValue.ToString() + "-" + ulong.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(sbyte))
         {
             s = sbyte.MinValue.ToString() + "-" + sbyte.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(double))
         {
             s = double.MinValue.ToString() + "-" + double.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(float))
         {
             s = float.MinValue.ToString() + "-" + float.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(decimal))
         {
             s = decimal.MinValue.ToString() + "-" + decimal.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(DateTime))
         {
             s = DateTime.MinValue.ToString() + "-" + DateTime.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType() == typeof(bool))
         {
             s = "True or False,";
         }
         else if (p.Value.GetType() == typeof(char))
         {
             s = char.MinValue.ToString() + "-" + char.MinValue.ToString() + ",";
         }
         else if (p.Value.GetType().IsSubclassOf(typeof(Enum)))
         {
             s = CommonProc.GetListString <string>(Enum.GetNames(p.Value.GetType()).ToList()) + ",";
         }
         else if (p.Value is string)
         {
             if (string.IsNullOrEmpty(p.Value.ToString().Trim()))
             {
                 return("");
             }
         }
         s += " default is " + p.DefaultValue;
         return(s);
     }
     catch (Exception ex)
     {
         LogSupport.Error(ex);
         return("");
     }
 }